From 32163b441b60008751e76284ecfc6eb39db8a705 Mon Sep 17 00:00:00 2001 From: Tom Gilder Date: Wed, 26 Oct 2005 00:57:14 +0000 Subject: [PATCH] Rewrite of JS onload hook code; allows add-on scripts to run functions as soon as content has loaded (i.e. a lot sooner than the actual onload event) --- skins/MonoBook.php | 2 +- skins/common/wikibits.js | 30 ++++++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/skins/MonoBook.php b/skins/MonoBook.php index a1460f7e64..d8ff280492 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -227,7 +227,7 @@ class MonoBookTemplate extends QuickTemplate { data['tagline']) { ?>
  • data['tagline'] ?>
  • - + html('reporttime') ?> diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index bfb3ec1437..32194ed816 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -14,19 +14,41 @@ if (clientPC.indexOf('opera')!=-1) { // add any onload functions in this hook (please don't hard-code any events in the xhtml source) var doneOnloadHook; +var onloadFuncts = []; -function onloadhook () { +function addOnloadHook( hookFunct ) +{ + // Allows add-on scripts to add onload functions + onloadFuncts[onloadFuncts.length] = hookFunct; +} + +function runOnloadHook() + { // don't run anything below this for non-dom browsers - if (doneOnloadHook || !(document.getElementById && document.getElementsByTagName)) return; + if ( doneOnloadHook || !( document.getElementById && document.getElementsByTagName ) ) + return; + histrowinit(); unhidetzbutton(); tabbedprefs(); akeytt(); + + // Run any added-on functions + for ( var i = 0; i < onloadFuncts.length; i++ ) + onloadFuncts[i](); + doneOnloadHook = true; } -if (window.addEventListener) window.addEventListener("load",onloadhook,false); -else if (window.attachEvent) window.attachEvent("onload",onloadhook); +function hookEvent( hookName, hookFunct ) +{ + if ( window.addEventListener ) + addEventListener( hookName, hookFunct, false ); + else if ( window.attachEvent ) + attachEvent( "on" + hookName, hookFunct ); +} + +hookEvent( "load", runOnloadHook ); // document.write special stylesheet links if(typeof stylepath != 'undefined' && typeof skin != 'undefined') { -- 2.20.1