| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/lang", |
| 4 |
"dojo/dom-class", |
| 5 |
"dojo/dom-construct", |
| 6 |
"dojo/dom-attr", |
| 7 |
"./iconUtils", |
| 8 |
"./_ItemBase" |
| 9 |
], function(declare, lang, domClass, domConstruct, domAttr, iconUtils, ItemBase){ |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
return declare("dojox.mobile.IconMenuItem", ItemBase, { |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
closeOnAction: false, |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
tag: "li", |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
baseClass: "mblIconMenuItem", |
| 34 |
selColor: "mblIconMenuItemSel", |
| 35 |
_selStartMethod: "touch", |
| 36 |
_selEndMethod: "touch", |
| 37 |
|
| 38 |
buildRendering: function(){ |
| 39 |
this.domNode = this.srcNodeRef || domConstruct.create(this.tag); |
| 40 |
domAttr.set(this.domNode, "role", "menuitemcheckbox"); |
| 41 |
domAttr.set(this.domNode, "aria-checked", "false"); |
| 42 |
this.inherited(arguments); |
| 43 |
if(this.selected){ |
| 44 |
domClass.add(this.domNode, this.selColor); |
| 45 |
} |
| 46 |
|
| 47 |
if(this.srcNodeRef){ |
| 48 |
if(!this.label){ |
| 49 |
this.label = lang.trim(this.srcNodeRef.innerHTML); |
| 50 |
} |
| 51 |
this.srcNodeRef.innerHTML = ""; |
| 52 |
} |
| 53 |
|
| 54 |
var a = this.anchorNode = this.containerNode = domConstruct.create("a", { |
| 55 |
className: "mblIconMenuItemAnchor", |
| 56 |
role: "presentation" |
| 57 |
}); |
| 58 |
var tbl = domConstruct.create("table", { |
| 59 |
className: "mblIconMenuItemTable", |
| 60 |
role: "presentation" |
| 61 |
}, a); |
| 62 |
var cell = this.iconParentNode = tbl.insertRow(-1).insertCell(-1); |
| 63 |
this.iconNode = domConstruct.create("div", { |
| 64 |
className: "mblIconMenuItemIcon" |
| 65 |
}, cell); |
| 66 |
this.labelNode = this.refNode = domConstruct.create("div", { |
| 67 |
className: "mblIconMenuItemLabel" |
| 68 |
}, cell); |
| 69 |
this.position = "before"; |
| 70 |
this.domNode.appendChild(a); |
| 71 |
}, |
| 72 |
|
| 73 |
startup: function(){ |
| 74 |
if(this._started){ return; } |
| 75 |
|
| 76 |
this.connect(this.domNode, "onkeydown", "_onClick"); |
| 77 |
|
| 78 |
this.inherited(arguments); |
| 79 |
if(!this._isOnLine){ |
| 80 |
this._isOnLine = true; |
| 81 |
|
| 82 |
|
| 83 |
this.set("icon", this._pendingIcon !== undefined ? this._pendingIcon : this.icon); |
| 84 |
|
| 85 |
delete this._pendingIcon; |
| 86 |
} |
| 87 |
}, |
| 88 |
|
| 89 |
_onClick: function(e){ |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
if(e && e.type === "keydown" && e.keyCode !== 13){ return; } |
| 95 |
if(this.onClick(e) === false){ return; } |
| 96 |
if(this.closeOnAction){ |
| 97 |
var p = this.getParent(); |
| 98 |
if(p && p.hide){ |
| 99 |
p.hide(); |
| 100 |
} |
| 101 |
} |
| 102 |
this.defaultClickAction(e); |
| 103 |
}, |
| 104 |
|
| 105 |
onClick: function( ){ |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
}, |
| 111 |
|
| 112 |
_setSelectedAttr: function(selected){ |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
this.inherited(arguments); |
| 118 |
domClass.toggle(this.domNode, this.selColor, selected); |
| 119 |
domAttr.set(this.domNode, "aria-checked", selected ? "true" : "false"); |
| 120 |
} |
| 121 |
}); |
| 122 |
}); |