root / trunk / web / dojo / dojox / widget / Portlet.js
History | View | Annotate | Download (6.04 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.widget.Portlet"]){ |
||
9 | dojo._hasResource["dojox.widget.Portlet"]=true; |
||
10 | dojo.experimental("dojox.widget.Portlet");
|
||
11 | dojo.provide("dojox.widget.Portlet");
|
||
12 | dojo.require("dijit.TitlePane");
|
||
13 | dojo.require("dojo.fx");
|
||
14 | dojo.declare("dojox.widget.Portlet",[dijit.TitlePane,dijit._Container],{resizeChildren:true,closable:true,_parents:null,_size:null,dragRestriction:false,buildRendering:function(){ |
||
15 | this.inherited(arguments); |
||
16 | dojo.style(this.domNode,"visibility","hidden"); |
||
17 | },postCreate:function(){ |
||
18 | this.inherited(arguments); |
||
19 | dojo.addClass(this.domNode,"dojoxPortlet"); |
||
20 | dojo.removeClass(this.arrowNode,"dijitArrowNode"); |
||
21 | dojo.addClass(this.arrowNode,"dojoxPortletIcon dojoxArrowDown"); |
||
22 | dojo.addClass(this.titleBarNode,"dojoxPortletTitle"); |
||
23 | dojo.addClass(this.hideNode,"dojoxPortletContentOuter"); |
||
24 | dojo.addClass(this.domNode,"dojoxPortlet-"+(!this.dragRestriction?"movable":"nonmovable")); |
||
25 | var _1=this; |
||
26 | if(this.resizeChildren){ |
||
27 | this.subscribe("/dnd/drop",function(){ |
||
28 | _1._updateSize(); |
||
29 | }); |
||
30 | this.subscribe("/Portlet/sizechange",function(_2){ |
||
31 | _1.onSizeChange(_2); |
||
32 | }); |
||
33 | this.connect(window,"onresize",function(){ |
||
34 | _1._updateSize(); |
||
35 | }); |
||
36 | var _3=dojo.hitch(this,function(id,_4){ |
||
37 | var _5=dijit.byId(id);
|
||
38 | if(_5.selectChild){
|
||
39 | var s=this.subscribe(id+"-selectChild",function(_6){ |
||
40 | var n=_1.domNode.parentNode;
|
||
41 | while(n){
|
||
42 | if(n==_6.domNode){
|
||
43 | _1.unsubscribe(s); |
||
44 | _1._updateSize(); |
||
45 | break;
|
||
46 | } |
||
47 | n=n.parentNode; |
||
48 | } |
||
49 | }); |
||
50 | var _7=dijit.byId(_4);
|
||
51 | if(_5&&_7){
|
||
52 | _1._parents.push({parent:_5,child:_7}); |
||
53 | } |
||
54 | } |
||
55 | }); |
||
56 | var _8;
|
||
57 | this._parents=[];
|
||
58 | for(var p=this.domNode.parentNode;p!=null;p=p.parentNode){ |
||
59 | var id=p.getAttribute?p.getAttribute("widgetId"):null; |
||
60 | if(id){
|
||
61 | _3(id,_8); |
||
62 | _8=id; |
||
63 | } |
||
64 | } |
||
65 | } |
||
66 | this.connect(this.titleBarNode,"onmousedown",function(_9){ |
||
67 | if(dojo.hasClass(_9.target,"dojoxPortletIcon")){ |
||
68 | dojo.stopEvent(_9); |
||
69 | return false; |
||
70 | } |
||
71 | return true; |
||
72 | }); |
||
73 | this.connect(this._wipeOut,"onEnd",function(){ |
||
74 | _1._publish(); |
||
75 | }); |
||
76 | this.connect(this._wipeIn,"onEnd",function(){ |
||
77 | _1._publish(); |
||
78 | }); |
||
79 | if(this.closable){ |
||
80 | this.closeIcon=this._createIcon("dojoxCloseNode","dojoxCloseNodeHover",dojo.hitch(this,"onClose")); |
||
81 | dojo.style(this.closeIcon,"display",""); |
||
82 | } |
||
83 | },startup:function(){ |
||
84 | if(this._started){ |
||
85 | return;
|
||
86 | } |
||
87 | var _a=this.getChildren(); |
||
88 | this._placeSettingsWidgets();
|
||
89 | dojo.forEach(_a,function(_b){
|
||
90 | try{
|
||
91 | if(!_b.started&&!_b._started){
|
||
92 | _b.startup(); |
||
93 | } |
||
94 | } |
||
95 | catch(e){
|
||
96 | } |
||
97 | }); |
||
98 | this.inherited(arguments); |
||
99 | dojo.style(this.domNode,"visibility","visible"); |
||
100 | },_placeSettingsWidgets:function(){ |
||
101 | dojo.forEach(this.getChildren(),dojo.hitch(this,function(_c){ |
||
102 | if(_c.portletIconClass&&_c.toggle&&!_c.attr("portlet")){ |
||
103 | this._createIcon(_c.portletIconClass,_c.portletIconHoverClass,dojo.hitch(_c,"toggle")); |
||
104 | dojo.place(_c.domNode,this.containerNode,"before"); |
||
105 | _c.attr("portlet",this); |
||
106 | this._settingsWidget=_c;
|
||
107 | } |
||
108 | })); |
||
109 | },_createIcon:function(_d,_e,fn){ |
||
110 | var _f=dojo.create("div",{"class":"dojoxPortletIcon "+_d,"waiRole":"presentation"}); |
||
111 | dojo.place(_f,this.arrowNode,"before"); |
||
112 | this.connect(_f,"onclick",fn); |
||
113 | if(_e){
|
||
114 | this.connect(_f,"onmouseover",function(){ |
||
115 | dojo.addClass(_f,_e); |
||
116 | }); |
||
117 | this.connect(_f,"onmouseout",function(){ |
||
118 | dojo.removeClass(_f,_e); |
||
119 | }); |
||
120 | } |
||
121 | return _f;
|
||
122 | },onClose:function(evt){ |
||
123 | dojo.style(this.domNode,"display","none"); |
||
124 | },onSizeChange:function(_10){ |
||
125 | if(_10==this){ |
||
126 | return;
|
||
127 | } |
||
128 | this._updateSize();
|
||
129 | },_updateSize:function(){ |
||
130 | if(!this.open||!this._started||!this.resizeChildren){ |
||
131 | return;
|
||
132 | } |
||
133 | if(this._timer){ |
||
134 | clearTimeout(this._timer);
|
||
135 | } |
||
136 | this._timer=setTimeout(dojo.hitch(this,function(){ |
||
137 | var _11={w:dojo.style(this.domNode,"width"),h:dojo.style(this.domNode,"height")}; |
||
138 | for(var i=0;i<this._parents.length;i++){ |
||
139 | var p=this._parents[i]; |
||
140 | var sel=p.parent.selectedChildWidget;
|
||
141 | if(sel&&sel!=p.child){
|
||
142 | return;
|
||
143 | } |
||
144 | } |
||
145 | if(this._size){ |
||
146 | if(this._size.w==_11.w&&this._size.h==_11.h){ |
||
147 | return;
|
||
148 | } |
||
149 | } |
||
150 | this._size=_11;
|
||
151 | var fns=["resize","layout"]; |
||
152 | this._timer=null; |
||
153 | var _12=this.getChildren(); |
||
154 | dojo.forEach(_12,function(_13){
|
||
155 | for(var i=0;i<fns.length;i++){ |
||
156 | if(dojo.isFunction(_13[fns[i]])){
|
||
157 | try{
|
||
158 | _13[fns[i]](); |
||
159 | } |
||
160 | catch(e){
|
||
161 | } |
||
162 | break;
|
||
163 | } |
||
164 | } |
||
165 | }); |
||
166 | this.onUpdateSize();
|
||
167 | }),100);
|
||
168 | },onUpdateSize:function(){ |
||
169 | },_publish:function(){ |
||
170 | dojo.publish("/Portlet/sizechange",[this]); |
||
171 | },_onTitleClick:function(evt){ |
||
172 | if(evt.target==this.arrowNode){ |
||
173 | this.inherited(arguments); |
||
174 | } |
||
175 | },addChild:function(_14){ |
||
176 | this._size=null; |
||
177 | this.inherited(arguments); |
||
178 | if(this._started){ |
||
179 | this._placeSettingsWidgets();
|
||
180 | this._updateSize();
|
||
181 | } |
||
182 | if(this._started&&!_14.started&&!_14._started){ |
||
183 | _14.startup(); |
||
184 | } |
||
185 | },destroyDescendants:function(_15){ |
||
186 | this.inherited(arguments); |
||
187 | if(this._settingsWidget){ |
||
188 | this._settingsWidget.destroyRecursive(_15);
|
||
189 | } |
||
190 | },_setCss:function(){ |
||
191 | this.inherited(arguments); |
||
192 | dojo.style(this.arrowNode,"display",this.toggleable?"":"none"); |
||
193 | }}); |
||
194 | dojo.declare("dojox.widget.PortletSettings",[dijit._Container,dijit.layout.ContentPane],{portletIconClass:"dojoxPortletSettingsIcon",portletIconHoverClass:"dojoxPortletSettingsIconHover",postCreate:function(){ |
||
195 | dojo.style(this.domNode,"display","none"); |
||
196 | dojo.addClass(this.domNode,"dojoxPortletSettingsContainer"); |
||
197 | dojo.removeClass(this.domNode,"dijitContentPane"); |
||
198 | },_setPortletAttr:function(_16){ |
||
199 | this.portlet=_16;
|
||
200 | },toggle:function(){ |
||
201 | var n=this.domNode; |
||
202 | if(dojo.style(n,"display")=="none"){ |
||
203 | dojo.style(n,{"display":"block","height":"1px","width":"auto"}); |
||
204 | dojo.fx.wipeIn({node:n}).play();
|
||
205 | }else{
|
||
206 | dojo.fx.wipeOut({node:n,onEnd:dojo.hitch(this,function(){ |
||
207 | dojo.style(n,{"display":"none","height":"","width":""}); |
||
208 | })}).play(); |
||
209 | } |
||
210 | }}); |
||
211 | dojo.declare("dojox.widget.PortletDialogSettings",dojox.widget.PortletSettings,{dimensions:null,constructor:function(_17,_18){ |
||
212 | this.dimensions=_17.dimensions||[300,100]; |
||
213 | },toggle:function(){ |
||
214 | if(!this.dialog){ |
||
215 | dojo["require"]("dijit.Dialog"); |
||
216 | this.dialog=new dijit.Dialog({title:this.title}); |
||
217 | dojo.body().appendChild(this.dialog.domNode);
|
||
218 | this.dialog.containerNode.appendChild(this.domNode); |
||
219 | dojo.style(this.dialog.domNode,{"width":this.dimensions[0]+"px","height":this.dimensions[1]+"px"}); |
||
220 | dojo.style(this.domNode,"display",""); |
||
221 | } |
||
222 | if(this.dialog.open){ |
||
223 | this.dialog.hide();
|
||
224 | }else{
|
||
225 | this.dialog.show(this.domNode); |
||
226 | } |
||
227 | }}); |
||
228 | } |