1 | define([ |
---|
2 | "dojo/_base/declare", |
---|
3 | "dojo/sniff", |
---|
4 | "dojo/dom-class", |
---|
5 | "dojo/dom-construct", |
---|
6 | "dojo/dom-style", |
---|
7 | "dojo/dom-attr", |
---|
8 | "dijit/_Contained", |
---|
9 | "dijit/_Container", |
---|
10 | "dijit/_WidgetBase", |
---|
11 | "dojo/has!dojo-bidi?dojox/mobile/bidi/IconMenu", |
---|
12 | "./IconMenuItem" |
---|
13 | ], function(declare, has, domClass, domConstruct, domStyle, domAttr, Contained, Container, WidgetBase, BidiIconMenu){ |
---|
14 | // module: |
---|
15 | // dojox/mobile/IconMenu |
---|
16 | |
---|
17 | var IconMenu = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiIconMenu" : "dojox.mobile.IconMenu", [WidgetBase, Container, Contained], { |
---|
18 | // summary: |
---|
19 | // A pop-up menu. |
---|
20 | // description: |
---|
21 | // The dojox/mobile/IconMenu widget displays a pop-up menu just |
---|
22 | // like iPhone's call options menu that is shown while you are on a |
---|
23 | // call. Each menu item must be dojox/mobile/IconMenuItem. |
---|
24 | |
---|
25 | // transition: String |
---|
26 | // The default animated transition effect for child items. |
---|
27 | transition: "slide", |
---|
28 | |
---|
29 | // iconBase: String |
---|
30 | // The default icon path for child items. |
---|
31 | iconBase: "", |
---|
32 | |
---|
33 | // iconPos: String |
---|
34 | // The default icon position for child items. |
---|
35 | iconPos: "", |
---|
36 | |
---|
37 | // cols: Number |
---|
38 | // The number of child items in a row. |
---|
39 | cols: 3, |
---|
40 | |
---|
41 | // tag: String |
---|
42 | // A name of html tag to create as domNode. |
---|
43 | tag: "ul", |
---|
44 | |
---|
45 | /* internal properties */ |
---|
46 | selectOne: false, |
---|
47 | |
---|
48 | // baseClass: String |
---|
49 | // The name of the CSS class of this widget. |
---|
50 | baseClass: "mblIconMenu", |
---|
51 | |
---|
52 | // childItemClass: String |
---|
53 | // The name of the CSS class of menu items. |
---|
54 | childItemClass: "mblIconMenuItem", |
---|
55 | |
---|
56 | // _createTerminator: [private] Boolean |
---|
57 | _createTerminator: false, |
---|
58 | |
---|
59 | buildRendering: function(){ |
---|
60 | this.domNode = this.containerNode = this.srcNodeRef || domConstruct.create(this.tag); |
---|
61 | domAttr.set(this.domNode, "role", "menu"); |
---|
62 | this.inherited(arguments); |
---|
63 | |
---|
64 | if(this._createTerminator){ |
---|
65 | var t = this._terminator = domConstruct.create("br"); |
---|
66 | t.className = this.childItemClass + "Terminator"; |
---|
67 | this.domNode.appendChild(t); |
---|
68 | } |
---|
69 | }, |
---|
70 | |
---|
71 | startup: function(){ |
---|
72 | if(this._started){ return; } |
---|
73 | this.refresh(); |
---|
74 | this.inherited(arguments); |
---|
75 | }, |
---|
76 | |
---|
77 | refresh: function(){ |
---|
78 | var p = this.getParent(); |
---|
79 | if(p){ |
---|
80 | domClass.remove(p.domNode, "mblSimpleDialogDecoration"); |
---|
81 | } |
---|
82 | var children = this.getChildren(); |
---|
83 | if(this.cols){ |
---|
84 | var nRows = Math.ceil(children.length / this.cols); |
---|
85 | var w = Math.floor(100/this.cols); |
---|
86 | var _w = 100 - w*this.cols; |
---|
87 | var h = Math.floor(100 / nRows); |
---|
88 | var _h = 100 - h*nRows; |
---|
89 | if(has("ie")){ |
---|
90 | _w--; |
---|
91 | _h--; |
---|
92 | } |
---|
93 | } |
---|
94 | for(var i = 0; i < children.length; i++){ |
---|
95 | var item = children[i]; |
---|
96 | if(this.cols){ |
---|
97 | var first = ((i % this.cols) === 0); // first column |
---|
98 | var last = (((i + 1) % this.cols) === 0); // last column |
---|
99 | var rowIdx = Math.floor(i / this.cols); |
---|
100 | domStyle.set(item.domNode, { |
---|
101 | width: w + (last ? _w : 0) + "%", |
---|
102 | height: h + ((rowIdx + 1 === nRows) ? _h : 0) + "%" |
---|
103 | }); |
---|
104 | domClass.toggle(item.domNode, this.childItemClass + "FirstColumn", first); |
---|
105 | domClass.toggle(item.domNode, this.childItemClass + "LastColumn", last); |
---|
106 | domClass.toggle(item.domNode, this.childItemClass + "FirstRow", rowIdx === 0); |
---|
107 | domClass.toggle(item.domNode, this.childItemClass + "LastRow", rowIdx + 1 === nRows); |
---|
108 | } |
---|
109 | }; |
---|
110 | }, |
---|
111 | |
---|
112 | addChild: function(widget, /*Number?*/insertIndex){ |
---|
113 | this.inherited(arguments); |
---|
114 | this.refresh(); |
---|
115 | }, |
---|
116 | |
---|
117 | hide: function(){ |
---|
118 | var p = this.getParent(); |
---|
119 | if(p && p.hide){ |
---|
120 | p.hide(); |
---|
121 | } |
---|
122 | } |
---|
123 | }); |
---|
124 | |
---|
125 | return has("dojo-bidi") ? declare("dojox.mobile.IconMenu", [IconMenu, BidiIconMenu]) : IconMenu; |
---|
126 | }); |
---|