-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer.js
More file actions
4727 lines (4000 loc) · 144 KB
/
container.js
File metadata and controls
4727 lines (4000 loc) · 144 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2007, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.net/yui/license.txt
version: 2.2.0
*/
/**
* 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.
* @namespace YAHOO.util
* @class Config
* @constructor
* @param {Object} owner The owner Object to which this Config Object belongs
*/
YAHOO.util.Config = function(owner) {
if (owner) {
this.init(owner);
}
};
YAHOO.util.Config.prototype = {
/**
* Object reference to the owner of this Config Object
* @property owner
* @type Object
*/
owner : null,
/**
* Boolean flag that specifies whether a queue is currently being executed
* @property queueInProgress
* @type Boolean
*/
queueInProgress : false,
/**
* Validates that the value passed in is a Boolean.
* @method checkBoolean
* @param {Object} val The value to validate
* @return {Boolean} true, if the value is valid
*/
checkBoolean: function(val) {
if (typeof val == 'boolean') {
return true;
} else {
return false;
}
},
/**
* Validates that the value passed in is a number.
* @method checkNumber
* @param {Object} val The value to validate
* @return {Boolean} true, if the value is valid
*/
checkNumber: function(val) {
if (isNaN(val)) {
return false;
} else {
return true;
}
}
};
/**
* Initializes the configuration Object and all of its local members.
* @method init
* @param {Object} owner The owner Object to which this Config Object belongs
*/
YAHOO.util.Config.prototype.init = function(owner) {
this.owner = owner;
/**
* Object reference to the owner of this Config Object
* @event configChangedEvent
*/
this.configChangedEvent = new YAHOO.util.CustomEvent("configChanged");
this.queueInProgress = false;
/* Private Members */
/**
* Maintains the local collection of configuration property objects and their specified values
* @property config
* @private
* @type Object
*/
var config = {};
/**
* Maintains the local collection of configuration property objects as they were initially applied.
* This object is used when resetting a property.
* @property initialConfig
* @private
* @type Object
*/
var initialConfig = {};
/**
* Maintains the local, normalized CustomEvent queue
* @property eventQueue
* @private
* @type Object
*/
var eventQueue = [];
/**
* Fires a configuration property event using the specified value.
* @method fireEvent
* @private
* @param {String} key The configuration property's name
* @param {value} Object The value of the correct type for the property
*/
var fireEvent = function( key, value ) {
key = key.toLowerCase();
var property = config[key];
if (typeof property != 'undefined' && property.event) {
property.event.fire(value);
}
};
/* End Private Members */
/**
* Adds a property to the Config Object's private config hash.
* @method addProperty
* @param {String} key The configuration property's name
* @param {Object} propertyObject The Object containing all of this property's arguments
*/
this.addProperty = function( key, propertyObject ) {
key = key.toLowerCase();
config[key] = propertyObject;
propertyObject.event = new YAHOO.util.CustomEvent(key);
propertyObject.key = key;
if (propertyObject.handler) {
propertyObject.event.subscribe(propertyObject.handler, this.owner, true);
}
this.setProperty(key, propertyObject.value, true);
if (! propertyObject.suppressEvent) {
this.queueProperty(key, propertyObject.value);
}
};
/**
* Returns a key-value configuration map of the values currently set in the Config Object.
* @method getConfig
* @return {Object} The current config, represented in a key-value map
*/
this.getConfig = function() {
var cfg = {};
for (var prop in config) {
var property = config[prop];
if (typeof property != 'undefined' && property.event) {
cfg[prop] = property.value;
}
}
return cfg;
};
/**
* Returns the value of specified property.
* @method getProperty
* @param {String} key The name of the property
* @return {Object} The value of the specified property
*/
this.getProperty = function(key) {
key = key.toLowerCase();
var property = config[key];
if (typeof property != 'undefined' && property.event) {
return property.value;
} else {
return undefined;
}
};
/**
* Resets the specified property's value to its initial value.
* @method resetProperty
* @param {String} key The name of the property
* @return {Boolean} True is the property was reset, false if not
*/
this.resetProperty = function(key) {
key = key.toLowerCase();
var property = config[key];
if (typeof property != 'undefined' && property.event) {
if (initialConfig[key] && initialConfig[key] != 'undefined') {
this.setProperty(key, initialConfig[key]);
}
return true;
} else {
return false;
}
};
/**
* Sets the value of a property. If the silent property is passed as true, the property's event will not be fired.
* @method setProperty
* @param {String} key The name of the property
* @param {String} value The value to set the property to
* @param {Boolean} silent Whether the value should be set silently, without firing the property event.
* @return {Boolean} True, if the set was successful, false if it failed.
*/
this.setProperty = function(key, value, silent) {
key = key.toLowerCase();
if (this.queueInProgress && ! silent) {
this.queueProperty(key,value); // Currently running through a queue...
return true;
} else {
var property = config[key];
if (typeof property != 'undefined' && property.event) {
if (property.validator && ! property.validator(value)) { // validator
return false;
} else {
property.value = value;
if (! silent) {
fireEvent(key, value);
this.configChangedEvent.fire([key, value]);
}
return true;
}
} else {
return false;
}
}
};
/**
* Sets the value of a property and queues its event to execute. If the event is already scheduled to execute, it is
* moved from its current position to the end of the queue.
* @method queueProperty
* @param {String} key The name of the property
* @param {String} value The value to set the property to
* @return {Boolean} true, if the set was successful, false if it failed.
*/
this.queueProperty = function(key, value) {
key = key.toLowerCase();
var property = config[key];
if (typeof property != 'undefined' && property.event) {
if (typeof value != 'undefined' && property.validator && ! property.validator(value)) { // validator
return false;
} else {
if (typeof value != 'undefined') {
property.value = value;
} else {
value = property.value;
}
var foundDuplicate = false;
for (var i=0;i<eventQueue.length;i++) {
var queueItem = eventQueue[i];
if (queueItem) {
var queueItemKey = queueItem[0];
var queueItemValue = queueItem[1];
if (queueItemKey.toLowerCase() == key) {
// found a dupe... push to end of queue, null current item, and break
eventQueue[i] = null;
eventQueue.push([key, (typeof value != 'undefined' ? value : queueItemValue)]);
foundDuplicate = true;
break;
}
}
}
if (! foundDuplicate && typeof value != 'undefined') { // this is a refire, or a new property in the queue
eventQueue.push([key, value]);
}
}
if (property.supercedes) {
for (var s=0;s<property.supercedes.length;s++) {
var supercedesCheck = property.supercedes[s];
for (var q=0;q<eventQueue.length;q++) {
var queueItemCheck = eventQueue[q];
if (queueItemCheck) {
var queueItemCheckKey = queueItemCheck[0];
var queueItemCheckValue = queueItemCheck[1];
if ( queueItemCheckKey.toLowerCase() == supercedesCheck.toLowerCase() ) {
eventQueue.push([queueItemCheckKey, queueItemCheckValue]);
eventQueue[q] = null;
break;
}
}
}
}
}
return true;
} else {
return false;
}
};
/**
* Fires the event for a property using the property's current value.
* @method refireEvent
* @param {String} key The name of the property
*/
this.refireEvent = function(key) {
key = key.toLowerCase();
var property = config[key];
if (typeof property != 'undefined' && property.event && typeof property.value != 'undefined') {
if (this.queueInProgress) {
this.queueProperty(key);
} else {
fireEvent(key, property.value);
}
}
};
/**
* Applies a key-value Object literal to the configuration, replacing any existing values, and queueing the property events.
* Although the values will be set, fireQueue() must be called for their associated events to execute.
* @method applyConfig
* @param {Object} userConfig The configuration Object literal
* @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.
*/
this.applyConfig = function(userConfig, init) {
if (init) {
initialConfig = userConfig;
}
for (var prop in userConfig) {
this.queueProperty(prop, userConfig[prop]);
}
};
/**
* Refires the events for all configuration properties using their current values.
* @method refresh
*/
this.refresh = function() {
for (var prop in config) {
this.refireEvent(prop);
}
};
/**
* Fires the normalized list of queued property change events
* @method fireQueue
*/
this.fireQueue = function() {
this.queueInProgress = true;
for (var i=0;i<eventQueue.length;i++) {
var queueItem = eventQueue[i];
if (queueItem) {
var key = queueItem[0];
var value = queueItem[1];
var property = config[key];
property.value = value;
fireEvent(key,value);
}
}
this.queueInProgress = false;
eventQueue = [];
};
/**
* Subscribes an external handler to the change event for any given property.
* @method subscribeToConfigEvent
* @param {String} key The property name
* @param {Function} handler The handler function to use subscribe to the property's event
* @param {Object} obj The Object to use for scoping the event handler (see CustomEvent documentation)
* @param {Boolean} override Optional. If true, will override "this" within the handler to map to the scope Object passed into the method.
* @return {Boolean} True, if the subscription was successful, otherwise false.
*/
this.subscribeToConfigEvent = function(key, handler, obj, override) {
key = key.toLowerCase();
var property = config[key];
if (typeof property != 'undefined' && property.event) {
if (! YAHOO.util.Config.alreadySubscribed(property.event, handler, obj)) {
property.event.subscribe(handler, obj, override);
}
return true;
} else {
return false;
}
};
/**
* Unsubscribes an external handler from the change event for any given property.
* @method unsubscribeFromConfigEvent
* @param {String} key The property name
* @param {Function} handler The handler function to use subscribe to the property's event
* @param {Object} obj The Object to use for scoping the event handler (see CustomEvent documentation)
* @return {Boolean} True, if the unsubscription was successful, otherwise false.
*/
this.unsubscribeFromConfigEvent = function(key, handler, obj) {
key = key.toLowerCase();
var property = config[key];
if (typeof property != 'undefined' && property.event) {
return property.event.unsubscribe(handler, obj);
} else {
return false;
}
};
/**
* Returns a string representation of the Config object
* @method toString
* @return {String} The Config object in string format.
*/
this.toString = function() {
var output = "Config";
if (this.owner) {
output += " [" + this.owner.toString() + "]";
}
return output;
};
/**
* Returns a string representation of the Config object's current CustomEvent queue
* @method outputEventQueue
* @return {String} The string list of CustomEvents currently queued for execution
*/
this.outputEventQueue = function() {
var output = "";
for (var q=0;q<eventQueue.length;q++) {
var queueItem = eventQueue[q];
if (queueItem) {
output += queueItem[0] + "=" + queueItem[1] + ", ";
}
}
return output;
};
};
/**
* Checks to determine if a particular function/Object pair are already subscribed to the specified CustomEvent
* @method YAHOO.util.Config.alreadySubscribed
* @static
* @param {YAHOO.util.CustomEvent} evt The CustomEvent for which to check the subscriptions
* @param {Function} fn The function to look for in the subscribers list
* @param {Object} obj The execution scope Object for the subscription
* @return {Boolean} true, if the function/Object pair is already subscribed to the CustomEvent passed in
*/
YAHOO.util.Config.alreadySubscribed = function(evt, fn, obj) {
for (var e=0;e<evt.subscribers.length;e++) {
var subsc = evt.subscribers[e];
if (subsc && subsc.obj == obj && subsc.fn == fn) {
return true;
}
}
return false;
};
/**
* 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.
* @module container
* @title Container
* @requires yahoo,dom,event,dragdrop,animation
*/
/**
* 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.
* @namespace YAHOO.widget
* @class Module
* @constructor
* @param {String} el The element ID representing the Module <em>OR</em>
* @param {HTMLElement} el The element representing the Module
* @param {Object} userConfig The configuration Object literal containing the configuration that should be set for this module. See configuration documentation for more details.
*/
YAHOO.widget.Module = function(el, userConfig) {
if (el) {
this.init(el, userConfig);
} else {
}
};
/**
* Constant representing the prefix path to use for non-secure images
* @property YAHOO.widget.Module.IMG_ROOT
* @static
* @final
* @type String
*/
YAHOO.widget.Module.IMG_ROOT = null;
/**
* Constant representing the prefix path to use for securely served images
* @property YAHOO.widget.Module.IMG_ROOT_SSL
* @static
* @final
* @type String
*/
YAHOO.widget.Module.IMG_ROOT_SSL = null;
/**
* Constant for the default CSS class name that represents a Module
* @property YAHOO.widget.Module.CSS_MODULE
* @static
* @final
* @type String
*/
YAHOO.widget.Module.CSS_MODULE = "module";
/**
* Constant representing the module header
* @property YAHOO.widget.Module.CSS_HEADER
* @static
* @final
* @type String
*/
YAHOO.widget.Module.CSS_HEADER = "hd";
/**
* Constant representing the module body
* @property YAHOO.widget.Module.CSS_BODY
* @static
* @final
* @type String
*/
YAHOO.widget.Module.CSS_BODY = "bd";
/**
* Constant representing the module footer
* @property YAHOO.widget.Module.CSS_FOOTER
* @static
* @final
* @type String
*/
YAHOO.widget.Module.CSS_FOOTER = "ft";
/**
* Constant representing the url for the "src" attribute of the iframe used to monitor changes to the browser's base font size
* @property YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL
* @static
* @final
* @type String
*/
YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL = "javascript:false;";
/**
* Singleton CustomEvent fired when the font size is changed in the browser.
* Opera's "zoom" functionality currently does not support text size detection.
* @event YAHOO.widget.Module.textResizeEvent
*/
YAHOO.widget.Module.textResizeEvent = new YAHOO.util.CustomEvent("textResize");
YAHOO.widget.Module.prototype = {
/**
* The class's constructor function
* @property contructor
* @type Function
*/
constructor : YAHOO.widget.Module,
/**
* The main module element that contains the header, body, and footer
* @property element
* @type HTMLElement
*/
element : null,
/**
* The header element, denoted with CSS class "hd"
* @property header
* @type HTMLElement
*/
header : null,
/**
* The body element, denoted with CSS class "bd"
* @property body
* @type HTMLElement
*/
body : null,
/**
* The footer element, denoted with CSS class "ft"
* @property footer
* @type HTMLElement
*/
footer : null,
/**
* The id of the element
* @property id
* @type String
*/
id : null,
/**
* The String representing the image root
* @property imageRoot
* @type String
*/
imageRoot : YAHOO.widget.Module.IMG_ROOT,
/**
* Initializes the custom events for Module which are fired automatically at appropriate times by the Module class.
* @method initEvents
*/
initEvents : function() {
/**
* CustomEvent fired prior to class initalization.
* @event beforeInitEvent
* @param {class} classRef class reference of the initializing class, such as this.beforeInitEvent.fire(YAHOO.widget.Module)
*/
this.beforeInitEvent = new YAHOO.util.CustomEvent("beforeInit");
/**
* CustomEvent fired after class initalization.
* @event initEvent
* @param {class} classRef class reference of the initializing class, such as this.beforeInitEvent.fire(YAHOO.widget.Module)
*/
this.initEvent = new YAHOO.util.CustomEvent("init");
/**
* CustomEvent fired when the Module is appended to the DOM
* @event appendEvent
*/
this.appendEvent = new YAHOO.util.CustomEvent("append");
/**
* CustomEvent fired before the Module is rendered
* @event beforeRenderEvent
*/
this.beforeRenderEvent = new YAHOO.util.CustomEvent("beforeRender");
/**
* CustomEvent fired after the Module is rendered
* @event renderEvent
*/
this.renderEvent = new YAHOO.util.CustomEvent("render");
/**
* CustomEvent fired when the header content of the Module is modified
* @event changeHeaderEvent
* @param {String/HTMLElement} content String/element representing the new header content
*/
this.changeHeaderEvent = new YAHOO.util.CustomEvent("changeHeader");
/**
* CustomEvent fired when the body content of the Module is modified
* @event changeBodyEvent
* @param {String/HTMLElement} content String/element representing the new body content
*/
this.changeBodyEvent = new YAHOO.util.CustomEvent("changeBody");
/**
* CustomEvent fired when the footer content of the Module is modified
* @event changeFooterEvent
* @param {String/HTMLElement} content String/element representing the new footer content
*/
this.changeFooterEvent = new YAHOO.util.CustomEvent("changeFooter");
/**
* CustomEvent fired when the content of the Module is modified
* @event changeContentEvent
*/
this.changeContentEvent = new YAHOO.util.CustomEvent("changeContent");
/**
* CustomEvent fired when the Module is destroyed
* @event destroyEvent
*/
this.destroyEvent = new YAHOO.util.CustomEvent("destroy");
/**
* CustomEvent fired before the Module is shown
* @event beforeShowEvent
*/
this.beforeShowEvent = new YAHOO.util.CustomEvent("beforeShow");
/**
* CustomEvent fired after the Module is shown
* @event showEvent
*/
this.showEvent = new YAHOO.util.CustomEvent("show");
/**
* CustomEvent fired before the Module is hidden
* @event beforeHideEvent
*/
this.beforeHideEvent = new YAHOO.util.CustomEvent("beforeHide");
/**
* CustomEvent fired after the Module is hidden
* @event hideEvent
*/
this.hideEvent = new YAHOO.util.CustomEvent("hide");
},
/**
* String representing the current user-agent platform
* @property platform
* @type String
*/
platform : function() {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1) {
return "windows";
} else if (ua.indexOf("macintosh") != -1) {
return "mac";
} else {
return false;
}
}(),
/**
* String representing the current user-agent browser
* @property browser
* @type String
*/
browser : function() {
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('opera')!=-1) { // Opera (check first in case of spoof)
return 'opera';
} else if (ua.indexOf('msie 7')!=-1) { // IE7
return 'ie7';
} else if (ua.indexOf('msie') !=-1) { // IE
return 'ie';
} else if (ua.indexOf('safari')!=-1) { // Safari (check before Gecko because it includes "like Gecko")
return 'safari';
} else if (ua.indexOf('gecko') != -1) { // Gecko
return 'gecko';
} else {
return false;
}
}(),
/**
* Boolean representing whether or not the current browsing context is secure (https)
* @property isSecure
* @type Boolean
*/
isSecure : function() {
if (window.location.href.toLowerCase().indexOf("https") === 0) {
return true;
} else {
return false;
}
}(),
/**
* Initializes the custom events for Module which are fired automatically at appropriate times by the Module class.
*/
initDefaultConfig : function() {
// Add properties //
/**
* Specifies whether the Module is visible on the page.
* @config visible
* @type Boolean
* @default true
*/
this.cfg.addProperty("visible", { value:true, handler:this.configVisible, validator:this.cfg.checkBoolean } );
/**
* Object or array of objects representing the ContainerEffect classes that are active for animating the container.
* @config effect
* @type Object
* @default null
*/
this.cfg.addProperty("effect", { suppressEvent:true, supercedes:["visible"] } );
/**
* Specifies whether to create a special proxy iframe to monitor for user font resizing in the document
* @config monitorresize
* @type Boolean
* @default true
*/
this.cfg.addProperty("monitorresize", { value:true, handler:this.configMonitorResize } );
},
/**
* 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.
* @method init
* @param {String} el The element ID representing the Module <em>OR</em>
* @param {HTMLElement} el The element representing the Module
* @param {Object} userConfig The configuration Object literal containing the configuration that should be set for this module. See configuration documentation for more details.
*/
init : function(el, userConfig) {
this.initEvents();
this.beforeInitEvent.fire(YAHOO.widget.Module);
/**
* The Module's Config object used for monitoring configuration properties.
* @property cfg
* @type YAHOO.util.Config
*/
this.cfg = new YAHOO.util.Config(this);
if (this.isSecure) {
this.imageRoot = YAHOO.widget.Module.IMG_ROOT_SSL;
}
if (typeof el == "string") {
var elId = el;
el = document.getElementById(el);
if (! el) {
el = document.createElement("div");
el.id = elId;
}
}
this.element = el;
if (el.id) {
this.id = el.id;
}
var childNodes = this.element.childNodes;
if (childNodes) {
for (var i=0;i<childNodes.length;i++) {
var child = childNodes[i];
switch (child.className) {
case YAHOO.widget.Module.CSS_HEADER:
this.header = child;
break;
case YAHOO.widget.Module.CSS_BODY:
this.body = child;
break;
case YAHOO.widget.Module.CSS_FOOTER:
this.footer = child;
break;
}
}
}
this.initDefaultConfig();
YAHOO.util.Dom.addClass(this.element, YAHOO.widget.Module.CSS_MODULE);
if (userConfig) {
this.cfg.applyConfig(userConfig, true);
}
// Subscribe to the fireQueue() method of Config so that any queued configuration changes are
// excecuted upon render of the Module
if (! YAHOO.util.Config.alreadySubscribed(this.renderEvent, this.cfg.fireQueue, this.cfg)) {
this.renderEvent.subscribe(this.cfg.fireQueue, this.cfg, true);
}
this.initEvent.fire(YAHOO.widget.Module);
},
/**
* Initialized an empty IFRAME that is placed out of the visible area that can be used to detect text resize.
* @method initResizeMonitor
*/
initResizeMonitor : function() {
if(this.browser != "opera") {
var resizeMonitor = document.getElementById("_yuiResizeMonitor");
if (! resizeMonitor) {
resizeMonitor = document.createElement("iframe");
var bIE = (this.browser.indexOf("ie") === 0);
if(this.isSecure && YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL && bIE) {
resizeMonitor.src = YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL;
}
resizeMonitor.id = "_yuiResizeMonitor";
resizeMonitor.style.visibility = "hidden";
document.body.appendChild(resizeMonitor);
resizeMonitor.style.width = "10em";
resizeMonitor.style.height = "10em";
resizeMonitor.style.position = "absolute";
var nLeft = -1 * resizeMonitor.offsetWidth;
var nTop = -1 * resizeMonitor.offsetHeight;
resizeMonitor.style.top = nTop + "px";
resizeMonitor.style.left = nLeft + "px";
resizeMonitor.style.borderStyle = "none";
resizeMonitor.style.borderWidth = "0";
YAHOO.util.Dom.setStyle(resizeMonitor, "opacity", "0");
resizeMonitor.style.visibility = "visible";
if(!bIE) {
var doc = resizeMonitor.contentWindow.document;
doc.open();
doc.close();
}
}
var fireTextResize = function() {
YAHOO.widget.Module.textResizeEvent.fire();
};
if(resizeMonitor && resizeMonitor.contentWindow) {
this.resizeMonitor = resizeMonitor;
YAHOO.widget.Module.textResizeEvent.subscribe(this.onDomResize, this, true);
if (! YAHOO.widget.Module.textResizeInitialized) {
if (! YAHOO.util.Event.addListener(this.resizeMonitor.contentWindow, "resize", fireTextResize)) {
// This will fail in IE if document.domain has changed, so we must change the listener to
// use the resizeMonitor element instead
YAHOO.util.Event.addListener(this.resizeMonitor, "resize", fireTextResize);
}
YAHOO.widget.Module.textResizeInitialized = true;
}
}
}
},
/**
* Event handler fired when the resize monitor element is resized.
* @method onDomResize
* @param {DOMEvent} e The DOM resize event
* @param {Object} obj The scope object passed to the handler
*/
onDomResize : function(e, obj) {
var nLeft = -1 * this.resizeMonitor.offsetWidth,
nTop = -1 * this.resizeMonitor.offsetHeight;
this.resizeMonitor.style.top = nTop + "px";
this.resizeMonitor.style.left = nLeft + "px";
},
/**
* 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.
* @method setHeader
* @param {String} headerContent The HTML used to set the header <em>OR</em>
* @param {HTMLElement} headerContent The HTMLElement to append to the header
*/
setHeader : function(headerContent) {
if (! this.header) {
this.header = document.createElement("div");
this.header.className = YAHOO.widget.Module.CSS_HEADER;
}
if (typeof headerContent == "string") {
this.header.innerHTML = headerContent;
} else {
this.header.innerHTML = "";
this.header.appendChild(headerContent);
}
this.changeHeaderEvent.fire(headerContent);
this.changeContentEvent.fire();
},
/**
* Appends the passed element to the header. If no header is present, one will be automatically created.
* @method appendToHeader
* @param {HTMLElement} element The element to append to the header
*/
appendToHeader : function(element) {
if (! this.header) {
this.header = document.createElement("div");
this.header.className = YAHOO.widget.Module.CSS_HEADER;
}
this.header.appendChild(element);
this.changeHeaderEvent.fire(element);
this.changeContentEvent.fire();
},
/**
* 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.