*
2
Script: Window.Base.js
3
Contains Window.onDomReady
4
5
Authors:
6
- Christophe Beyls, <http://www.digitalia.be>
7
- Valerio Proietti, <http://mad4milk.net>
8
9
License:
10
MIT-style license.
11
*/
12
13
/*
14
Class: Window
15
Cross browser methods to get the window size, onDomReady method.
16
*/
17
18
window.extend({
19
20
/*
21
Property: window.addEvent
22
same as <Element.addEvent> but allows the event 'domready', which is the same as <window.onDomReady>
23
24
Credits:
25
(c) Dean Edwards/Matthias Miller/John Resig, remastered for mootools.
26
27
Arguments:
28
init - the function to execute when the DOM is ready
29
30
Example:
31
> window.addEvent('domready', function(){alert('the dom is ready')});
32
*/
33
34
addEvent: function(type, fn){
35
if (type == 'domready'){
36
if (this.loaded) fn();
37
else if (!this.events || !this.events.domready){
38
var domReady = function(){
39
if (this.loaded) return;
40
this.loaded = true;
41
if (this.timer) this.timer = $clear(this.timer);
42
Element.prototype.fireEvent.call(this, 'domready');
43
this.events.domready = null;
44
}.bind(this);
45
if (document.readyState && this.khtml){ //safari and konqueror
46
this.timer = function(){
47
if (['loaded','complete'].test(document.readyState)) domReady();
48
}.periodical(50);
49
}
50
else if (document.readyState && this.ie){ //ie
51
document.write("<script id=ie_ready defer src=javascript:void(0)><\/script>");
52
$('ie_ready').onreadystatechange = function(){
53
if (this.readyState == 'complete') domReady();
54
};
55
} else { //others
56
this.addEvent("load", domReady);
57
document.addEvent("DOMContentLoaded", domReady);
58
}
59
}
60
}
61
Element.prototype.addEvent.call(this, type, fn);
62
return this;
63
},
64
65
/*
66
Property: window.onDomReady
67
Executes the passed in function when the DOM is ready (when the document tree has loaded, not waiting for images).
68
Same as <window.addEvent> ('domready', init).
69
70
Arguments:
71
init - the function to execute when the DOM is ready
72
73
Example:
74
> window.addEvent('domready', function(){alert('the dom is ready')});
75
*/
76
77
onDomReady: function(init){
78
return this.addEvent('domready', init);
79
}
80
81
}); 
