* (bug 12773) addOnloadHook() now calls functions immediately when scripts are
authorBrion Vibber <brion@users.mediawiki.org>
Mon, 19 May 2008 22:52:12 +0000 (22:52 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Mon, 19 May 2008 22:52:12 +0000 (22:52 +0000)
  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
includes/DefaultSettings.php
skins/common/wikibits.js

index 21f5a5d..cc1957d 100644 (file)
@@ -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 ===
 
index f61fb5a..c2431e9 100644 (file)
@@ -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:
index 3368c73..d40c571 100644 (file)
@@ -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) {