| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/_base/declare", |
| 4 |
"dojo/_base/window", |
| 5 |
"dojo/dom", |
| 6 |
"dojo/dom-class", |
| 7 |
"dojo/dom-construct", |
| 8 |
"dojo/touch", |
| 9 |
"dojo/on", |
| 10 |
"./common", |
| 11 |
"dijit/_WidgetBase", |
| 12 |
"dijit/form/_ButtonMixin", |
| 13 |
"dijit/form/_FormWidgetMixin", |
| 14 |
"dojo/has", |
| 15 |
"dojo/has!dojo-bidi?dojox/mobile/bidi/Button" |
| 16 |
], |
| 17 |
function(array, declare, win, dom, domClass, domConstruct, touch, on, common, WidgetBase, ButtonMixin, FormWidgetMixin, has, BidiButton){ |
| 18 |
|
| 19 |
var Button = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiButton" : "dojox.mobile.Button", [WidgetBase, FormWidgetMixin, ButtonMixin], { |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
baseClass: "mblButton", |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
_setTypeAttr: null, |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
isFocusable: function(){ |
| 48 |
|
| 49 |
return false; |
| 50 |
}, |
| 51 |
|
| 52 |
buildRendering: function(){ |
| 53 |
if(!this.srcNodeRef){ |
| 54 |
this.srcNodeRef = domConstruct.create("button", {"type": this.type}); |
| 55 |
}else if(this._cv){ |
| 56 |
var n = this.srcNodeRef.firstChild; |
| 57 |
if(n && n.nodeType === 3){ |
| 58 |
n.nodeValue = this._cv(n.nodeValue); |
| 59 |
} |
| 60 |
} |
| 61 |
this.inherited(arguments); |
| 62 |
this.focusNode = this.domNode; |
| 63 |
}, |
| 64 |
|
| 65 |
postCreate: function(){ |
| 66 |
this.inherited(arguments); |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
this.domNode.dojoClick = "useTarget"; |
| 72 |
|
| 73 |
var _this = this; |
| 74 |
this.on(touch.press, function(e){ |
| 75 |
e.preventDefault(); |
| 76 |
|
| 77 |
if(_this.domNode.disabled){return;} |
| 78 |
_this._press(true); |
| 79 |
|
| 80 |
|
| 81 |
var isFirstMoveDone = false; |
| 82 |
_this._moveh = on(win.doc, touch.move, function(e){ |
| 83 |
if(!isFirstMoveDone){ |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
e.preventDefault(); |
| 90 |
isFirstMoveDone = true; |
| 91 |
} |
| 92 |
_this._press(dom.isDescendant(e.target, _this.domNode)); |
| 93 |
}); |
| 94 |
|
| 95 |
|
| 96 |
_this._endh = on(win.doc, touch.release, function(e){ |
| 97 |
_this._press(false); |
| 98 |
_this._moveh.remove(); |
| 99 |
_this._endh.remove(); |
| 100 |
}); |
| 101 |
}); |
| 102 |
|
| 103 |
common.setSelectable(this.focusNode, false); |
| 104 |
this.connect(this.domNode, "onclick", "_onClick"); |
| 105 |
}, |
| 106 |
|
| 107 |
_press: function(pressed){ |
| 108 |
|
| 109 |
|
| 110 |
if(pressed != this._pressed){ |
| 111 |
this._pressed = pressed; |
| 112 |
var button = this.focusNode || this.domNode; |
| 113 |
var newStateClasses = (this.baseClass + ' ' + this["class"]).split(" "); |
| 114 |
newStateClasses = array.map(newStateClasses, function(c){ |
| 115 |
return c + "Selected"; |
| 116 |
}); |
| 117 |
domClass.toggle(button, newStateClasses, pressed); |
| 118 |
} |
| 119 |
}, |
| 120 |
|
| 121 |
_setLabelAttr: function( content){ |
| 122 |
|
| 123 |
|
| 124 |
this.inherited(arguments, [this._cv ? this._cv(content) : content]); |
| 125 |
} |
| 126 |
}); |
| 127 |
|
| 128 |
return has("dojo-bidi") ? declare("dojox.mobile.Button", [Button, BidiButton]) : Button; |
| 129 |
}); |