Debian Codegraph @

dojox/mobile/IconContainer.js

raw symbols SCIP
1 define([
2 "dojo/_base/array",
3 "dojo/_base/declare",
4 "dojo/_base/lang",
5 "dojo/_base/window",
6 "dojo/dom-construct",
7 "dijit/_Contained",
8 "dijit/_Container",
9 "dijit/_WidgetBase",
10 "./IconItem", // to load IconItem for you (no direct references)
11 "./Heading",
12 "./View"
13 ], function(array, declare, lang, win, domConstruct, Contained, Container, WidgetBase, IconItem, Heading, View){
14
15 // module:
16 // dojox/mobile/IconContainer
17
18 return declare("dojox.mobile.IconContainer", [WidgetBase, Container, Contained],{
19 // summary:
20 // A container widget which can hold multiple icons.
21 // description:
22 // IconContainer is a container widget which can hold multiple
23 // icons. Each icon must be a subclass of dojox/mobile/IconItem
24 // and can be associated with a panel which opens when touching
25 // the icon.
26
27 // defaultIcon: String
28 // The default fallback icon, which is displayed only when the
29 // specified icon has failed to load.
30 defaultIcon: "",
31
32 // transition: [const] String
33 // A type of animated transition effect. You can choose from the
34 // standard transition types: "slide", "fade", "flip", or from the
35 // extended transition types: "cover", "coverv", "dissolve",
36 // "reveal", "revealv", "scaleIn", "scaleOut", "slidev",
37 // "swirl", "zoomIn", "zoomOut", "cube", and "swap". If "none" is
38 // specified, the transition occurs immediately without animation. If
39 // "below" is specified, the application contents are displayed
40 // below the icons. The default value is "below". Note that changing
41 // the value of the property after the widget creation has no effect.
42 transition: "below",
43
44 // pressedIconOpacity: Number
45 // The opacity of the pressed icon image. The default value is 0.4.
46 pressedIconOpacity: 0.4,
47
48 // iconBase: String
49 // The default icon path for child items.
50 iconBase: "",
51
52 // iconPos: String
53 // The default icon position for child items.
54 iconPos: "",
55
56 // back: String
57 // A label for the navigational control.
58 back: "Home",
59
60 // label: String
61 // A title text of the heading.
62 label: "My Application",
63
64 // single: Boolean
65 // If true, only one icon content can be opened at a time.
66 single: false,
67
68 // editable: [const] Boolean
69 // If true, the icons can be removed or reordered. You can enter
70 // into edit mode by pressing on a child IconItem until it starts shaking.
71 // The default value is false. Note that changing the value of the property after
72 // the widget creation has no effect.
73 editable: false,
74
75 // tag: String
76 // A name of html tag to create as domNode.
77 tag: "ul",
78
79 /* internal properties */
80 baseClass: "mblIconContainer",
81 editableMixinClass: "dojox/mobile/_EditableIconMixin",
82 iconItemPaneContainerClass: "dojox/mobile/Container",
83 iconItemPaneContainerProps: null,
84 iconItemPaneClass: "dojox/mobile/_IconItemPane",
85 iconItemPaneProps: null,
86
87 buildRendering: function(){
88 this.domNode = this.containerNode = this.srcNodeRef || domConstruct.create(this.tag);
89 // _terminator is used to apply the clear:both style to terminate floating icons.
90 this._terminator = domConstruct.create(this.tag === "ul" ? "li" : "div",
91 {className:"mblIconItemTerminator"}, this.domNode);
92 this.inherited(arguments);
93 },
94
95 postCreate: function(){
96 if(this.editable && !this.startEdit){ // if editable is true but editableMixinClass is not inherited
97 require([this.editableMixinClass], lang.hitch(this, function(module){
98 declare.safeMixin(this, new module());
99 this.set("editable", this.editable);
100 }));
101 }
102 },
103
104 startup: function(){
105 if(this._started){ return; }
106
107 require([this.iconItemPaneContainerClass], lang.hitch(this, function(module){
108 this.paneContainerWidget = new module(this.iconItemPaneContainerProps);
109 if(this.transition === "below"){
110 domConstruct.place(this.paneContainerWidget.domNode, this.domNode, "after");
111 }else{
112 var view = this.appView = new View({id:this.id+"_mblApplView"});
113 var _this = this;
114 view.onAfterTransitionIn = function(moveTo, dir, transition, context, method){
115 _this._opening._open_1();
116 };
117 view.domNode.style.visibility = "hidden";
118 var heading = view._heading
119 = new Heading({back: this._cv ? this._cv(this.back) : this.back,
120 label: this._cv ? this._cv(this.label) : this.label,
121 moveTo: this.domNode.parentNode.id,
122 transition: this.transition == "zoomIn" ? "zoomOut" : this.transition});
123 view.addChild(heading);
124 view.addChild(this.paneContainerWidget);
125
126 var target;
127 for(var w = this.getParent(); w; w = w.getParent()){
128 if(w instanceof View){
129 target = w.domNode.parentNode;
130 break;
131 }
132 }
133 if(!target){ target = win.body(); }
134 target.appendChild(view.domNode);
135
136 view.startup();
137 }
138 }));
139
140 this.inherited(arguments);
141 },
142
143 closeAll: function(){
144 // summary:
145 // Closes all the icon items.
146 array.forEach(this.getChildren(), function(w){
147 w.close(true); // disables closing animation
148 }, this);
149 },
150
151 addChild: function(widget, /*Number?*/insertIndex){
152 this.inherited(arguments);
153 // #16597: if removeChild(item) was called to remove the item, it also removes the paneWidget from its container,
154 // But then calling addChild(item) again does not re-add it as it should: it was added the first time through startup
155 // called by addChild, but startup is not called any more the subsequent times.
156 // So we add the pane explicitly if it is orphan.
157 if(this._started && widget.paneWidget && !widget.paneWidget.getParent()){
158 this.paneContainerWidget.addChild(widget.paneWidget, insertIndex);
159 }
160 this.domNode.appendChild(this._terminator); // to ensure that _terminator is always the last node
161 },
162
163 removeChild: function(/*Widget|Number*/widget){
164 var index = (typeof widget == "number") ? widget : widget.getIndexInParent();
165 this.paneContainerWidget.removeChild(index);
166 this.inherited(arguments);
167 },
168
169 _setLabelAttr: function(/*String*/text){
170 // tags:
171 // private
172 if(!this.appView){ return; }
173 this.label = text;
174 var s = this._cv ? this._cv(text) : text;
175 this.appView._heading.set("label", s);
176 }
177 });
178 });