From 36b19314a4a9d4c5ea03b30304be56575a687d58 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 19 May 2008 22:52:12 +0000 Subject: [PATCH] * (bug 12773) addOnloadHook() now calls functions immediately when scripts are loaded after the primary page completion, instead of dropping them * (bug 13232) importScript(), importStylesheet() funcs available to custom JS Increases wikibits.js by 1k or so, but it should help with those custom scripts :D --- RELEASE-NOTES | 5 +++++ includes/DefaultSettings.php | 2 +- skins/common/wikibits.js | 41 +++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 21f5a5d373..cc1957dd93 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -117,6 +117,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Use rel="start", "prev", "next" appropriately on Pager-based pages * Add support for SQLite * AutoAuthenticate hook renamed to UserLoadFromSession +* (bug 13232) importScript(), importStylesheet() funcs available to custom JS + === Bug fixes in 1.13 === @@ -282,6 +284,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 13693) Categories sometimes claim to have a negative number of members * (bug 1701) Korean Hangul syllables now broken down properly in Category lists even if the wiki's overall content language is not Korean +* (bug 12773) addOnloadHook() now calls functions immediately when scripts are + loaded after the primary page completion, instead of dropping them + === API changes in 1.13 === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f61fb5a8ef..c2431e9d96 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1347,7 +1347,7 @@ $wgCacheEpoch = '20030516000000'; * to ensure that client-side caches don't keep obsolete copies of global * styles. */ -$wgStyleVersion = '145'; +$wgStyleVersion = '146'; # Server-side caching: diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index 3368c7335c..d40c571df2 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -31,7 +31,11 @@ if (!window.onloadFuncts) { function addOnloadHook(hookFunct) { // Allows add-on scripts to add onload functions - onloadFuncts[onloadFuncts.length] = hookFunct; + if(!doneOnloadHook) { + onloadFuncts[onloadFuncts.length] = hookFunct; + } else { + hookFunct(); // bug in MSIE script loading + } } function hookEvent(hookName, hookFunct) { @@ -42,6 +46,41 @@ function hookEvent(hookName, hookFunct) { } } +function importScript(page) { + return importScriptURI(wgScript + '?action=raw&ctype=text/javascript&title=' + encodeURIComponent(page.replace(/ /g,'_'))); +} + +var loadedScripts = {}; // included-scripts tracker +function importScriptURI(url) { + if (loadedScripts[url]) { + return; + } + loadedScripts[url] = true; + var s = document.createElement('script'); + s.setAttribute('src',url); + s.setAttribute('type','text/javascript'); + document.getElementsByTagName('head')[0].appendChild(s); + return s; +} + +function importStylesheet(page) { + return importStylesheetURI(wgScript + '?action=raw&ctype=text/css&title=' + encodeURIComponent(page.replace(/ /g,'_'))); +} + +function importStylesheetURI(url) { + return document.createStyleSheet ? document.createStyleSheet(url) : appendCSS('@import "' + url + '";'); +} + +function appendCSS(text) { + var s = document.createElement('style'); + s.type = 'text/css'; + s.rel = 'stylesheet'; + if (s.styleSheet) s.styleSheet.cssText = text //IE + else s.appendChild(document.createTextNode(text + '')) //Safari sometimes borks on null + document.getElementsByTagName('head')[0].appendChild(s); + return s; +} + // document.write special stylesheet links if (typeof stylepath != 'undefined' && typeof skin != 'undefined') { if (is_opera_preseven) { -- 2.20.1