dom.onload() example
/*dom object =============== */
dom = {
__n:0,
_onload_timeout:10,
_onload_max_timeout:200,
hasChildren:false,
onload:function () {
if (typeof document.getElementsByTagName == 'undefined' || arguments.length < 1)
return false;
var i, iStart = typeof arguments [0] == 'object'? 2: 1;
this.readyList = this.readyList? this.readyList: [];
var args = [];
for (i=iStart ; i= this._onload_max_timeout)
return alert ('A timeout error has occurred in DOM-nodes');
if(this.__n++ < this._onload_max_timeout)
setTimeout('dom._onload()', this._onload_timeout);
},
_onReady:function () {
for (var el in this.readyList)
if (typeof this.readyList [el].obj == 'undefined')
this.readyList [el].func.apply (window, this.readyList [el].args );
else
this.readyList [el].func.apply (this.readyList [el].obj, this.readyList [el].args );
this.readyList = [];
},
hasChildNodes:function () {
if (typeof document.getElementsByTagName != 'undefined' && (document.getElementsByTagName('body')[0] != null || document.body != null))
this.hasChildren = true;
return this.hasChildren;
}
}
/*dom object =============== */
/*example 1: simple functions*/
function foo(el,el2) {
alert(el + " " + el2)
}
dom.onload(foo, 'hello','world');
/*example 2: javascript classes with constructor*/
var bar = function () {
this.id = 'bar';
}
bar.prototype.test = function (el) {
alert ( el + this.id );
}
var b = new bar ();
dom.onload(b, b.test, 'welcome to the ');
....
...
...
...