summaryrefslogtreecommitdiff
path: root/frontend/beta/js/YUI/container.js
Unidiff
Diffstat (limited to 'frontend/beta/js/YUI/container.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/beta/js/YUI/container.js4561
1 files changed, 4561 insertions, 0 deletions
diff --git a/frontend/beta/js/YUI/container.js b/frontend/beta/js/YUI/container.js
new file mode 100644
index 0000000..ec0f864
--- a/dev/null
+++ b/frontend/beta/js/YUI/container.js
@@ -0,0 +1,4561 @@
1/*
2Copyright (c) 2006, Yahoo! Inc. All rights reserved.
3Code licensed under the BSD License:
4http://developer.yahoo.net/yui/license.txt
5version 0.12.0
6*/
7
8/**
9* Config is a utility used within an Object to allow the implementer to maintain a list of local configuration properties and listen for changes to those properties dynamically using CustomEvent. The initial values are also maintained so that the configuration can be reset at any given point to its initial state.
10* @class YAHOO.util.Config
11* @constructor
12 * @param {Object} ownerThe owner Object to which this Config Object belongs
13*/
14YAHOO.util.Config = function(owner) {
15 if (owner) {
16 this.init(owner);
17 }
18};
19
20YAHOO.util.Config.prototype = {
21
22 /**
23 * Object reference to the owner of this Config Object
24 * @property owner
25 * @type Object
26 */
27 owner : null,
28
29 /**
30 * Boolean flag that specifies whether a queue is currently being executed
31 * @property queueInProgress
32 * @type Boolean
33 */
34 queueInProgress : false,
35
36
37 /**
38 * Validates that the value passed in is a Boolean.
39 * @method checkBoolean
40 * @param {Object} valThe value to validate
41 * @return {Boolean}true, if the value is valid
42 */
43 checkBoolean: function(val) {
44 if (typeof val == 'boolean') {
45 return true;
46 } else {
47 return false;
48 }
49 },
50
51 /**
52 * Validates that the value passed in is a number.
53 * @method checkNumber
54 * @param {Object} valThe value to validate
55 * @return {Boolean}true, if the value is valid
56 */
57 checkNumber: function(val) {
58 if (isNaN(val)) {
59 return false;
60 } else {
61 return true;
62 }
63 }
64};
65
66
67/**
68* Initializes the configuration Object and all of its local members.
69* @method init
70 * @param {Object} ownerThe owner Object to which this Config Object belongs
71*/
72YAHOO.util.Config.prototype.init = function(owner) {
73
74 this.owner = owner;
75
76 /**
77 * Object reference to the owner of this Config Object
78 * @event configChangedEvent
79 */
80 this.configChangedEvent = new YAHOO.util.CustomEvent("configChanged");
81
82 this.queueInProgress = false;
83
84 /* Private Members */
85
86 /**
87 * Maintains the local collection of configuration property objects and their specified values
88 * @property config
89 * @private
90 * @type Object
91 */
92 var config = {};
93
94 /**
95 * Maintains the local collection of configuration property objects as they were initially applied.
96 * This object is used when resetting a property.
97 * @property initialConfig
98 * @private
99 * @type Object
100 */
101 var initialConfig = {};
102
103 /**
104 * Maintains the local, normalized CustomEvent queue
105 * @property eventQueue
106 * @private
107 * @type Object
108 */
109 var eventQueue = [];
110
111 /**
112 * Fires a configuration property event using the specified value.
113 * @method fireEvent
114 * @private
115 * @param {String} key The configuration property's name
116 * @param {value} Object The value of the correct type for the property
117 */
118 var fireEvent = function( key, value ) {
119 key = key.toLowerCase();
120
121 var property = config[key];
122
123 if (typeof property != 'undefined' && property.event) {
124 property.event.fire(value);
125 }
126 };
127 /* End Private Members */
128
129 /**
130 * Adds a property to the Config Object's private config hash.
131 * @method addProperty
132 * @param {String} keyThe configuration property's name
133 * @param {Object} propertyObjectThe Object containing all of this property's arguments
134 */
135 this.addProperty = function( key, propertyObject ) {
136 key = key.toLowerCase();
137
138 config[key] = propertyObject;
139
140 propertyObject.event = new YAHOO.util.CustomEvent(key);
141 propertyObject.key = key;
142
143 if (propertyObject.handler) {
144 propertyObject.event.subscribe(propertyObject.handler, this.owner, true);
145 }
146
147 this.setProperty(key, propertyObject.value, true);
148
149 if (! propertyObject.suppressEvent) {
150 this.queueProperty(key, propertyObject.value);
151 }
152 };
153
154 /**
155 * Returns a key-value configuration map of the values currently set in the Config Object.
156 * @method getConfig
157 * @return {Object} The current config, represented in a key-value map
158 */
159 this.getConfig = function() {
160 var cfg = {};
161
162 for (var prop in config) {
163 var property = config[prop];
164 if (typeof property != 'undefined' && property.event) {
165 cfg[prop] = property.value;
166 }
167 }
168
169 return cfg;
170 };
171
172 /**
173 * Returns the value of specified property.
174 * @method getProperty
175 * @param {String} keyThe name of the property
176 * @return {Object} The value of the specified property
177 */
178 this.getProperty = function(key) {
179 key = key.toLowerCase();
180
181 var property = config[key];
182 if (typeof property != 'undefined' && property.event) {
183 return property.value;
184 } else {
185 return undefined;
186 }
187 };
188
189 /**
190 * Resets the specified property's value to its initial value.
191 * @method resetProperty
192 * @param {String} keyThe name of the property
193 * @return {Boolean} True is the property was reset, false if not
194 */
195 this.resetProperty = function(key) {
196 key = key.toLowerCase();
197
198 var property = config[key];
199 if (typeof property != 'undefined' && property.event) {
200 if (initialConfig[key] && initialConfig[key] != 'undefined'){
201 this.setProperty(key, initialConfig[key]);
202 }
203 return true;
204 } else {
205 return false;
206 }
207 };
208
209 /**
210 * Sets the value of a property. If the silent property is passed as true, the property's event will not be fired.
211 * @method setProperty
212 * @param {String} key The name of the property
213 * @param {String} value The value to set the property to
214 * @param {Boolean} silentWhether the value should be set silently, without firing the property event.
215 * @return {Boolean} True, if the set was successful, false if it failed.
216 */
217 this.setProperty = function(key, value, silent) {
218 key = key.toLowerCase();
219
220 if (this.queueInProgress && ! silent) {
221 this.queueProperty(key,value); // Currently running through a queue...
222 return true;
223 } else {
224 var property = config[key];
225 if (typeof property != 'undefined' && property.event) {
226 if (property.validator && ! property.validator(value)) { // validator
227 return false;
228 } else {
229 property.value = value;
230 if (! silent) {
231 fireEvent(key, value);
232 this.configChangedEvent.fire([key, value]);
233 }
234 return true;
235 }
236 } else {
237 return false;
238 }
239 }
240 };
241
242 /**
243 * Sets the value of a property and queues its event to execute. If the event is already scheduled to execute, it is
244 * moved from its current position to the end of the queue.
245 * @method queueProperty
246 * @param {String} keyThe name of the property
247 * @param {String} valueThe value to set the property to
248 * @return {Boolean} true, if the set was successful, false if it failed.
249 */
250 this.queueProperty = function(key, value) {
251 key = key.toLowerCase();
252
253 var property = config[key];
254
255 if (typeof property != 'undefined' && property.event) {
256 if (typeof value != 'undefined' && property.validator && ! property.validator(value)) { // validator
257 return false;
258 } else {
259
260 if (typeof value != 'undefined') {
261 property.value = value;
262 } else {
263 value = property.value;
264 }
265
266 var foundDuplicate = false;
267
268 for (var i=0;i<eventQueue.length;i++) {
269 var queueItem = eventQueue[i];
270
271 if (queueItem) {
272 var queueItemKey = queueItem[0];
273 var queueItemValue = queueItem[1];
274
275 if (queueItemKey.toLowerCase() == key) {
276 // found a dupe... push to end of queue, null current item, and break
277 eventQueue[i] = null;
278 eventQueue.push([key, (typeof value != 'undefined' ? value : queueItemValue)]);
279 foundDuplicate = true;
280 break;
281 }
282 }
283 }
284
285 if (! foundDuplicate && typeof value != 'undefined') { // this is a refire, or a new property in the queue
286 eventQueue.push([key, value]);
287 }
288 }
289
290 if (property.supercedes) {
291 for (var s=0;s<property.supercedes.length;s++) {
292 var supercedesCheck = property.supercedes[s];
293
294 for (var q=0;q<eventQueue.length;q++) {
295 var queueItemCheck = eventQueue[q];
296
297 if (queueItemCheck) {
298 var queueItemCheckKey = queueItemCheck[0];
299 var queueItemCheckValue = queueItemCheck[1];
300
301 if ( queueItemCheckKey.toLowerCase() == supercedesCheck.toLowerCase() ) {
302 eventQueue.push([queueItemCheckKey, queueItemCheckValue]);
303 eventQueue[q] = null;
304 break;
305 }
306 }
307 }
308 }
309 }
310
311 return true;
312 } else {
313 return false;
314 }
315 };
316
317 /**
318 * Fires the event for a property using the property's current value.
319 * @method refireEvent
320 * @param {String} keyThe name of the property
321 */
322 this.refireEvent = function(key) {
323 key = key.toLowerCase();
324
325 var property = config[key];
326 if (typeof property != 'undefined' && property.event && typeof property.value != 'undefined') {
327 if (this.queueInProgress) {
328 this.queueProperty(key);
329 } else {
330 fireEvent(key, property.value);
331 }
332 }
333 };
334
335 /**
336 * Applies a key-value Object literal to the configuration, replacing any existing values, and queueing the property events.
337 * Although the values will be set, fireQueue() must be called for their associated events to execute.
338 * @method applyConfig
339 * @param {Object} userConfigThe configuration Object literal
340 * @param {Boolean} init When set to true, the initialConfig will be set to the userConfig passed in, so that calling a reset will reset the properties to the passed values.
341 */
342 this.applyConfig = function(userConfig, init) {
343 if (init) {
344 initialConfig = userConfig;
345 }
346 for (var prop in userConfig) {
347 this.queueProperty(prop, userConfig[prop]);
348 }
349 };
350
351 /**
352 * Refires the events for all configuration properties using their current values.
353 * @method refresh
354 */
355 this.refresh = function() {
356 for (var prop in config) {
357 this.refireEvent(prop);
358 }
359 };
360
361 /**
362 * Fires the normalized list of queued property change events
363 * @method fireQueue
364 */
365 this.fireQueue = function() {
366 this.queueInProgress = true;
367 for (var i=0;i<eventQueue.length;i++) {
368 var queueItem = eventQueue[i];
369 if (queueItem) {
370 var key = queueItem[0];
371 var value = queueItem[1];
372
373 var property = config[key];
374 property.value = value;
375
376 fireEvent(key,value);
377 }
378 }
379
380 this.queueInProgress = false;
381 eventQueue = [];
382 };
383
384 /**
385 * Subscribes an external handler to the change event for any given property.
386 * @method subscribeToConfigEvent
387 * @param {String} key The property name
388 * @param {Function} handler The handler function to use subscribe to the property's event
389 * @param {Object} obj The Object to use for scoping the event handler (see CustomEvent documentation)
390 * @param {Boolean} overrideOptional. If true, will override "this" within the handler to map to the scope Object passed into the method.
391 * @return {Boolean} True, if the subscription was successful, otherwise false.
392 */
393 this.subscribeToConfigEvent = function(key, handler, obj, override) {
394 key = key.toLowerCase();
395
396 var property = config[key];
397 if (typeof property != 'undefined' && property.event) {
398 if (! YAHOO.util.Config.alreadySubscribed(property.event, handler, obj)) {
399 property.event.subscribe(handler, obj, override);
400 }
401 return true;
402 } else {
403 return false;
404 }
405 };
406
407 /**
408 * Unsubscribes an external handler from the change event for any given property.
409 * @method unsubscribeFromConfigEvent
410 * @param {String} key The property name
411 * @param {Function} handler The handler function to use subscribe to the property's event
412 * @param {Object} obj The Object to use for scoping the event handler (see CustomEvent documentation)
413 * @return {Boolean} True, if the unsubscription was successful, otherwise false.
414 */
415 this.unsubscribeFromConfigEvent = function(key, handler, obj) {
416 key = key.toLowerCase();
417
418 var property = config[key];
419 if (typeof property != 'undefined' && property.event) {
420 return property.event.unsubscribe(handler, obj);
421 } else {
422 return false;
423 }
424 };
425
426 /**
427 * Returns a string representation of the Config object
428 * @method toString
429 * @return {String}The Config object in string format.
430 */
431 this.toString = function() {
432 var output = "Config";
433 if (this.owner) {
434 output += " [" + this.owner.toString() + "]";
435 }
436 return output;
437 };
438
439 /**
440 * Returns a string representation of the Config object's current CustomEvent queue
441 * @method outputEventQueue
442 * @return {String}The string list of CustomEvents currently queued for execution
443 */
444 this.outputEventQueue = function() {
445 var output = "";
446 for (var q=0;q<eventQueue.length;q++) {
447 var queueItem = eventQueue[q];
448 if (queueItem) {
449 output += queueItem[0] + "=" + queueItem[1] + ", ";
450 }
451 }
452 return output;
453 };
454};
455
456/**
457* Checks to determine if a particular function/Object pair are already subscribed to the specified CustomEvent
458* @method YAHOO.util.Config.alreadySubscribed
459* @static
460 * @param {YAHOO.util.CustomEvent} evtThe CustomEvent for which to check the subscriptions
461 * @param {Function} fnThe function to look for in the subscribers list
462 * @param {Object} objThe execution scope Object for the subscription
463 * @return {Boolean}true, if the function/Object pair is already subscribed to the CustomEvent passed in
464*/
465YAHOO.util.Config.alreadySubscribed = function(evt, fn, obj) {
466 for (var e=0;e<evt.subscribers.length;e++) {
467 var subsc = evt.subscribers[e];
468 if (subsc && subsc.obj == obj && subsc.fn == fn) {
469 return true;
470 }
471 }
472 return false;
473};
474
475/**
476* The Container family of components is designed to enable developers to create different kinds of content-containing modules on the web. Module and Overlay are the most basic containers, and they can be used directly or extended to build custom containers. Also part of the Container family are four UI controls that extend Module and Overlay: Tooltip, Panel, Dialog, and SimpleDialog.
477* @module Container
478* @requires yahoo,dom,event,dragdrop,animation
479*/
480
481/**
482* Module is a JavaScript representation of the Standard Module Format. Standard Module Format is a simple standard for markup containers where child nodes representing the header, body, and footer of the content are denoted using the CSS classes "hd", "bd", and "ft" respectively. Module is the base class for all other classes in the YUI Container package.
483* @class Module
484* @namespace YAHOO.widget
485* @constructor
486 * @param {String} el The element ID representing the Module <em>OR</em>
487 * @param {HTMLElement} el The element representing the Module
488 * @param {Object} userConfigThe configuration Object literal containing the configuration that should be set for this module. See configuration documentation for more details.
489*/
490YAHOO.widget.Module = function(el, userConfig) {
491 if (el) {
492 this.init(el, userConfig);
493 }
494};
495
496/**
497* Constant representing the prefix path to use for non-secure images
498* @property YAHOO.widget.Module.IMG_ROOT
499* @static
500* @final
501* @type String
502*/
503YAHOO.widget.Module.IMG_ROOT = "http://us.i1.yimg.com/us.yimg.com/i/";
504
505/**
506* Constant representing the prefix path to use for securely served images
507* @property YAHOO.widget.Module.IMG_ROOT_SSL
508* @static
509* @final
510* @type String
511*/
512YAHOO.widget.Module.IMG_ROOT_SSL = "https://a248.e.akamai.net/sec.yimg.com/i/";
513
514/**
515* Constant for the default CSS class name that represents a Module
516* @property YAHOO.widget.Module.CSS_MODULE
517* @static
518* @final
519* @type String
520*/
521YAHOO.widget.Module.CSS_MODULE = "module";
522
523/**
524* Constant representing the module header
525* @property YAHOO.widget.Module.CSS_HEADER
526* @static
527* @final
528* @type String
529*/
530YAHOO.widget.Module.CSS_HEADER = "hd";
531
532/**
533* Constant representing the module body
534* @property YAHOO.widget.Module.CSS_BODY
535* @static
536* @final
537* @type String
538*/
539YAHOO.widget.Module.CSS_BODY = "bd";
540
541/**
542* Constant representing the module footer
543* @property YAHOO.widget.Module.CSS_FOOTER
544* @static
545* @final
546* @type String
547*/
548YAHOO.widget.Module.CSS_FOOTER = "ft";
549
550/**
551* Constant representing the url for the "src" attribute of the iframe used to monitor changes to the browser's base font size
552* @property YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL
553* @static
554* @final
555* @type String
556*/
557YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL = "javascript:false;";
558
559YAHOO.widget.Module.prototype = {
560 /**
561 * The class's constructor function
562 * @property contructor
563 * @type Function
564 */
565 constructor : YAHOO.widget.Module,
566
567 /**
568 * The main module element that contains the header, body, and footer
569 * @property element
570 * @type HTMLElement
571 */
572 element : null,
573
574 /**
575 * The header element, denoted with CSS class "hd"
576 * @property header
577 * @type HTMLElement
578 */
579 header : null,
580
581 /**
582 * The body element, denoted with CSS class "bd"
583 * @property body
584 * @type HTMLElement
585 */
586 body : null,
587
588 /**
589 * The footer element, denoted with CSS class "ft"
590 * @property footer
591 * @type HTMLElement
592 */
593 footer : null,
594
595 /**
596 * The id of the element
597 * @property id
598 * @type String
599 */
600 id : null,
601
602 /**
603 * The String representing the image root
604 * @property imageRoot
605 * @type String
606 */
607 imageRoot : YAHOO.widget.Module.IMG_ROOT,
608
609 /**
610 * Initializes the custom events for Module which are fired automatically at appropriate times by the Module class.
611 * @method initEvents
612 */
613 initEvents : function() {
614
615 /**
616 * CustomEvent fired prior to class initalization.
617 * @event beforeInitEvent
618 * @param {class} classRefclass reference of the initializing class, such as this.beforeInitEvent.fire(YAHOO.widget.Module)
619 */
620 this.beforeInitEvent = new YAHOO.util.CustomEvent("beforeInit");
621
622 /**
623 * CustomEvent fired after class initalization.
624 * @event initEvent
625 * @param {class} classRefclass reference of the initializing class, such as this.beforeInitEvent.fire(YAHOO.widget.Module)
626 */
627 this.initEvent = new YAHOO.util.CustomEvent("init");
628
629 /**
630 * CustomEvent fired when the Module is appended to the DOM
631 * @event appendEvent
632 */
633 this.appendEvent = new YAHOO.util.CustomEvent("append");
634
635 /**
636 * CustomEvent fired before the Module is rendered
637 * @event beforeRenderEvent
638 */
639 this.beforeRenderEvent = new YAHOO.util.CustomEvent("beforeRender");
640
641 /**
642 * CustomEvent fired after the Module is rendered
643 * @event renderEvent
644 */
645 this.renderEvent = new YAHOO.util.CustomEvent("render");
646
647 /**
648 * CustomEvent fired when the header content of the Module is modified
649 * @event changeHeaderEvent
650 * @param {String/HTMLElement} contentString/element representing the new header content
651 */
652 this.changeHeaderEvent = new YAHOO.util.CustomEvent("changeHeader");
653
654 /**
655 * CustomEvent fired when the body content of the Module is modified
656 * @event changeBodyEvent
657 * @param {String/HTMLElement} contentString/element representing the new body content
658 */
659 this.changeBodyEvent = new YAHOO.util.CustomEvent("changeBody");
660
661 /**
662 * CustomEvent fired when the footer content of the Module is modified
663 * @event changeFooterEvent
664 * @param {String/HTMLElement} contentString/element representing the new footer content
665 */
666 this.changeFooterEvent = new YAHOO.util.CustomEvent("changeFooter");
667
668 /**
669 * CustomEvent fired when the content of the Module is modified
670 * @event changeContentEvent
671 */
672 this.changeContentEvent = new YAHOO.util.CustomEvent("changeContent");
673
674 /**
675 * CustomEvent fired when the Module is destroyed
676 * @event destroyEvent
677 */
678 this.destroyEvent = new YAHOO.util.CustomEvent("destroy");
679
680 /**
681 * CustomEvent fired before the Module is shown
682 * @event beforeShowEvent
683 */
684 this.beforeShowEvent = new YAHOO.util.CustomEvent("beforeShow");
685
686 /**
687 * CustomEvent fired after the Module is shown
688 * @event showEvent
689 */
690 this.showEvent = new YAHOO.util.CustomEvent("show");
691
692 /**
693 * CustomEvent fired before the Module is hidden
694 * @event beforeHideEvent
695 */
696 this.beforeHideEvent = new YAHOO.util.CustomEvent("beforeHide");
697
698 /**
699 * CustomEvent fired after the Module is hidden
700 * @event hideEvent
701 */
702 this.hideEvent = new YAHOO.util.CustomEvent("hide");
703 },
704
705 /**
706 * String representing the current user-agent platform
707 * @property platform
708 * @type String
709 */
710 platform : function() {
711 var ua = navigator.userAgent.toLowerCase();
712 if (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1) {
713 return "windows";
714 } else if (ua.indexOf("macintosh") != -1) {
715 return "mac";
716 } else {
717 return false;
718 }
719 }(),
720
721 /**
722 * String representing the current user-agent browser
723 * @property browser
724 * @type String
725 */
726 browser : function() {
727 var ua = navigator.userAgent.toLowerCase();
728 if (ua.indexOf('opera')!=-1) { // Opera (check first in case of spoof)
729 return 'opera';
730 } else if (ua.indexOf('msie 7')!=-1) { // IE7
731 return 'ie7';
732 } else if (ua.indexOf('msie') !=-1) { // IE
733 return 'ie';
734 } else if (ua.indexOf('safari')!=-1) { // Safari (check before Gecko because it includes "like Gecko")
735 return 'safari';
736 } else if (ua.indexOf('gecko') != -1) { // Gecko
737 return 'gecko';
738 } else {
739 return false;
740 }
741 }(),
742
743 /**
744 * Boolean representing whether or not the current browsing context is secure (https)
745 * @property isSecure
746 * @type Boolean
747 */
748 isSecure : function() {
749 if (window.location.href.toLowerCase().indexOf("https") === 0) {
750 return true;
751 } else {
752 return false;
753 }
754 }(),
755
756 /**
757 * Initializes the custom events for Module which are fired automatically at appropriate times by the Module class.
758 */
759 initDefaultConfig : function() {
760 // Add properties //
761
762 /**
763 * Specifies whether the Module is visible on the page.
764 * @config visible
765 * @type Boolean
766 * @default true
767 */
768 this.cfg.addProperty("visible", { value:true, handler:this.configVisible, validator:this.cfg.checkBoolean } );
769
770 /**
771 * Object or array of objects representing the ContainerEffect classes that are active for animating the container.
772 * @config effect
773 * @type Object
774 * @default null
775 */
776 this.cfg.addProperty("effect", { suppressEvent:true, supercedes:["visible"] } );
777
778 /**
779 * Specifies whether to create a special proxy iframe to monitor for user font resizing in the document
780 * @config monitorresize
781 * @type Boolean
782 * @default true
783 */
784 this.cfg.addProperty("monitorresize", { value:true, handler:this.configMonitorResize } );
785 },
786
787 /**
788 * The Module class's initialization method, which is executed for Module and all of its subclasses. This method is automatically called by the constructor, and sets up all DOM references for pre-existing markup, and creates required markup if it is not already present.
789 * @method init
790 * @param {String} elThe element ID representing the Module <em>OR</em>
791 * @param {HTMLElement} elThe element representing the Module
792 * @param {Object} userConfigThe configuration Object literal containing the configuration that should be set for this module. See configuration documentation for more details.
793 */
794 init : function(el, userConfig) {
795
796 this.initEvents();
797
798 this.beforeInitEvent.fire(YAHOO.widget.Module);
799
800 /**
801 * The Module's Config object used for monitoring configuration properties.
802 * @property cfg
803 * @type YAHOO.util.Config
804 */
805 this.cfg = new YAHOO.util.Config(this);
806
807 if (this.isSecure) {
808 this.imageRoot = YAHOO.widget.Module.IMG_ROOT_SSL;
809 }
810
811 if (typeof el == "string") {
812 var elId = el;
813
814 el = document.getElementById(el);
815 if (! el) {
816 el = document.createElement("DIV");
817 el.id = elId;
818 }
819 }
820
821 this.element = el;
822
823 if (el.id) {
824 this.id = el.id;
825 }
826
827 var childNodes = this.element.childNodes;
828
829 if (childNodes) {
830 for (var i=0;i<childNodes.length;i++) {
831 var child = childNodes[i];
832 switch (child.className) {
833 case YAHOO.widget.Module.CSS_HEADER:
834 this.header = child;
835 break;
836 case YAHOO.widget.Module.CSS_BODY:
837 this.body = child;
838 break;
839 case YAHOO.widget.Module.CSS_FOOTER:
840 this.footer = child;
841 break;
842 }
843 }
844 }
845
846 this.initDefaultConfig();
847
848 YAHOO.util.Dom.addClass(this.element, YAHOO.widget.Module.CSS_MODULE);
849
850 if (userConfig) {
851 this.cfg.applyConfig(userConfig, true);
852 }
853
854 // Subscribe to the fireQueue() method of Config so that any queued configuration changes are
855 // excecuted upon render of the Module
856 if (! YAHOO.util.Config.alreadySubscribed(this.renderEvent, this.cfg.fireQueue, this.cfg)) {
857 this.renderEvent.subscribe(this.cfg.fireQueue, this.cfg, true);
858 }
859
860 this.initEvent.fire(YAHOO.widget.Module);
861 },
862
863 /**
864 * Initialized an empty IFRAME that is placed out of the visible area that can be used to detect text resize.
865 * @method initResizeMonitor
866 */
867 initResizeMonitor : function() {
868
869 if(this.browser != "opera") {
870
871 var resizeMonitor = document.getElementById("_yuiResizeMonitor");
872
873 if (! resizeMonitor) {
874
875 resizeMonitor = document.createElement("iframe");
876
877 var bIE = (this.browser.indexOf("ie") === 0);
878
879 if(this.isSecure &&
880 YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL &&
881 bIE) {
882
883 resizeMonitor.src =
884 YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL;
885
886 }
887
888 resizeMonitor.id = "_yuiResizeMonitor";
889 resizeMonitor.style.visibility = "hidden";
890
891 document.body.appendChild(resizeMonitor);
892
893 resizeMonitor.style.width = "10em";
894 resizeMonitor.style.height = "10em";
895 resizeMonitor.style.position = "absolute";
896
897 var nLeft = -1 * resizeMonitor.offsetWidth,
898 nTop = -1 * resizeMonitor.offsetHeight;
899
900 resizeMonitor.style.top = nTop + "px";
901 resizeMonitor.style.left = nLeft + "px";
902 resizeMonitor.style.borderStyle = "none";
903 resizeMonitor.style.borderWidth = "0";
904 YAHOO.util.Dom.setStyle(resizeMonitor, "opacity", "0");
905
906 resizeMonitor.style.visibility = "visible";
907
908 if(!bIE) {
909
910 var doc = resizeMonitor.contentWindow.document;
911
912 doc.open();
913 doc.close();
914
915 }
916
917 }
918
919 if(resizeMonitor && resizeMonitor.contentWindow) {
920
921 this.resizeMonitor = resizeMonitor;
922
923 YAHOO.util.Event.addListener(this.resizeMonitor.contentWindow, "resize", this.onDomResize, this, true);
924
925 }
926
927 }
928
929 },
930
931 /**
932 * Event handler fired when the resize monitor element is resized.
933 * @method onDomResize
934 * @param {DOMEvent} eThe DOM resize event
935 * @param {Object} objThe scope object passed to the handler
936 */
937 onDomResize : function(e, obj) {
938
939 var nLeft = -1 * this.resizeMonitor.offsetWidth,
940 nTop = -1 * this.resizeMonitor.offsetHeight;
941
942 this.resizeMonitor.style.top = nTop + "px";
943 this.resizeMonitor.style.left = nLeft + "px";
944
945 },
946
947 /**
948 * Sets the Module's header content to the HTML specified, or appends the passed element to the header. If no header is present, one will be automatically created.
949 * @method setHeader
950 * @param {String} headerContentThe HTML used to set the header <em>OR</em>
951 * @param {HTMLElement} headerContentThe HTMLElement to append to the header
952 */
953 setHeader : function(headerContent) {
954 if (! this.header) {
955 this.header = document.createElement("DIV");
956 this.header.className = YAHOO.widget.Module.CSS_HEADER;
957 }
958
959 if (typeof headerContent == "string") {
960 this.header.innerHTML = headerContent;
961 } else {
962 this.header.innerHTML = "";
963 this.header.appendChild(headerContent);
964 }
965
966 this.changeHeaderEvent.fire(headerContent);
967 this.changeContentEvent.fire();
968 },
969
970 /**
971 * Appends the passed element to the header. If no header is present, one will be automatically created.
972 * @method appendToHeader
973 * @param {HTMLElement} elementThe element to append to the header
974 */
975 appendToHeader : function(element) {
976 if (! this.header) {
977 this.header = document.createElement("DIV");
978 this.header.className = YAHOO.widget.Module.CSS_HEADER;
979 }
980
981 this.header.appendChild(element);
982 this.changeHeaderEvent.fire(element);
983 this.changeContentEvent.fire();
984 },
985
986 /**
987 * Sets the Module's body content to the HTML specified, or appends the passed element to the body. If no body is present, one will be automatically created.
988 * @method setBody
989 * @param {String} bodyContentThe HTML used to set the body <em>OR</em>
990 * @param {HTMLElement} bodyContentThe HTMLElement to append to the body
991 */
992 setBody : function(bodyContent) {
993 if (! this.body) {
994 this.body = document.createElement("DIV");
995 this.body.className = YAHOO.widget.Module.CSS_BODY;
996 }
997
998 if (typeof bodyContent == "string")
999 {
1000 this.body.innerHTML = bodyContent;
1001 } else {
1002 this.body.innerHTML = "";
1003 this.body.appendChild(bodyContent);
1004 }
1005
1006 this.changeBodyEvent.fire(bodyContent);
1007 this.changeContentEvent.fire();
1008 },
1009
1010 /**
1011 * Appends the passed element to the body. If no body is present, one will be automatically created.
1012 * @method appendToBody
1013 * @param {HTMLElement} elementThe element to append to the body
1014 */
1015 appendToBody : function(element) {
1016 if (! this.body) {
1017 this.body = document.createElement("DIV");
1018 this.body.className = YAHOO.widget.Module.CSS_BODY;
1019 }
1020
1021 this.body.appendChild(element);
1022 this.changeBodyEvent.fire(element);
1023 this.changeContentEvent.fire();
1024 },
1025
1026 /**
1027 * Sets the Module's footer content to the HTML specified, or appends the passed element to the footer. If no footer is present, one will be automatically created.
1028 * @method setFooter
1029 * @param {String} footerContentThe HTML used to set the footer <em>OR</em>
1030 * @param {HTMLElement} footerContentThe HTMLElement to append to the footer
1031 */
1032 setFooter : function(footerContent) {
1033 if (! this.footer) {
1034 this.footer = document.createElement("DIV");
1035 this.footer.className = YAHOO.widget.Module.CSS_FOOTER;
1036 }
1037
1038 if (typeof footerContent == "string") {
1039 this.footer.innerHTML = footerContent;
1040 } else {
1041 this.footer.innerHTML = "";
1042 this.footer.appendChild(footerContent);
1043 }
1044
1045 this.changeFooterEvent.fire(footerContent);
1046 this.changeContentEvent.fire();
1047 },
1048
1049 /**
1050 * Appends the passed element to the footer. If no footer is present, one will be automatically created.
1051 * @method appendToFooter
1052 * @param {HTMLElement} elementThe element to append to the footer
1053 */
1054 appendToFooter : function(element) {
1055 if (! this.footer) {
1056 this.footer = document.createElement("DIV");
1057 this.footer.className = YAHOO.widget.Module.CSS_FOOTER;
1058 }
1059
1060 this.footer.appendChild(element);
1061 this.changeFooterEvent.fire(element);
1062 this.changeContentEvent.fire();
1063 },
1064
1065 /**
1066 * Renders the Module by inserting the elements that are not already in the main Module into their correct places. Optionally appends the Module to the specified node prior to the render's execution. NOTE: For Modules without existing markup, the appendToNode argument is REQUIRED. If this argument is ommitted and the current element is not present in the document, the function will return false, indicating that the render was a failure.
1067 * @method render
1068 * @param {String} appendToNodeThe element id to which the Module should be appended to prior to rendering <em>OR</em>
1069 * @param {HTMLElement} appendToNodeThe element to which the Module should be appended to prior to rendering
1070 * @param {HTMLElement} moduleElementOPTIONAL. The element that represents the actual Standard Module container.
1071 * @return {Boolean} Success or failure of the render
1072 */
1073 render : function(appendToNode, moduleElement) {
1074 this.beforeRenderEvent.fire();
1075
1076 if (! moduleElement) {
1077 moduleElement = this.element;
1078 }
1079
1080 var me = this;
1081 var appendTo = function(element) {
1082 if (typeof element == "string") {
1083 element = document.getElementById(element);
1084 }
1085
1086 if (element) {
1087 element.appendChild(me.element);
1088 me.appendEvent.fire();
1089 }
1090 };
1091
1092 if (appendToNode) {
1093 appendTo(appendToNode);
1094 } else { // No node was passed in. If the element is not pre-marked up, this fails
1095 if (! YAHOO.util.Dom.inDocument(this.element)) {
1096 return false;
1097 }
1098 }
1099
1100 // Need to get everything into the DOM if it isn't already
1101
1102 if (this.header && ! YAHOO.util.Dom.inDocument(this.header)) {
1103 // There is a header, but it's not in the DOM yet... need to add it
1104 var firstChild = moduleElement.firstChild;
1105 if (firstChild) { // Insert before first child if exists
1106 moduleElement.insertBefore(this.header, firstChild);
1107 } else { // Append to empty body because there are no children
1108 moduleElement.appendChild(this.header);
1109 }
1110 }
1111
1112 if (this.body && ! YAHOO.util.Dom.inDocument(this.body)) {
1113 // There is a body, but it's not in the DOM yet... need to add it
1114 if (this.footer && YAHOO.util.Dom.isAncestor(this.moduleElement, this.footer)) { // Insert before footer if exists in DOM
1115 moduleElement.insertBefore(this.body, this.footer);
1116 } else { // Append to element because there is no footer
1117 moduleElement.appendChild(this.body);
1118 }
1119 }
1120
1121 if (this.footer && ! YAHOO.util.Dom.inDocument(this.footer)) {
1122 // There is a footer, but it's not in the DOM yet... need to add it
1123 moduleElement.appendChild(this.footer);
1124 }
1125
1126 this.renderEvent.fire();
1127 return true;
1128 },
1129
1130 /**
1131 * Removes the Module element from the DOM and sets all child elements to null.
1132 * @method destroy
1133 */
1134 destroy : function() {
1135 if (this.element) {
1136 var parent = this.element.parentNode;
1137 }
1138 if (parent) {
1139 parent.removeChild(this.element);
1140 }
1141
1142 this.element = null;
1143 this.header = null;
1144 this.body = null;
1145 this.footer = null;
1146
1147 this.destroyEvent.fire();
1148 },
1149
1150 /**
1151 * Shows the Module element by setting the visible configuration property to true. Also fires two events: beforeShowEvent prior to the visibility change, and showEvent after.
1152 * @method show
1153 */
1154 show : function() {
1155 this.cfg.setProperty("visible", true);
1156 },
1157
1158 /**
1159 * Hides the Module element by setting the visible configuration property to false. Also fires two events: beforeHideEvent prior to the visibility change, and hideEvent after.
1160 * @method hide
1161 */
1162 hide : function() {
1163 this.cfg.setProperty("visible", false);
1164 },
1165
1166 // BUILT-IN EVENT HANDLERS FOR MODULE //
1167
1168 /**
1169 * Default event handler for changing the visibility property of a Module. By default, this is achieved by switching the "display" style between "block" and "none".
1170 * This method is responsible for firing showEvent and hideEvent.
1171 * @param {String} typeThe CustomEvent type (usually the property name)
1172 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1173 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1174 * @method configVisible
1175 */
1176 configVisible : function(type, args, obj) {
1177 var visible = args[0];
1178 if (visible) {
1179 this.beforeShowEvent.fire();
1180 YAHOO.util.Dom.setStyle(this.element, "display", "block");
1181 this.showEvent.fire();
1182 } else {
1183 this.beforeHideEvent.fire();
1184 YAHOO.util.Dom.setStyle(this.element, "display", "none");
1185 this.hideEvent.fire();
1186 }
1187 },
1188
1189 /**
1190 * Default event handler for the "monitorresize" configuration property
1191 * @param {String} typeThe CustomEvent type (usually the property name)
1192 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1193 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1194 * @method configMonitorResize
1195 */
1196 configMonitorResize : function(type, args, obj) {
1197 var monitor = args[0];
1198 if (monitor) {
1199 this.initResizeMonitor();
1200 } else {
1201 YAHOO.util.Event.removeListener(this.resizeMonitor, "resize", this.onDomResize);
1202 this.resizeMonitor = null;
1203 }
1204 }
1205};
1206
1207/**
1208* Returns a String representation of the Object.
1209* @method toString
1210 * @return {String}The string representation of the Module
1211*/
1212YAHOO.widget.Module.prototype.toString = function() {
1213 return "Module " + this.id;
1214};
1215
1216/**
1217* Overlay is a Module that is absolutely positioned above the page flow. It has convenience methods for positioning and sizing, as well as options for controlling zIndex and constraining the Overlay's position to the current visible viewport. Overlay also contains a dynamicly generated IFRAME which is placed beneath it for Internet Explorer 6 and 5.x so that it will be properly rendered above SELECT elements.
1218* @class Overlay
1219* @namespace YAHOO.widget
1220* @extends YAHOO.widget.Module
1221 * @param {String} elThe element ID representing the Overlay <em>OR</em>
1222 * @param {HTMLElement} elThe element representing the Overlay
1223 * @param {Object} userConfigThe configuration object literal containing 10/23/2006the configuration that should be set for this Overlay. See configuration documentation for more details.
1224* @constructor
1225*/
1226YAHOO.widget.Overlay = function(el, userConfig) {
1227 YAHOO.widget.Overlay.superclass.constructor.call(this, el, userConfig);
1228};
1229
1230YAHOO.extend(YAHOO.widget.Overlay, YAHOO.widget.Module);
1231
1232/**
1233* The URL that will be placed in the iframe
1234* @property YAHOO.widget.Overlay.IFRAME_SRC
1235* @static
1236* @final
1237* @type String
1238*/
1239YAHOO.widget.Overlay.IFRAME_SRC = "javascript:false;"
1240
1241/**
1242* Constant representing the top left corner of an element, used for configuring the context element alignment
1243* @property YAHOO.widget.Overlay.TOP_LEFT
1244* @static
1245* @final
1246* @type String
1247*/
1248YAHOO.widget.Overlay.TOP_LEFT = "tl";
1249
1250/**
1251* Constant representing the top right corner of an element, used for configuring the context element alignment
1252* @property YAHOO.widget.Overlay.TOP_RIGHT
1253* @static
1254* @final
1255* @type String
1256*/
1257YAHOO.widget.Overlay.TOP_RIGHT = "tr";
1258
1259/**
1260* Constant representing the top bottom left corner of an element, used for configuring the context element alignment
1261* @property YAHOO.widget.Overlay.BOTTOM_LEFT
1262* @static
1263* @final
1264* @type String
1265*/
1266YAHOO.widget.Overlay.BOTTOM_LEFT = "bl";
1267
1268/**
1269* Constant representing the bottom right corner of an element, used for configuring the context element alignment
1270* @property YAHOO.widget.Overlay.BOTTOM_RIGHT
1271* @static
1272* @final
1273* @type String
1274*/
1275YAHOO.widget.Overlay.BOTTOM_RIGHT = "br";
1276
1277/**
1278* Constant representing the default CSS class used for an Overlay
1279* @property YAHOO.widget.Overlay.CSS_OVERLAY
1280* @static
1281* @final
1282* @type String
1283*/
1284YAHOO.widget.Overlay.CSS_OVERLAY = "overlay";
1285
1286/**
1287* The Overlay initialization method, which is executed for Overlay and all of its subclasses. This method is automatically called by the constructor, and sets up all DOM references for pre-existing markup, and creates required markup if it is not already present.
1288* @method init
1289 * @param {String} elThe element ID representing the Overlay <em>OR</em>
1290 * @param {HTMLElement} elThe element representing the Overlay
1291 * @param {Object} userConfigThe configuration object literal containing the configuration that should be set for this Overlay. See configuration documentation for more details.
1292*/
1293YAHOO.widget.Overlay.prototype.init = function(el, userConfig) {
1294 YAHOO.widget.Overlay.superclass.init.call(this, el/*, userConfig*/); // Note that we don't pass the user config in here yet because we only want it executed once, at the lowest subclass level
1295
1296 this.beforeInitEvent.fire(YAHOO.widget.Overlay);
1297
1298 YAHOO.util.Dom.addClass(this.element, YAHOO.widget.Overlay.CSS_OVERLAY);
1299
1300 if (userConfig) {
1301 this.cfg.applyConfig(userConfig, true);
1302 }
1303
1304 if (this.platform == "mac" && this.browser == "gecko") {
1305 if (! YAHOO.util.Config.alreadySubscribed(this.showEvent,this.showMacGeckoScrollbars,this)) {
1306 this.showEvent.subscribe(this.showMacGeckoScrollbars,this,true);
1307 }
1308 if (! YAHOO.util.Config.alreadySubscribed(this.hideEvent,this.hideMacGeckoScrollbars,this)) {
1309 this.hideEvent.subscribe(this.hideMacGeckoScrollbars,this,true);
1310 }
1311 }
1312
1313 this.initEvent.fire(YAHOO.widget.Overlay);
1314};
1315
1316/**
1317* Initializes the custom events for Overlay which are fired automatically at appropriate times by the Overlay class.
1318* @method initEvents
1319*/
1320YAHOO.widget.Overlay.prototype.initEvents = function() {
1321 YAHOO.widget.Overlay.superclass.initEvents.call(this);
1322
1323 /**
1324 * CustomEvent fired before the Overlay is moved.
1325 * @event beforeMoveEvent
1326 * @param {Number} xx coordinate
1327 * @param {Number} yy coordinate
1328 */
1329 this.beforeMoveEvent = new YAHOO.util.CustomEvent("beforeMove", this);
1330
1331 /**
1332 * CustomEvent fired after the Overlay is moved.
1333 * @event moveEvent
1334 * @param {Number} xx coordinate
1335 * @param {Number} yy coordinate
1336 */
1337 this.moveEvent = new YAHOO.util.CustomEvent("move", this);
1338};
1339
1340/**
1341* Initializes the class's configurable properties which can be changed using the Overlay's Config object (cfg).
1342* @method initDefaultConfig
1343*/
1344YAHOO.widget.Overlay.prototype.initDefaultConfig = function() {
1345 YAHOO.widget.Overlay.superclass.initDefaultConfig.call(this);
1346
1347 // Add overlay config properties //
1348
1349 /**
1350 * The absolute x-coordinate position of the Overlay
1351 * @config x
1352 * @type Number
1353 * @default null
1354 */
1355 this.cfg.addProperty("x", { handler:this.configX, validator:this.cfg.checkNumber, suppressEvent:true, supercedes:["iframe"] } );
1356
1357 /**
1358 * The absolute y-coordinate position of the Overlay
1359 * @config y
1360 * @type Number
1361 * @default null
1362 */
1363 this.cfg.addProperty("y", { handler:this.configY, validator:this.cfg.checkNumber, suppressEvent:true, supercedes:["iframe"] } );
1364
1365 /**
1366 * An array with the absolute x and y positions of the Overlay
1367 * @config xy
1368 * @type Number[]
1369 * @default null
1370 */
1371 this.cfg.addProperty("xy",{ handler:this.configXY, suppressEvent:true, supercedes:["iframe"] } );
1372
1373 /**
1374 * The array of context arguments for context-sensitive positioning. The format is: [id or element, element corner, context corner]. For example, setting this property to ["img1", "tl", "bl"] would align the Overlay's top left corner to the context element's bottom left corner.
1375 * @config context
1376 * @type Array
1377 * @default null
1378 */
1379 this.cfg.addProperty("context",{ handler:this.configContext, suppressEvent:true, supercedes:["iframe"] } );
1380
1381 /**
1382 * True if the Overlay should be anchored to the center of the viewport.
1383 * @config fixedcenter
1384 * @type Boolean
1385 * @default false
1386 */
1387 this.cfg.addProperty("fixedcenter", { value:false, handler:this.configFixedCenter, validator:this.cfg.checkBoolean, supercedes:["iframe","visible"] } );
1388
1389 /**
1390 * CSS width of the Overlay.
1391 * @config width
1392 * @type String
1393 * @default null
1394 */
1395 this.cfg.addProperty("width", { handler:this.configWidth, suppressEvent:true, supercedes:["iframe"] } );
1396
1397 /**
1398 * CSS height of the Overlay.
1399 * @config height
1400 * @type String
1401 * @default null
1402 */
1403 this.cfg.addProperty("height", { handler:this.configHeight, suppressEvent:true, supercedes:["iframe"] } );
1404
1405 /**
1406 * CSS z-index of the Overlay.
1407 * @config zIndex
1408 * @type Number
1409 * @default null
1410 */
1411 this.cfg.addProperty("zIndex", { value:null, handler:this.configzIndex } );
1412
1413 /**
1414 * True if the Overlay should be prevented from being positioned out of the viewport.
1415 * @config constraintoviewport
1416 * @type Boolean
1417 * @default false
1418 */
1419 this.cfg.addProperty("constraintoviewport", { value:false, handler:this.configConstrainToViewport, validator:this.cfg.checkBoolean, supercedes:["iframe","x","y","xy"] } );
1420
1421 /**
1422 * True if the Overlay should have an IFRAME shim (for correcting the select z-index bug in IE6 and below).
1423 * @config iframe
1424 * @type Boolean
1425 * @default true for IE6 and below, false for all others
1426 */
1427 this.cfg.addProperty("iframe", { value:(this.browser == "ie" ? true : false), handler:this.configIframe, validator:this.cfg.checkBoolean, supercedes:["zIndex"] } );
1428};
1429
1430/**
1431* Moves the Overlay to the specified position. This function is identical to calling this.cfg.setProperty("xy", [x,y]);
1432* @method moveTo
1433 * @param {Number} xThe Overlay's new x position
1434 * @param {Number} yThe Overlay's new y position
1435*/
1436YAHOO.widget.Overlay.prototype.moveTo = function(x, y) {
1437 this.cfg.setProperty("xy",[x,y]);
1438};
1439
1440/**
1441* Adds a special CSS class to the Overlay when Mac/Gecko is in use, to work around a Gecko bug where
1442* scrollbars cannot be hidden. See https://bugzilla.mozilla.org/show_bug.cgi?id=187435
1443* @method hideMacGeckoScrollbars
1444*/
1445YAHOO.widget.Overlay.prototype.hideMacGeckoScrollbars = function() {
1446 YAHOO.util.Dom.removeClass(this.element, "show-scrollbars");
1447 YAHOO.util.Dom.addClass(this.element, "hide-scrollbars");
1448};
1449
1450/**
1451* Removes a special CSS class from the Overlay when Mac/Gecko is in use, to work around a Gecko bug where
1452* scrollbars cannot be hidden. See https://bugzilla.mozilla.org/show_bug.cgi?id=187435
1453* @method showMacGeckoScrollbars
1454*/
1455YAHOO.widget.Overlay.prototype.showMacGeckoScrollbars = function() {
1456 YAHOO.util.Dom.removeClass(this.element, "hide-scrollbars");
1457 YAHOO.util.Dom.addClass(this.element, "show-scrollbars");
1458};
1459
1460// BEGIN BUILT-IN PROPERTY EVENT HANDLERS //
1461
1462/**
1463* The default event handler fired when the "visible" property is changed. This method is responsible for firing showEvent and hideEvent.
1464* @method configVisible
1465 * @param {String} typeThe CustomEvent type (usually the property name)
1466 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1467 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1468*/
1469YAHOO.widget.Overlay.prototype.configVisible = function(type, args, obj) {
1470 var visible = args[0];
1471
1472 var currentVis = YAHOO.util.Dom.getStyle(this.element, "visibility");
1473
1474 if (currentVis == "inherit") {
1475 var e = this.element.parentNode;
1476 while (e.nodeType != 9 && e.nodeType != 11) {
1477 currentVis = YAHOO.util.Dom.getStyle(e, "visibility");
1478 if (currentVis != "inherit") { break; }
1479 e = e.parentNode;
1480 }
1481 if (currentVis == "inherit") {
1482 currentVis = "visible";
1483 }
1484 }
1485
1486 var effect = this.cfg.getProperty("effect");
1487
1488 var effectInstances = [];
1489 if (effect) {
1490 if (effect instanceof Array) {
1491 for (var i=0;i<effect.length;i++) {
1492 var eff = effect[i];
1493 effectInstances[effectInstances.length] = eff.effect(this, eff.duration);
1494 }
1495 } else {
1496 effectInstances[effectInstances.length] = effect.effect(this, effect.duration);
1497 }
1498 }
1499
1500 var isMacGecko = (this.platform == "mac" && this.browser == "gecko");
1501
1502 if (visible) { // Show
1503 if (isMacGecko) {
1504 this.showMacGeckoScrollbars();
1505 }
1506
1507 if (effect) { // Animate in
1508 if (visible) { // Animate in if not showing
1509 if (currentVis != "visible" || currentVis === "") {
1510 this.beforeShowEvent.fire();
1511 for (var j=0;j<effectInstances.length;j++) {
1512 var ei = effectInstances[j];
1513 if (j === 0 && ! YAHOO.util.Config.alreadySubscribed(ei.animateInCompleteEvent,this.showEvent.fire,this.showEvent)) {
1514 ei.animateInCompleteEvent.subscribe(this.showEvent.fire,this.showEvent,true); // Delegate showEvent until end of animateInComplete
1515 }
1516 ei.animateIn();
1517 }
1518 }
1519 }
1520 } else { // Show
1521 if (currentVis != "visible" || currentVis === "") {
1522 this.beforeShowEvent.fire();
1523 YAHOO.util.Dom.setStyle(this.element, "visibility", "visible");
1524 this.cfg.refireEvent("iframe");
1525 this.showEvent.fire();
1526 }
1527 }
1528
1529 } else { // Hide
1530 if (isMacGecko) {
1531 this.hideMacGeckoScrollbars();
1532 }
1533
1534 if (effect) { // Animate out if showing
1535 if (currentVis == "visible") {
1536 this.beforeHideEvent.fire();
1537 for (var k=0;k<effectInstances.length;k++) {
1538 var h = effectInstances[k];
1539 if (k === 0 && ! YAHOO.util.Config.alreadySubscribed(h.animateOutCompleteEvent,this.hideEvent.fire,this.hideEvent)) {
1540 h.animateOutCompleteEvent.subscribe(this.hideEvent.fire,this.hideEvent,true); // Delegate hideEvent until end of animateOutComplete
1541 }
1542 h.animateOut();
1543 }
1544 } else if (currentVis === "") {
1545 YAHOO.util.Dom.setStyle(this.element, "visibility", "hidden");
1546 }
1547 } else { // Simple hide
1548 if (currentVis == "visible" || currentVis === "") {
1549 this.beforeHideEvent.fire();
1550 YAHOO.util.Dom.setStyle(this.element, "visibility", "hidden");
1551 this.cfg.refireEvent("iframe");
1552 this.hideEvent.fire();
1553 }
1554 }
1555 }
1556};
1557
1558/**
1559* Center event handler used for centering on scroll/resize, but only if the Overlay is visible
1560* @method doCenterOnDOMEvent
1561*/
1562YAHOO.widget.Overlay.prototype.doCenterOnDOMEvent = function() {
1563 if (this.cfg.getProperty("visible")) {
1564 this.center();
1565 }
1566};
1567
1568/**
1569* The default event handler fired when the "fixedcenter" property is changed.
1570* @method configFixedCenter
1571 * @param {String} typeThe CustomEvent type (usually the property name)
1572 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1573 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1574*/
1575YAHOO.widget.Overlay.prototype.configFixedCenter = function(type, args, obj) {
1576 var val = args[0];
1577
1578 if (val) {
1579 this.center();
1580
1581 if (! YAHOO.util.Config.alreadySubscribed(this.beforeShowEvent, this.center, this)) {
1582 this.beforeShowEvent.subscribe(this.center, this, true);
1583 }
1584
1585 if (! YAHOO.util.Config.alreadySubscribed(YAHOO.widget.Overlay.windowResizeEvent, this.doCenterOnDOMEvent, this)) {
1586 YAHOO.widget.Overlay.windowResizeEvent.subscribe(this.doCenterOnDOMEvent, this, true);
1587 }
1588
1589 if (! YAHOO.util.Config.alreadySubscribed(YAHOO.widget.Overlay.windowScrollEvent, this.doCenterOnDOMEvent, this)) {
1590 YAHOO.widget.Overlay.windowScrollEvent.subscribe( this.doCenterOnDOMEvent, this, true);
1591 }
1592 } else {
1593 YAHOO.widget.Overlay.windowResizeEvent.unsubscribe(this.doCenterOnDOMEvent, this);
1594 YAHOO.widget.Overlay.windowScrollEvent.unsubscribe(this.doCenterOnDOMEvent, this);
1595 }
1596};
1597
1598/**
1599* The default event handler fired when the "height" property is changed.
1600* @method configHeight
1601 * @param {String} typeThe CustomEvent type (usually the property name)
1602 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1603 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1604*/
1605YAHOO.widget.Overlay.prototype.configHeight = function(type, args, obj) {
1606 var height = args[0];
1607 var el = this.element;
1608 YAHOO.util.Dom.setStyle(el, "height", height);
1609 this.cfg.refireEvent("iframe");
1610};
1611
1612/**
1613* The default event handler fired when the "width" property is changed.
1614* @method configWidth
1615 * @param {String} typeThe CustomEvent type (usually the property name)
1616 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1617 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1618*/
1619YAHOO.widget.Overlay.prototype.configWidth = function(type, args, obj) {
1620 var width = args[0];
1621 var el = this.element;
1622 YAHOO.util.Dom.setStyle(el, "width", width);
1623 this.cfg.refireEvent("iframe");
1624};
1625
1626/**
1627* The default event handler fired when the "zIndex" property is changed.
1628* @method configzIndex
1629 * @param {String} typeThe CustomEvent type (usually the property name)
1630 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1631 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1632*/
1633YAHOO.widget.Overlay.prototype.configzIndex = function(type, args, obj) {
1634 var zIndex = args[0];
1635
1636 var el = this.element;
1637
1638 if (! zIndex) {
1639 zIndex = YAHOO.util.Dom.getStyle(el, "zIndex");
1640 if (! zIndex || isNaN(zIndex)) {
1641 zIndex = 0;
1642 }
1643 }
1644
1645 if (this.iframe) {
1646 if (zIndex <= 0) {
1647 zIndex = 1;
1648 }
1649 YAHOO.util.Dom.setStyle(this.iframe, "zIndex", (zIndex-1));
1650 }
1651
1652 YAHOO.util.Dom.setStyle(el, "zIndex", zIndex);
1653 this.cfg.setProperty("zIndex", zIndex, true);
1654};
1655
1656/**
1657* The default event handler fired when the "xy" property is changed.
1658* @method configXY
1659 * @param {String} typeThe CustomEvent type (usually the property name)
1660 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1661 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1662*/
1663YAHOO.widget.Overlay.prototype.configXY = function(type, args, obj) {
1664 var pos = args[0];
1665 var x = pos[0];
1666 var y = pos[1];
1667
1668 this.cfg.setProperty("x", x);
1669 this.cfg.setProperty("y", y);
1670
1671 this.beforeMoveEvent.fire([x,y]);
1672
1673 x = this.cfg.getProperty("x");
1674 y = this.cfg.getProperty("y");
1675
1676 this.cfg.refireEvent("iframe");
1677 this.moveEvent.fire([x,y]);
1678};
1679
1680/**
1681* The default event handler fired when the "x" property is changed.
1682* @method configX
1683 * @param {String} typeThe CustomEvent type (usually the property name)
1684 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1685 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1686*/
1687YAHOO.widget.Overlay.prototype.configX = function(type, args, obj) {
1688 var x = args[0];
1689 var y = this.cfg.getProperty("y");
1690
1691 this.cfg.setProperty("x", x, true);
1692 this.cfg.setProperty("y", y, true);
1693
1694 this.beforeMoveEvent.fire([x,y]);
1695
1696 x = this.cfg.getProperty("x");
1697 y = this.cfg.getProperty("y");
1698
1699 YAHOO.util.Dom.setX(this.element, x, true);
1700
1701 this.cfg.setProperty("xy", [x, y], true);
1702
1703 this.cfg.refireEvent("iframe");
1704 this.moveEvent.fire([x, y]);
1705};
1706
1707/**
1708* The default event handler fired when the "y" property is changed.
1709* @method configY
1710 * @param {String} typeThe CustomEvent type (usually the property name)
1711 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1712 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1713*/
1714YAHOO.widget.Overlay.prototype.configY = function(type, args, obj) {
1715 var x = this.cfg.getProperty("x");
1716 var y = args[0];
1717
1718 this.cfg.setProperty("x", x, true);
1719 this.cfg.setProperty("y", y, true);
1720
1721 this.beforeMoveEvent.fire([x,y]);
1722
1723 x = this.cfg.getProperty("x");
1724 y = this.cfg.getProperty("y");
1725
1726 YAHOO.util.Dom.setY(this.element, y, true);
1727
1728 this.cfg.setProperty("xy", [x, y], true);
1729
1730 this.cfg.refireEvent("iframe");
1731 this.moveEvent.fire([x, y]);
1732};
1733
1734/**
1735* Shows the iframe shim, if it has been enabled
1736* @method showIframe
1737*/
1738YAHOO.widget.Overlay.prototype.showIframe = function() {
1739 if (this.iframe) {
1740 this.iframe.style.display = "block";
1741 }
1742};
1743
1744/**
1745* Hides the iframe shim, if it has been enabled
1746* @method hideIframe
1747*/
1748YAHOO.widget.Overlay.prototype.hideIframe = function() {
1749 if (this.iframe) {
1750 this.iframe.style.display = "none";
1751 }
1752};
1753
1754/**
1755* The default event handler fired when the "iframe" property is changed.
1756* @method configIframe
1757 * @param {String} typeThe CustomEvent type (usually the property name)
1758 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1759 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1760*/
1761YAHOO.widget.Overlay.prototype.configIframe = function(type, args, obj) {
1762
1763 var val = args[0];
1764
1765 if (val) { // IFRAME shim is enabled
1766
1767 if (! YAHOO.util.Config.alreadySubscribed(this.showEvent, this.showIframe, this)) {
1768 this.showEvent.subscribe(this.showIframe, this, true);
1769 }
1770 if (! YAHOO.util.Config.alreadySubscribed(this.hideEvent, this.hideIframe, this)) {
1771 this.hideEvent.subscribe(this.hideIframe, this, true);
1772 }
1773
1774 var x = this.cfg.getProperty("x");
1775 var y = this.cfg.getProperty("y");
1776
1777 if (! x || ! y) {
1778 this.syncPosition();
1779 x = this.cfg.getProperty("x");
1780 y = this.cfg.getProperty("y");
1781 }
1782
1783 if (! isNaN(x) && ! isNaN(y)) {
1784 if (! this.iframe) {
1785 this.iframe = document.createElement("iframe");
1786 if (this.isSecure) {
1787 this.iframe.src = this.imageRoot + YAHOO.widget.Overlay.IFRAME_SRC;
1788 }
1789
1790 var parent = this.element.parentNode;
1791 if (parent) {
1792 parent.appendChild(this.iframe);
1793 } else {
1794 document.body.appendChild(this.iframe);
1795 }
1796
1797 YAHOO.util.Dom.setStyle(this.iframe, "position", "absolute");
1798 YAHOO.util.Dom.setStyle(this.iframe, "border", "none");
1799 YAHOO.util.Dom.setStyle(this.iframe, "margin", "0");
1800 YAHOO.util.Dom.setStyle(this.iframe, "padding", "0");
1801 YAHOO.util.Dom.setStyle(this.iframe, "opacity", "0");
1802 if (this.cfg.getProperty("visible")) {
1803 this.showIframe();
1804 } else {
1805 this.hideIframe();
1806 }
1807 }
1808
1809 var iframeDisplay = YAHOO.util.Dom.getStyle(this.iframe, "display");
1810
1811 if (iframeDisplay == "none") {
1812 this.iframe.style.display = "block";
1813 }
1814
1815 YAHOO.util.Dom.setXY(this.iframe, [x,y]);
1816
1817 var width = this.element.clientWidth;
1818 var height = this.element.clientHeight;
1819
1820 YAHOO.util.Dom.setStyle(this.iframe, "width", (width+2) + "px");
1821 YAHOO.util.Dom.setStyle(this.iframe, "height", (height+2) + "px");
1822
1823 if (iframeDisplay == "none") {
1824 this.iframe.style.display = "none";
1825 }
1826 }
1827 } else {
1828 if (this.iframe) {
1829 this.iframe.style.display = "none";
1830 }
1831 this.showEvent.unsubscribe(this.showIframe, this);
1832 this.hideEvent.unsubscribe(this.hideIframe, this);
1833 }
1834};
1835
1836
1837/**
1838* The default event handler fired when the "constraintoviewport" property is changed.
1839* @method configConstrainToViewport
1840 * @param {String} typeThe CustomEvent type (usually the property name)
1841 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1842 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1843*/
1844YAHOO.widget.Overlay.prototype.configConstrainToViewport = function(type, args, obj) {
1845 var val = args[0];
1846 if (val) {
1847 if (! YAHOO.util.Config.alreadySubscribed(this.beforeMoveEvent, this.enforceConstraints, this)) {
1848 this.beforeMoveEvent.subscribe(this.enforceConstraints, this, true);
1849 }
1850 } else {
1851 this.beforeMoveEvent.unsubscribe(this.enforceConstraints, this);
1852 }
1853};
1854
1855/**
1856* The default event handler fired when the "context" property is changed.
1857* @method configContext
1858 * @param {String} typeThe CustomEvent type (usually the property name)
1859 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1860 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1861*/
1862YAHOO.widget.Overlay.prototype.configContext = function(type, args, obj) {
1863 var contextArgs = args[0];
1864
1865 if (contextArgs) {
1866 var contextEl = contextArgs[0];
1867 var elementMagnetCorner = contextArgs[1];
1868 var contextMagnetCorner = contextArgs[2];
1869
1870 if (contextEl) {
1871 if (typeof contextEl == "string") {
1872 this.cfg.setProperty("context", [document.getElementById(contextEl),elementMagnetCorner,contextMagnetCorner], true);
1873 }
1874
1875 if (elementMagnetCorner && contextMagnetCorner) {
1876 this.align(elementMagnetCorner, contextMagnetCorner);
1877 }
1878 }
1879 }
1880};
1881
1882
1883// END BUILT-IN PROPERTY EVENT HANDLERS //
1884
1885/**
1886* Aligns the Overlay to its context element using the specified corner points (represented by the constants TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, and BOTTOM_RIGHT.
1887* @method align
1888 * @param {String} elementAlign The String representing the corner of the Overlay that should be aligned to the context element
1889 * @param {String} contextAlign The corner of the context element that the elementAlign corner should stick to.
1890*/
1891YAHOO.widget.Overlay.prototype.align = function(elementAlign, contextAlign) {
1892 var contextArgs = this.cfg.getProperty("context");
1893 if (contextArgs) {
1894 var context = contextArgs[0];
1895
1896 var element = this.element;
1897 var me = this;
1898
1899 if (! elementAlign) {
1900 elementAlign = contextArgs[1];
1901 }
1902
1903 if (! contextAlign) {
1904 contextAlign = contextArgs[2];
1905 }
1906
1907 if (element && context) {
1908 var elementRegion = YAHOO.util.Dom.getRegion(element);
1909 var contextRegion = YAHOO.util.Dom.getRegion(context);
1910
1911 var doAlign = function(v,h) {
1912 switch (elementAlign) {
1913 case YAHOO.widget.Overlay.TOP_LEFT:
1914 me.moveTo(h,v);
1915 break;
1916 case YAHOO.widget.Overlay.TOP_RIGHT:
1917 me.moveTo(h-element.offsetWidth,v);
1918 break;
1919 case YAHOO.widget.Overlay.BOTTOM_LEFT:
1920 me.moveTo(h,v-element.offsetHeight);
1921 break;
1922 case YAHOO.widget.Overlay.BOTTOM_RIGHT:
1923 me.moveTo(h-element.offsetWidth,v-element.offsetHeight);
1924 break;
1925 }
1926 };
1927
1928 switch (contextAlign) {
1929 case YAHOO.widget.Overlay.TOP_LEFT:
1930 doAlign(contextRegion.top, contextRegion.left);
1931 break;
1932 case YAHOO.widget.Overlay.TOP_RIGHT:
1933 doAlign(contextRegion.top, contextRegion.right);
1934 break;
1935 case YAHOO.widget.Overlay.BOTTOM_LEFT:
1936 doAlign(contextRegion.bottom, contextRegion.left);
1937 break;
1938 case YAHOO.widget.Overlay.BOTTOM_RIGHT:
1939 doAlign(contextRegion.bottom, contextRegion.right);
1940 break;
1941 }
1942 }
1943 }
1944};
1945
1946/**
1947* The default event handler executed when the moveEvent is fired, if the "constraintoviewport" is set to true.
1948* @method enforceConstraints
1949 * @param {String} typeThe CustomEvent type (usually the property name)
1950 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
1951 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
1952*/
1953YAHOO.widget.Overlay.prototype.enforceConstraints = function(type, args, obj) {
1954 var pos = args[0];
1955
1956 var x = pos[0];
1957 var y = pos[1];
1958
1959 var offsetHeight = this.element.offsetHeight;
1960 var offsetWidth = this.element.offsetWidth;
1961
1962 var viewPortWidth = YAHOO.util.Dom.getViewportWidth();
1963 var viewPortHeight = YAHOO.util.Dom.getViewportHeight();
1964
1965 var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
1966 var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
1967
1968 var topConstraint = scrollY + 10;
1969 var leftConstraint = scrollX + 10;
1970 var bottomConstraint = scrollY + viewPortHeight - offsetHeight - 10;
1971 var rightConstraint = scrollX + viewPortWidth - offsetWidth - 10;
1972
1973 if (x < leftConstraint) {
1974 x = leftConstraint;
1975 } else if (x > rightConstraint) {
1976 x = rightConstraint;
1977 }
1978
1979 if (y < topConstraint) {
1980 y = topConstraint;
1981 } else if (y > bottomConstraint) {
1982 y = bottomConstraint;
1983 }
1984
1985 this.cfg.setProperty("x", x, true);
1986 this.cfg.setProperty("y", y, true);
1987 this.cfg.setProperty("xy", [x,y], true);
1988};
1989
1990/**
1991* Centers the container in the viewport.
1992* @method center
1993*/
1994YAHOO.widget.Overlay.prototype.center = function() {
1995 var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft;
1996 var scrollY = document.documentElement.scrollTop || document.body.scrollTop;
1997
1998 var viewPortWidth = YAHOO.util.Dom.getClientWidth();
1999 var viewPortHeight = YAHOO.util.Dom.getClientHeight();
2000
2001 var elementWidth = this.element.offsetWidth;
2002 var elementHeight = this.element.offsetHeight;
2003
2004 var x = (viewPortWidth / 2) - (elementWidth / 2) + scrollX;
2005 var y = (viewPortHeight / 2) - (elementHeight / 2) + scrollY;
2006
2007 this.cfg.setProperty("xy", [parseInt(x, 10), parseInt(y, 10)]);
2008
2009 this.cfg.refireEvent("iframe");
2010};
2011
2012/**
2013* Synchronizes the Panel's "xy", "x", and "y" properties with the Panel's position in the DOM. This is primarily used to update position information during drag & drop.
2014* @method syncPosition
2015*/
2016YAHOO.widget.Overlay.prototype.syncPosition = function() {
2017 var pos = YAHOO.util.Dom.getXY(this.element);
2018 this.cfg.setProperty("x", pos[0], true);
2019 this.cfg.setProperty("y", pos[1], true);
2020 this.cfg.setProperty("xy", pos, true);
2021};
2022
2023/**
2024* Event handler fired when the resize monitor element is resized.
2025* @method onDomResize
2026 * @param {DOMEvent} eThe resize DOM event
2027 * @param {Object} objThe scope object
2028*/
2029YAHOO.widget.Overlay.prototype.onDomResize = function(e, obj) {
2030 YAHOO.widget.Overlay.superclass.onDomResize.call(this, e, obj);
2031 var me = this;
2032 setTimeout(function() {
2033 me.syncPosition();
2034 me.cfg.refireEvent("iframe");
2035 me.cfg.refireEvent("context");
2036 }, 0);
2037};
2038
2039/**
2040* Removes the Overlay element from the DOM and sets all child elements to null.
2041* @method destroy
2042*/
2043YAHOO.widget.Overlay.prototype.destroy = function() {
2044 if (this.iframe) {
2045 this.iframe.parentNode.removeChild(this.iframe);
2046 }
2047
2048 this.iframe = null;
2049
2050 YAHOO.widget.Overlay.superclass.destroy.call(this);
2051};
2052
2053/**
2054* Returns a String representation of the object.
2055* @method toString
2056* @return {String} The string representation of the Overlay.
2057*/
2058YAHOO.widget.Overlay.prototype.toString = function() {
2059 return "Overlay " + this.id;
2060};
2061
2062/**
2063* A singleton CustomEvent used for reacting to the DOM event for window scroll
2064* @event YAHOO.widget.Overlay.windowScrollEvent
2065*/
2066YAHOO.widget.Overlay.windowScrollEvent = new YAHOO.util.CustomEvent("windowScroll");
2067
2068/**
2069* A singleton CustomEvent used for reacting to the DOM event for window resize
2070* @event YAHOO.widget.Overlay.windowResizeEvent
2071*/
2072YAHOO.widget.Overlay.windowResizeEvent = new YAHOO.util.CustomEvent("windowResize");
2073
2074/**
2075* The DOM event handler used to fire the CustomEvent for window scroll
2076* @method YAHOO.widget.Overlay.windowScrollHandler
2077* @static
2078* @param {DOMEvent} e The DOM scroll event
2079*/
2080YAHOO.widget.Overlay.windowScrollHandler = function(e) {
2081 if (YAHOO.widget.Module.prototype.browser == "ie" || YAHOO.widget.Module.prototype.browser == "ie7") {
2082 if (! window.scrollEnd) {
2083 window.scrollEnd = -1;
2084 }
2085 clearTimeout(window.scrollEnd);
2086 window.scrollEnd = setTimeout(function() { YAHOO.widget.Overlay.windowScrollEvent.fire(); }, 1);
2087 } else {
2088 YAHOO.widget.Overlay.windowScrollEvent.fire();
2089 }
2090};
2091
2092/**
2093* The DOM event handler used to fire the CustomEvent for window resize
2094* @method YAHOO.widget.Overlay.windowResizeHandler
2095* @static
2096* @param {DOMEvent} e The DOM resize event
2097*/
2098YAHOO.widget.Overlay.windowResizeHandler = function(e) {
2099 if (YAHOO.widget.Module.prototype.browser == "ie" || YAHOO.widget.Module.prototype.browser == "ie7") {
2100 if (! window.resizeEnd) {
2101 window.resizeEnd = -1;
2102 }
2103 clearTimeout(window.resizeEnd);
2104 window.resizeEnd = setTimeout(function() { YAHOO.widget.Overlay.windowResizeEvent.fire(); }, 100);
2105 } else {
2106 YAHOO.widget.Overlay.windowResizeEvent.fire();
2107 }
2108};
2109
2110/**
2111* A boolean that indicated whether the window resize and scroll events have already been subscribed to.
2112* @property YAHOO.widget.Overlay._initialized
2113* @private
2114* @type Boolean
2115*/
2116YAHOO.widget.Overlay._initialized = null;
2117
2118if (YAHOO.widget.Overlay._initialized === null) {
2119 YAHOO.util.Event.addListener(window, "scroll", YAHOO.widget.Overlay.windowScrollHandler);
2120 YAHOO.util.Event.addListener(window, "resize", YAHOO.widget.Overlay.windowResizeHandler);
2121
2122 YAHOO.widget.Overlay._initialized = true;
2123}
2124
2125/**
2126* OverlayManager is used for maintaining the focus status of multiple Overlays.* @namespace YAHOO.widget
2127* @namespace YAHOO.widget
2128* @class OverlayManager
2129* @constructor
2130 * @param {Array} overlaysOptional. A collection of Overlays to register with the manager.
2131 * @param {Object} userConfig The object literal representing the user configuration of the OverlayManager
2132*/
2133YAHOO.widget.OverlayManager = function(userConfig) {
2134 this.init(userConfig);
2135};
2136
2137/**
2138* The CSS class representing a focused Overlay
2139* @property YAHOO.widget.OverlayManager.CSS_FOCUSED
2140* @static
2141* @final
2142* @type String
2143*/
2144YAHOO.widget.OverlayManager.CSS_FOCUSED = "focused";
2145
2146YAHOO.widget.OverlayManager.prototype = {
2147 /**
2148 * The class's constructor function
2149 * @property contructor
2150 * @type Function
2151 */
2152 constructor : YAHOO.widget.OverlayManager,
2153
2154 /**
2155 * The array of Overlays that are currently registered
2156 * @property overlays
2157 * @type YAHOO.widget.Overlay[]
2158 */
2159 overlays : null,
2160
2161 /**
2162 * Initializes the default configuration of the OverlayManager
2163 * @method initDefaultConfig
2164 */
2165 initDefaultConfig : function() {
2166 /**
2167 * The collection of registered Overlays in use by the OverlayManager
2168 * @config overlays
2169 * @type YAHOO.widget.Overlay[]
2170 * @default null
2171 */
2172 this.cfg.addProperty("overlays", { suppressEvent:true } );
2173
2174 /**
2175 * The default DOM event that should be used to focus an Overlay
2176 * @config focusevent
2177 * @type String
2178 * @default "mousedown"
2179 */
2180 this.cfg.addProperty("focusevent", { value:"mousedown" } );
2181 },
2182
2183 /**
2184 * Initializes the OverlayManager
2185 * @method init
2186 * @param {YAHOO.widget.Overlay[]} overlaysOptional. A collection of Overlays to register with the manager.
2187 * @param {Object} userConfig The object literal representing the user configuration of the OverlayManager
2188 */
2189 init : function(userConfig) {
2190 /**
2191 * The OverlayManager's Config object used for monitoring configuration properties.
2192 * @property cfg
2193 * @type YAHOO.util.Config
2194 */
2195 this.cfg = new YAHOO.util.Config(this);
2196
2197 this.initDefaultConfig();
2198
2199 if (userConfig) {
2200 this.cfg.applyConfig(userConfig, true);
2201 }
2202 this.cfg.fireQueue();
2203
2204 /**
2205 * The currently activated Overlay
2206 * @property activeOverlay
2207 * @private
2208 * @type YAHOO.widget.Overlay
2209 */
2210 var activeOverlay = null;
2211
2212 /**
2213 * Returns the currently focused Overlay
2214 * @method getActive
2215 * @return {YAHOO.widget.Overlay}The currently focused Overlay
2216 */
2217 this.getActive = function() {
2218 return activeOverlay;
2219 };
2220
2221 /**
2222 * Focuses the specified Overlay
2223 * @method focus
2224 * @param {YAHOO.widget.Overlay} overlayThe Overlay to focus
2225 * @param {String} overlayThe id of the Overlay to focus
2226 */
2227 this.focus = function(overlay) {
2228 var o = this.find(overlay);
2229 if (o) {
2230 this.blurAll();
2231 activeOverlay = o;
2232 YAHOO.util.Dom.addClass(activeOverlay.element, YAHOO.widget.OverlayManager.CSS_FOCUSED);
2233 this.overlays.sort(this.compareZIndexDesc);
2234 var topZIndex = YAHOO.util.Dom.getStyle(this.overlays[0].element, "zIndex");
2235 if (! isNaN(topZIndex) && this.overlays[0] != overlay) {
2236 activeOverlay.cfg.setProperty("zIndex", (parseInt(topZIndex, 10) + 2));
2237 }
2238 this.overlays.sort(this.compareZIndexDesc);
2239 }
2240 };
2241
2242 /**
2243 * Removes the specified Overlay from the manager
2244 * @method remove
2245 * @param {YAHOO.widget.Overlay} overlayThe Overlay to remove
2246 * @param {String} overlayThe id of the Overlay to remove
2247 */
2248 this.remove = function(overlay) {
2249 var o = this.find(overlay);
2250 if (o) {
2251 var originalZ = YAHOO.util.Dom.getStyle(o.element, "zIndex");
2252 o.cfg.setProperty("zIndex", -1000, true);
2253 this.overlays.sort(this.compareZIndexDesc);
2254 this.overlays = this.overlays.slice(0, this.overlays.length-1);
2255 o.cfg.setProperty("zIndex", originalZ, true);
2256
2257 o.cfg.setProperty("manager", null);
2258 o.focusEvent = null;
2259 o.blurEvent = null;
2260 o.focus = null;
2261 o.blur = null;
2262 }
2263 };
2264
2265 /**
2266 * Removes focus from all registered Overlays in the manager
2267 * @method blurAll
2268 */
2269 this.blurAll = function() {
2270 activeOverlay = null;
2271 for (var o=0;o<this.overlays.length;o++) {
2272 YAHOO.util.Dom.removeClass(this.overlays[o].element, YAHOO.widget.OverlayManager.CSS_FOCUSED);
2273 }
2274 };
2275
2276 var overlays = this.cfg.getProperty("overlays");
2277
2278 if (! this.overlays) {
2279 this.overlays = [];
2280 }
2281
2282 if (overlays) {
2283 this.register(overlays);
2284 this.overlays.sort(this.compareZIndexDesc);
2285 }
2286 },
2287
2288 /**
2289 * Registers an Overlay or an array of Overlays with the manager. Upon registration, the Overlay receives functions for focus and blur, along with CustomEvents for each.
2290 * @method register
2291 * @param {YAHOO.widget.Overlay} overlay An Overlay to register with the manager.
2292 * @param {YAHOO.widget.Overlay[]} overlay An array of Overlays to register with the manager.
2293 * @return {Boolean}True if any Overlays are registered.
2294 */
2295 register : function(overlay) {
2296 if (overlay instanceof YAHOO.widget.Overlay) {
2297 overlay.cfg.addProperty("manager", { value:this } );
2298
2299 overlay.focusEvent = new YAHOO.util.CustomEvent("focus");
2300 overlay.blurEvent = new YAHOO.util.CustomEvent("blur");
2301
2302 var mgr=this;
2303
2304 overlay.focus = function() {
2305 mgr.focus(this);
2306 this.focusEvent.fire();
2307 };
2308
2309 overlay.blur = function() {
2310 mgr.blurAll();
2311 this.blurEvent.fire();
2312 };
2313
2314 var focusOnDomEvent = function(e,obj) {
2315 overlay.focus();
2316 };
2317
2318 var focusevent = this.cfg.getProperty("focusevent");
2319 YAHOO.util.Event.addListener(overlay.element,focusevent,focusOnDomEvent,this,true);
2320
2321 var zIndex = YAHOO.util.Dom.getStyle(overlay.element, "zIndex");
2322 if (! isNaN(zIndex)) {
2323 overlay.cfg.setProperty("zIndex", parseInt(zIndex, 10));
2324 } else {
2325 overlay.cfg.setProperty("zIndex", 0);
2326 }
2327
2328 this.overlays.push(overlay);
2329 return true;
2330 } else if (overlay instanceof Array) {
2331 var regcount = 0;
2332 for (var i=0;i<overlay.length;i++) {
2333 if (this.register(overlay[i])) {
2334 regcount++;
2335 }
2336 }
2337 if (regcount > 0) {
2338 return true;
2339 }
2340 } else {
2341 return false;
2342 }
2343 },
2344
2345 /**
2346 * Attempts to locate an Overlay by instance or ID.
2347 * @method find
2348 * @param {YAHOO.widget.Overlay} overlay An Overlay to locate within the manager
2349 * @param {String} overlay An Overlay id to locate within the manager
2350 * @return {YAHOO.widget.Overlay}The requested Overlay, if found, or null if it cannot be located.
2351 */
2352 find : function(overlay) {
2353 if (overlay instanceof YAHOO.widget.Overlay) {
2354 for (var o=0;o<this.overlays.length;o++) {
2355 if (this.overlays[o] == overlay) {
2356 return this.overlays[o];
2357 }
2358 }
2359 } else if (typeof overlay == "string") {
2360 for (var p=0;p<this.overlays.length;p++) {
2361 if (this.overlays[p].id == overlay) {
2362 return this.overlays[p];
2363 }
2364 }
2365 }
2366 return null;
2367 },
2368
2369 /**
2370 * Used for sorting the manager's Overlays by z-index.
2371 * @method compareZIndexDesc
2372 * @private
2373 * @return {Number}0, 1, or -1, depending on where the Overlay should fall in the stacking order.
2374 */
2375 compareZIndexDesc : function(o1, o2) {
2376 var zIndex1 = o1.cfg.getProperty("zIndex");
2377 var zIndex2 = o2.cfg.getProperty("zIndex");
2378
2379 if (zIndex1 > zIndex2) {
2380 return -1;
2381 } else if (zIndex1 < zIndex2) {
2382 return 1;
2383 } else {
2384 return 0;
2385 }
2386 },
2387
2388 /**
2389 * Shows all Overlays in the manager.
2390 * @method showAll
2391 */
2392 showAll : function() {
2393 for (var o=0;o<this.overlays.length;o++) {
2394 this.overlays[o].show();
2395 }
2396 },
2397
2398 /**
2399 * Hides all Overlays in the manager.
2400 * @method hideAll
2401 */
2402 hideAll : function() {
2403 for (var o=0;o<this.overlays.length;o++) {
2404 this.overlays[o].hide();
2405 }
2406 },
2407
2408
2409 /**
2410 * Returns a string representation of the object.
2411 * @method toString
2412 * @return {String}The string representation of the OverlayManager
2413 */
2414 toString : function() {
2415 return "OverlayManager";
2416 }
2417
2418};
2419
2420/**
2421* KeyListener is a utility that provides an easy interface for listening for keydown/keyup events fired against DOM elements.
2422* @namespace YAHOO.util
2423* @class KeyListener
2424* @constructor
2425 * @param {HTMLElement} attachToThe element or element ID to which the key event should be attached
2426 * @param {String} attachToThe element or element ID to which the key event should be attached
2427 * @param {Object} keyData The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes).
2428 * @param {Function} handler The CustomEvent handler to fire when the key event is detected
2429 * @param {Object} handler An object literal representing the handler.
2430 * @param {String} event Optional. The event (keydown or keyup) to listen for. Defaults automatically to keydown.
2431*/
2432YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
2433 if (! event) {
2434 event = YAHOO.util.KeyListener.KEYDOWN;
2435 }
2436
2437 /**
2438 * The CustomEvent fired internally when a key is pressed
2439 * @event keyEvent
2440 * @private
2441 * @param {Object} keyData The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes).
2442 */
2443 var keyEvent = new YAHOO.util.CustomEvent("keyPressed");
2444
2445 /**
2446 * The CustomEvent fired when the KeyListener is enabled via the enable() function
2447 * @event enabledEvent
2448 * @param {Object} keyData The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes).
2449 */
2450 this.enabledEvent = new YAHOO.util.CustomEvent("enabled");
2451
2452 /**
2453 * The CustomEvent fired when the KeyListener is disabled via the disable() function
2454 * @event disabledEvent
2455 * @param {Object} keyData The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes).
2456 */
2457 this.disabledEvent = new YAHOO.util.CustomEvent("disabled");
2458
2459 if (typeof attachTo == 'string') {
2460 attachTo = document.getElementById(attachTo);
2461 }
2462
2463 if (typeof handler == 'function') {
2464 keyEvent.subscribe(handler);
2465 } else {
2466 keyEvent.subscribe(handler.fn, handler.scope, handler.correctScope);
2467 }
2468
2469 /**
2470 * Handles the key event when a key is pressed.
2471 * @method handleKeyPress
2472 * @param {DOMEvent} eThe keypress DOM event
2473 * @param {Object} objThe DOM event scope object
2474 * @private
2475 */
2476 function handleKeyPress(e, obj) {
2477 if (! keyData.shift) {
2478 keyData.shift = false;
2479 }
2480 if (! keyData.alt) {
2481 keyData.alt = false;
2482 }
2483 if (! keyData.ctrl) {
2484 keyData.ctrl = false;
2485 }
2486
2487 // check held down modifying keys first
2488 if (e.shiftKey == keyData.shift &&
2489 e.altKey == keyData.alt &&
2490 e.ctrlKey == keyData.ctrl) { // if we pass this, all modifiers match
2491
2492 var dataItem;
2493 var keyPressed;
2494
2495 if (keyData.keys instanceof Array) {
2496 for (var i=0;i<keyData.keys.length;i++) {
2497 dataItem = keyData.keys[i];
2498
2499 if (dataItem == e.charCode ) {
2500 keyEvent.fire(e.charCode, e);
2501 break;
2502 } else if (dataItem == e.keyCode) {
2503 keyEvent.fire(e.keyCode, e);
2504 break;
2505 }
2506 }
2507 } else {
2508 dataItem = keyData.keys;
2509
2510 if (dataItem == e.charCode ) {
2511 keyEvent.fire(e.charCode, e);
2512 } else if (dataItem == e.keyCode) {
2513 keyEvent.fire(e.keyCode, e);
2514 }
2515 }
2516 }
2517 }
2518
2519 /**
2520 * Enables the KeyListener by attaching the DOM event listeners to the target DOM element
2521 * @method enable
2522 */
2523 this.enable = function() {
2524 if (! this.enabled) {
2525 YAHOO.util.Event.addListener(attachTo, event, handleKeyPress);
2526 this.enabledEvent.fire(keyData);
2527 }
2528 /**
2529 * Boolean indicating the enabled/disabled state of the Tooltip
2530 * @property enabled
2531 * @type Boolean
2532 */
2533 this.enabled = true;
2534 };
2535
2536 /**
2537 * Disables the KeyListener by removing the DOM event listeners from the target DOM element
2538 * @method disable
2539 */
2540 this.disable = function() {
2541 if (this.enabled) {
2542 YAHOO.util.Event.removeListener(attachTo, event, handleKeyPress);
2543 this.disabledEvent.fire(keyData);
2544 }
2545 this.enabled = false;
2546 };
2547
2548 /**
2549 * Returns a String representation of the object.
2550 * @method toString
2551 * @return {String}The string representation of the KeyListener
2552 */
2553 this.toString = function() {
2554 return "KeyListener [" + keyData.keys + "] " + attachTo.tagName + (attachTo.id ? "[" + attachTo.id + "]" : "");
2555 };
2556
2557};
2558
2559/**
2560* Constant representing the DOM "keydown" event.
2561* @property YAHOO.util.KeyListener.KEYDOWN
2562* @static
2563* @final
2564* @type String
2565*/
2566YAHOO.util.KeyListener.KEYDOWN = "keydown";
2567
2568/**
2569* Constant representing the DOM "keyup" event.
2570* @property YAHOO.util.KeyListener.KEYUP
2571* @static
2572* @final
2573* @type String
2574*/
2575YAHOO.util.KeyListener.KEYUP = "keyup";
2576
2577/**
2578* Tooltip is an implementation of Overlay that behaves like an OS tooltip, displaying when the user mouses over a particular element, and disappearing on mouse out.
2579* @namespace YAHOO.widget
2580* @class Tooltip
2581* @extends YAHOO.widget.Overlay
2582* @constructor
2583 * @param {String} elThe element ID representing the Tooltip <em>OR</em>
2584 * @param {HTMLElement} elThe element representing the Tooltip
2585 * @param {Object} userConfigThe configuration object literal containing the configuration that should be set for this Overlay. See configuration documentation for more details.
2586*/
2587YAHOO.widget.Tooltip = function(el, userConfig) {
2588 YAHOO.widget.Tooltip.superclass.constructor.call(this, el, userConfig);
2589};
2590
2591YAHOO.extend(YAHOO.widget.Tooltip, YAHOO.widget.Overlay);
2592
2593/**
2594* Constant representing the Tooltip CSS class
2595* @property YAHOO.widget.Tooltip.CSS_TOOLTIP
2596* @static
2597* @final
2598* @type String
2599*/
2600YAHOO.widget.Tooltip.CSS_TOOLTIP = "tt";
2601
2602/**
2603* The Tooltip initialization method. This method is automatically called by the constructor. A Tooltip is automatically rendered by the init method, and it also is set to be invisible by default, and constrained to viewport by default as well.
2604* @method init
2605 * @param {String} elThe element ID representing the Tooltip <em>OR</em>
2606 * @param {HTMLElement} elThe element representing the Tooltip
2607 * @param {Object} userConfigThe configuration object literal containing the configuration that should be set for this Tooltip. See configuration documentation for more details.
2608*/
2609YAHOO.widget.Tooltip.prototype.init = function(el, userConfig) {
2610 if (document.readyState && document.readyState != "complete") {
2611 var deferredInit = function() {
2612 this.init(el, userConfig);
2613 };
2614 YAHOO.util.Event.addListener(window, "load", deferredInit, this, true);
2615 } else {
2616 YAHOO.widget.Tooltip.superclass.init.call(this, el);
2617
2618 this.beforeInitEvent.fire(YAHOO.widget.Tooltip);
2619
2620 YAHOO.util.Dom.addClass(this.element, YAHOO.widget.Tooltip.CSS_TOOLTIP);
2621
2622 if (userConfig) {
2623 this.cfg.applyConfig(userConfig, true);
2624 }
2625
2626 this.cfg.queueProperty("visible",false);
2627 this.cfg.queueProperty("constraintoviewport",true);
2628
2629 this.setBody("");
2630 this.render(this.cfg.getProperty("container"));
2631
2632 this.initEvent.fire(YAHOO.widget.Tooltip);
2633 }
2634};
2635
2636/**
2637* Initializes the class's configurable properties which can be changed using the Overlay's Config object (cfg).
2638* @method initDefaultConfig
2639*/
2640YAHOO.widget.Tooltip.prototype.initDefaultConfig = function() {
2641 YAHOO.widget.Tooltip.superclass.initDefaultConfig.call(this);
2642
2643 /**
2644 * Specifies whether the Tooltip should be kept from overlapping its context element.
2645 * @config preventoverlap
2646 * @type Boolean
2647 * @default true
2648 */
2649 this.cfg.addProperty("preventoverlap", { value:true, validator:this.cfg.checkBoolean, supercedes:["x","y","xy"] } );
2650
2651 /**
2652 * The number of milliseconds to wait before showing a Tooltip on mouseover.
2653 * @config showdelay
2654 * @type Number
2655 * @default 200
2656 */
2657 this.cfg.addProperty("showdelay", { value:200, handler:this.configShowDelay, validator:this.cfg.checkNumber } );
2658
2659 /**
2660 * The number of milliseconds to wait before automatically dismissing a Tooltip after the mouse has been resting on the context element.
2661 * @config autodismissdelay
2662 * @type Number
2663 * @default 5000
2664 */
2665 this.cfg.addProperty("autodismissdelay",{ value:5000, handler:this.configAutoDismissDelay, validator:this.cfg.checkNumber } );
2666
2667 /**
2668 * The number of milliseconds to wait before hiding a Tooltip on mouseover.
2669 * @config hidedelay
2670 * @type Number
2671 * @default 250
2672 */
2673 this.cfg.addProperty("hidedelay", { value:250, handler:this.configHideDelay, validator:this.cfg.checkNumber } );
2674
2675 /**
2676 * Specifies the Tooltip's text.
2677 * @config text
2678 * @type String
2679 * @default null
2680 */
2681 this.cfg.addProperty("text", { handler:this.configText, suppressEvent:true } );
2682
2683 /**
2684 * Specifies the container element that the Tooltip's markup should be rendered into.
2685 * @config container
2686 * @type HTMLElement/String
2687 * @default document.body
2688 */
2689 this.cfg.addProperty("container", { value:document.body, handler:this.configContainer } );
2690
2691 /**
2692 * Specifies the element or elements that the Tooltip should be anchored to on mouseover.
2693 * @config context
2694 * @type HTMLElement[]/String[]
2695 * @default null
2696 */
2697
2698};
2699
2700// BEGIN BUILT-IN PROPERTY EVENT HANDLERS //
2701
2702/**
2703* The default event handler fired when the "text" property is changed.
2704* @method configText
2705 * @param {String} typeThe CustomEvent type (usually the property name)
2706 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
2707 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
2708*/
2709YAHOO.widget.Tooltip.prototype.configText = function(type, args, obj) {
2710 var text = args[0];
2711 if (text) {
2712 this.setBody(text);
2713 }
2714};
2715
2716/**
2717* The default event handler fired when the "container" property is changed.
2718* @method configContainer
2719 * @param {String} typeThe CustomEvent type (usually the property name)
2720 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
2721 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
2722*/
2723YAHOO.widget.Tooltip.prototype.configContainer = function(type, args, obj) {
2724 var container = args[0];
2725 if (typeof container == 'string') {
2726 this.cfg.setProperty("container", document.getElementById(container), true);
2727 }
2728};
2729
2730/**
2731* The default event handler fired when the "context" property is changed.
2732* @method configContext
2733 * @param {String} typeThe CustomEvent type (usually the property name)
2734 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
2735 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
2736*/
2737YAHOO.widget.Tooltip.prototype.configContext = function(type, args, obj) {
2738 var context = args[0];
2739 if (context) {
2740
2741 // Normalize parameter into an array
2742 if (! (context instanceof Array)) {
2743 if (typeof context == "string") {
2744 this.cfg.setProperty("context", [document.getElementById(context)], true);
2745 } else { // Assuming this is an element
2746 this.cfg.setProperty("context", [context], true);
2747 }
2748 context = this.cfg.getProperty("context");
2749 }
2750
2751
2752 // Remove any existing mouseover/mouseout listeners
2753 if (this._context) {
2754 for (var c=0;c<this._context.length;++c) {
2755 var el = this._context[c];
2756 YAHOO.util.Event.removeListener(el, "mouseover", this.onContextMouseOver);
2757 YAHOO.util.Event.removeListener(el, "mousemove", this.onContextMouseMove);
2758 YAHOO.util.Event.removeListener(el, "mouseout", this.onContextMouseOut);
2759 }
2760 }
2761
2762 // Add mouseover/mouseout listeners to context elements
2763 this._context = context;
2764 for (var d=0;d<this._context.length;++d) {
2765 var el2 = this._context[d];
2766 YAHOO.util.Event.addListener(el2, "mouseover", this.onContextMouseOver, this);
2767 YAHOO.util.Event.addListener(el2, "mousemove", this.onContextMouseMove, this);
2768 YAHOO.util.Event.addListener(el2, "mouseout", this.onContextMouseOut, this);
2769 }
2770 }
2771};
2772
2773// END BUILT-IN PROPERTY EVENT HANDLERS //
2774
2775// BEGIN BUILT-IN DOM EVENT HANDLERS //
2776
2777/**
2778* The default event handler fired when the user moves the mouse while over the context element.
2779* @method onContextMouseMove
2780 * @param {DOMEvent} eThe current DOM event
2781 * @param {Object} objThe object argument
2782*/
2783YAHOO.widget.Tooltip.prototype.onContextMouseMove = function(e, obj) {
2784 obj.pageX = YAHOO.util.Event.getPageX(e);
2785 obj.pageY = YAHOO.util.Event.getPageY(e);
2786
2787};
2788
2789/**
2790* The default event handler fired when the user mouses over the context element.
2791* @method onContextMouseOver
2792 * @param {DOMEvent} eThe current DOM event
2793 * @param {Object} objThe object argument
2794*/
2795YAHOO.widget.Tooltip.prototype.onContextMouseOver = function(e, obj) {
2796
2797 if (obj.hideProcId) {
2798 clearTimeout(obj.hideProcId);
2799 obj.hideProcId = null;
2800 }
2801
2802 var context = this;
2803 YAHOO.util.Event.addListener(context, "mousemove", obj.onContextMouseMove, obj);
2804
2805 if (context.title) {
2806 obj._tempTitle = context.title;
2807 context.title = "";
2808 }
2809
2810 /**
2811 * The unique process ID associated with the thread responsible for showing the Tooltip.
2812 * @type int
2813 */
2814 obj.showProcId = obj.doShow(e, context);
2815};
2816
2817/**
2818* The default event handler fired when the user mouses out of the context element.
2819* @method onContextMouseOut
2820 * @param {DOMEvent} eThe current DOM event
2821 * @param {Object} objThe object argument
2822*/
2823YAHOO.widget.Tooltip.prototype.onContextMouseOut = function(e, obj) {
2824 var el = this;
2825
2826 if (obj._tempTitle) {
2827 el.title = obj._tempTitle;
2828 obj._tempTitle = null;
2829 }
2830
2831 if (obj.showProcId) {
2832 clearTimeout(obj.showProcId);
2833 obj.showProcId = null;
2834 }
2835
2836 if (obj.hideProcId) {
2837 clearTimeout(obj.hideProcId);
2838 obj.hideProcId = null;
2839 }
2840
2841
2842 obj.hideProcId = setTimeout(function() {
2843 obj.hide();
2844 }, obj.cfg.getProperty("hidedelay"));
2845};
2846
2847// END BUILT-IN DOM EVENT HANDLERS //
2848
2849/**
2850* Processes the showing of the Tooltip by setting the timeout delay and offset of the Tooltip.
2851* @method doShow
2852 * @param {DOMEvent} eThe current DOM event
2853 * @return {Number}The process ID of the timeout function associated with doShow
2854*/
2855YAHOO.widget.Tooltip.prototype.doShow = function(e, context) {
2856
2857 var yOffset = 25;
2858 if (this.browser == "opera" && context.tagName == "A") {
2859 yOffset += 12;
2860 }
2861
2862 var me = this;
2863 return setTimeout(
2864 function() {
2865 if (me._tempTitle) {
2866 me.setBody(me._tempTitle);
2867 } else {
2868 me.cfg.refireEvent("text");
2869 }
2870
2871 me.moveTo(me.pageX, me.pageY + yOffset);
2872 if (me.cfg.getProperty("preventoverlap")) {
2873 me.preventOverlap(me.pageX, me.pageY);
2874 }
2875
2876 YAHOO.util.Event.removeListener(context, "mousemove", me.onContextMouseMove);
2877
2878 me.show();
2879 me.hideProcId = me.doHide();
2880 },
2881 this.cfg.getProperty("showdelay"));
2882};
2883
2884/**
2885* Sets the timeout for the auto-dismiss delay, which by default is 5 seconds, meaning that a tooltip will automatically dismiss itself after 5 seconds of being displayed.
2886* @method doHide
2887*/
2888YAHOO.widget.Tooltip.prototype.doHide = function() {
2889 var me = this;
2890 return setTimeout(
2891 function() {
2892 me.hide();
2893 },
2894 this.cfg.getProperty("autodismissdelay"));
2895};
2896
2897/**
2898* Fired when the Tooltip is moved, this event handler is used to prevent the Tooltip from overlapping with its context element.
2899* @method preventOverlay
2900 * @param {Number} pageXThe x coordinate position of the mouse pointer
2901 * @param {Number} pageYThe y coordinate position of the mouse pointer
2902*/
2903YAHOO.widget.Tooltip.prototype.preventOverlap = function(pageX, pageY) {
2904
2905 var height = this.element.offsetHeight;
2906
2907 var elementRegion = YAHOO.util.Dom.getRegion(this.element);
2908
2909 elementRegion.top -= 5;
2910 elementRegion.left -= 5;
2911 elementRegion.right += 5;
2912 elementRegion.bottom += 5;
2913
2914 var mousePoint = new YAHOO.util.Point(pageX, pageY);
2915
2916 if (elementRegion.contains(mousePoint)) {
2917 this.cfg.setProperty("y", (pageY-height-5));
2918 }
2919};
2920
2921/**
2922* Returns a string representation of the object.
2923* @method toString
2924 * @return {String}The string representation of the Tooltip
2925*/
2926YAHOO.widget.Tooltip.prototype.toString = function() {
2927 return "Tooltip " + this.id;
2928};
2929
2930/**
2931* Panel is an implementation of Overlay that behaves like an OS window, with a draggable header and an optional close icon at the top right.
2932* @namespace YAHOO.widget
2933* @class Panel
2934* @extends YAHOO.widget.Overlay
2935* @constructor
2936 * @param {String} elThe element ID representing the Panel <em>OR</em>
2937 * @param {HTMLElement} elThe element representing the Panel
2938 * @param {Object} userConfigThe configuration object literal containing the configuration that should be set for this Panel. See configuration documentation for more details.
2939*/
2940YAHOO.widget.Panel = function(el, userConfig) {
2941 YAHOO.widget.Panel.superclass.constructor.call(this, el, userConfig);
2942};
2943
2944YAHOO.extend(YAHOO.widget.Panel, YAHOO.widget.Overlay);
2945
2946/**
2947* Constant representing the default CSS class used for a Panel
2948* @property YAHOO.widget.Panel.CSS_PANEL
2949* @static
2950* @final
2951* @type String
2952*/
2953YAHOO.widget.Panel.CSS_PANEL = "panel";
2954
2955/**
2956* Constant representing the default CSS class used for a Panel's wrapping container
2957* @property YAHOO.widget.Panel.CSS_PANEL_CONTAINER
2958* @static
2959* @final
2960* @type String
2961*/
2962YAHOO.widget.Panel.CSS_PANEL_CONTAINER = "panel-container";
2963
2964/**
2965* The Overlay initialization method, which is executed for Overlay and all of its subclasses. This method is automatically called by the constructor, and sets up all DOM references for pre-existing markup, and creates required markup if it is not already present.
2966* @method init
2967 * @param {String} elThe element ID representing the Overlay <em>OR</em>
2968 * @param {HTMLElement} elThe element representing the Overlay
2969 * @param {Object} userConfigThe configuration object literal containing the configuration that should be set for this Overlay. See configuration documentation for more details.
2970*/
2971YAHOO.widget.Panel.prototype.init = function(el, userConfig) {
2972 YAHOO.widget.Panel.superclass.init.call(this, el/*, userConfig*/); // Note that we don't pass the user config in here yet because we only want it executed once, at the lowest subclass level
2973
2974 this.beforeInitEvent.fire(YAHOO.widget.Panel);
2975
2976 YAHOO.util.Dom.addClass(this.element, YAHOO.widget.Panel.CSS_PANEL);
2977
2978 this.buildWrapper();
2979
2980 if (userConfig) {
2981 this.cfg.applyConfig(userConfig, true);
2982 }
2983
2984 this.beforeRenderEvent.subscribe(function() {
2985 var draggable = this.cfg.getProperty("draggable");
2986 if (draggable) {
2987 if (! this.header) {
2988 this.setHeader("&nbsp;");
2989 }
2990 }
2991 }, this, true);
2992
2993 var me = this;
2994
2995 this.showMaskEvent.subscribe(function() {
2996 var checkFocusable = function(el) {
2997 if (el.tagName == "A" || el.tagName == "BUTTON" || el.tagName == "SELECT" || el.tagName == "INPUT" || el.tagName == "TEXTAREA" || el.tagName == "FORM") {
2998 if (! YAHOO.util.Dom.isAncestor(me.element, el)) {
2999 YAHOO.util.Event.addListener(el, "focus", el.blur);
3000 return true;
3001 }
3002 } else {
3003 return false;
3004 }
3005 };
3006
3007 this.focusableElements = YAHOO.util.Dom.getElementsBy(checkFocusable);
3008 }, this, true);
3009
3010 this.hideMaskEvent.subscribe(function() {
3011 for (var i=0;i<this.focusableElements.length;i++) {
3012 var el2 = this.focusableElements[i];
3013 YAHOO.util.Event.removeListener(el2, "focus", el2.blur);
3014 }
3015 }, this, true);
3016
3017 this.beforeShowEvent.subscribe(function() {
3018 this.cfg.refireEvent("underlay");
3019 }, this, true);
3020
3021 this.initEvent.fire(YAHOO.widget.Panel);
3022};
3023
3024/**
3025* Initializes the custom events for Module which are fired automatically at appropriate times by the Module class.
3026*/
3027YAHOO.widget.Panel.prototype.initEvents = function() {
3028 YAHOO.widget.Panel.superclass.initEvents.call(this);
3029
3030 /**
3031 * CustomEvent fired after the modality mask is shown
3032 * @event showMaskEvent
3033 */
3034 this.showMaskEvent = new YAHOO.util.CustomEvent("showMask");
3035
3036 /**
3037 * CustomEvent fired after the modality mask is hidden
3038 * @event hideMaskEvent
3039 */
3040 this.hideMaskEvent = new YAHOO.util.CustomEvent("hideMask");
3041
3042 /**
3043 * CustomEvent when the Panel is dragged
3044 * @event dragEvent
3045 */
3046 this.dragEvent = new YAHOO.util.CustomEvent("drag");
3047};
3048
3049/**
3050* Initializes the class's configurable properties which can be changed using the Panel's Config object (cfg).
3051* @method initDefaultConfig
3052*/
3053YAHOO.widget.Panel.prototype.initDefaultConfig = function() {
3054 YAHOO.widget.Panel.superclass.initDefaultConfig.call(this);
3055
3056 // Add panel config properties //
3057
3058 /**
3059 * True if the Panel should display a "close" button
3060 * @config close
3061 * @type Boolean
3062 * @default true
3063 */
3064 this.cfg.addProperty("close", { value:true, handler:this.configClose, validator:this.cfg.checkBoolean, supercedes:["visible"] } );
3065
3066 /**
3067 * True if the Panel should be draggable
3068 * @config draggable
3069 * @type Boolean
3070 * @default true
3071 */
3072 this.cfg.addProperty("draggable", { value:true,handler:this.configDraggable, validator:this.cfg.checkBoolean, supercedes:["visible"] } );
3073
3074 /**
3075 * Sets the type of underlay to display for the Panel. Valid values are "shadow", "matte", and "none".
3076 * @config underlay
3077 * @type String
3078 * @default shadow
3079 */
3080 this.cfg.addProperty("underlay", { value:"shadow", handler:this.configUnderlay, supercedes:["visible"] } );
3081
3082 /**
3083 * True if the Panel should be displayed in a modal fashion, automatically creating a transparent mask over the document that will not be removed until the Panel is dismissed.
3084 * @config modal
3085 * @type Boolean
3086 * @default false
3087 */
3088 this.cfg.addProperty("modal",{ value:false, handler:this.configModal, validator:this.cfg.checkBoolean, supercedes:["visible"] } );
3089
3090 /**
3091 * A KeyListener (or array of KeyListeners) that will be enabled when the Panel is shown, and disabled when the Panel is hidden.
3092 * @config keylisteners
3093 * @type YAHOO.util.KeyListener[]
3094 * @default null
3095 */
3096 this.cfg.addProperty("keylisteners", { handler:this.configKeyListeners, suppressEvent:true, supercedes:["visible"] } );
3097};
3098
3099// BEGIN BUILT-IN PROPERTY EVENT HANDLERS //
3100
3101/**
3102* The default event handler fired when the "close" property is changed. The method controls the appending or hiding of the close icon at the top right of the Panel.
3103* @method configClose
3104 * @param {String} typeThe CustomEvent type (usually the property name)
3105 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
3106 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
3107*/
3108YAHOO.widget.Panel.prototype.configClose = function(type, args, obj) {
3109 var val = args[0];
3110
3111 var doHide = function(e, obj) {
3112 obj.hide();
3113 };
3114
3115 if (val) {
3116 if (! this.close) {
3117 this.close = document.createElement("DIV");
3118 YAHOO.util.Dom.addClass(this.close, "close");
3119
3120 if (this.isSecure) {
3121 YAHOO.util.Dom.addClass(this.close, "secure");
3122 } else {
3123 YAHOO.util.Dom.addClass(this.close, "nonsecure");
3124 }
3125
3126 this.close.innerHTML = "&nbsp;";
3127 this.innerElement.appendChild(this.close);
3128 YAHOO.util.Event.addListener(this.close, "click", doHide, this);
3129 } else {
3130 this.close.style.display = "block";
3131 }
3132 } else {
3133 if (this.close) {
3134 this.close.style.display = "none";
3135 }
3136 }
3137};
3138
3139/**
3140* The default event handler fired when the "draggable" property is changed.
3141* @method configDraggable
3142 * @param {String} typeThe CustomEvent type (usually the property name)
3143 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
3144 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
3145*/
3146YAHOO.widget.Panel.prototype.configDraggable = function(type, args, obj) {
3147 var val = args[0];
3148 if (val) {
3149 if (this.header) {
3150 YAHOO.util.Dom.setStyle(this.header,"cursor","move");
3151 this.registerDragDrop();
3152 }
3153 } else {
3154 if (this.dd) {
3155 this.dd.unreg();
3156 }
3157 if (this.header) {
3158 YAHOO.util.Dom.setStyle(this.header,"cursor","auto");
3159 }
3160 }
3161};
3162
3163/**
3164* The default event handler fired when the "underlay" property is changed.
3165* @method configUnderlay
3166 * @param {String} typeThe CustomEvent type (usually the property name)
3167 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
3168 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
3169*/
3170YAHOO.widget.Panel.prototype.configUnderlay = function(type, args, obj) {
3171 var val = args[0];
3172
3173 switch (val.toLowerCase()) {
3174 case "shadow":
3175 YAHOO.util.Dom.removeClass(this.element, "matte");
3176 YAHOO.util.Dom.addClass(this.element, "shadow");
3177
3178 if (! this.underlay) { // create if not already in DOM
3179 this.underlay = document.createElement("DIV");
3180 this.underlay.className = "underlay";
3181 this.underlay.innerHTML = "&nbsp;";
3182 this.element.appendChild(this.underlay);
3183 }
3184
3185 this.sizeUnderlay();
3186 break;
3187 case "matte":
3188 YAHOO.util.Dom.removeClass(this.element, "shadow");
3189 YAHOO.util.Dom.addClass(this.element, "matte");
3190 break;
3191 default:
3192 YAHOO.util.Dom.removeClass(this.element, "shadow");
3193 YAHOO.util.Dom.removeClass(this.element, "matte");
3194 break;
3195 }
3196};
3197
3198/**
3199* The default event handler fired when the "modal" property is changed. This handler subscribes or unsubscribes to the show and hide events to handle the display or hide of the modality mask.
3200* @method configModal
3201 * @param {String} typeThe CustomEvent type (usually the property name)
3202 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
3203 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
3204*/
3205YAHOO.widget.Panel.prototype.configModal = function(type, args, obj) {
3206 var modal = args[0];
3207
3208 if (modal) {
3209 this.buildMask();
3210
3211 if (! YAHOO.util.Config.alreadySubscribed( this.beforeShowEvent, this.showMask, this ) ) {
3212 this.beforeShowEvent.subscribe(this.showMask, this, true);
3213 }
3214 if (! YAHOO.util.Config.alreadySubscribed( this.hideEvent, this.hideMask, this) ) {
3215 this.hideEvent.subscribe(this.hideMask, this, true);
3216 }
3217 if (! YAHOO.util.Config.alreadySubscribed( YAHOO.widget.Overlay.windowResizeEvent, this.sizeMask, this ) ) {
3218 YAHOO.widget.Overlay.windowResizeEvent.subscribe(this.sizeMask, this, true);
3219 }
3220 if (! YAHOO.util.Config.alreadySubscribed( this.destroyEvent, this.removeMask, this) ) {
3221 this.destroyEvent.subscribe(this.removeMask, this, true);
3222 }
3223
3224 this.cfg.refireEvent("zIndex");
3225 } else {
3226 this.beforeShowEvent.unsubscribe(this.showMask, this);
3227 this.hideEvent.unsubscribe(this.hideMask, this);
3228 YAHOO.widget.Overlay.windowResizeEvent.unsubscribe(this.sizeMask, this);
3229 this.destroyEvent.unsubscribe(this.removeMask, this);
3230 }
3231};
3232
3233/**
3234* Removes the modality mask.
3235* @method removeMask
3236*/
3237YAHOO.widget.Panel.prototype.removeMask = function() {
3238 if (this.mask) {
3239 if (this.mask.parentNode) {
3240 this.mask.parentNode.removeChild(this.mask);
3241 }
3242 this.mask = null;
3243 }
3244};
3245
3246/**
3247* The default event handler fired when the "keylisteners" property is changed.
3248* @method configKeyListeners
3249 * @param {String} typeThe CustomEvent type (usually the property name)
3250 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
3251 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
3252*/
3253YAHOO.widget.Panel.prototype.configKeyListeners = function(type, args, obj) {
3254 var listeners = args[0];
3255
3256 if (listeners) {
3257 if (listeners instanceof Array) {
3258 for (var i=0;i<listeners.length;i++) {
3259 var listener = listeners[i];
3260
3261 if (! YAHOO.util.Config.alreadySubscribed(this.showEvent, listener.enable, listener)) {
3262 this.showEvent.subscribe(listener.enable, listener, true);
3263 }
3264 if (! YAHOO.util.Config.alreadySubscribed(this.hideEvent, listener.disable, listener)) {
3265 this.hideEvent.subscribe(listener.disable, listener, true);
3266 this.destroyEvent.subscribe(listener.disable, listener, true);
3267 }
3268 }
3269 } else {
3270 if (! YAHOO.util.Config.alreadySubscribed(this.showEvent, listeners.enable, listeners)) {
3271 this.showEvent.subscribe(listeners.enable, listeners, true);
3272 }
3273 if (! YAHOO.util.Config.alreadySubscribed(this.hideEvent, listeners.disable, listeners)) {
3274 this.hideEvent.subscribe(listeners.disable, listeners, true);
3275 this.destroyEvent.subscribe(listeners.disable, listeners, true);
3276 }
3277 }
3278 }
3279};
3280
3281/**
3282* The default event handler fired when the "height" property is changed.
3283* @method configHeight
3284 * @param {String} typeThe CustomEvent type (usually the property name)
3285 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
3286 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
3287*/
3288YAHOO.widget.Panel.prototype.configHeight = function(type, args, obj) {
3289 var height = args[0];
3290 var el = this.innerElement;
3291 YAHOO.util.Dom.setStyle(el, "height", height);
3292 this.cfg.refireEvent("underlay");
3293 this.cfg.refireEvent("iframe");
3294};
3295
3296/**
3297* The default event handler fired when the "width" property is changed.
3298* @method configWidth
3299 * @param {String} typeThe CustomEvent type (usually the property name)
3300 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
3301 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
3302*/
3303YAHOO.widget.Panel.prototype.configWidth = function(type, args, obj) {
3304 var width = args[0];
3305 var el = this.innerElement;
3306 YAHOO.util.Dom.setStyle(el, "width", width);
3307 this.cfg.refireEvent("underlay");
3308 this.cfg.refireEvent("iframe");
3309};
3310
3311/**
3312* The default event handler fired when the "zIndex" property is changed.
3313* @method configzIndex
3314 * @param {String} typeThe CustomEvent type (usually the property name)
3315 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
3316 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
3317*/
3318YAHOO.widget.Panel.prototype.configzIndex = function(type, args, obj) {
3319 YAHOO.widget.Panel.superclass.configzIndex.call(this, type, args, obj);
3320
3321 var maskZ = 0;
3322 var currentZ = YAHOO.util.Dom.getStyle(this.element, "zIndex");
3323
3324 if (this.mask) {
3325 if (! currentZ || isNaN(currentZ)) {
3326 currentZ = 0;
3327 }
3328
3329 if (currentZ === 0) {
3330 this.cfg.setProperty("zIndex", 1);
3331 } else {
3332 maskZ = currentZ - 1;
3333 YAHOO.util.Dom.setStyle(this.mask, "zIndex", maskZ);
3334 }
3335
3336 }
3337};
3338
3339// END BUILT-IN PROPERTY EVENT HANDLERS //
3340
3341/**
3342* Builds the wrapping container around the Panel that is used for positioning the shadow and matte underlays. The container element is assigned to a local instance variable called container, and the element is reinserted inside of it.
3343* @method buildWrapper
3344*/
3345YAHOO.widget.Panel.prototype.buildWrapper = function() {
3346 var elementParent = this.element.parentNode;
3347 var originalElement = this.element;
3348
3349 var wrapper = document.createElement("DIV");
3350 wrapper.className = YAHOO.widget.Panel.CSS_PANEL_CONTAINER;
3351 wrapper.id = originalElement.id + "_c";
3352
3353 if (elementParent) {
3354 elementParent.insertBefore(wrapper, originalElement);
3355 }
3356
3357 wrapper.appendChild(originalElement);
3358
3359 this.element = wrapper;
3360 this.innerElement = originalElement;
3361
3362 YAHOO.util.Dom.setStyle(this.innerElement, "visibility", "inherit");
3363};
3364
3365/**
3366* Adjusts the size of the shadow based on the size of the element.
3367* @method sizeUnderlay
3368*/
3369YAHOO.widget.Panel.prototype.sizeUnderlay = function() {
3370 if (this.underlay && this.browser != "gecko" && this.browser != "safari") {
3371 this.underlay.style.width = this.innerElement.offsetWidth + "px";
3372 this.underlay.style.height = this.innerElement.offsetHeight + "px";
3373 }
3374};
3375
3376/**
3377* Event handler fired when the resize monitor element is resized.
3378* @method onDomResize
3379 * @param {DOMEvent} eThe resize DOM event
3380 * @param {Object} objThe scope object
3381*/
3382YAHOO.widget.Panel.prototype.onDomResize = function(e, obj) {
3383 YAHOO.widget.Panel.superclass.onDomResize.call(this, e, obj);
3384 var me = this;
3385 setTimeout(function() {
3386 me.sizeUnderlay();
3387 }, 0);
3388};
3389
3390/**
3391* Registers the Panel's header for drag & drop capability.
3392* @method registerDragDrop
3393*/
3394YAHOO.widget.Panel.prototype.registerDragDrop = function() {
3395 if (this.header) {
3396 this.dd = new YAHOO.util.DD(this.element.id, this.id);
3397
3398 if (! this.header.id) {
3399 this.header.id = this.id + "_h";
3400 }
3401
3402 var me = this;
3403
3404 this.dd.startDrag = function() {
3405
3406 if (me.browser == "ie") {
3407 YAHOO.util.Dom.addClass(me.element,"drag");
3408 }
3409
3410 if (me.cfg.getProperty("constraintoviewport")) {
3411 var offsetHeight = me.element.offsetHeight;
3412 var offsetWidth = me.element.offsetWidth;
3413
3414 var viewPortWidth = YAHOO.util.Dom.getViewportWidth();
3415 var viewPortHeight = YAHOO.util.Dom.getViewportHeight();
3416
3417 var scrollX = window.scrollX || document.documentElement.scrollLeft;
3418 var scrollY = window.scrollY || document.documentElement.scrollTop;
3419
3420 var topConstraint = scrollY + 10;
3421 var leftConstraint = scrollX + 10;
3422 var bottomConstraint = scrollY + viewPortHeight - offsetHeight - 10;
3423 var rightConstraint = scrollX + viewPortWidth - offsetWidth - 10;
3424
3425 this.minX = leftConstraint;
3426 this.maxX = rightConstraint;
3427 this.constrainX = true;
3428
3429 this.minY = topConstraint;
3430 this.maxY = bottomConstraint;
3431 this.constrainY = true;
3432 } else {
3433 this.constrainX = false;
3434 this.constrainY = false;
3435 }
3436
3437 me.dragEvent.fire("startDrag", arguments);
3438 };
3439
3440 this.dd.onDrag = function() {
3441 me.syncPosition();
3442 me.cfg.refireEvent("iframe");
3443 if (this.platform == "mac" && this.browser == "gecko") {
3444 this.showMacGeckoScrollbars();
3445 }
3446
3447 me.dragEvent.fire("onDrag", arguments);
3448 };
3449
3450 this.dd.endDrag = function() {
3451 if (me.browser == "ie") {
3452 YAHOO.util.Dom.removeClass(me.element,"drag");
3453 }
3454
3455 me.dragEvent.fire("endDrag", arguments);
3456 };
3457
3458 this.dd.setHandleElId(this.header.id);
3459 this.dd.addInvalidHandleType("INPUT");
3460 this.dd.addInvalidHandleType("SELECT");
3461 this.dd.addInvalidHandleType("TEXTAREA");
3462 }
3463};
3464
3465/**
3466* Builds the mask that is laid over the document when the Panel is configured to be modal.
3467* @method buildMask
3468*/
3469YAHOO.widget.Panel.prototype.buildMask = function() {
3470 if (! this.mask) {
3471 this.mask = document.createElement("DIV");
3472 this.mask.id = this.id + "_mask";
3473 this.mask.className = "mask";
3474 this.mask.innerHTML = "&nbsp;";
3475
3476 var maskClick = function(e, obj) {
3477 YAHOO.util.Event.stopEvent(e);
3478 };
3479
3480 var firstChild = document.body.firstChild;
3481 if (firstChild){
3482 document.body.insertBefore(this.mask, document.body.firstChild);
3483 } else {
3484 document.body.appendChild(this.mask);
3485 }
3486 }
3487};
3488
3489/**
3490* Hides the modality mask.
3491* @method hideMask
3492*/
3493YAHOO.widget.Panel.prototype.hideMask = function() {
3494 if (this.cfg.getProperty("modal") && this.mask) {
3495 this.mask.style.display = "none";
3496 this.hideMaskEvent.fire();
3497 YAHOO.util.Dom.removeClass(document.body, "masked");
3498 }
3499};
3500
3501/**
3502* Shows the modality mask.
3503* @method showMask
3504*/
3505YAHOO.widget.Panel.prototype.showMask = function() {
3506 if (this.cfg.getProperty("modal") && this.mask) {
3507 YAHOO.util.Dom.addClass(document.body, "masked");
3508 this.sizeMask();
3509 this.mask.style.display = "block";
3510 this.showMaskEvent.fire();
3511 }
3512};
3513
3514/**
3515* Sets the size of the modality mask to cover the entire scrollable area of the document
3516* @method sizeMask
3517*/
3518YAHOO.widget.Panel.prototype.sizeMask = function() {
3519 if (this.mask) {
3520 this.mask.style.height = YAHOO.util.Dom.getDocumentHeight()+"px";
3521 this.mask.style.width = YAHOO.util.Dom.getDocumentWidth()+"px";
3522 }
3523};
3524
3525/**
3526* Renders the Panel by inserting the elements that are not already in the main Panel into their correct places. Optionally appends the Panel to the specified node prior to the render's execution. NOTE: For Panels without existing markup, the appendToNode argument is REQUIRED. If this argument is ommitted and the current element is not present in the document, the function will return false, indicating that the render was a failure.
3527* @method render
3528 * @param {String} appendToNodeThe element id to which the Module should be appended to prior to rendering <em>OR</em>
3529 * @param {HTMLElement} appendToNodeThe element to which the Module should be appended to prior to rendering
3530* @return {boolean} Success or failure of the render
3531*/
3532YAHOO.widget.Panel.prototype.render = function(appendToNode) {
3533 return YAHOO.widget.Panel.superclass.render.call(this, appendToNode, this.innerElement);
3534};
3535
3536/**
3537* Returns a String representation of the object.
3538* @method toString
3539* @return {String} The string representation of the Panel.
3540*/
3541YAHOO.widget.Panel.prototype.toString = function() {
3542 return "Panel " + this.id;
3543};
3544
3545/**
3546* Dialog is an implementation of Panel that can be used to submit form data. Built-in functionality for buttons with event handlers is included, and button sets can be build dynamically, or the preincluded ones for Submit/Cancel and OK/Cancel can be utilized. Forms can be processed in 3 ways -- via an asynchronous Connection utility call, a simple form POST or GET, or manually.
3547* @namespace YAHOO.widget
3548* @class Dialog
3549* @extends YAHOO.widget.Panel
3550* @constructor
3551 * @param {String} elThe element ID representing the Dialog <em>OR</em>
3552 * @param {HTMLElement} elThe element representing the Dialog
3553 * @param {Object} userConfigThe configuration object literal containing the configuration that should be set for this Dialog. See configuration documentation for more details.
3554*/
3555YAHOO.widget.Dialog = function(el, userConfig) {
3556 YAHOO.widget.Dialog.superclass.constructor.call(this, el, userConfig);
3557};
3558
3559YAHOO.extend(YAHOO.widget.Dialog, YAHOO.widget.Panel);
3560
3561/**
3562* Constant representing the default CSS class used for a Dialog
3563* @property YAHOO.widget.Dialog.CSS_DIALOG
3564* @static
3565* @final
3566* @type String
3567*/
3568YAHOO.widget.Dialog.CSS_DIALOG = "dialog";
3569
3570/**
3571* Initializes the class's configurable properties which can be changed using the Dialog's Config object (cfg).
3572* @method initDefaultConfig
3573*/
3574YAHOO.widget.Dialog.prototype.initDefaultConfig = function() {
3575 YAHOO.widget.Dialog.superclass.initDefaultConfig.call(this);
3576
3577 /**
3578 * The internally maintained callback object for use with the Connection utility
3579 * @property callback
3580 * @type Object
3581 */
3582 this.callback = {
3583 /**
3584 * The function to execute upon success of the Connection submission
3585 * @property callback.success
3586 * @type Function
3587 */
3588 success : null,
3589 /**
3590 * The function to execute upon failure of the Connection submission
3591 * @property callback.failure
3592 * @type Function
3593 */
3594 failure : null,
3595 /**
3596 * The arbitraty argument or arguments to pass to the Connection callback functions
3597 * @property callback.argument
3598 * @type Object
3599 */
3600 argument: null
3601 };
3602
3603 // Add form dialog config properties //
3604
3605 /**
3606 * The method to use for posting the Dialog's form. Possible values are "async", "form", and "manual".
3607 * @config postmethod
3608 * @type String
3609 * @default async
3610 */
3611 this.cfg.addProperty("postmethod", { value:"async", validator:function(val) {
3612 if (val != "form" && val != "async" && val != "none" && val != "manual") {
3613 return false;
3614 } else {
3615 return true;
3616 }
3617 } });
3618
3619 /**
3620 * Object literal(s) defining the buttons for the Dialog's footer.
3621 * @config buttons
3622 * @type Object[]
3623 * @default "none"
3624 */
3625 this.cfg.addProperty("buttons", { value:"none",handler:this.configButtons } );
3626};
3627
3628/**
3629* Initializes the custom events for Dialog which are fired automatically at appropriate times by the Dialog class.
3630* @method initEvents
3631*/
3632YAHOO.widget.Dialog.prototype.initEvents = function() {
3633 YAHOO.widget.Dialog.superclass.initEvents.call(this);
3634
3635 /**
3636 * CustomEvent fired prior to submission
3637 * @event beforeSumitEvent
3638 */
3639 this.beforeSubmitEvent= new YAHOO.util.CustomEvent("beforeSubmit");
3640
3641 /**
3642 * CustomEvent fired after submission
3643 * @event submitEvent
3644 */
3645 this.submitEvent = new YAHOO.util.CustomEvent("submit");
3646
3647 /**
3648 * CustomEvent fired prior to manual submission
3649 * @event manualSubmitEvent
3650 */
3651 this.manualSubmitEvent= new YAHOO.util.CustomEvent("manualSubmit");
3652
3653 /**
3654 * CustomEvent fired prior to asynchronous submission
3655 * @event asyncSubmitEvent
3656 */
3657 this.asyncSubmitEvent= new YAHOO.util.CustomEvent("asyncSubmit");
3658
3659 /**
3660 * CustomEvent fired prior to form-based submission
3661 * @event formSubmitEvent
3662 */
3663 this.formSubmitEvent= new YAHOO.util.CustomEvent("formSubmit");
3664
3665 /**
3666 * CustomEvent fired after cancel
3667 * @event cancelEvent
3668 */
3669 this.cancelEvent = new YAHOO.util.CustomEvent("cancel");
3670};
3671
3672/**
3673* The Dialog initialization method, which is executed for Dialog and all of its subclasses. This method is automatically called by the constructor, and sets up all DOM references for pre-existing markup, and creates required markup if it is not already present.
3674* @method init
3675 * @param {String} elThe element ID representing the Dialog <em>OR</em>
3676 * @param {HTMLElement} elThe element representing the Dialog
3677 * @param {Object} userConfigThe configuration object literal containing the configuration that should be set for this Dialog. See configuration documentation for more details.
3678*/
3679YAHOO.widget.Dialog.prototype.init = function(el, userConfig) {
3680 YAHOO.widget.Dialog.superclass.init.call(this, el/*, userConfig*/); // Note that we don't pass the user config in here yet because we only want it executed once, at the lowest subclass level
3681
3682 this.beforeInitEvent.fire(YAHOO.widget.Dialog);
3683
3684 YAHOO.util.Dom.addClass(this.element, YAHOO.widget.Dialog.CSS_DIALOG);
3685
3686 this.cfg.setProperty("visible", false);
3687
3688 if (userConfig) {
3689 this.cfg.applyConfig(userConfig, true);
3690 }
3691
3692 this.renderEvent.subscribe(this.registerForm, this, true);
3693
3694 this.showEvent.subscribe(this.focusFirst, this, true);
3695 this.beforeHideEvent.subscribe(this.blurButtons, this, true);
3696
3697 this.beforeRenderEvent.subscribe(function() {
3698 var buttonCfg = this.cfg.getProperty("buttons");
3699 if (buttonCfg && buttonCfg != "none") {
3700 if (! this.footer) {
3701 this.setFooter("");
3702 }
3703 }
3704 }, this, true);
3705
3706 this.initEvent.fire(YAHOO.widget.Dialog);
3707};
3708
3709/**
3710* Performs the submission of the Dialog form depending on the value of "postmethod" property.
3711* @method doSubmit
3712*/
3713YAHOO.widget.Dialog.prototype.doSubmit = function() {
3714 var pm = this.cfg.getProperty("postmethod");
3715 switch (pm) {
3716 case "async":
3717 var method = this.form.getAttribute("method") || 'POST';
3718 method = method.toUpperCase();
3719 YAHOO.util.Connect.setForm(this.form);
3720 var cObj = YAHOO.util.Connect.asyncRequest(method, this.form.getAttribute("action"), this.callback);
3721 this.asyncSubmitEvent.fire();
3722 break;
3723 case "form":
3724 this.form.submit();
3725 this.formSubmitEvent.fire();
3726 break;
3727 case "none":
3728 case "manual":
3729 this.manualSubmitEvent.fire();
3730 break;
3731 }
3732};
3733
3734/**
3735* Prepares the Dialog's internal FORM object, creating one if one is not currently present.
3736* @method registerForm
3737*/
3738YAHOO.widget.Dialog.prototype.registerForm = function() {
3739 var form = this.element.getElementsByTagName("FORM")[0];
3740
3741 if (! form) {
3742 var formHTML = "<form name=\"frm_" + this.id + "\" action=\"\"></form>";
3743 this.body.innerHTML += formHTML;
3744 form = this.element.getElementsByTagName("FORM")[0];
3745 }
3746
3747 this.firstFormElement = function() {
3748 for (var f=0;f<form.elements.length;f++ ) {
3749 var el = form.elements[f];
3750 if (el.focus) {
3751 if (el.type && el.type != "hidden") {
3752 return el;
3753 }
3754 }
3755 }
3756 return null;
3757 }();
3758
3759 this.lastFormElement = function() {
3760 for (var f=form.elements.length-1;f>=0;f-- ) {
3761 var el = form.elements[f];
3762 if (el.focus) {
3763 if (el.type && el.type != "hidden") {
3764 return el;
3765 }
3766 }
3767 }
3768 return null;
3769 }();
3770
3771 this.form = form;
3772
3773 if (this.cfg.getProperty("modal") && this.form) {
3774
3775 var me = this;
3776
3777 var firstElement = this.firstFormElement || this.firstButton;
3778 if (firstElement) {
3779 this.preventBackTab = new YAHOO.util.KeyListener(firstElement, { shift:true, keys:9 }, {fn:me.focusLast, scope:me, correctScope:true} );
3780 this.showEvent.subscribe(this.preventBackTab.enable, this.preventBackTab, true);
3781 this.hideEvent.subscribe(this.preventBackTab.disable, this.preventBackTab, true);
3782 }
3783
3784 var lastElement = this.lastButton || this.lastFormElement;
3785 if (lastElement) {
3786 this.preventTabOut = new YAHOO.util.KeyListener(lastElement, { shift:false, keys:9 }, {fn:me.focusFirst, scope:me, correctScope:true} );
3787 this.showEvent.subscribe(this.preventTabOut.enable, this.preventTabOut, true);
3788 this.hideEvent.subscribe(this.preventTabOut.disable, this.preventTabOut, true);
3789 }
3790 }
3791};
3792
3793// BEGIN BUILT-IN PROPERTY EVENT HANDLERS //
3794
3795/**
3796* The default event handler for the "buttons" configuration property
3797* @method configButtons
3798 * @param {String} typeThe CustomEvent type (usually the property name)
3799 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
3800 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
3801*/
3802YAHOO.widget.Dialog.prototype.configButtons = function(type, args, obj) {
3803 var buttons = args[0];
3804 if (buttons != "none") {
3805 this.buttonSpan = null;
3806 this.buttonSpan = document.createElement("SPAN");
3807 this.buttonSpan.className = "button-group";
3808
3809 for (var b=0;b<buttons.length;b++) {
3810 var button = buttons[b];
3811
3812 var htmlButton = document.createElement("BUTTON");
3813 htmlButton.setAttribute("type", "button");
3814
3815 if (button.isDefault) {
3816 htmlButton.className = "default";
3817 this.defaultHtmlButton = htmlButton;
3818 }
3819
3820 htmlButton.appendChild(document.createTextNode(button.text));
3821 YAHOO.util.Event.addListener(htmlButton, "click", button.handler, this, true);
3822
3823 this.buttonSpan.appendChild(htmlButton);
3824 button.htmlButton = htmlButton;
3825
3826 if (b === 0) {
3827 this.firstButton = button.htmlButton;
3828 }
3829
3830 if (b == (buttons.length-1)) {
3831 this.lastButton = button.htmlButton;
3832 }
3833
3834 }
3835
3836 this.setFooter(this.buttonSpan);
3837
3838 this.cfg.refireEvent("iframe");
3839 this.cfg.refireEvent("underlay");
3840 } else { // Do cleanup
3841 if (this.buttonSpan) {
3842 if (this.buttonSpan.parentNode) {
3843 this.buttonSpan.parentNode.removeChild(this.buttonSpan);
3844 }
3845
3846 this.buttonSpan = null;
3847 this.firstButton = null;
3848 this.lastButton = null;
3849 this.defaultHtmlButton = null;
3850 }
3851 }
3852};
3853
3854
3855/**
3856* The default event handler used to focus the first field of the form when the Dialog is shown.
3857* @method focusFirst
3858*/
3859YAHOO.widget.Dialog.prototype.focusFirst = function(type,args,obj) {
3860 if (args) {
3861 var e = args[1];
3862 if (e) {
3863 YAHOO.util.Event.stopEvent(e);
3864 }
3865 }
3866
3867 if (this.firstFormElement) {
3868 this.firstFormElement.focus();
3869 } else {
3870 this.focusDefaultButton();
3871 }
3872};
3873
3874/**
3875* Sets the focus to the last button in the button or form element in the Dialog
3876* @method focusLast
3877*/
3878YAHOO.widget.Dialog.prototype.focusLast = function(type,args,obj) {
3879 if (args) {
3880 var e = args[1];
3881 if (e) {
3882 YAHOO.util.Event.stopEvent(e);
3883 }
3884 }
3885
3886 var buttons = this.cfg.getProperty("buttons");
3887 if (buttons && buttons instanceof Array) {
3888 this.focusLastButton();
3889 } else {
3890 if (this.lastFormElement) {
3891 this.lastFormElement.focus();
3892 }
3893 }
3894};
3895
3896/**
3897* Sets the focus to the button that is designated as the default. By default, his handler is executed when the show event is fired.
3898* @method focusDefaultButton
3899*/
3900YAHOO.widget.Dialog.prototype.focusDefaultButton = function() {
3901 if (this.defaultHtmlButton) {
3902 this.defaultHtmlButton.focus();
3903 }
3904};
3905
3906/**
3907* Blurs all the html buttons
3908* @method blurButtons
3909*/
3910YAHOO.widget.Dialog.prototype.blurButtons = function() {
3911 var buttons = this.cfg.getProperty("buttons");
3912 if (buttons && buttons instanceof Array) {
3913 var html = buttons[0].htmlButton;
3914 if (html) {
3915 html.blur();
3916 }
3917 }
3918};
3919
3920/**
3921* Sets the focus to the first button in the button list
3922* @method focusFirstButton
3923*/
3924YAHOO.widget.Dialog.prototype.focusFirstButton = function() {
3925 var buttons = this.cfg.getProperty("buttons");
3926 if (buttons && buttons instanceof Array) {
3927 var html = buttons[0].htmlButton;
3928 if (html) {
3929 html.focus();
3930 }
3931 }
3932};
3933
3934/**
3935* Sets the focus to the first button in the button list
3936* @method focusLastButton
3937*/
3938YAHOO.widget.Dialog.prototype.focusLastButton = function() {
3939 var buttons = this.cfg.getProperty("buttons");
3940 if (buttons && buttons instanceof Array) {
3941 var html = buttons[buttons.length-1].htmlButton;
3942 if (html) {
3943 html.focus();
3944 }
3945 }
3946};
3947
3948// END BUILT-IN PROPERTY EVENT HANDLERS //
3949
3950/**
3951* Built-in function hook for writing a validation function that will be checked for a "true" value prior to a submit. This function, as implemented by default, always returns true, so it should be overridden if validation is necessary.
3952* @method validate
3953*/
3954YAHOO.widget.Dialog.prototype.validate = function() {
3955 return true;
3956};
3957
3958/**
3959* Executes a submit of the Dialog followed by a hide, if validation is successful.
3960* @method submit
3961*/
3962YAHOO.widget.Dialog.prototype.submit = function() {
3963 if (this.validate()) {
3964 this.beforeSubmitEvent.fire();
3965 this.doSubmit();
3966 this.submitEvent.fire();
3967 this.hide();
3968 return true;
3969 } else {
3970 return false;
3971 }
3972};
3973
3974/**
3975* Executes the cancel of the Dialog followed by a hide.
3976* @method cancel
3977*/
3978YAHOO.widget.Dialog.prototype.cancel = function() {
3979 this.cancelEvent.fire();
3980 this.hide();
3981};
3982
3983/**
3984* Returns a JSON-compatible data structure representing the data currently contained in the form.
3985* @method getData
3986* @return {Object} A JSON object reprsenting the data of the current form.
3987*/
3988YAHOO.widget.Dialog.prototype.getData = function() {
3989 var form = this.form;
3990 var data = {};
3991
3992 if (form) {
3993 for (var i in this.form) {
3994 var formItem = form[i];
3995 if (formItem) {
3996 if (formItem.tagName) { // Got a single form item
3997 switch (formItem.tagName) {
3998 case "INPUT":
3999 switch (formItem.type) {
4000 case "checkbox":
4001 data[i] = formItem.checked;
4002 break;
4003 case "textbox":
4004 case "text":
4005 case "hidden":
4006 data[i] = formItem.value;
4007 break;
4008 }
4009 break;
4010 case "TEXTAREA":
4011 data[i] = formItem.value;
4012 break;
4013 case "SELECT":
4014 var val = [];
4015 for (var x=0;x<formItem.options.length;x++){
4016 var option = formItem.options[x];
4017 if (option.selected) {
4018 var selval = option.value;
4019 if (! selval || selval === "") {
4020 selval = option.text;
4021 }
4022 val[val.length] = selval;
4023 }
4024 }
4025 data[i] = val;
4026 break;
4027 }
4028 } else if (formItem[0] && formItem[0].tagName) { // this is an array of form items
4029 if (formItem[0].tagName == "INPUT") {
4030 switch (formItem[0].type) {
4031 case "radio":
4032 for (var r=0; r<formItem.length; r++) {
4033 var radio = formItem[r];
4034 if (radio.checked) {
4035 data[radio.name] = radio.value;
4036 break;
4037 }
4038 }
4039 break;
4040 case "checkbox":
4041 var cbArray = [];
4042 for (var c=0; c<formItem.length; c++) {
4043 var check = formItem[c];
4044 if (check.checked) {
4045 cbArray[cbArray.length] = check.value;
4046 }
4047 }
4048 data[formItem[0].name] = cbArray;
4049 break;
4050 }
4051 }
4052 }
4053 }
4054 }
4055 }
4056 return data;
4057};
4058
4059/**
4060* Returns a string representation of the object.
4061* @method toString
4062 * @return {String}The string representation of the Dialog
4063*/
4064YAHOO.widget.Dialog.prototype.toString = function() {
4065 return "Dialog " + this.id;
4066};
4067
4068/**
4069* SimpleDialog is a simple implementation of Dialog that can be used to submit a single value. Forms can be processed in 3 ways -- via an asynchronous Connection utility call, a simple form POST or GET, or manually.
4070* @namespace YAHOO.widget
4071* @class SimpleDialog
4072* @extends YAHOO.widget.Dialog
4073* @constructor
4074 * @param {String} elThe element ID representing the SimpleDialog <em>OR</em>
4075 * @param {HTMLElement} elThe element representing the SimpleDialog
4076 * @param {Object} userConfigThe configuration object literal containing the configuration that should be set for this SimpleDialog. See configuration documentation for more details.
4077*/
4078YAHOO.widget.SimpleDialog = function(el, userConfig) {
4079 YAHOO.widget.SimpleDialog.superclass.constructor.call(this, el, userConfig);
4080};
4081
4082YAHOO.extend(YAHOO.widget.SimpleDialog, YAHOO.widget.Dialog);
4083
4084/**
4085* Constant for the standard network icon for a blocking action
4086* @property YAHOO.widget.SimpleDialog.ICON_BLOCK
4087* @static
4088* @final
4089* @type String
4090*/
4091YAHOO.widget.SimpleDialog.ICON_BLOCK = "nt/ic/ut/bsc/blck16_1.gif";
4092
4093/**
4094* Constant for the standard network icon for alarm
4095* @property YAHOO.widget.SimpleDialog.ICON_ALARM
4096* @static
4097* @final
4098* @type String
4099*/
4100YAHOO.widget.SimpleDialog.ICON_ALARM = "nt/ic/ut/bsc/alrt16_1.gif";
4101
4102/**
4103* Constant for the standard network icon for help
4104* @property YAHOO.widget.SimpleDialog.ICON_HELP
4105* @static
4106* @final
4107* @type String
4108*/
4109YAHOO.widget.SimpleDialog.ICON_HELP = "nt/ic/ut/bsc/hlp16_1.gif";
4110
4111/**
4112* Constant for the standard network icon for info
4113* @property YAHOO.widget.SimpleDialog.ICON_INFO
4114* @static
4115* @final
4116* @type String
4117*/
4118YAHOO.widget.SimpleDialog.ICON_INFO = "nt/ic/ut/bsc/info16_1.gif";
4119
4120/**
4121* Constant for the standard network icon for warn
4122* @property YAHOO.widget.SimpleDialog.ICON_WARN
4123* @static
4124* @final
4125* @type String
4126*/
4127YAHOO.widget.SimpleDialog.ICON_WARN = "nt/ic/ut/bsc/warn16_1.gif";
4128
4129/**
4130* Constant for the standard network icon for a tip
4131* @property YAHOO.widget.SimpleDialog.ICON_TIP
4132* @static
4133* @final
4134* @type String
4135*/
4136YAHOO.widget.SimpleDialog.ICON_TIP = "nt/ic/ut/bsc/tip16_1.gif";
4137
4138/**
4139* Constant representing the default CSS class used for a SimpleDialog
4140* @property YAHOO.widget.SimpleDialog.CSS_SIMPLEDIALOG
4141* @static
4142* @final
4143* @type String
4144*/
4145YAHOO.widget.SimpleDialog.CSS_SIMPLEDIALOG = "simple-dialog";
4146
4147/**
4148* Initializes the class's configurable properties which can be changed using the SimpleDialog's Config object (cfg).
4149* @method initDefaultConfig
4150*/
4151YAHOO.widget.SimpleDialog.prototype.initDefaultConfig = function() {
4152 YAHOO.widget.SimpleDialog.superclass.initDefaultConfig.call(this);
4153
4154 // Add dialog config properties //
4155
4156 /**
4157 * Sets the informational icon for the SimpleDialog
4158 * @config icon
4159 * @type String
4160 * @default "none"
4161 */
4162 this.cfg.addProperty("icon", { value:"none",handler:this.configIcon, suppressEvent:true } );
4163
4164 /**
4165 * Sets the text for the SimpleDialog
4166 * @config text
4167 * @type String
4168 * @default ""
4169 */
4170 this.cfg.addProperty("text",{ value:"", handler:this.configText, suppressEvent:true, supercedes:["icon"] } );
4171};
4172
4173
4174/**
4175* The SimpleDialog initialization method, which is executed for SimpleDialog and all of its subclasses. This method is automatically called by the constructor, and sets up all DOM references for pre-existing markup, and creates required markup if it is not already present.
4176* @method init
4177 * @param {String} elThe element ID representing the SimpleDialog <em>OR</em>
4178 * @param {HTMLElement} elThe element representing the SimpleDialog
4179 * @param {Object} userConfigThe configuration object literal containing the configuration that should be set for this SimpleDialog. See configuration documentation for more details.
4180*/
4181YAHOO.widget.SimpleDialog.prototype.init = function(el, userConfig) {
4182 YAHOO.widget.SimpleDialog.superclass.init.call(this, el/*, userConfig*/); // Note that we don't pass the user config in here yet because we only want it executed once, at the lowest subclass level
4183
4184 this.beforeInitEvent.fire(YAHOO.widget.SimpleDialog);
4185
4186 YAHOO.util.Dom.addClass(this.element, YAHOO.widget.SimpleDialog.CSS_SIMPLEDIALOG);
4187
4188 this.cfg.queueProperty("postmethod", "manual");
4189
4190 if (userConfig) {
4191 this.cfg.applyConfig(userConfig, true);
4192 }
4193
4194 this.beforeRenderEvent.subscribe(function() {
4195 if (! this.body) {
4196 this.setBody("");
4197 }
4198 }, this, true);
4199
4200 this.initEvent.fire(YAHOO.widget.SimpleDialog);
4201
4202};
4203/**
4204* Prepares the SimpleDialog's internal FORM object, creating one if one is not currently present, and adding the value hidden field.
4205* @method registerForm
4206*/
4207YAHOO.widget.SimpleDialog.prototype.registerForm = function() {
4208 YAHOO.widget.SimpleDialog.superclass.registerForm.call(this);
4209 this.form.innerHTML += "<input type=\"hidden\" name=\"" + this.id + "\" value=\"\"/>";
4210};
4211
4212// BEGIN BUILT-IN PROPERTY EVENT HANDLERS //
4213
4214/**
4215* Fired when the "icon" property is set.
4216* @method configIcon
4217 * @param {String} typeThe CustomEvent type (usually the property name)
4218 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
4219 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
4220*/
4221YAHOO.widget.SimpleDialog.prototype.configIcon = function(type,args,obj) {
4222 var icon = args[0];
4223 if (icon && icon != "none") {
4224 var iconHTML = "<img src=\"" + this.imageRoot + icon + "\" class=\"icon\" />";
4225 this.body.innerHTML = iconHTML + this.body.innerHTML;
4226 }
4227};
4228
4229/**
4230* Fired when the "text" property is set.
4231* @method configText
4232 * @param {String} typeThe CustomEvent type (usually the property name)
4233 * @param {Object[]} argsThe CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property.
4234 * @param {Object} objThe scope object. For configuration handlers, this will usually equal the owner.
4235*/
4236YAHOO.widget.SimpleDialog.prototype.configText = function(type,args,obj) {
4237 var text = args[0];
4238 if (text) {
4239 this.setBody(text);
4240 this.cfg.refireEvent("icon");
4241 }
4242};
4243// END BUILT-IN PROPERTY EVENT HANDLERS //
4244
4245/**
4246* Returns a string representation of the object.
4247* @method toString
4248 * @return {String}The string representation of the SimpleDialog
4249*/
4250YAHOO.widget.SimpleDialog.prototype.toString = function() {
4251 return "SimpleDialog " + this.id;
4252};
4253
4254/**
4255* ContainerEffect encapsulates animation transitions that are executed when an Overlay is shown or hidden.
4256* @namespace YAHOO.widget
4257* @class ContainerEffect
4258* @constructor
4259 * @param {YAHOO.widget.Overlay} overlay The Overlay that the animation should be associated with
4260 * @param {Object} attrIn The object literal representing the animation arguments to be used for the animate-in transition. The arguments for this literal are: attributes(object, see YAHOO.util.Anim for description), duration(Number), and method(i.e. YAHOO.util.Easing.easeIn).
4261 * @param {Object} attrOut The object literal representing the animation arguments to be used for the animate-out transition. The arguments for this literal are: attributes(object, see YAHOO.util.Anim for description), duration(Number), and method(i.e. YAHOO.util.Easing.easeIn).
4262 * @param {HTMLElement} targetElementOptional. The target element that should be animated during the transition. Defaults to overlay.element.
4263 * @param {class}Optional. The animation class to instantiate. Defaults to YAHOO.util.Anim. Other options include YAHOO.util.Motion.
4264*/
4265YAHOO.widget.ContainerEffect = function(overlay, attrIn, attrOut, targetElement, animClass) {
4266 if (! animClass) {
4267 animClass = YAHOO.util.Anim;
4268 }
4269
4270 /**
4271 * The overlay to animate
4272 * @property overlay
4273 * @type YAHOO.widget.Overlay
4274 */
4275 this.overlay = overlay;
4276 /**
4277 * The animation attributes to use when transitioning into view
4278 * @property attrIn
4279 * @type Object
4280 */
4281 this.attrIn = attrIn;
4282 /**
4283 * The animation attributes to use when transitioning out of view
4284 * @property attrOut
4285 * @type Object
4286 */
4287 this.attrOut = attrOut;
4288 /**
4289 * The target element to be animated
4290 * @property targetElement
4291 * @type HTMLElement
4292 */
4293 this.targetElement = targetElement || overlay.element;
4294 /**
4295 * The animation class to use for animating the overlay
4296 * @property animClass
4297 * @type class
4298 */
4299 this.animClass = animClass;
4300};
4301
4302/**
4303* Initializes the animation classes and events.
4304* @method init
4305*/
4306YAHOO.widget.ContainerEffect.prototype.init = function() {
4307 this.beforeAnimateInEvent = new YAHOO.util.CustomEvent("beforeAnimateIn");
4308 this.beforeAnimateOutEvent = new YAHOO.util.CustomEvent("beforeAnimateOut");
4309
4310 this.animateInCompleteEvent = new YAHOO.util.CustomEvent("animateInComplete");
4311 this.animateOutCompleteEvent = new YAHOO.util.CustomEvent("animateOutComplete");
4312
4313 this.animIn = new this.animClass(this.targetElement, this.attrIn.attributes, this.attrIn.duration, this.attrIn.method);
4314 this.animIn.onStart.subscribe(this.handleStartAnimateIn, this);
4315 this.animIn.onTween.subscribe(this.handleTweenAnimateIn, this);
4316 this.animIn.onComplete.subscribe(this.handleCompleteAnimateIn, this);
4317
4318 this.animOut = new this.animClass(this.targetElement, this.attrOut.attributes, this.attrOut.duration, this.attrOut.method);
4319 this.animOut.onStart.subscribe(this.handleStartAnimateOut, this);
4320 this.animOut.onTween.subscribe(this.handleTweenAnimateOut, this);
4321 this.animOut.onComplete.subscribe(this.handleCompleteAnimateOut, this);
4322};
4323
4324/**
4325* Triggers the in-animation.
4326* @method animateIn
4327*/
4328YAHOO.widget.ContainerEffect.prototype.animateIn = function() {
4329 this.beforeAnimateInEvent.fire();
4330 this.animIn.animate();
4331};
4332
4333/**
4334* Triggers the out-animation.
4335* @method animateOut
4336*/
4337YAHOO.widget.ContainerEffect.prototype.animateOut = function() {
4338 this.beforeAnimateOutEvent.fire();
4339 this.animOut.animate();
4340};
4341
4342/**
4343* The default onStart handler for the in-animation.
4344* @method handleStartAnimateIn
4345 * @param {String} typeThe CustomEvent type
4346 * @param {Object[]} argsThe CustomEvent arguments
4347 * @param {Object} objThe scope object
4348*/
4349YAHOO.widget.ContainerEffect.prototype.handleStartAnimateIn = function(type, args, obj) { };
4350/**
4351* The default onTween handler for the in-animation.
4352* @method handleTweenAnimateIn
4353 * @param {String} typeThe CustomEvent type
4354 * @param {Object[]} argsThe CustomEvent arguments
4355 * @param {Object} objThe scope object
4356*/
4357YAHOO.widget.ContainerEffect.prototype.handleTweenAnimateIn = function(type, args, obj) { };
4358/**
4359* The default onComplete handler for the in-animation.
4360* @method handleCompleteAnimateIn
4361 * @param {String} typeThe CustomEvent type
4362 * @param {Object[]} argsThe CustomEvent arguments
4363 * @param {Object} objThe scope object
4364*/
4365YAHOO.widget.ContainerEffect.prototype.handleCompleteAnimateIn = function(type, args, obj) { };
4366
4367/**
4368* The default onStart handler for the out-animation.
4369* @method handleStartAnimateOut
4370 * @param {String} typeThe CustomEvent type
4371 * @param {Object[]} argsThe CustomEvent arguments
4372 * @param {Object} objThe scope object
4373*/
4374YAHOO.widget.ContainerEffect.prototype.handleStartAnimateOut = function(type, args, obj) { };
4375/**
4376* The default onTween handler for the out-animation.
4377* @method handleTweenAnimateOut
4378 * @param {String} typeThe CustomEvent type
4379 * @param {Object[]} argsThe CustomEvent arguments
4380 * @param {Object} objThe scope object
4381*/
4382YAHOO.widget.ContainerEffect.prototype.handleTweenAnimateOut = function(type, args, obj) { };
4383/**
4384* The default onComplete handler for the out-animation.
4385* @method handleCompleteAnimateOut
4386 * @param {String} typeThe CustomEvent type
4387 * @param {Object[]} argsThe CustomEvent arguments
4388 * @param {Object} objThe scope object
4389*/
4390YAHOO.widget.ContainerEffect.prototype.handleCompleteAnimateOut = function(type, args, obj) { };
4391
4392/**
4393* Returns a string representation of the object.
4394* @method toString
4395 * @return {String}The string representation of the ContainerEffect
4396*/
4397YAHOO.widget.ContainerEffect.prototype.toString = function() {
4398 var output = "ContainerEffect";
4399 if (this.overlay) {
4400 output += " [" + this.overlay.toString() + "]";
4401 }
4402 return output;
4403};
4404
4405/**
4406* A pre-configured ContainerEffect instance that can be used for fading an overlay in and out.
4407* @method FADE
4408* @static
4409 * @param {Overlay}The Overlay object to animate
4410 * @param {Number}The duration of the animation
4411 * @return {ContainerEffect}The configured ContainerEffect object
4412*/
4413YAHOO.widget.ContainerEffect.FADE = function(overlay, dur) {
4414 var fade = new YAHOO.widget.ContainerEffect(overlay, { attributes:{opacity: {from:0, to:1}}, duration:dur, method:YAHOO.util.Easing.easeIn }, { attributes:{opacity: {to:0}}, duration:dur, method:YAHOO.util.Easing.easeOut}, overlay.element );
4415
4416 fade.handleStartAnimateIn = function(type,args,obj) {
4417 YAHOO.util.Dom.addClass(obj.overlay.element, "hide-select");
4418
4419 if (! obj.overlay.underlay) {
4420 obj.overlay.cfg.refireEvent("underlay");
4421 }
4422
4423 if (obj.overlay.underlay) {
4424 obj.initialUnderlayOpacity = YAHOO.util.Dom.getStyle(obj.overlay.underlay, "opacity");
4425 obj.overlay.underlay.style.filter = null;
4426 }
4427
4428 YAHOO.util.Dom.setStyle(obj.overlay.element, "visibility", "visible");
4429 YAHOO.util.Dom.setStyle(obj.overlay.element, "opacity", 0);
4430 };
4431
4432 fade.handleCompleteAnimateIn = function(type,args,obj) {
4433 YAHOO.util.Dom.removeClass(obj.overlay.element, "hide-select");
4434
4435 if (obj.overlay.element.style.filter) {
4436 obj.overlay.element.style.filter = null;
4437 }
4438
4439 if (obj.overlay.underlay) {
4440 YAHOO.util.Dom.setStyle(obj.overlay.underlay, "opacity", obj.initialUnderlayOpacity);
4441 }
4442
4443 obj.overlay.cfg.refireEvent("iframe");
4444 obj.animateInCompleteEvent.fire();
4445 };
4446
4447 fade.handleStartAnimateOut = function(type, args, obj) {
4448 YAHOO.util.Dom.addClass(obj.overlay.element, "hide-select");
4449
4450 if (obj.overlay.underlay) {
4451 obj.overlay.underlay.style.filter = null;
4452 }
4453 };
4454
4455 fade.handleCompleteAnimateOut = function(type, args, obj) {
4456 YAHOO.util.Dom.removeClass(obj.overlay.element, "hide-select");
4457 if (obj.overlay.element.style.filter) {
4458 obj.overlay.element.style.filter = null;
4459 }
4460 YAHOO.util.Dom.setStyle(obj.overlay.element, "visibility", "hidden");
4461 YAHOO.util.Dom.setStyle(obj.overlay.element, "opacity", 1);
4462
4463 obj.overlay.cfg.refireEvent("iframe");
4464
4465 obj.animateOutCompleteEvent.fire();
4466 };
4467
4468 fade.init();
4469 return fade;
4470};
4471
4472
4473/**
4474* A pre-configured ContainerEffect instance that can be used for sliding an overlay in and out.
4475* @method SLIDE
4476* @static
4477 * @param {Overlay}The Overlay object to animate
4478 * @param {Number}The duration of the animation
4479 * @return {ContainerEffect}The configured ContainerEffect object
4480*/
4481YAHOO.widget.ContainerEffect.SLIDE = function(overlay, dur) {
4482 var x = overlay.cfg.getProperty("x") || YAHOO.util.Dom.getX(overlay.element);
4483 var y = overlay.cfg.getProperty("y") || YAHOO.util.Dom.getY(overlay.element);
4484
4485 var clientWidth = YAHOO.util.Dom.getClientWidth();
4486 var offsetWidth = overlay.element.offsetWidth;
4487
4488 var slide = new YAHOO.widget.ContainerEffect(overlay, {
4489 attributes:{ points: { to:[x, y] } },
4490 duration:dur,
4491 method:YAHOO.util.Easing.easeIn
4492 },
4493 {
4494 attributes:{ points: { to:[(clientWidth+25), y] } },
4495 duration:dur,
4496 method:YAHOO.util.Easing.easeOut
4497 },
4498 overlay.element,
4499 YAHOO.util.Motion);
4500
4501
4502 slide.handleStartAnimateIn = function(type,args,obj) {
4503 obj.overlay.element.style.left = (-25-offsetWidth) + "px";
4504 obj.overlay.element.style.top = y + "px";
4505 };
4506
4507 slide.handleTweenAnimateIn = function(type, args, obj) {
4508
4509
4510 var pos = YAHOO.util.Dom.getXY(obj.overlay.element);
4511
4512 var currentX = pos[0];
4513 var currentY = pos[1];
4514
4515 if (YAHOO.util.Dom.getStyle(obj.overlay.element, "visibility") == "hidden" && currentX < x) {
4516 YAHOO.util.Dom.setStyle(obj.overlay.element, "visibility", "visible");
4517 }
4518
4519 obj.overlay.cfg.setProperty("xy", [currentX,currentY], true);
4520 obj.overlay.cfg.refireEvent("iframe");
4521 };
4522
4523 slide.handleCompleteAnimateIn = function(type, args, obj) {
4524 obj.overlay.cfg.setProperty("xy", [x,y], true);
4525 obj.startX = x;
4526 obj.startY = y;
4527 obj.overlay.cfg.refireEvent("iframe");
4528 obj.animateInCompleteEvent.fire();
4529 };
4530
4531 slide.handleStartAnimateOut = function(type, args, obj) {
4532 var vw = YAHOO.util.Dom.getViewportWidth();
4533
4534 var pos = YAHOO.util.Dom.getXY(obj.overlay.element);
4535
4536 var yso = pos[1];
4537
4538 var currentTo = obj.animOut.attributes.points.to;
4539 obj.animOut.attributes.points.to = [(vw+25), yso];
4540 };
4541
4542 slide.handleTweenAnimateOut = function(type, args, obj) {
4543 var pos = YAHOO.util.Dom.getXY(obj.overlay.element);
4544
4545 var xto = pos[0];
4546 var yto = pos[1];
4547
4548 obj.overlay.cfg.setProperty("xy", [xto,yto], true);
4549 obj.overlay.cfg.refireEvent("iframe");
4550 };
4551
4552 slide.handleCompleteAnimateOut = function(type, args, obj) {
4553 YAHOO.util.Dom.setStyle(obj.overlay.element, "visibility", "hidden");
4554
4555 obj.overlay.cfg.setProperty("xy", [x,y]);
4556 obj.animateOutCompleteEvent.fire();
4557 };
4558
4559 slide.init();
4560 return slide;
4561}; \ No newline at end of file