source: Dev/branches/rest-dojo-ui/client/dojox/mobile/ToolBarButton.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.9 KB
Line 
1define([
2        "dojo/_base/declare",
3        "dojo/_base/window",
4        "dojo/dom-class",
5        "dojo/dom-construct",
6        "dojo/dom-style",
7        "./common",
8        "./_ItemBase"
9], function(declare, win, domClass, domConstruct, domStyle, common, ItemBase){
10/*=====
11        var ItemBase = dojox.mobile._ItemBase;
12=====*/
13
14        // module:
15        //              dojox/mobile/ToolBarButton
16        // summary:
17        //              A button widget that is placed in the Heading widget.
18
19        return declare("dojox.mobile.ToolBarButton", ItemBase, {
20                // summary:
21                //              A button widget that is placed in the Heading widget.
22                // description:
23                //              ToolBarButton is a button that is placed in the Heading
24                //              widget. It is a subclass of dojox.mobile._ItemBase just like
25                //              ListItem or IconItem. So, unlike Button, it has basically the
26                //              same capability as ListItem or IconItem, such as icon support,
27                //              transition, etc.
28
29                // selected: Boolean
30                //              If true, the button is in the selected status.
31                selected: false,
32
33                // btnClass: String
34                //              Deprecated.
35                btnClass: "",
36
37                /* internal properties */       
38                _defaultColor: "mblColorDefault",
39                _selColor: "mblColorDefaultSel",
40
41                buildRendering: function(){
42                        this.domNode = this.containerNode = this.srcNodeRef || win.doc.createElement("div");
43                        this.inheritParams();
44                        domClass.add(this.domNode, "mblToolBarButton mblArrowButtonText");
45                        var color;
46                        if(this.selected){
47                                color = this._selColor;
48                        }else if(this.domNode.className.indexOf("mblColor") == -1){
49                                color = this._defaultColor;
50                        }
51                        domClass.add(this.domNode, color);
52       
53                        if(!this.label){
54                                this.label = this.domNode.innerHTML;
55                        }
56
57                        if(this.icon && this.icon != "none"){
58                                this.iconNode = domConstruct.create("div", {className:"mblToolBarButtonIcon"}, this.domNode);
59                                common.createIcon(this.icon, this.iconPos, null, this.alt, this.iconNode);
60                                if(this.iconPos){
61                                        domClass.add(this.iconNode.firstChild, "mblToolBarButtonSpriteIcon");
62                                }
63                        }else{
64                                if(common.createDomButton(this.domNode)){
65                                        domClass.add(this.domNode, "mblToolBarButtonDomButton");
66                                }else{
67                                        domClass.add(this.domNode, "mblToolBarButtonText");
68                                }
69                        }
70                        this.connect(this.domNode, "onclick", "onClick");
71                },
72       
73                select: function(){
74                        // summary:
75                        //              Makes this widget in the selected state.
76                        domClass.toggle(this.domNode, this._selColor, !arguments[0]);
77                        this.selected = !arguments[0];
78                },
79               
80                deselect: function(){
81                        // summary:
82                        //              Makes this widget in the deselected state.
83                        this.select(true);
84                },
85       
86                onClick: function(e){
87                        this.setTransitionPos(e);
88                        this.defaultClickAction();
89                },
90       
91                _setBtnClassAttr: function(/*String*/btnClass){
92                        var node = this.domNode;
93                        if(node.className.match(/(mblDomButton\w+)/)){
94                                domClass.remove(node, RegExp.$1);
95                        }
96                        domClass.add(node, btnClass);
97                        if(common.createDomButton(this.domNode)){
98                                domClass.add(this.domNode, "mblToolBarButtonDomButton");
99                        }
100                },
101
102                _setLabelAttr: function(/*String*/text){
103                        this.label = text;
104                        this.domNode.innerHTML = this._cv ? this._cv(text) : text;
105                }
106        });
107});
Note: See TracBrowser for help on using the repository browser.