source: Dev/trunk/src/client/dojox/widget/rotator/ThumbnailController.js

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

Added Dojo 1.9.3 release.

File size: 2.9 KB
Line 
1define([
2        "dojo/_base/declare",
3        "dojo/_base/connect",
4        "dojo/_base/lang",
5        "dojo/_base/event",
6        "dojo/aspect",
7        "dojo/dom-attr",
8        "dojo/dom-class",
9        "dojo/dom-construct",
10        "dojo/query"
11], function(declare, connect, lang, event, aspect, domAttr, domClass, domConstruct, query) {
12
13        var _css = "dojoxRotatorThumb",
14                _selected = _css + "Selected";
15
16        return declare("dojox.widget.rotator.ThumbnailController", null, {
17                // summary:
18                //              A rotator controller that displays thumbnails of each rotator pane.
19                // description:
20                //              The ThumbnailController will look at each of the rotator's panes and
21                //              only if the node is an `<img>` tag, then it will create an thumbnail of
22                //              the pane's image using the `<img>` tag's "thumbsrc" or "src" attribute.
23                //
24                //              The size of the thumbnails and the style of the selected thumbnail is
25                //              controlled using CSS.
26                // example:
27                //      |       <div dojoType="dojox.widget.Rotator" jsId="myRotator">
28                //      |               <img src="/path/to/image1.jpg" thumbsrc="/path/to/thumb1.jpg" alt="Image 1"/>
29                //      |               <img src="/path/to/image2.jpg" thumbsrc="/path/to/thumb2.jpg" alt="Image 2"/>
30                //      |       </div>
31                //      |       <div dojoType="dojox.widget.rotator.ThumbnailController" rotator="myRotator"></div>
32
33                // rotator: dojox/widget/Rotator
34                //              An instance of a Rotator widget.
35                rotator: null,
36
37                constructor: function(/*Object*/params, /*DomNode|string*/node){
38                        // summary:
39                        //              Initializes the thumbnails and connect to the rotator.
40
41                        lang.mixin(this, params);
42
43                        this._domNode = node;
44
45                        // check if we have a valid rotator
46                        var r = this.rotator;
47                        if(r){
48                                // remove all of the controller's child nodes just in case
49                                while(node.firstChild){
50                                        node.removeChild(node.firstChild);
51                                }
52
53                                for(var i=0; i<r.panes.length; i++){
54                                        var n = r.panes[i].node,
55                                                s = domAttr.get(n, "thumbsrc") || domAttr.get(n, "src"),
56                                                t = domAttr.get(n, "alt") || "";
57
58                                        if(/img/i.test(n.tagName)){
59                                                (function(j){
60                                                        domConstruct.create("a", {
61                                                                classname: _css + ' ' + _css + j + ' ' + (j == r.idx ? _selected : ""),
62                                                                href: s,
63                                                                onclick: function(e){
64                                                                        event.stop(e);
65                                                                        if(r){
66                                                                                r.control.apply(r, ["go", j]);
67                                                                        }
68                                                                },
69                                                                title: t,
70                                                                innerHTML: '<img src="' + s + '" alt="' + t + '"/>'
71                                                        }, node);
72                                                })(i);
73                                        }
74                                }
75
76                                aspect.after(r, 'onUpdate', lang.hitch(this, "_onUpdate"), true);
77                        }
78                },
79
80                destroy: function(){
81                        // summary:
82                        //              Disconnect from the rotator.
83
84                        domConstruct.destroy(this._domNode);
85                },
86
87                _onUpdate: function(/*string*/type){
88                        // summary:
89                        //              Updates various pager controls when the rotator updates.
90
91                        var r = this.rotator; // no need to test if this is null since _onUpdate is only fired by the rotator
92                        if(type == "onAfterTransition"){
93                                var n = query('.' + _css, this._domNode).removeClass(_selected);
94                                if(r.idx < n.length){
95                                        domClass.add(n[r.idx], _selected);
96                                }
97                        }
98                }
99        });
100
101});
Note: See TracBrowser for help on using the repository browser.