| 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 |
|
| 15 |
|
| 16 |
|
| 17 |
var IconMenu = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiIconMenu" : "dojox.mobile.IconMenu", [WidgetBase, Container, Contained], { |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
transition: "slide", |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
iconBase: "", |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
iconPos: "", |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
cols: 3, |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
tag: "ul", |
| 44 |
|
| 45 |
|
| 46 |
selectOne: false, |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
baseClass: "mblIconMenu", |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
childItemClass: "mblIconMenuItem", |
| 55 |
|
| 56 |
|
| 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); |
| 98 |
var last = (((i + 1) % this.cols) === 0); |
| 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, 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 |
}); |