source: Dev/branches/rest-dojo-ui/client/dojox/widget/Loader.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: 3.2 KB
Line 
1dojo.provide("dojox.widget.Loader");
2dojo.deprecated("dojox.widget.Loader", "", "2.0");
3
4dojo.require("dijit._Widget");
5dojo.require("dijit._Templated");
6
7dojo.declare("dojox.widget.Loader", [dijit._Widget,dijit._Templated], {
8        // summary: a configurable global xhr-listener to display
9        // a loading message during running xhr's or to simply provide
10        // base-level topic to subscribe to for custom loading messages
11        //
12        // loadIcon: String
13        //      location to the icon used.
14        loadIcon: dojo.moduleUrl("dojox.widget.Loader","icons/loading.gif"),
15
16        // loadMessage: String
17        //      string to use for progress loading
18        loadMessage: 'Loading ...',
19
20        // hasVisuals: Boolean
21        //      true to display a fixed loading message in TR cornder, false to unly provide
22        //      "Loader" topic to subscribe to for your own custom loading message.
23        hasVisuals: true,
24
25        // attachToPointer
26        //      true to use visual indicator where cursor is
27        attachToPointer: true,
28
29        // duration: Integer
30        //      time in ms to toggle in/out the visual load indicator
31        duration: 125,
32
33        // _offset: Integer
34        //      distance in px from the mouse pointer to show attachToPointer avatar
35        _offset: 16,
36
37        // holder for mousemove connection
38        _pointerConnect: null,
39        _xhrStart: null,
40        _xhrEnd: null,
41
42        templateString: '<div dojoAttachPoint="loadNode" class="dojoxLoader">'
43                +'<img src="${loadIcon}" class="dojoxLoaderIcon"> <span dojoAttachPoint="loadMessageNode" class="dojoxLoaderMessage"></span>'
44                +'</div>',
45       
46        postCreate: function(){
47                // summary: setup the loader
48
49                if(!this.hasVisuals){
50                        this.loadNode.style.display = "none"; // _destroy()?
51                }else{
52                        if(this.attachToPointer){
53                                dojo.removeClass(this.loadNode,"dojoxLoader");
54                                dojo.addClass(this.loadNode,"dojoxLoaderPointer");
55                        }
56                        this._hide();
57                }
58                this._setMessage(this.loadMessage);
59
60                // FIXME: create our connections.  would be easier, and this might be redundant
61                // if Deferred published something. XHR published stuff. FIXME to use that.
62                this._xhrStart = this.connect(dojo,"_ioSetArgs","_show");
63                this._xhrEnd = this.connect(dojo.Deferred.prototype,"_fire","_hide");
64
65        },
66
67        _setMessage: function(/* String */ message){
68                // summary: set's the message in the loader
69                this.loadMessageNode.innerHTML = message;
70        },
71
72        _putLoader: function(/* Event */ e){
73                // summary: place the floating loading element based on mousemove connection position
74                dijit.placeOnScreen(this.loadNode,{ x: e.clientX+this._offset, y:e.clientY+this._offset }, ["TL","BR"]);
75        },
76
77        _show: function(){
78                // summary: publish and show progress indicator
79                dojo.publish("Loader",[{ message: 'started' }]);
80                if(this.hasVisuals){
81                        if(this.attachToPointer){
82                                this._pointerConnect = this.connect(document,"onmousemove","_putLoader");
83                        }
84                        dojo.style(this.loadNode, {
85                                opacity:0, display:""
86                        });
87                        dojo.fadeIn({ node: this.loadNode, duration:this.duration }).play();
88                }
89        },
90
91        _hide: function(){
92                // summary: publish "xhr ended" and hide progress indicator
93                dojo.publish("Loader",[{ message: 'ended' }]);
94                if(this.hasVisuals){
95                        if(this.attachToPointer){
96                                this.disconnect(this._pointerConnect);
97                        }
98                        dojo.fadeOut({
99                                node: this.loadNode,
100                                duration:this.duration,
101                                onEnd: dojo.partial(dojo.style, this.loadNode, "display", "none")
102                        }).play();
103                }
104        }
105
106});
Note: See TracBrowser for help on using the repository browser.