source: Dev/branches/rest-dojo-ui/client/dojox/widget/Standby.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).

  • Property svn:executable set to *
File size: 22.6 KB
Line 
1define(["dojo/_base/kernel",
2        "dojo/_base/declare",
3        "dojo/_base/array",
4        "dojo/_base/event",
5        "dojo/_base/sniff",
6        "dojo/dom",
7        "dojo/dom-attr",
8        "dojo/dom-construct",
9        "dojo/dom-geometry",
10        "dojo/dom-style",
11        "dojo/window",
12        "dojo/_base/window",
13        "dojo/_base/fx",
14        "dojo/fx",
15        "dijit/_Widget",
16        "dijit/_TemplatedMixin",
17        "dijit/registry"],
18
19function(kernel,
20                declare,
21                array,
22                event,
23                has,
24                dom,
25                attr,
26                construct,
27                geometry,
28                domStyle,
29                window,
30                baseWindow,
31                baseFx,
32                fx,
33                _Widget,
34                _TemplatedMixin,
35                registry) {
36
37kernel.experimental("dojox.widget.Standby");
38
39return declare("dojox.widget.Standby", [_Widget, _TemplatedMixin],{
40        // summary:
41        //              A widget designed to act as a Standby/Busy/Disable/Blocking widget to indicate a
42        //              particular DOM node is processing and cannot be clicked on at this time.
43        //              This widget uses absolute positioning to apply the overlay and image.
44        //
45        // image:
46        //              A URL to an image to center within the blocking overlay.
47        //              The default is a basic spinner.
48        //
49        // imageText:
50        //              Text to set on the ALT tag of the image.
51        //              The default is 'Please wait...'
52        //
53        // text:
54        //              Text to display in the center instead of an image.
55        //              Defaults to 'Please Wait...'
56        //
57        // centerIndicator:
58        //              Which to use as the center info, the text or the image.
59        //              Defaults to image.
60        //
61        // color:
62        //              The color to use for the translucent overlay.
63        //              Text string such as: darkblue, #FE02FD, etc.
64        //
65        // duration:
66        //              How long the fade in and out effects should run in milliseconds.
67        //              Default is 500ms
68        //
69        // zIndex:
70        //              Control that lets you specify if the zIndex for the overlay
71        //              should be auto-computed based off parent zIndex, or should be set
72        //              to a particular value.  This is useful when you want to overlay
73        //              things in digit.Dialogs, you can specify a base zIndex to append from.
74        //              Default is 'auto'.
75
76        // templateString: [protected] String
77        //              The template string defining out the basics of the widget.  No need for an external
78        //              file.
79        templateString:
80                "<div>" +
81                        "<div style=\"display: none; opacity: 0; z-index: 9999; " +
82                                "position: absolute; cursor:wait;\" dojoAttachPoint=\"_underlayNode\"></div>" +
83                        "<img src=\"${image}\" style=\"opacity: 0; display: none; z-index: -10000; " +
84                                "position: absolute; top: 0px; left: 0px; cursor:wait;\" "+
85                                "dojoAttachPoint=\"_imageNode\">" +
86                        "<div style=\"opacity: 0; display: none; z-index: -10000; position: absolute; " +
87                                "top: 0px;\" dojoAttachPoint=\"_textNode\"></div>" +
88                "</div>",
89
90        // _underlayNode: [private] DOMNode
91        //              The node that is the translucent underlay for the
92        //              image that blocks access to the target.
93        _underlayNode: null,
94
95        // _imageNode: [private] DOMNode
96        //              The image node where we attach and define the image to display.
97        _imageNode: null,
98
99        // _textNode: [private] DOMNode
100        //              The div to attach text/HTML in the overlay center item.
101        _textNode: null,
102
103        // _centerNode: [private] DOMNode
104        //              Which node to use as the center node, the image or the text node.
105        _centerNode: null,
106
107        // image: String
108        //              The URL to the image to center in the overlay.
109        image: require.toUrl("dojox/widget/Standby/images/loading.gif").toString(),
110
111        // imageText: String
112        //              Text for the ALT tag.
113        imageText: "Please Wait...", // TODO: i18n
114
115        // text: String
116        //              Text/HTML to display in the center of the overlay
117        //              This is used if image center is disabled.
118        text: "Please wait...",
119
120        // centerIndicator: String
121        //              Property to define if the image and its alt text should be used, or
122        //              a simple Text/HTML node should be used.  Allowable values are 'image'
123        //              and 'text'.
124        //              Default is 'image'.
125        centerIndicator: "image",
126
127        // _displayed: [private] Boolean
128        //              Flag to indicate if the overlay is displayed or not.
129        _displayed: false,
130
131        // _resizeCheck: [private] Object
132        //              Handle to interval function that checks the target for changes.
133        _resizeCheck: null,
134       
135        // target: DOMNode||DOMID(String)||WidgetID(String)
136        //              The target to overlay when active.  Can be a widget id, a
137        //              dom id, or a direct node reference.
138        target: "",
139
140        // color:       String
141        //              The color to set the overlay.  Should be in #XXXXXX form.
142        //              Default color for the translucent overlay is light gray.
143        color: "#C0C0C0",
144
145        // duration: integer
146        //              Integer defining how long the show and hide effects should take.
147        duration: 500,
148
149        // _started: [private] Boolean
150        //              Trap flag to ensure startup only processes once.
151        _started: false,
152
153        // _parent: [private] DOMNode
154        //              Wrapping div for the widget, also used for IE 7 in dealing with the
155        //              zoom issue.
156        _parent: null,
157
158        // zIndex: String
159        //              Control that lets you specify if the zIndex for the overlay
160        //              should be auto-computed based off parent zIndex, or should be set
161        //              to a particular value.  This is useful when you want to overlay
162        //              things in digit.Dialogs, you can specify a base zIndex to append from.
163        zIndex: "auto",
164
165        startup: function(args){
166                // summary:
167                //              Over-ride of the basic widget startup function.
168                //              Configures the target node and sets the image to use.
169                if(!this._started){
170                        if(typeof this.target === "string"){
171                                var w = registry.byId(this.target);
172                                this.target = w ? w.domNode : dom.byId(this.target);
173                        }
174
175                        if(this.text){
176                                this._textNode.innerHTML = this.text;
177                        }
178                        if(this.centerIndicator === "image"){
179                                this._centerNode = this._imageNode;
180                                attr.set(this._imageNode, "src", this.image);
181                                attr.set(this._imageNode, "alt", this.imageText);
182                        }else{
183                                this._centerNode = this._textNode;
184                        }
185                        domStyle.set(this._underlayNode, {
186                                display: "none",
187                                backgroundColor: this.color
188                        });
189                        domStyle.set(this._centerNode, "display", "none");
190                        this.connect(this._underlayNode, "onclick", "_ignore");
191
192                        //Last thing to do is move the widgets parent, if any, to the current document body.
193                        //Avoids having to deal with parent relative/absolute mess.  Otherwise positioning
194                        //tends to go goofy.
195                        if(this.domNode.parentNode && this.domNode.parentNode != baseWindow.body()){
196                                baseWindow.body().appendChild(this.domNode);
197                        }
198
199                        //IE 7 has a horrible bug with zoom, so we have to create this node
200                        //to cross-check later.  Sigh.
201                        if(has("ie") == 7){
202                                this._ieFixNode = construct.create("div");
203                                domStyle.set(this._ieFixNode, {
204                                        opacity: "0",
205                                        zIndex: "-1000",
206                                        position: "absolute",
207                                        top: "-1000px"
208                                });
209                                baseWindow.body().appendChild(this._ieFixNode);
210                        }
211                        this.inherited(arguments);
212                }               
213        },
214
215        show: function(){
216                // summary:
217                //              Function to display the blocking overlay and busy/status icon or text.
218                if(!this._displayed){
219                        if(this._anim){
220                                this._anim.stop();
221                                delete this._anim;
222                        }
223                        this._displayed = true;
224                        this._size();
225                        this._disableOverflow();
226                        this._fadeIn();
227                }
228        },
229
230        hide: function(){
231                // summary:
232                //              Function to hide the blocking overlay and status icon or text.
233                if(this._displayed){
234                        if(this._anim){
235                                this._anim.stop();
236                                delete this._anim;
237                        }
238                        this._size();
239                        this._fadeOut();
240                        this._displayed = false;
241                        if(this._resizeCheck !== null){
242                                clearInterval(this._resizeCheck);
243                                this._resizeCheck = null;
244                        }
245                }
246        },
247
248        isVisible: function(){
249                // summary:
250                //              Helper function so you can test if the widget is already visible or not.
251                // returns:
252                //              boolean indicating if the widget is in 'show' state or not.
253                return this._displayed; // boolean
254        },
255
256        onShow: function(){
257                // summary:
258                //              Event that fires when the display of the Standby completes.
259        },
260
261        onHide: function(){
262                // summary:
263                //              Event that fires when the display of the Standby completes.
264        },
265
266        uninitialize: function(){
267                // summary:
268                //              Over-ride to hide the widget, which clears intervals, before cleanup.
269                this._displayed = false;
270                if(this._resizeCheck){
271                        clearInterval(this._resizeCheck);
272                }
273                domStyle.set(this._centerNode, "display", "none");
274                domStyle.set(this._underlayNode, "display", "none");
275                if(has("ie") == 7 && this._ieFixNode){
276                        baseWindow.body().removeChild(this._ieFixNode);
277                        delete this._ieFixNode;
278                }
279                if(this._anim){
280                        this._anim.stop();
281                        delete this._anim;
282                }
283                this.target = null;
284                this._imageNode = null;
285                this._textNode = null;
286                this._centerNode = null;
287                this.inherited(arguments);
288        },
289
290        _size: function(){
291                // summary:
292                //              Internal function that handles resizing the overlay and
293                //              centering of the image on window resizing.
294                // tags:
295                //              private
296                if(this._displayed){
297                        var dir = attr.get(baseWindow.body(), "dir");
298                        if(dir){dir = dir.toLowerCase();}
299                        var _ie7zoom;
300                        var scrollers = this._scrollerWidths();
301
302                        var target = this.target;
303
304                        //Show the image and make sure the zIndex is set high.
305                        var curStyle = domStyle.get(this._centerNode, "display");
306                        domStyle.set(this._centerNode, "display", "block");
307                        var box = geometry.position(target, true);
308                        if(target === baseWindow.body() || target === baseWindow.doc){
309                                // Target is the whole doc, so scale to viewport.
310                                box = window.getBox();
311                                box.x = box.l;
312                                box.y = box.t;
313                        }
314
315                        var cntrIndicator = geometry.getMarginBox(this._centerNode);
316                        domStyle.set(this._centerNode, "display", curStyle);
317
318                        //IE has a horrible zoom bug.  So, we have to try and account for
319                        //it and fix up the scaling.
320                        if(this._ieFixNode){
321                                _ie7zoom = -this._ieFixNode.offsetTop / 1000;
322                                box.x = Math.floor((box.x + 0.9) / _ie7zoom);
323                                box.y = Math.floor((box.y + 0.9) / _ie7zoom);
324                                box.w = Math.floor((box.w + 0.9) / _ie7zoom);
325                                box.h = Math.floor((box.h + 0.9) / _ie7zoom);
326                        }
327
328                        //Figure out how to zIndex this thing over the target.
329                        var zi = domStyle.get(target, "zIndex");
330                        var ziUl = zi;
331                        var ziIn = zi;
332
333                        if(this.zIndex === "auto"){
334                                if(zi != "auto"){
335                                        ziUl = parseInt(ziUl, 10) + 1;
336                                        ziIn = parseInt(ziIn, 10) + 2;
337                                }else{
338                                        //We need to search up the chain to see if there
339                                        //are any parent zIndexs to overlay.
340                                        var cNode = target.parentNode;
341                                        var oldZi = -100000;
342                                        while(cNode && cNode !== baseWindow.body()){
343                                                zi = domStyle.get(cNode, "zIndex");
344                                                if(!zi || zi === "auto"){
345                                                        cNode = cNode.parentNode;
346                                                }else{
347                                                        var newZi = parseInt(zi, 10);
348                                                        if(oldZi < newZi){
349                                                                oldZi = newZi;
350                                                                ziUl = newZi + 1;
351                                                                ziIn = newZi + 2;
352                                                        }
353                                                        // Keep looking until we run out, we want the highest zIndex.
354                                                        cNode = cNode.parentNode;
355                                                }
356                                        }
357                                }
358                        }else{
359                                ziUl = parseInt(this.zIndex, 10) + 1;
360                                ziIn = parseInt(this.zIndex, 10) + 2;
361                        }
362
363                        domStyle.set(this._centerNode, "zIndex", ziIn);
364                        domStyle.set(this._underlayNode, "zIndex", ziUl);
365
366
367                        var pn = target.parentNode;
368                        if(pn && pn !== baseWindow.body() &&
369                                target !== baseWindow.body() &&
370                                target !== baseWindow.doc){
371                               
372                                // If the parent is the body tag itself,
373                                // we can avoid all this, the body takes
374                                // care of overflow for me.  Besides, browser
375                                // weirdness with height and width on body causes
376                                // problems with this sort of intersect testing
377                                // anyway.
378                                var obh = box.h;
379                                var obw = box.w;
380                                var pnBox = geometry.position(pn, true);
381
382                                //More IE zoom corrections.  Grr.
383                                if(this._ieFixNode){
384                                        _ie7zoom = -this._ieFixNode.offsetTop / 1000;
385                                        pnBox.x = Math.floor((pnBox.x + 0.9) / _ie7zoom);
386                                        pnBox.y = Math.floor((pnBox.y + 0.9) / _ie7zoom);
387                                        pnBox.w = Math.floor((pnBox.w + 0.9) / _ie7zoom);
388                                        pnBox.h = Math.floor((pnBox.h + 0.9) / _ie7zoom);
389                                }
390                               
391                                //Shift the parent width/height a bit if scollers are present.
392                                pnBox.w -= pn.scrollHeight > pn.clientHeight &&
393                                        pn.clientHeight > 0 ? scrollers.v: 0;
394                                pnBox.h -= pn.scrollWidth > pn.clientWidth &&
395                                        pn.clientWidth > 0 ? scrollers.h: 0;
396
397                                //RTL requires a bit of massaging in some cases
398                                //(and differently depending on browser, ugh!)
399                                //WebKit and others still need work.
400                                if(dir === "rtl"){
401                                        if(has("opera")){
402                                                box.x += pn.scrollHeight > pn.clientHeight &&
403                                                        pn.clientHeight > 0 ? scrollers.v: 0;
404                                                pnBox.x += pn.scrollHeight > pn.clientHeight &&
405                                                        pn.clientHeight > 0 ? scrollers.v: 0;
406                                        }else if(has("ie")){
407                                                pnBox.x += pn.scrollHeight > pn.clientHeight &&
408                                                        pn.clientHeight > 0 ? scrollers.v: 0;
409                                        }else if(has("webkit")){
410                                                //TODO:  FIX THIS!
411                                        }
412                                }
413
414                                //Figure out if we need to adjust the overlay to fit a viewable
415                                //area, then resize it, we saved the original height/width above.
416                                //This is causing issues on IE.  Argh!
417                                if(pnBox.w < box.w){
418                                        //Scale down the width if necessary.
419                                        box.w = box.w - pnBox.w;
420                                }
421                                if(pnBox.h < box.h){
422                                        //Scale down the width if necessary.
423                                        box.h = box.h - pnBox.h;
424                                }
425
426                                //Look at the y positions and see if we intersect with the
427                                //viewport borders.  Will have to do computations off it.
428                                var vpTop = pnBox.y;
429                                var vpBottom = pnBox.y + pnBox.h;
430                                var bTop = box.y;
431                                var bBottom = box.y + obh;
432                                var vpLeft = pnBox.x;
433                                var vpRight = pnBox.x + pnBox.w;
434                                var bLeft = box.x;
435                                var bRight = box.x + obw;
436                                var delta;
437                                //Adjust the height now
438                                if(bBottom > vpTop &&
439                                        bTop < vpTop){
440                                        box.y = pnBox.y;
441                                        //intersecting top, need to do some shifting.
442                                        delta = vpTop - bTop;
443                                        var visHeight = obh - delta;
444                                        //If the visible height < viewport height,
445                                        //We need to shift it.
446                                        if(visHeight < pnBox.h){
447                                                box.h = visHeight;
448                                        }else{
449                                                //Deal with horizontal scrollbars if necessary.
450                                                box.h -= 2*(pn.scrollWidth > pn.clientWidth &&
451                                                        pn.clientWidth > 0? scrollers.h: 0);
452                                        }
453                                }else if(bTop < vpBottom && bBottom > vpBottom){
454                                        //Intersecting bottom, just figure out how much
455                                        //overlay to show.
456                                        box.h = vpBottom - bTop;
457                                }else if(bBottom <= vpTop || bTop >= vpBottom){
458                                        //Outside view, hide it.
459                                        box.h = 0;
460                                }
461
462                                //adjust width
463                                if(bRight > vpLeft && bLeft < vpLeft){
464                                        box.x = pnBox.x;
465                                        //intersecting left, need to do some shifting.
466                                        delta = vpLeft - bLeft;
467                                        var visWidth = obw - delta;
468                                        //If the visible width < viewport width,
469                                        //We need to shift it.
470                                        if(visWidth < pnBox.w){
471                                                box.w = visWidth;
472                                        }else{
473                                                //Deal with horizontal scrollbars if necessary.
474                                                box.w -= 2*(pn.scrollHeight > pn.clientHeight &&
475                                                        pn.clientHeight > 0? scrollers.w:0);
476                                        }
477                                }else if(bLeft < vpRight && bRight > vpRight){
478                                        //Intersecting right, just figure out how much
479                                        //overlay to show.
480                                        box.w = vpRight - bLeft;
481                                }else if(bRight <= vpLeft || bLeft >= vpRight){
482                                        //Outside view, hide it.
483                                        box.w = 0;
484                                }
485                        }
486
487                        if(box.h > 0 && box.w > 0){
488                                //Set position and size of the blocking div overlay.
489                                domStyle.set(this._underlayNode, {
490                                        display: "block",
491                                        width: box.w + "px",
492                                        height: box.h + "px",
493                                        top: box.y + "px",
494                                        left: box.x + "px"
495                                });
496
497                                var styles = ["borderRadius", "borderTopLeftRadius",
498                                        "borderTopRightRadius","borderBottomLeftRadius",
499                                        "borderBottomRightRadius"];
500                                this._cloneStyles(styles);
501                                if(!has("ie")){
502                                        //Browser specific styles to try and clone if non-IE.
503                                        styles = ["MozBorderRadius", "MozBorderRadiusTopleft",
504                                                "MozBorderRadiusTopright","MozBorderRadiusBottomleft",
505                                                "MozBorderRadiusBottomright","WebkitBorderRadius",
506                                                "WebkitBorderTopLeftRadius", "WebkitBorderTopRightRadius",
507                                                "WebkitBorderBottomLeftRadius","WebkitBorderBottomRightRadius"
508                                        ];
509                                        this._cloneStyles(styles, this);
510                                }
511                                var cntrIndicatorTop = (box.h/2) - (cntrIndicator.h/2);
512                                var cntrIndicatorLeft = (box.w/2) - (cntrIndicator.w/2);
513                                //Only show the image if there is height and width room.
514                                if(box.h >= cntrIndicator.h && box.w >= cntrIndicator.w){
515                                        domStyle.set(this._centerNode, {
516                                                top: (cntrIndicatorTop + box.y) + "px",
517                                                left: (cntrIndicatorLeft + box.x) + "px",
518                                                display: "block"
519                                        });
520                                }else{
521                                        domStyle.set(this._centerNode, "display", "none");
522                                }
523                        }else{
524                                //Target has no size, display nothing on it!
525                                domStyle.set(this._underlayNode, "display", "none");
526                                domStyle.set(this._centerNode, "display", "none");
527                        }
528                        if(this._resizeCheck === null){
529                                //Set an interval timer that checks the target size and scales as needed.
530                                //Checking every 10th of a second seems to generate a fairly smooth update.
531                                var self = this;
532                                this._resizeCheck = setInterval(function(){self._size();}, 100);
533                        }
534                }
535        },
536
537        _cloneStyles: function(list){
538                // summary:
539                //              Internal function to clone a set of styles from the target to
540                //              the underlay.
541                // list: Array
542                //              An array of style names to clone.
543                //
544                // tags:
545                //              private
546                array.forEach(list, function(s){
547                        domStyle.set(this._underlayNode, s, domStyle.get(this.target, s));
548                }, this);
549        },
550
551        _fadeIn: function(){
552                // summary:
553                //              Internal function that does the opacity style fade in animation.
554                // tags:
555                //              private
556                var self = this;
557                var underlayNodeAnim = baseFx.animateProperty({
558                        duration: self.duration,
559                        node: self._underlayNode,
560                        properties: {opacity: {start: 0, end: 0.75}}
561                });
562                var imageAnim = baseFx.animateProperty({
563                        duration: self.duration,
564                        node: self._centerNode,
565                        properties: {opacity: {start: 0, end: 1}},
566                        onEnd: function(){
567                                self.onShow();
568                                delete self._anim;
569                        }
570                });
571                this._anim = fx.combine([underlayNodeAnim,imageAnim]);
572                this._anim.play();
573        },
574
575        _fadeOut: function(){
576                // summary:
577                //              Internal function that does the opacity style fade out animation.
578                // tags:
579                //              private
580                var self = this;
581                var underlayNodeAnim = baseFx.animateProperty({
582                        duration: self.duration,
583                        node: self._underlayNode,
584                        properties: {opacity: {start: 0.75, end: 0}},
585                        onEnd: function(){
586                                domStyle.set(this.node,{"display":"none", "zIndex": "-1000"});
587                        }
588                });
589                var imageAnim = baseFx.animateProperty({
590                        duration: self.duration,
591                        node: self._centerNode,
592                        properties: {opacity: {start: 1, end: 0}},
593                        onEnd: function(){
594                                domStyle.set(this.node,{"display":"none", "zIndex": "-1000"});
595                                self.onHide();
596                                self._enableOverflow();
597                                delete self._anim;
598                        }
599                });
600                this._anim = fx.combine([underlayNodeAnim,imageAnim]);
601                this._anim.play();
602        },
603
604        _ignore: function(e){
605                // summary:
606                //              Function to ignore events that occur on the overlay.
607                // event: Event
608                //              The event to halt
609                // tags:
610                //              private
611                if(e){
612                        event.stop(e);
613                }
614        },
615
616        _scrollerWidths: function(){
617                // summary:
618                //              This function will calculate the size of the vertical and
619                //              horizontaol scrollbars.
620                // returns:
621                //              Object of form: {v: Number, h: Number} where v is vertical scrollbar width
622                //              and h is horizontal scrollbar width.
623                // tags:
624                //              private
625                var div = construct.create("div");
626                domStyle.set(div, {
627                        position: "absolute",
628                        opacity: 0,
629                        overflow: "hidden",
630                        width: "50px",
631                        height: "50px",
632                        zIndex: "-100",
633                        top: "-200px",
634                        padding: "0px",
635                        margin: "0px"
636                });
637                var iDiv = construct.create("div");
638                domStyle.set(iDiv, {
639                        width: "200px",
640                        height: "10px"
641                });
642                div.appendChild(iDiv);
643                baseWindow.body().appendChild(div);
644
645                //Figure out content size before and after
646                //scrollbars are there, then just subtract to
647                //get width.
648                var b = geometry.getContentBox(div);
649                domStyle.set(div, "overflow", "scroll");
650                var a = geometry.getContentBox(div);
651                baseWindow.body().removeChild(div);
652                return { v: b.w - a.w, h: b.h - a.h };
653        },
654
655        /* The following are functions that tie into _Widget.attr() */
656
657        _setTextAttr: function(text){
658                // summary:
659                //              Function to allow widget.attr to set the text displayed in center
660                //              if using text display.
661                // text: String
662                //              The text to set.
663                this._textNode.innerHTML = text;
664                this.text = text;
665        },
666
667        _setColorAttr: function(c){
668                // summary:
669                //              Function to allow widget.attr to set the color used for the translucent
670                //              div overlay.
671                // c: String
672                //              The color to set the background underlay to in #XXXXXX format..
673                domStyle.set(this._underlayNode, "backgroundColor", c);
674                this.color = c;
675        },
676
677        _setImageTextAttr: function(text){
678                // summary:
679                //              Function to allow widget.attr to set the ALT text text displayed for
680                //              the image (if using image center display).
681                // text: String
682                //              The text to set.
683                attr.set(this._imageNode, "alt", text);
684                this.imageText = text;
685        },
686
687        _setImageAttr: function(url){
688                // summary:
689                //              Function to allow widget.attr to set the url source for the center image
690                // text: String
691                //              The url to set for the image.
692                attr.set(this._imageNode, "src", url);
693                this.image = url;
694        },
695
696        _setCenterIndicatorAttr: function(indicator){
697                // summary:
698                //              Function to allow widget.attr to set the node used for the center indicator,
699                //              either the image or the text.
700                // indicator: String
701                //              The indicator to use, either 'image' or 'text'.
702                this.centerIndicator = indicator;
703                if(indicator === "image"){
704                        this._centerNode = this._imageNode;
705                        domStyle.set(this._textNode, "display", "none");
706                }else{
707                        this._centerNode = this._textNode;
708                        domStyle.set(this._imageNode, "display", "none");
709                }
710        },
711
712        _disableOverflow: function(){
713                 // summary:
714                 //             Function to disable scrollbars on the body.  Only used if the overlay
715                 //             targets the body or the document.
716                 if(this.target === baseWindow.body() || this.target === baseWindow.doc){
717                         // Store the overflow state we have to restore later.
718                         // IE had issues, so have to check that it's defined.  Ugh.
719                         this._overflowDisabled = true;
720                         var body = baseWindow.body();
721                         if(body.style && body.style.overflow){
722                                 this._oldOverflow = domStyle.set(body, "overflow");
723                         }else{
724                                 this._oldOverflow = "";
725                         }
726                         if(has("ie") && !has("quirks")){
727                                 // IE will put scrollbars in anyway, html (parent of body)
728                                 // also controls them in standards mode, so we have to
729                                 // remove them, argh.
730                                 if(body.parentNode &&
731                                        body.parentNode.style &&
732                                        body.parentNode.style.overflow){
733                                         this._oldBodyParentOverflow = body.parentNode.style.overflow;
734                                 }else{
735                                         try{
736                                                this._oldBodyParentOverflow = domStyle.set(body.parentNode, "overflow");
737                                         }catch(e){
738                                                 this._oldBodyParentOverflow = "scroll";
739                                         }
740                                 }
741                                 domStyle.set(body.parentNode, "overflow", "hidden");
742                         }
743                         domStyle.set(body, "overflow", "hidden");
744                 }
745        },
746
747        _enableOverflow: function(){
748                 // summary:
749                 //             Function to restore scrollbars on the body.  Only used if the overlay
750                 //             targets the body or the document.
751                 if(this._overflowDisabled){
752                        delete this._overflowDisabled;
753                        var body = baseWindow.body();
754                        // Restore all the overflow.
755                        if(has("ie") && !has("quirks")){
756                                body.parentNode.style.overflow = this._oldBodyParentOverflow;
757                                delete this._oldBodyParentOverflow;
758                        }
759                        domStyle.set(body, "overflow", this._oldOverflow);
760                        if(has("webkit")){
761                                //Gotta poke WebKit, or scrollers don't come back. :-(
762                                var div = construct.create("div", { style: {
763                                                height: "2px"
764                                        }
765                                });
766                                body.appendChild(div);
767                                setTimeout(function(){
768                                        body.removeChild(div);
769                                }, 0);
770                        }
771                        delete this._oldOverflow;
772                }
773        }
774});
775
776});
Note: See TracBrowser for help on using the repository browser.