X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=skins%2Fcommon%2Fwikibits.js;h=95b2e06974cc8ebe9f5a0f5d054ecd49bc9b3aeb;hb=4f278f513d5bf24c7252732a168e3646cc5af101;hp=ca91418cb33c8532b34f700386b47a253583440b;hpb=d6229fdbab72d7a48531a1301a1f8f42355f7579;p=lhc%2Fweb%2Fwiklou.git diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index ca91418cb3..95b2e06974 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -10,11 +10,9 @@ if (webkit_match) { var is_safari_win = is_safari && clientPC.indexOf('windows') != -1; var webkit_version = parseInt(webkit_match[1]); } -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; @@ -22,7 +20,10 @@ if (clientPC.indexOf('opera') != -1) { var is_opera = true; 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 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. @@ -44,17 +45,19 @@ function addOnloadHook(hookFunct) { } } + function hookEvent(hookName, hookFunct) { addHandler(window, hookName, hookFunct); } function importScript(page) { + // TODO: might want to introduce a utility function to match wfUrlencode() in PHP var uri = wgScript + '?title=' + - encodeURIComponent(page.replace(/ /g,'_')).replace('%2F','/').replace('%3A',':') + + encodeURIComponent(page.replace(/ /g,'_')).replace(/%2F/ig,'/').replace(/%3A/ig,':') + '&action=raw&ctype=text/javascript'; return importScriptURI(uri); } - + var loadedScripts = {}; // included-scripts tracker function importScriptURI(url) { if (loadedScripts[url]) { @@ -67,15 +70,21 @@ function importScriptURI(url) { 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 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) { var s = document.createElement('style'); s.type = 'text/css'; @@ -88,19 +97,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) { @@ -113,7 +123,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; } @@ -150,6 +162,7 @@ function changeText(el, newText) { } function toggleToc() { + var tocmain = document.getElementById('toc'); var toc = document.getElementById('toc').getElementsByTagName('ul')[0]; var toggleLink = document.getElementById('togglelink'); @@ -157,10 +170,12 @@ function toggleToc() { changeText(toggleLink, tocHideText); toc.style.display = 'block'; document.cookie = "hidetoc=0"; + tocmain.className = 'toc'; } else { changeText(toggleLink, tocShowText); toc.style.display = 'none'; document.cookie = "hidetoc=1"; + tocmain.className = 'toc tochidden'; } } @@ -215,10 +230,19 @@ var tooltipAccessKeyRegexp = /\[(ctrl-)?(alt-)?(shift-)?(esc-)?(.)\]$/; */ function updateTooltipAccessKeys( nodeList ) { if ( !nodeList ) { - // skins without a "column-one" element don't seem to have links with accesskeys either - var columnOne = document.getElementById("column-one"); - if ( columnOne ) - updateTooltipAccessKeys( columnOne.getElementsByTagName("a") ); + // Rather than scan all links on the whole page, we can just scan these + // containers which contain the relevant links. This is really just an + // optimization technique. + var linkContainers = [ + "column-one", // Monobook and Modern + "head", "panel", "p-logo" // Vector + ]; + for ( var i in linkContainers ) { + var linkContainer = document.getElementById( linkContainers[i] ); + if ( linkContainer ) { + updateTooltipAccessKeys( linkContainer.getElementsByTagName("a") ); + } + } // these are rare enough that no such optimization is needed updateTooltipAccessKeys( document.getElementsByTagName("input") ); updateTooltipAccessKeys( document.getElementsByTagName("label") ); @@ -265,13 +289,19 @@ function updateTooltipAccessKeys( nodeList ) { * @return Node -- the DOM node of the new item (an LI element) or null */ function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) { - var node = document.getElementById(portlet); - if ( !node ) return null; - node = node.getElementsByTagName( "ul" )[0]; + var root = document.getElementById(portlet); + if ( !root ) return null; + var node = root.getElementsByTagName( "ul" )[0]; if ( !node ) return null; + // unhide portlet if it was hidden before + root.className = root.className.replace( /(^| )emptyPortlet( |$)/, "$2" ); + + var span = document.createElement( "span" ); + span.appendChild( document.createTextNode( text ) ); + var link = document.createElement( "a" ); - link.appendChild( document.createTextNode( text ) ); + link.appendChild( span ); link.href = href; var item = document.createElement( "li" ); @@ -319,63 +349,8 @@ function getInnerText(el) { return str; } - -/** - * Set up accesskeys/tooltips from the deprecated ta array. If doId - * is specified, only set up for that id. Note that this function is - * deprecated and will not be supported indefinitely -- use - * updateTooltipAccessKey() instead. - * - * @param mixed doId string or null - */ +/* Dummy for deprecated function */ function akeytt( doId ) { - // A lot of user scripts (and some of the code below) break if - // ta isn't defined, so we make sure it is. Explictly using - // window.ta avoids a "ta is not defined" error. - if (!window.ta) window.ta = new Array; - - // Make a local, possibly restricted, copy to avoid clobbering - // the original. - var ta; - if ( doId ) { - ta = [doId]; - } else { - ta = window.ta; - } - - // Now deal with evil deprecated ta - var watchCheckboxExists = document.getElementById( 'wpWatchthis' ) ? true : false; - for (var id in ta) { - var n = document.getElementById(id); - if (n) { - var a = null; - var ak = ''; - // Are we putting accesskey in it - if (ta[id][0].length > 0) { - // Is this object a object? If not assume it's the next child. - - if (n.nodeName.toLowerCase() == "a") { - a = n; - } else { - a = n.childNodes[0]; - } - // Don't add an accesskey for the watch tab if the watch - // checkbox is also available. - if (a && ((id != 'ca-watch' && id != 'ca-unwatch') || !watchCheckboxExists)) { - a.accessKey = ta[id][0]; - ak = ' ['+tooltipAccessKeyPrefix+ta[id][0]+']'; - } - } else { - // We don't care what type the object is when assigning tooltip - a = n; - ak = ''; - } - - if (a) { - a.title = ta[id][1]+ak; - } - } - } } var checkboxes; @@ -431,27 +406,13 @@ function checkboxClickHandler(e) { } for (var i = start; i <= finish; ++i ) { checkboxes[i].checked = endState; - if( i > start ) checkboxes[i].onchange(); // fire triggers + if( i > start && typeof checkboxes[i].onchange == 'function' ) + checkboxes[i].onchange(); // fire triggers } lastCheckbox = this.index; return true; } -function toggle_element_activation(ida,idb) { - if (!document.getElementById) { - return; - } - document.getElementById(ida).disabled=true; - document.getElementById(idb).disabled=false; -} - -function toggle_element_check(ida,idb) { - if (!document.getElementById) { - return; - } - document.getElementById(ida).checked=true; - document.getElementById(idb).checked=false; -} /* Written by Jonathan Snook, http://www.snook.ca/jonathan @@ -572,8 +533,7 @@ function ts_makeSortable(table) { for (var i = 0; i < firstRow.cells.length; i++) { var cell = firstRow.cells[i]; if ((" "+cell.className+" ").indexOf(" unsortable ") == -1) { - cell.innerHTML += '  ' - + '' + '' + '