source: Dev/branches/rest-dojo-ui/client/dojox/mobile/IconContainer.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 5.3 KB
Line 
1define([
2        "dojo/_base/array",
3        "dojo/_base/declare",
4        "dojo/_base/window",
5        "dojo/dom-construct",
6        "dojo/dom-style",
7        "dijit/registry",       // registry.byNode
8        "dijit/_Contained",
9        "dijit/_Container",
10        "dijit/_WidgetBase",
11        "./IconItem",
12        "./Heading",
13        "./View"
14], function(array, declare, win, domConstruct, domStyle, registry, Contained, Container, WidgetBase, IconItem, Heading, View){
15
16/*=====
17        var Contained = dijit._Contained;
18        var Container = dijit._Container;
19        var WidgetBase = dijit._WidgetBase;
20=====*/
21
22        // module:
23        //              dojox/mobile/IconContainer
24        // summary:
25        //              A container widget that holds multiple icons.
26
27        return declare("dojox.mobile.IconContainer", [WidgetBase, Container, Contained],{
28                // summary:
29                //              A container widget that holds multiple icons.
30                // description:
31                //              IconContainer is a container widget that holds multiple icons
32                //              each of which represents application component.
33
34                // defaultIcon: String
35                //              The default fall-back icon, which is displayed only when the
36                //              specified icon has failed to load.
37                defaultIcon: "",
38
39                // transition: String
40                //              A type of animated transition effect. You can choose from the
41                //              standard transition types, "slide", "fade", "flip", or from the
42                //              extended transition types, "cover", "coverv", "dissolve",
43                //              "reveal", "revealv", "scaleIn", "scaleOut", "slidev",
44                //              "swirl", "zoomIn", "zoomOut". If "none" is specified, transition
45                //              occurs immediately without animation. If "below" is specified,
46                //              the application contents are displayed below the icons.
47                transition: "below",
48
49                // pressedIconOpacity: Number
50                //              The opacity of the pressed icon image.
51                pressedIconOpacity: 0.4,
52
53                // iconBase: String
54                //              The default icon path for child items.
55                iconBase: "",
56
57                // iconPos: String
58                //              The default icon position for child items.
59                iconPos: "",
60
61                // back: String
62                //              A label for the navigational control.
63                back: "Home",
64
65                // label: String
66                //              A title text of the heading.
67                label: "My Application",
68
69                // single: Boolean
70                //              If true, only one icon content can be opened at a time.
71                single: false,
72
73                buildRendering: function(){
74                        this.domNode = this.containerNode = this.srcNodeRef || win.doc.createElement("UL");
75                        this.domNode.className = "mblIconContainer";
76                        var t = this._terminator = domConstruct.create("LI");
77                        t.className = "mblIconItemTerminator";
78                        t.innerHTML = " ";
79                        this.domNode.appendChild(t);
80                },
81
82                _setupSubNodes: function(ul){
83                        array.forEach(this.getChildren(), function(w){
84                                ul.appendChild(w.subNode);
85                        });
86                },
87
88                startup: function(){
89                        if(this._started){ return; }
90                        if(this.transition === "below"){
91                                this._setupSubNodes(this.domNode);
92                        }else{
93                                var view = this.appView = new View({id:this.id+"_mblApplView"});
94                                var _this = this;
95                                view.onAfterTransitionIn = function(moveTo, dir, transition, context, method){
96                                        _this._opening._open_1();
97                                };
98                                view.domNode.style.visibility = "hidden";
99                                var heading = view._heading
100                                        = new Heading({back: this._cv ? this._cv(this.back) : this.back,
101                                                                        label: this._cv ? this._cv(this.label) : this.label,
102                                                                        moveTo: this.domNode.parentNode.id,
103                                                                        transition: this.transition});
104                                view.addChild(heading);
105                                var ul = view._ul = win.doc.createElement("UL");
106                                ul.className = "mblIconContainer";
107                                ul.style.marginTop = "0px";
108                                this._setupSubNodes(ul);
109                                view.domNode.appendChild(ul);
110
111                                var target;
112                                for(var w = this.getParent(); w; w = w.getParent()){
113                                        if(w instanceof View){
114                                                target = w.domNode.parentNode;
115                                                break;
116                                        }
117                                }
118                                if(!target){ target = win.body(); }
119                                target.appendChild(view.domNode);
120
121                                view.startup();
122                        }
123                        this.inherited(arguments);
124                },
125
126                closeAll: function(){
127                        // summary:
128                        //              Closes all the icon items.
129                        var len = this.domNode.childNodes.length, child, w;
130                        for(var i = 0; i < len; i++){
131                                var child = this.domNode.childNodes[i];
132                                if(child.nodeType !== 1){ continue; }
133                                if(child === this._terminator){ break; }
134                                var w = registry.byNode(child);
135                                w.containerNode.parentNode.style.display = "none";
136                                domStyle.set(w.iconNode, "opacity", 1);
137                        }
138                },
139
140                addChild: function(widget, /*Number?*/insertIndex){
141                        var children = this.getChildren();
142                        if(typeof insertIndex !== "number" || insertIndex > children.length){
143                                insertIndex = children.length;
144                        }
145                        var idx = insertIndex;
146                        var refNode = this.containerNode;
147                        if(idx > 0){
148                                refNode = children[idx - 1].domNode;
149                                idx = "after";
150                        }
151                        domConstruct.place(widget.domNode, refNode, idx);
152
153                        widget.transition = this.transition;
154                        if(this.transition === "below"){
155                                for(var i = 0, refNode = this._terminator; i < insertIndex; i++){
156                                        refNode = refNode.nextSibling;
157                                }
158                                domConstruct.place(widget.subNode, refNode, "after");
159                        }else{
160                                domConstruct.place(widget.subNode, this.appView._ul, insertIndex);
161                        }
162                        widget.inheritParams();
163                        widget._setIconAttr(widget.icon);
164
165                        if(this._started && !widget._started){
166                                widget.startup();
167                        }
168                },
169
170                removeChild: function(/*Widget|Number*/widget){
171                        if(typeof widget === "number"){
172                                widget = this.getChildren()[widget];
173                        }
174                        if(widget){
175                                this.inherited(arguments);
176                                if(this.transition === "below"){
177                                        this.containerNode.removeChild(widget.subNode);
178                                }else{
179                                        this.appView._ul.removeChild(widget.subNode);
180                                }
181                        }
182                }
183        });
184});
Note: See TracBrowser for help on using the repository browser.