Mercurial > hg > LGMap
comparison WindowWidget.js @ 0:57bde4830927
first commit
author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
---|---|
date | Tue, 24 Mar 2015 11:37:17 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:57bde4830927 |
---|---|
1 var windowWidgetObjArray=[]; | |
2 var windowZ=10001; | |
3 function initWindowWidget(){ | |
4 var i=0; | |
5 $(".windowWidget").each(function(){ | |
6 windowWidgetObjArray[i]=new WindowWidget($(this)); | |
7 }); | |
8 } | |
9 | |
10 function WindowWidget(obj,x,y,width,height){ | |
11 x = typeof x !== 'undefined' ? x:0; | |
12 y = typeof y !== 'undefined' ? y:0; | |
13 width = typeof width !== 'undefined' ? width:"auto"; | |
14 height = typeof height !== 'undefined' ? height:"auto"; | |
15 var that=this; | |
16 this.obj=obj; | |
17 this.setX(x); | |
18 this.setY(y); | |
19 this.setWidth(width); | |
20 this.setHeight(height); | |
21 //this.isDragging=false; | |
22 //this.obj.attr("draggable","true"); | |
23 /*this.obj.mousedown(function(e){ | |
24 var h=that.obj.outerHeight(); | |
25 var w=that.obj.outerWidth(); | |
26 var x=that.obj.offset().top+h-e.pageX; | |
27 var y=that.obj.offset().left+w-e.pageY; | |
28 $(window).mousemove(function(e){ | |
29 that.isDragging=true; | |
30 that.setX(e.pageX+x-w); | |
31 that.setY(e.pageY+y-h); | |
32 console.log(e.pageX+" "+e.pageY); | |
33 }).mouseup(function(){ | |
34 $(window).unbind("mousemove"); | |
35 | |
36 }); | |
37 }).mouseup(function(){ | |
38 var wasDragging=that.isDragging; | |
39 that.isDragging=false; | |
40 $(window).unbind("mousemove"); | |
41 if(!wasDragging){ | |
42 | |
43 } | |
44 });*/ | |
45 this.obj.css("z-index",(windowZ++)); | |
46 this.title=this.obj.attr("title"); | |
47 this.obj.wrapInner("<div class='content'></div>"); | |
48 this.obj.draggable({cancel:".content",stack:".windowWidget"}); | |
49 this.obj.children(".content").hide(); | |
50 this.initTitleBar(); | |
51 this.obj.click(function(){ | |
52 that.bringToFront(); | |
53 }); | |
54 } | |
55 WindowWidget.prototype.constructor=WindowWidget; | |
56 | |
57 WindowWidget.prototype.initTitleBar=function(){ | |
58 var titleBarObj=$("<div>").addClass("windowWidgetBar"); | |
59 this.obj.prepend(titleBarObj); | |
60 var visibilityButtonObj=$("<div>").addClass("visibilityButton"); | |
61 titleBarObj.append(visibilityButtonObj); | |
62 visibilityButtonObj.html("+"); | |
63 var titleObj=$("<div>").addClass("title"); | |
64 titleBarObj.append(titleObj); | |
65 titleObj.html(this.title); | |
66 var that=this; | |
67 visibilityButtonObj.click(function(){ | |
68 //if(that.obj.children(".content").is(":visible")){ | |
69 if(visibilityButtonObj.html()=="-"){ | |
70 visibilityButtonObj.html("+"); | |
71 that.obj.children(".content").hide(); | |
72 }else{ | |
73 visibilityButtonObj.html("-"); | |
74 that.obj.children(".content").show(); | |
75 } | |
76 }); | |
77 }; | |
78 WindowWidget.prototype.bringToFront=function(){ | |
79 var frontWindowObj; | |
80 var maxZ=0; | |
81 $(".windowWidget").each(function(){ | |
82 var z=$(this).css("z-index"); | |
83 if(z>maxZ){ | |
84 maxZ=z; | |
85 frontWindowObj=$(this); | |
86 } | |
87 }); | |
88 var z=this.obj.css("z-index"); | |
89 this.obj.css("z-index",maxZ); | |
90 frontWindowObj.css("z-index",z); | |
91 /*$(".windowWidget").sort(function(a,b){ | |
92 return $(a).css("z-index")-$(b).css("z-index"); | |
93 });*/ | |
94 | |
95 }; | |
96 WindowWidget.prototype.hideWindow=function(){}; | |
97 WindowWidget.prototype.showWindow=function(){}; | |
98 WindowWidget.prototype.resizeWindow=function(){}; | |
99 WindowWidget.prototype.setX=function(val){ | |
100 this.x=val; | |
101 this.obj.css("left",this.x); | |
102 }; | |
103 WindowWidget.prototype.setY=function(val){ | |
104 this.y=val; | |
105 this.obj.css("top",this.y); | |
106 }; | |
107 WindowWidget.prototype.setWidth=function(val){ | |
108 this.width=val; | |
109 this.obj.css("width",this.width); | |
110 }; | |
111 WindowWidget.prototype.setHeight=function(val){ | |
112 this.height=val; | |
113 this.obj.css("height",this.height); | |
114 }; |