Debian Codegraph @

dojox/mobile/Button.js

raw symbols SCIP
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 // summary:
21 // Non-templated BUTTON widget with a thin API wrapper for click
22 // events and for setting the label.
23 //
24 // Buttons can display a label, an icon, or both.
25 // A label should always be specified (through innerHTML) or the label
26 // attribute. It can be hidden via showLabel=false.
27 // example:
28 // | <button data-dojo-type="dojox/mobile/Button" onClick="...">Hello world</button>
29
30 // baseClass: String
31 // The name of the CSS class of this widget.
32 baseClass: "mblButton",
33
34 // _setTypeAttr: [private] Function
35 // Overrides the automatic assignment of type to nodes, because it causes
36 // exception on IE. Instead, the type must be specified as this.type
37 // when the node is created, as part of the original DOM.
38 _setTypeAttr: null,
39
40 /*=====
41 // label: String
42 // The label of the button.
43 label: "",
44 =====*/
45
46
47 isFocusable: function(){
48 // Override of the method of dijit/_WidgetBase.
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 // we need to ensure the synthetic click is emitted by
69 // touch.doClicks even if we moved (inside or outside) before we
70 // released in the button area.
71 this.domNode.dojoClick = "useTarget";
72 // handle touch.press event
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 // change button state depending on where we are
81 var isFirstMoveDone = false;
82 _this._moveh = on(win.doc, touch.move, function(e){
83 if(!isFirstMoveDone){
84 // #17220: preventDefault may not have any effect.
85 // causing minor impact on some android
86 // (Galaxy Tab 2 with stock browser 4.1.1) where button
87 // display does not reflect the actual button state
88 // when user moves back and forth from the button area.
89 e.preventDefault();
90 isFirstMoveDone = true;
91 }
92 _this._press(dom.isDescendant(e.target, _this.domNode));
93 });
94
95 // handle touch.release
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 // tags:
109 // private
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(/*String*/ content){
122 // tags:
123 // private
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 });