mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/ConfirmEdit
synced 2024-11-28 10:00:29 +00:00
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
/*!
|
|
* contentloaded.js
|
|
*
|
|
* Author: Diego Perini (diego.perini at gmail.com)
|
|
* Summary: cross-browser wrapper for DOMContentLoaded
|
|
* Updated: 20101020
|
|
* License: MIT
|
|
* Version: 1.2
|
|
*
|
|
* URL:
|
|
* http://javascript.nwbox.com/ContentLoaded/
|
|
* http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
|
|
*
|
|
*/
|
|
|
|
// @win window reference
|
|
// @fn function reference
|
|
function contentLoaded(win, fn) {
|
|
|
|
var done = false, top = true,
|
|
|
|
doc = win.document, root = doc.documentElement,
|
|
|
|
add = doc.addEventListener ? 'addEventListener' : 'attachEvent',
|
|
rem = doc.addEventListener ? 'removeEventListener' : 'detachEvent',
|
|
pre = doc.addEventListener ? '' : 'on',
|
|
|
|
init = function(e) {
|
|
if (e.type == 'readystatechange' && doc.readyState != 'complete') return;
|
|
(e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
|
|
if (!done && (done = true)) fn.call(win, e.type || e);
|
|
},
|
|
|
|
poll = function() {
|
|
try { root.doScroll('left'); } catch(e) { setTimeout(poll, 50); return; }
|
|
init('poll');
|
|
};
|
|
|
|
if (doc.readyState == 'complete') fn.call(win, 'lazy');
|
|
else {
|
|
if (doc.createEventObject && root.doScroll) {
|
|
try { top = !win.frameElement; } catch(e) { }
|
|
if (top) poll();
|
|
}
|
|
doc[add](pre + 'DOMContentLoaded', init, false);
|
|
doc[add](pre + 'readystatechange', init, false);
|
|
win[add](pre + 'load', init, false);
|
|
}
|
|
|
|
}
|