source: Dev/trunk/src/client/dojox/mobile/PageIndicator.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 3.2 KB
Line 
1define([
2        "dojo/_base/connect",
3        "dojo/_base/declare",
4        "dojo/dom",
5        "dojo/dom-class",
6        "dojo/dom-construct",
7        "dijit/registry",
8        "dijit/_Contained",
9        "dijit/_WidgetBase"
10], function(connect, declare, dom, domClass, domConstruct, registry, Contained, WidgetBase){
11
12        // module:
13        //              dojox/mobile/PageIndicator
14
15        return declare("dojox.mobile.PageIndicator", [WidgetBase, Contained],{
16                // summary:
17                //              A current page indicator.
18                // description:
19                //              PageIndicator displays a series of gray and white dots to
20                //              indicate which page is currently being viewed. It can typically
21                //              be used with dojox/mobile/SwapView. It is also internally used
22                //              in dojox/mobile/Carousel.
23
24                // refId: String
25                //              An ID of a DOM node to be searched. Siblings of the reference
26                //              node will be searched for views. If not specified, this.domNode
27                //              will be the reference node.
28                refId: "",
29
30                // baseClass: String
31                //              The name of the CSS class of this widget.
32                baseClass: "mblPageIndicator",
33
34                buildRendering: function(){
35                        this.inherited(arguments);
36                        this._tblNode = domConstruct.create("table", {className:"mblPageIndicatorContainer"}, this.domNode);
37                        this._tblNode.insertRow(-1);
38                        this.connect(this.domNode, "onclick", "_onClick");
39                        this.subscribe("/dojox/mobile/viewChanged", function(view){
40                                this.reset();
41                        });
42                },
43
44                startup: function(){
45                        var _this = this;
46                        _this.defer(function(){ // to wait until views' visibility is determined
47                                _this.reset();
48                        });
49                },
50
51                reset: function(){
52                        // summary:
53                        //              Updates the indicator.
54                        var r = this._tblNode.rows[0];
55                        var i, c, a = [], dot;
56                        var refNode = (this.refId && dom.byId(this.refId)) || this.domNode;
57                        var children = refNode.parentNode.childNodes;
58                        for(i = 0; i < children.length; i++){
59                                c = children[i];
60                                if(this.isView(c)){
61                                        a.push(c);
62                                }
63                        }
64                        if(r.cells.length !== a.length){
65                                domConstruct.empty(r);
66                                for(i = 0; i < a.length; i++){
67                                        c = a[i];
68                                        dot = domConstruct.create("div", {className:"mblPageIndicatorDot"});
69                                        r.insertCell(-1).appendChild(dot);
70                                }
71                        }
72                        if(a.length === 0){ return; }
73                        var currentView = registry.byNode(a[0]).getShowingView();
74                        for(i = 0; i < r.cells.length; i++){
75                                dot = r.cells[i].firstChild;
76                                if(a[i] === currentView.domNode){
77                                        domClass.add(dot, "mblPageIndicatorDotSelected");
78                                }else{
79                                        domClass.remove(dot, "mblPageIndicatorDotSelected");
80                                }
81                        }
82                },
83
84                isView: function(node){
85                        // summary:
86                        //              Returns true if the given node is a view.
87                        return (node && node.nodeType === 1 && domClass.contains(node, "mblView")); // Boolean
88                },
89
90                _onClick: function(e){
91                        // summary:
92                        //              Internal handler for click events.
93                        // tags:
94                        //              private
95                        if(this.onClick(e) === false){ return; } // user's click action
96                        if(e.target !== this.domNode){ return; }
97                        if(e.layerX < this._tblNode.offsetLeft){
98                                connect.publish("/dojox/mobile/prevPage", [this]);
99                        }else if(e.layerX > this._tblNode.offsetLeft + this._tblNode.offsetWidth){
100                                connect.publish("/dojox/mobile/nextPage", [this]);
101                        }
102                },
103
104                onClick: function(/*Event*/ /*===== e =====*/){
105                        // summary:
106                        //              User-defined function to handle clicks.
107                        // tags:
108                        //              callback
109                }
110        });
111});
Note: See TracBrowser for help on using the repository browser.