| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/_base/event", |
| 4 |
"dojo/_base/lang", |
| 5 |
"dojo/sniff", |
| 6 |
"dojo/_base/window", |
| 7 |
"dojo/dom-class", |
| 8 |
"dojo/dom-construct", |
| 9 |
"dojo/dom-geometry", |
| 10 |
"dojo/dom-style", |
| 11 |
"./_ItemBase", |
| 12 |
"./Badge", |
| 13 |
"./TransitionEvent", |
| 14 |
"./iconUtils", |
| 15 |
"./lazyLoadUtils", |
| 16 |
"./viewRegistry", |
| 17 |
"./_css3", |
| 18 |
"dojo/has!dojo-bidi?dojox/mobile/bidi/IconItem" |
| 19 |
], function(declare, event, lang, has, win, domClass, domConstruct, domGeometry, domStyle, ItemBase, Badge, TransitionEvent, iconUtils, lazyLoadUtils, viewRegistry, css3, BidiIconItem){ |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
var IconItem = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiIconItem" : "dojox.mobile.IconItem", ItemBase, { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
lazy: false, |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
requires: "", |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
timeout: 10, |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
content: "", |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
badge: "", |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
badgeClass: "mblDomButtonRedBadge", |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
deletable: true, |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
deleteIcon: "", |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
tag: "li", |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
paramsToInherit: "transition,icon,deleteIcon,badgeClass,deleteIconTitle,deleteIconRole", |
| 87 |
baseClass: "mblIconItem", |
| 88 |
_selStartMethod: "touch", |
| 89 |
_selEndMethod: "none", |
| 90 |
|
| 91 |
destroy: function(){ |
| 92 |
if(this.badgeObj){ |
| 93 |
delete this.badgeObj; |
| 94 |
} |
| 95 |
this.inherited(arguments); |
| 96 |
}, |
| 97 |
|
| 98 |
buildRendering: function(){ |
| 99 |
this.domNode = this.srcNodeRef || domConstruct.create(this.tag); |
| 100 |
|
| 101 |
if(this.srcNodeRef){ |
| 102 |
|
| 103 |
this._tmpNode = domConstruct.create("div"); |
| 104 |
for(var i = 0, len = this.srcNodeRef.childNodes.length; i < len; i++){ |
| 105 |
this._tmpNode.appendChild(this.srcNodeRef.firstChild); |
| 106 |
} |
| 107 |
} |
| 108 |
|
| 109 |
this.iconDivNode = domConstruct.create("div", {className:"mblIconArea"}, this.domNode); |
| 110 |
this.iconParentNode = domConstruct.create("div", {className:"mblIconAreaInner"}, this.iconDivNode); |
| 111 |
this.labelNode = domConstruct.create("span", {className:"mblIconAreaTitle"}, this.iconDivNode); |
| 112 |
|
| 113 |
this.inherited(arguments); |
| 114 |
}, |
| 115 |
|
| 116 |
startup: function(){ |
| 117 |
if(this._started){ return; } |
| 118 |
|
| 119 |
var p = this.getParent(); |
| 120 |
require([p.iconItemPaneClass], lang.hitch(this, function(module){ |
| 121 |
var w = this.paneWidget = new module(p.iconItemPaneProps); |
| 122 |
this.containerNode = w.containerNode; |
| 123 |
if(this._tmpNode){ |
| 124 |
|
| 125 |
for(var i = 0, len = this._tmpNode.childNodes.length; i < len; i++){ |
| 126 |
w.containerNode.appendChild(this._tmpNode.firstChild); |
| 127 |
} |
| 128 |
this._tmpNode = null; |
| 129 |
} |
| 130 |
p.paneContainerWidget.addChild(w, this.getIndexInParent()); |
| 131 |
w.set("label", this.label); |
| 132 |
this._clickCloseHandle = this.connect(w.closeIconNode, "onclick", "_closeIconClicked"); |
| 133 |
this._keydownCloseHandle = this.connect(w.closeIconNode, "onkeydown", "_closeIconClicked"); |
| 134 |
})); |
| 135 |
|
| 136 |
this.inherited(arguments); |
| 137 |
if(!this._isOnLine){ |
| 138 |
this._isOnLine = true; |
| 139 |
|
| 140 |
|
| 141 |
this.set("icon", this._pendingIcon !== undefined ? this._pendingIcon : this.icon); |
| 142 |
|
| 143 |
delete this._pendingIcon; |
| 144 |
} |
| 145 |
if(!this.icon && p.defaultIcon){ |
| 146 |
this.set("icon", p.defaultIcon); |
| 147 |
} |
| 148 |
|
| 149 |
this._dragstartHandle = this.connect(this.domNode, "ondragstart", event.stop); |
| 150 |
this.connect(this.domNode, "onkeydown", "_onClick"); |
| 151 |
}, |
| 152 |
|
| 153 |
highlight: function(timeout){ |
| 154 |
|
| 155 |
|
| 156 |
domClass.add(this.iconDivNode, "mblVibrate"); |
| 157 |
timeout = (timeout !== undefined) ? timeout : this.timeout; |
| 158 |
if(timeout > 0){ |
| 159 |
var _this = this; |
| 160 |
_this.defer(function(){ |
| 161 |
_this.unhighlight(); |
| 162 |
}, timeout*1000); |
| 163 |
} |
| 164 |
}, |
| 165 |
|
| 166 |
unhighlight: function(){ |
| 167 |
|
| 168 |
|
| 169 |
if(!has("ie") && has("trident") === 7){ |
| 170 |
|
| 171 |
domStyle.set(this.iconDivNode, "animation-name", ""); |
| 172 |
} |
| 173 |
domClass.remove(this.iconDivNode, "mblVibrate"); |
| 174 |
}, |
| 175 |
|
| 176 |
isOpen: function(e){ |
| 177 |
|
| 178 |
|
| 179 |
return this.paneWidget.isOpen(); |
| 180 |
}, |
| 181 |
|
| 182 |
_onClick: function(e){ |
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
if(this.getParent().isEditing || e && e.type === "keydown" && e.keyCode !== 13){ return; } |
| 188 |
if(this.onClick(e) === false){ return; } |
| 189 |
this.defaultClickAction(e); |
| 190 |
}, |
| 191 |
|
| 192 |
onClick: function( ){ |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
}, |
| 198 |
|
| 199 |
_onNewWindowOpened: function(e){ |
| 200 |
|
| 201 |
this.set("selected", false); |
| 202 |
}, |
| 203 |
|
| 204 |
_prepareForTransition: function(e, transOpts){ |
| 205 |
|
| 206 |
if(transOpts){ |
| 207 |
this.defer(function(d){ |
| 208 |
this.set("selected", false); |
| 209 |
}, 1500); |
| 210 |
return true; |
| 211 |
}else{ |
| 212 |
if(this.getParent().transition === "below" && this.isOpen()){ |
| 213 |
this.close(); |
| 214 |
}else{ |
| 215 |
this.open(e); |
| 216 |
} |
| 217 |
return false; |
| 218 |
} |
| 219 |
}, |
| 220 |
|
| 221 |
_closeIconClicked: function(e){ |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
if(e){ |
| 227 |
if(e.type === "keydown" && e.keyCode !== 13){ return; } |
| 228 |
if(this.closeIconClicked(e) === false){ return; } |
| 229 |
this.defer(function(d){ this._closeIconClicked(); }); |
| 230 |
return; |
| 231 |
} |
| 232 |
this.close(); |
| 233 |
}, |
| 234 |
|
| 235 |
closeIconClicked: function( ){ |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
}, |
| 241 |
|
| 242 |
open: function(e){ |
| 243 |
|
| 244 |
|
| 245 |
var parent = this.getParent(); |
| 246 |
if(this.transition === "below"){ |
| 247 |
if(parent.single){ |
| 248 |
parent.closeAll(); |
| 249 |
} |
| 250 |
this._open_1(); |
| 251 |
}else{ |
| 252 |
parent._opening = this; |
| 253 |
if(parent.single){ |
| 254 |
this.paneWidget.closeHeaderNode.style.display = "none"; |
| 255 |
if(!this.isOpen()){ |
| 256 |
parent.closeAll(); |
| 257 |
} |
| 258 |
parent.appView._heading.set("label", this.label); |
| 259 |
} |
| 260 |
this.moveTo = parent.id + "_mblApplView"; |
| 261 |
new TransitionEvent(this.domNode, this.getTransOpts(), e).dispatch(); |
| 262 |
} |
| 263 |
}, |
| 264 |
|
| 265 |
_open_1: function(){ |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
this.paneWidget.show(); |
| 271 |
this.unhighlight(); |
| 272 |
if(this.lazy){ |
| 273 |
lazyLoadUtils.instantiateLazyWidgets(this.containerNode, this.requires); |
| 274 |
this.lazy = false; |
| 275 |
} |
| 276 |
this.scrollIntoView(this.paneWidget.domNode); |
| 277 |
this.onOpen(); |
| 278 |
}, |
| 279 |
|
| 280 |
scrollIntoView: function(node){ |
| 281 |
|
| 282 |
|
| 283 |
var s = viewRegistry.getEnclosingScrollable(node); |
| 284 |
if(s){ |
| 285 |
var dim = s.getDim(); |
| 286 |
if(dim.c.h >= dim.d.h){ |
| 287 |
s.scrollIntoView(node, true); |
| 288 |
} |
| 289 |
}else{ |
| 290 |
win.global.scrollBy(0, domGeometry.position(node, false).y); |
| 291 |
} |
| 292 |
}, |
| 293 |
|
| 294 |
close: function(noAnimation){ |
| 295 |
|
| 296 |
|
| 297 |
if(!this.isOpen()){ return; } |
| 298 |
this.set("selected", false); |
| 299 |
if(has("css3-animations") && !noAnimation){ |
| 300 |
var contentNode = this.paneWidget.domNode; |
| 301 |
if(this.getParent().transition == "below"){ |
| 302 |
domClass.add(contentNode, "mblCloseContent mblShrink"); |
| 303 |
var nodePos = domGeometry.position(contentNode, true); |
| 304 |
var targetPos = domGeometry.position(this.domNode, true); |
| 305 |
var origin = (targetPos.x + targetPos.w/2 - nodePos.x) + "px " + (targetPos.y + targetPos.h/2 - nodePos.y) + "px"; |
| 306 |
domStyle.set(contentNode, css3.add({}, { transformOrigin:origin })); |
| 307 |
}else{ |
| 308 |
domClass.add(contentNode, "mblCloseContent mblShrink0"); |
| 309 |
} |
| 310 |
}else{ |
| 311 |
this.paneWidget.hide(); |
| 312 |
} |
| 313 |
this.onClose(); |
| 314 |
}, |
| 315 |
|
| 316 |
onOpen: function(){ |
| 317 |
|
| 318 |
|
| 319 |
}, |
| 320 |
|
| 321 |
onClose: function(){ |
| 322 |
|
| 323 |
|
| 324 |
}, |
| 325 |
|
| 326 |
_setLabelAttr: function(text){ |
| 327 |
|
| 328 |
|
| 329 |
this.label = text; |
| 330 |
var s = this._cv ? this._cv(text) : text; |
| 331 |
this.labelNode.innerHTML = s; |
| 332 |
if(this.paneWidget){ |
| 333 |
this.paneWidget.set("label", text); |
| 334 |
} |
| 335 |
}, |
| 336 |
|
| 337 |
_getBadgeAttr: function(){ |
| 338 |
|
| 339 |
|
| 340 |
return this.badgeObj ? this.badgeObj.getValue() : null; |
| 341 |
}, |
| 342 |
|
| 343 |
_setBadgeAttr: function(value){ |
| 344 |
|
| 345 |
|
| 346 |
if(!this.badgeObj){ |
| 347 |
this.badgeObj = new Badge({fontSize:14, className:this.badgeClass}); |
| 348 |
domStyle.set(this.badgeObj.domNode, { |
| 349 |
position: "absolute", |
| 350 |
top: "-2px", |
| 351 |
right: "2px" |
| 352 |
}); |
| 353 |
} |
| 354 |
this.badgeObj.setValue(value); |
| 355 |
if(value){ |
| 356 |
this.iconDivNode.appendChild(this.badgeObj.domNode); |
| 357 |
}else{ |
| 358 |
this.iconDivNode.removeChild(this.badgeObj.domNode); |
| 359 |
} |
| 360 |
}, |
| 361 |
|
| 362 |
_setDeleteIconAttr: function(icon){ |
| 363 |
|
| 364 |
|
| 365 |
if(!this.getParent()){ return; } |
| 366 |
|
| 367 |
this._set("deleteIcon", icon); |
| 368 |
icon = this.deletable ? icon : ""; |
| 369 |
this.deleteIconNode = iconUtils.setIcon(icon, this.deleteIconPos, this.deleteIconNode, |
| 370 |
this.deleteIconTitle || this.alt, this.iconDivNode); |
| 371 |
if(this.deleteIconNode){ |
| 372 |
domClass.add(this.deleteIconNode, "mblIconItemDeleteIcon"); |
| 373 |
if(this.deleteIconRole){ |
| 374 |
this.deleteIconNode.setAttribute("role", this.deleteIconRole); |
| 375 |
} |
| 376 |
} |
| 377 |
}, |
| 378 |
|
| 379 |
_setContentAttr: function(data){ |
| 380 |
|
| 381 |
|
| 382 |
var root; |
| 383 |
if(!this.paneWidget){ |
| 384 |
if(!this._tmpNode){ |
| 385 |
this._tmpNode = domConstruct.create("div"); |
| 386 |
} |
| 387 |
root = this._tmpNode; |
| 388 |
}else{ |
| 389 |
root = this.paneWidget.containerNode; |
| 390 |
} |
| 391 |
|
| 392 |
if(typeof data === "object"){ |
| 393 |
domConstruct.empty(root); |
| 394 |
root.appendChild(data); |
| 395 |
}else{ |
| 396 |
root.innerHTML = data; |
| 397 |
} |
| 398 |
}, |
| 399 |
|
| 400 |
_setSelectedAttr: function(selected){ |
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
this.inherited(arguments); |
| 406 |
this.iconNode && domStyle.set(this.iconNode, "opacity", |
| 407 |
selected ? this.getParent().pressedIconOpacity : 1); |
| 408 |
} |
| 409 |
}); |
| 410 |
|
| 411 |
return has("dojo-bidi") ? declare("dojox.mobile.IconItem", [IconItem, BidiIconItem]) : IconItem; |
| 412 |
}); |