Debian Codegraph @

dojox/mobile/IconMenuItem.js

raw symbols SCIP
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 // module:
11 // dojox/mobile/IconMenuItem
12
13 return declare("dojox.mobile.IconMenuItem", ItemBase, {
14 // summary:
15 // An item of IconMenu.
16 // description:
17 // IconMenuItem represents a menu item of dojox/mobile/MenuItem.
18 // This widget inherits from dojox/mobile/_ItemBase. Its basic usage is
19 // similar to other subclasses such as dojox/mobile/ListItem.
20
21 // closeOnAction: Boolean
22 // If true, the internal handler of click events calls the hide() method
23 // of the parent widget, which is typically a dojox/mobile/SimpleDialog.
24 // The default value is false.
25 closeOnAction: false,
26
27 // tag: String
28 // The name of the HTML tag to create as domNode.
29 tag: "li",
30
31 /* internal properties */
32 // Note these are overrides for similar properties defined in _ItemBase.
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"); // for desktop browsers
77
78 this.inherited(arguments);
79 if(!this._isOnLine){
80 this._isOnLine = true;
81 // retry applying the attribute for which the custom setter delays the actual
82 // work until _isOnLine is true.
83 this.set("icon", this._pendingIcon !== undefined ? this._pendingIcon : this.icon);
84 // Not needed anymore (this code executes only once per life cycle):
85 delete this._pendingIcon;
86 }
87 },
88
89 _onClick: function(e){
90 // summary:
91 // Internal handler for click events.
92 // tags:
93 // private
94 if(e && e.type === "keydown" && e.keyCode !== 13){ return; }
95 if(this.onClick(e) === false){ return; } // user's click action
96 if(this.closeOnAction){
97 var p = this.getParent(); // maybe SimpleDialog
98 if(p && p.hide){
99 p.hide();
100 }
101 }
102 this.defaultClickAction(e);
103 },
104
105 onClick: function(/*Event*/ /*===== e =====*/){
106 // summary:
107 // User-defined function to handle clicks.
108 // tags:
109 // callback
110 },
111
112 _setSelectedAttr: function(/*Boolean*/selected){
113 // summary:
114 // Makes this widget in the selected or unselected state.
115 // tags:
116 // private
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 });