Use capability testing instead of UA sniffing
[lhc/web/wiklou.git] / skins / common / wikibits.js
index 5e8e6ad..595d66d 100644 (file)
@@ -14,7 +14,7 @@ var is_khtml = navigator.vendor == 'KDE' ||
        ( document.childNodes && !document.all && !navigator.taintEnabled );
 // For accesskeys; note that FF3+ is included here!
 var is_ff2 = /firefox\/[2-9]|minefield\/3/.test( clientPC );
-var is_ff2_ = /firefox\/2/.test( clientPC );
+var ff2_bugs = /firefox\/2/.test( clientPC );
 // These aren't used here, but some custom scripts rely on them
 var is_ff2_win = is_ff2 && clientPC.indexOf('windows') != -1;
 var is_ff2_x11 = is_ff2 && clientPC.indexOf('x11') != -1;
@@ -23,6 +23,9 @@ if (clientPC.indexOf('opera') != -1) {
        var is_opera_preseven = window.opera && !document.childNodes;
        var is_opera_seven = window.opera && document.childNodes;
        var is_opera_95 = /opera\/(9.[5-9]|[1-9][0-9])/.test( clientPC );
+       var opera6_bugs = is_opera_preseven;     
+    var opera7_bugs = is_opera_seven && !is_opera_95;   
+    var opera95_bugs = /opera\/(9\.5)/.test( clientPC );
 }
 
 // Global external objects used by this script.
@@ -33,9 +36,10 @@ var doneOnloadHook;
 
 if (!window.onloadFuncts) {
        var onloadFuncts = [];
-}
-
-function addOnloadHook(hookFunct) {
+}      
+       
+//should use mwAddOnloadHook once js2 is enabled
+function addOnloadHook(hookFunct) {    
        // Allows add-on scripts to add onload functions
        if(!doneOnloadHook) {
                onloadFuncts[onloadFuncts.length] = hookFunct;
@@ -73,8 +77,14 @@ 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 importStylesheetURI(url,media) {
+       var l = document.createElement('link');
+       l.type = 'text/css';
+       l.rel = 'stylesheet';
+       l.href = url;
+       if(media) l.media = media
+       document.getElementsByTagName('head')[0].appendChild(l);
+       return l;
 }
  
 function appendCSS(text) {
@@ -89,19 +99,20 @@ function appendCSS(text) {
 
 // special stylesheet links
 if (typeof stylepath != 'undefined' && typeof skin != 'undefined') {
-       if (is_opera_preseven) {
+       // FIXME: This tries to load the stylesheets even for skins where they
+       // don't exist, i.e., everything but Monobook.
+       if (opera6_bugs) {
                importStylesheetURI(stylepath+'/'+skin+'/Opera6Fixes.css');
-       } else if (is_opera_seven && !is_opera_95) {
+       } else if (opera7_bugs) {
                importStylesheetURI(stylepath+'/'+skin+'/Opera7Fixes.css');
-       } else if (is_opera_95) {
+       } else if (opera95_bugs) {
                importStylesheetURI(stylepath+'/'+skin+'/Opera9Fixes.css');
-       } else if (is_khtml) {
-               importStylesheetURI(stylepath+'/'+skin+'/KHTMLFixes.css');
-       } else if (is_ff2_) {
+       } else if (ff2_bugs) {
                importStylesheetURI(stylepath+'/'+skin+'/FF2Fixes.css');
        }
 }
 
+
 if (wgBreakFrames) {
        // Un-trap us from framesets
        if (window.top != window) {
@@ -114,7 +125,9 @@ function showTocToggle() {
                // Uses DOM calls to avoid document.write + XHTML issues
 
                var linkHolder = document.getElementById('toctitle');
-               if (!linkHolder) {
+               var existingLink = document.getElementById('togglelink');
+               if (!linkHolder || existingLink) {
+                       // Don't add the toggle link twice
                        return;
                }
 
@@ -443,8 +456,23 @@ function toggle_element_activation(ida,idb) {
        if (!document.getElementById) {
                return;
        }
-       document.getElementById(ida).disabled=true;
-       document.getElementById(idb).disabled=false;
+       //hide and show appropriate upload sizes
+       if(idb == 'wpUploadFileURL'){
+               var e = document.getElementById('mw-upload-maxfilesize');
+               if(e) e.style.display = "none";         
+               
+               var e = document.getElementById('mw-upload-maxfilesize-url');
+               if(e) e.style.display = "block";                
+       }
+       if(idb == 'wpUploadFile'){
+               var e = document.getElementById('mw-upload-maxfilesize-url');
+               if(e) e.style.display =  "none";
+                                       
+               var e = document.getElementById('mw-upload-maxfilesize');
+               if(e) e.style.display =  "block";
+       }
+       document.getElementById(ida).disabled = true;
+       document.getElementById(idb).disabled = false;
 }
 
 function toggle_element_check(ida,idb) {