1 | define([ |
---|
2 | "dojo/_base/array", |
---|
3 | "dojo/_base/declare", |
---|
4 | "dojo/dom-class", |
---|
5 | "dojo/dom-construct", |
---|
6 | "dijit/_WidgetBase", |
---|
7 | "dijit/form/_ButtonMixin", |
---|
8 | "dijit/form/_FormWidgetMixin", |
---|
9 | "dojo/has", |
---|
10 | "dojo/has!dojo-bidi?dojox/mobile/bidi/Button" |
---|
11 | ], |
---|
12 | function(array, declare, domClass, domConstruct, WidgetBase, ButtonMixin, FormWidgetMixin, has, BidiButton){ |
---|
13 | |
---|
14 | var Button = declare(has("dojo-bidi") ? "dojox.mobile.NonBidiButton" : "dojox.mobile.Button", [WidgetBase, FormWidgetMixin, ButtonMixin], { |
---|
15 | // summary: |
---|
16 | // Non-templated BUTTON widget with a thin API wrapper for click |
---|
17 | // events and for setting the label. |
---|
18 | // |
---|
19 | // Buttons can display a label, an icon, or both. |
---|
20 | // A label should always be specified (through innerHTML) or the label |
---|
21 | // attribute. It can be hidden via showLabel=false. |
---|
22 | // example: |
---|
23 | // | <button data-dojo-type="dojox/mobile/Button" onClick="...">Hello world</button> |
---|
24 | |
---|
25 | // baseClass: String |
---|
26 | // The name of the CSS class of this widget. |
---|
27 | baseClass: "mblButton", |
---|
28 | |
---|
29 | // _setTypeAttr: [private] Function |
---|
30 | // Overrides the automatic assignment of type to nodes, because it causes |
---|
31 | // exception on IE. Instead, the type must be specified as this.type |
---|
32 | // when the node is created, as part of the original DOM. |
---|
33 | _setTypeAttr: null, |
---|
34 | |
---|
35 | // duration: Number |
---|
36 | // The duration of selection, in milliseconds, or -1 for no post-click CSS styling. |
---|
37 | duration: 1000, |
---|
38 | |
---|
39 | /*===== |
---|
40 | // label: String |
---|
41 | // The label of the button. |
---|
42 | label: "", |
---|
43 | =====*/ |
---|
44 | |
---|
45 | _onClick: function(e){ |
---|
46 | // tags: |
---|
47 | // private |
---|
48 | var ret = this.inherited(arguments); |
---|
49 | if(ret && this.duration >= 0){ // if its not a button with a state, then emulate press styles |
---|
50 | var button = this.focusNode || this.domNode; |
---|
51 | var newStateClasses = (this.baseClass+' '+this["class"]).split(" "); |
---|
52 | newStateClasses = array.map(newStateClasses, function(c){ return c+"Selected"; }); |
---|
53 | domClass.add(button, newStateClasses); |
---|
54 | this.defer(function(){ |
---|
55 | domClass.remove(button, newStateClasses); |
---|
56 | }, this.duration); |
---|
57 | } |
---|
58 | return ret; |
---|
59 | }, |
---|
60 | |
---|
61 | isFocusable: function(){ |
---|
62 | // Override of the method of dijit/_WidgetBase. |
---|
63 | return false; |
---|
64 | }, |
---|
65 | |
---|
66 | buildRendering: function(){ |
---|
67 | if(!this.srcNodeRef){ |
---|
68 | this.srcNodeRef = domConstruct.create("button", {"type": this.type}); |
---|
69 | }else if(this._cv){ |
---|
70 | var n = this.srcNodeRef.firstChild; |
---|
71 | if(n && n.nodeType === 3){ |
---|
72 | n.nodeValue = this._cv(n.nodeValue); |
---|
73 | } |
---|
74 | } |
---|
75 | this.inherited(arguments); |
---|
76 | this.focusNode = this.domNode; |
---|
77 | }, |
---|
78 | |
---|
79 | postCreate: function(){ |
---|
80 | this.inherited(arguments); |
---|
81 | this.connect(this.domNode, "onclick", "_onClick"); |
---|
82 | }, |
---|
83 | |
---|
84 | _setLabelAttr: function(/*String*/ content){ |
---|
85 | // tags: |
---|
86 | // private |
---|
87 | this.inherited(arguments, [this._cv ? this._cv(content) : content]); |
---|
88 | } |
---|
89 | }); |
---|
90 | |
---|
91 | return has("dojo-bidi") ? declare("dojox.mobile.Button", [Button, BidiButton]) : Button; |
---|
92 | }); |
---|