source: Dev/branches/rest-dojo-ui/client/dojox/mobile/Button.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 2.4 KB
Line 
1define([
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],
10        function(array, declare, domClass, domConstruct, WidgetBase, ButtonMixin, FormWidgetMixin){
11
12        /*=====
13                WidgetBase = dijit._WidgetBase;
14                FormWidgetMixin = dijit.form._FormWidgetMixin;
15                ButtonMixin = dijit.form._ButtonMixin;
16        =====*/
17        return declare("dojox.mobile.Button", [WidgetBase, FormWidgetMixin, ButtonMixin], {
18                // summary:
19                //      Non-templated BUTTON widget with a thin API wrapper for click events and setting the label
20                //
21                // description:
22                //              Buttons can display a label, an icon, or both.
23                //              A label should always be specified (through innerHTML) or the label
24                //              attribute.  It can be hidden via showLabel=false.
25                // example:
26                // |    <button dojoType="dijit.form.Button" onClick="...">Hello world</button>
27
28                baseClass: "mblButton",
29
30                // Override automatic assigning type --> node, it causes exception on IE.
31                // Instead, type must be specified as this.type when the node is created, as part of the original DOM
32                _setTypeAttr: null,
33
34                // duration: Number
35                //      duration of selection, milliseconds or -1 for no post-click CSS styling
36                duration: 1000,
37
38                _onClick: function(e){
39                        var ret = this.inherited(arguments);
40                        if(ret && this.duration >= 0){ // if its not a button with a state, then emulate press styles
41                                var button = this.focusNode || this.domNode;
42                                var newStateClasses = (this.baseClass+' '+this["class"]).split(" ");
43                                newStateClasses = array.map(newStateClasses, function(c){ return c+"Selected"; });
44                                domClass.add(button, newStateClasses);
45                                setTimeout(function(){
46                                        domClass.remove(button, newStateClasses);
47                                }, this.duration);
48                        }
49                        return ret;
50                },
51
52                isFocusable: function(){ return false; },
53
54                buildRendering: function(){
55                        if(!this.srcNodeRef){
56                                this.srcNodeRef = domConstruct.create("button", {"type": this.type});
57                        }else if(this._cv){
58                                var n = this.srcNodeRef.firstChild;
59                                if(n && n.nodeType === 3){
60                                        n.nodeValue = this._cv(n.nodeValue);
61                                }
62                        }
63                        this.inherited(arguments);
64                        this.focusNode = this.domNode;
65                },
66
67                postCreate: function(){
68                        this.inherited(arguments);
69                        this.connect(this.domNode, "onclick", "_onClick");
70                },
71
72                _setLabelAttr: function(/*String*/ content){
73                        this.inherited(arguments, [this._cv ? this._cv(content) : content]);
74                }
75        });
76
77});
Note: See TracBrowser for help on using the repository browser.