From 0da22435e3ef38eb9fc2e2e3ca6edaf68886342b Mon Sep 17 00:00:00 2001 From: Jack Phoenix Date: Wed, 13 Jan 2010 13:17:19 +0000 Subject: [PATCH] JavaScript cleanup: add spacing, missing braces, use single quotes instead of double quotes where appropriate and fix some comparisons --- includes/DefaultSettings.php | 2 +- skins/common/block.js | 32 +- skins/common/edit.js | 150 +++++---- skins/common/htmlform.js | 30 +- skins/common/metadata.js | 36 +- skins/common/prefs.js | 185 ++++++----- skins/common/search.js | 41 ++- skins/common/wikibits.js | 615 ++++++++++++++++++----------------- 8 files changed, 582 insertions(+), 509 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index d3175a320d..ddef2a0263 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1658,7 +1658,7 @@ $wgCacheEpoch = '20030516000000'; * to ensure that client-side caches do not keep obsolete copies of global * styles. */ -$wgStyleVersion = '260'; +$wgStyleVersion = '261'; # Server-side caching: diff --git a/skins/common/block.js b/skins/common/block.js index e08bb15865..ad04f8103b 100644 --- a/skins/common/block.js +++ b/skins/common/block.js @@ -1,19 +1,19 @@ -addOnloadHook(considerChangingExpiryFocus); +addOnloadHook( considerChangingExpiryFocus ); function considerChangingExpiryFocus() { - if (!document.getElementById) { + if ( !document.getElementById ) { return; } - var drop = document.getElementById('wpBlockExpiry'); - if (!drop) { + var drop = document.getElementById( 'wpBlockExpiry' ); + if ( !drop ) { return; } - var field = document.getElementById('wpBlockOther'); - if (!field) { + var field = document.getElementById( 'wpBlockOther' ); + if ( !field ) { return; } var opt = drop.value; - if (opt == 'other') { + if ( opt == 'other' ) { field.style.display = ''; } else { field.style.display = 'none'; @@ -21,34 +21,36 @@ function considerChangingExpiryFocus() { } function updateBlockOptions() { - if (!document.getElementById) + if ( !document.getElementById ) { return; + } - var target = document.getElementById('mw-bi-target'); - if (!target) + var target = document.getElementById( 'mw-bi-target' ); + if ( !target ) { return; + } var addy = target.value; var isEmpty = addy.match(/^\s*$/); var isIp = addy.match(/^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|:(:[0-9A-Fa-f]{1,4}){1,7}|[0-9A-Fa-f]{1,4}(:{1,2}[0-9A-Fa-f]{1,4}|::$){1,7})(\/\d+)?$/); var isIpRange = isIp && addy.match(/\/\d+$/); - var anonymousRow = document.getElementById('wpAnonOnlyRow'); + var anonymousRow = document.getElementById( 'wpAnonOnlyRow' ); if( anonymousRow ) { - anonymousRow.style.display = (!isIp && !isEmpty) ? 'none' : ''; + anonymousRow.style.display = ( !isIp && !isEmpty ) ? 'none' : ''; } - var autoblockRow = document.getElementById('wpEnableAutoblockRow'); + var autoblockRow = document.getElementById( 'wpEnableAutoblockRow' ); if( autoblockRow ) { autoblockRow.style.display = isIp && !isEmpty ? 'none' : ''; } - var hideuserRow = document.getElementById('wpEnableHideUser'); + var hideuserRow = document.getElementById( 'wpEnableHideUser' ); if( hideuserRow ) { hideuserRow.style.display = isIp && !isEmpty ? 'none' : ''; } - var watchuserRow = document.getElementById('wpEnableWatchUser'); + var watchuserRow = document.getElementById( 'wpEnableWatchUser' ); if( watchuserRow ) { watchuserRow.style.display = isIpRange && !isEmpty ? 'none' : ''; } diff --git a/skins/common/edit.js b/skins/common/edit.js index f9a9711b34..e39d35b151 100644 --- a/skins/common/edit.js +++ b/skins/common/edit.js @@ -2,144 +2,150 @@ var currentFocused; // this function generates the actual toolbar buttons with localized text // we use it to avoid creating the toolbar where javascript is not enabled -function addButton(imageFile, speedTip, tagOpen, tagClose, sampleText, imageId) { +function addButton( imageFile, speedTip, tagOpen, tagClose, sampleText, imageId ) { // Don't generate buttons for browsers which don't fully // support it. - mwEditButtons.push( - {"imageId": imageId, - "imageFile": imageFile, - "speedTip": speedTip, - "tagOpen": tagOpen, - "tagClose": tagClose, - "sampleText": sampleText}); + mwEditButtons.push({ + 'imageId': imageId, + 'imageFile': imageFile, + 'speedTip': speedTip, + 'tagOpen': tagOpen, + 'tagClose': tagClose, + 'sampleText': sampleText + }); } // this function generates the actual toolbar buttons with localized text -// we use it to avoid creating the toolbar where javascript is not enabled -function mwInsertEditButton(parent, item) { - var image = document.createElement("img"); +// we use it to avoid creating the toolbar where JavaScript is not enabled +function mwInsertEditButton( parent, item ) { + var image = document.createElement( 'img' ); image.width = 23; image.height = 22; - image.className = "mw-toolbar-editbutton"; - if (item.imageId) image.id = item.imageId; + image.className = 'mw-toolbar-editbutton'; + if ( item.imageId ) { + image.id = item.imageId; + } image.src = item.imageFile; image.border = 0; image.alt = item.speedTip; image.title = item.speedTip; - image.style.cursor = "pointer"; + image.style.cursor = 'pointer'; image.onclick = function() { - insertTags(item.tagOpen, item.tagClose, item.sampleText); - //click tracking - if ( ( typeof $j != 'undefined' ) && ( typeof $j.trackAction != 'undefined' ) ) { - $j.trackAction("oldedit." + item.speedTip.replace(/ /g, "-")); + insertTags( item.tagOpen, item.tagClose, item.sampleText ); + // click tracking + if ( ( typeof $j != 'undefined' ) && ( typeof $j.trackAction != 'undefined' ) ) { + $j.trackAction( 'oldedit.' + item.speedTip.replace(/ /g, "-") ); } return false; }; - parent.appendChild(image); + parent.appendChild( image ); return true; } function mwSetupToolbar() { - var toolbar = document.getElementById('toolbar'); - if (!toolbar) { return false; } + var toolbar = document.getElementById( 'toolbar' ); + if ( !toolbar ) { + return false; + } // Don't generate buttons for browsers which don't fully // support it. // but don't assume wpTextbox1 is always here - var textboxes = document.getElementsByTagName('textarea'); + var textboxes = document.getElementsByTagName( 'textarea' ); if ( !textboxes.length ) { // No toolbar if we can't find any textarea return false; } - if (!(document.selection && document.selection.createRange) - && textboxes[0].selectionStart === null) { + if ( !( document.selection && document.selection.createRange ) + && textboxes[0].selectionStart === null ) { return false; } - for (var i = 0; i < mwEditButtons.length; i++) { - mwInsertEditButton(toolbar, mwEditButtons[i]); + for ( var i = 0; i < mwEditButtons.length; i++ ) { + mwInsertEditButton( toolbar, mwEditButtons[i] ); } - for (var i = 0; i < mwCustomEditButtons.length; i++) { - mwInsertEditButton(toolbar, mwCustomEditButtons[i]); + for ( var i = 0; i < mwCustomEditButtons.length; i++ ) { + mwInsertEditButton( toolbar, mwCustomEditButtons[i] ); } return true; } // apply tagOpen/tagClose to selection in textarea, // use sampleText instead of selection if there is none -function insertTags(tagOpen, tagClose, sampleText) { +function insertTags( tagOpen, tagClose, sampleText ) { var txtarea; - if (document.editform) { + if ( document.editform ) { txtarea = currentFocused; } else { // some alternate form? take the first one we can find - var areas = document.getElementsByTagName('textarea'); + var areas = document.getElementsByTagName( 'textarea' ); txtarea = areas[0]; } var selText, isSample = false; - if (document.selection && document.selection.createRange) { // IE/Opera - - //save window scroll position - if (document.documentElement && document.documentElement.scrollTop) + if ( document.selection && document.selection.createRange ) { // IE/Opera + // save window scroll position + if ( document.documentElement && document.documentElement.scrollTop ) { var winScroll = document.documentElement.scrollTop - else if (document.body) + } else if ( document.body ) { var winScroll = document.body.scrollTop; - //get current selection + } + // get current selection txtarea.focus(); var range = document.selection.createRange(); selText = range.text; - //insert tags + // insert tags checkSelectedText(); range.text = tagOpen + selText + tagClose; - //mark sample text as selected - if (isSample && range.moveStart) { - if (window.opera) + // mark sample text as selected + if ( isSample && range.moveStart ) { + if ( window.opera ) { tagClose = tagClose.replace(/\n/g,''); + } range.moveStart('character', - tagClose.length - selText.length); range.moveEnd('character', - tagClose.length); } range.select(); - //restore window scroll position - if (document.documentElement && document.documentElement.scrollTop) - document.documentElement.scrollTop = winScroll - else if (document.body) + // restore window scroll position + if ( document.documentElement && document.documentElement.scrollTop ) { + document.documentElement.scrollTop = winScroll; + } else if ( document.body ) { document.body.scrollTop = winScroll; + } - } else if (txtarea.selectionStart || txtarea.selectionStart == '0') { // Mozilla - - //save textarea scroll position + } else if ( txtarea.selectionStart || txtarea.selectionStart == '0' ) { // Mozilla + // save textarea scroll position var textScroll = txtarea.scrollTop; - //get current selection + // get current selection txtarea.focus(); var startPos = txtarea.selectionStart; var endPos = txtarea.selectionEnd; - selText = txtarea.value.substring(startPos, endPos); - //insert tags + selText = txtarea.value.substring( startPos, endPos ); + // insert tags checkSelectedText(); txtarea.value = txtarea.value.substring(0, startPos) + tagOpen + selText + tagClose + txtarea.value.substring(endPos, txtarea.value.length); - //set new selection - if (isSample) { + // set new selection + if ( isSample ) { txtarea.selectionStart = startPos + tagOpen.length; txtarea.selectionEnd = startPos + tagOpen.length + selText.length; } else { txtarea.selectionStart = startPos + tagOpen.length + selText.length + tagClose.length; txtarea.selectionEnd = txtarea.selectionStart; } - //restore textarea scroll position + // restore textarea scroll position txtarea.scrollTop = textScroll; } - function checkSelectedText(){ - if (!selText) { + function checkSelectedText() { + if ( !selText ) { selText = sampleText; isSample = true; - } else if (selText.charAt(selText.length - 1) == ' ') { //exclude ending space char + } else if ( selText.charAt(selText.length - 1) == ' ' ) { // exclude ending space char selText = selText.substring(0, selText.length - 1); - tagClose += ' ' + tagClose += ' '; } } @@ -154,8 +160,9 @@ function scrollEditBox() { var scrollTop = document.getElementById( 'wpScrolltop' ); var editForm = document.getElementById( 'editform' ); if( editForm && editBox && scrollTop ) { - if( scrollTop.value ) + if( scrollTop.value ) { editBox.scrollTop = scrollTop.value; + } addHandler( editForm, 'submit', function() { scrollTop.value = editBox.scrollTop; } ); @@ -169,31 +176,34 @@ hookEvent( 'load', function() { // focus does not bubble normally, but using a trick we can do event delegation // on the focus event on all text inputs to make the toolbox usable on all of them var editForm = document.getElementById( 'editform' ); - if ( !editForm ) + if ( !editForm ) { return; - - function onfocus(e) { + } + function onfocus( e ) { var elm = e.target; - if ( !elm ) + if ( !elm ) { return; + } var tagName = elm.tagName.toLowerCase(); var type = elm.type.toLowerCase(); - if ( tagName !== "textarea" && tagName !== "input" ) + if ( tagName !== 'textarea' && tagName !== 'input' ) { return; - if ( tagName === "input" && type && type !== "text" ) + } + if ( tagName === 'input' && type && type !== 'text' ) { return; - + } + currentFocused = elm; } - + if ( editForm.addEventListener ) { // Gecko, WebKit, Opera, etc... (all standards compliant browsers) - editForm.addEventListener('focus', onfocus, true); // This MUST be true to work + editForm.addEventListener( 'focus', onfocus, true ); // This MUST be true to work } else if ( editForm.attachEvent ) { // IE needs a specific trick here since it doesn't support the standard - editForm.attachEvent( 'onfocusin', function() { onfocus(event); } ); + editForm.attachEvent( 'onfocusin', function() { onfocus( event ); } ); } - + editForm } ); diff --git a/skins/common/htmlform.js b/skins/common/htmlform.js index 77c83610ca..2045ab4845 100644 --- a/skins/common/htmlform.js +++ b/skins/common/htmlform.js @@ -1,30 +1,36 @@ // Find select-or-other fields. addOnloadHook( function() { var fields = getElementsByClassName( document, 'select', 'mw-htmlform-select-or-other' ); - + for( var i = 0; i < fields.length; i++ ) { var select = fields[i]; - + addHandler( select, 'change', htmlforms.selectOrOtherSelectChanged ); - + // Use a fake 'e' to update it. htmlforms.selectOrOtherSelectChanged( { 'target': select } ); } } ); var htmlforms = { - 'selectOrOtherSelectChanged' : function(e) { + 'selectOrOtherSelectChanged' : function( e ) { var select; - if (!e) e = window.event; - if (e.target) select = e.target; - else if (e.srcElement) select = e.srcElement; - if (select.nodeType == 3) // defeat Safari bug + if ( !e ) { + e = window.event; + } + if ( e.target ) { + select = e.target; + } else if ( e.srcElement ) { + select = e.srcElement; + } + if ( select.nodeType == 3 ) { // defeat Safari bug select = select.parentNode; - + } + var id = select.id; - var textbox = document.getElementById( id+'-other' ); - - if (select.value == 'other') { + var textbox = document.getElementById( id + '-other' ); + + if ( select.value == 'other' ) { textbox.disabled = false; } else { textbox.disabled = true; diff --git a/skins/common/metadata.js b/skins/common/metadata.js index a73b693721..86fc6bd4a7 100644 --- a/skins/common/metadata.js +++ b/skins/common/metadata.js @@ -3,42 +3,42 @@ // Add an expand/collapse link and collapse by default if set to // (with JS disabled, user will see all items) // -// attachMetadataToggle("mw_metadata", "More...", "Fewer..."); +// attachMetadataToggle('mw_metadata', 'More...', 'Fewer...'); - -function attachMetadataToggle(tableId, showText, hideText) { - if (document.createTextNode) { - var box = document.getElementById(tableId); - if (!box) +function attachMetadataToggle( tableId, showText, hideText ) { + if ( document.createTextNode ) { + var box = document.getElementById( tableId ); + if ( !box ) { return false; + } var tbody = box.getElementsByTagName('tbody')[0]; - var row = document.createElement('tr'); + var row = document.createElement( 'tr' ); - var col = document.createElement('td'); + var col = document.createElement( 'td' ); col.colSpan = 2; - var link = document.createElement('a'); + var link = document.createElement( 'a' ); link.href = '#'; link.onclick = function() { - if (box.className == 'mw_metadata collapsed') { - changeText(link, hideText); + if ( box.className == 'mw_metadata collapsed' ) { + changeText( link, hideText ); box.className = 'mw_metadata expanded'; } else { - changeText(link, showText); + changeText( link, showText ); box.className = 'mw_metadata collapsed'; } return false; - } + }; - var text = document.createTextNode(hideText); + var text = document.createTextNode( hideText ); - link.appendChild(text); - col.appendChild(link); - row.appendChild(col); - tbody.appendChild(row); + link.appendChild( text ); + col.appendChild( link ); + row.appendChild( col ); + tbody.appendChild( row ); // And collapse! link.onclick(); diff --git a/skins/common/prefs.js b/skins/common/prefs.js index b0887ee8c2..ca55632c95 100644 --- a/skins/common/prefs.js +++ b/skins/common/prefs.js @@ -1,73 +1,74 @@ - // generate toc from prefs form, fold sections // XXX: needs testing on IE/Mac and safari // more comments to follow function tabbedprefs() { - var prefform = document.getElementById('preferences'); - if (!prefform || !document.createElement) { + var prefform = document.getElementById( 'preferences' ); + if ( !prefform || !document.createElement ) { return; } - if (prefform.nodeName.toLowerCase() == 'a') { + if ( prefform.nodeName.toLowerCase() == 'a' ) { return; // Occasional IE problem } prefform.className = prefform.className + 'jsprefs'; var sections = []; var children = prefform.childNodes; var seci = 0; - for (var i = 0; i < children.length; i++) { - if (children[i].nodeName.toLowerCase() == 'fieldset') { + for ( var i = 0; i < children.length; i++ ) { + if ( children[i].nodeName.toLowerCase() == 'fieldset' ) { children[i].id = 'prefsection-' + seci; children[i].className = 'prefsection'; - if (is_opera) { + if ( is_opera ) { children[i].className = 'prefsection operaprefsection'; } var legends = children[i].getElementsByTagName('legend'); sections[seci] = {}; - if (legends[0]) legends[0].className = 'mainLegend'; - if (legends[0] && legends[0].firstChild.nodeValue) { + if ( legends[0] ) { + legends[0].className = 'mainLegend'; + } + if ( legends[0] && legends[0].firstChild.nodeValue ) { sections[seci].text = legends[0].firstChild.nodeValue; } else { sections[seci].text = '# ' + seci; } sections[seci].secid = children[i].id; seci++; - if (sections.length != 1) { + if ( sections.length != 1 ) { children[i].style.display = 'none'; } else { var selectedid = children[i].id; } } } - var toc = document.createElement('ul'); + var toc = document.createElement( 'ul' ); toc.id = 'preftoc'; toc.selectedid = selectedid; - for (i = 0; i < sections.length; i++) { - var li = document.createElement('li'); - if (i === 0) { + for ( i = 0; i < sections.length; i++ ) { + var li = document.createElement( 'li' ); + if ( i === 0 ) { li.className = 'selected'; } - var a = document.createElement('a'); + var a = document.createElement( 'a' ); a.href = '#' + sections[i].secid; a.onmousedown = a.onclick = uncoversection; - a.appendChild(document.createTextNode(sections[i].text)); + a.appendChild( document.createTextNode( sections[i].text ) ); a.secid = sections[i].secid; - li.appendChild(a); - toc.appendChild(li); + li.appendChild( a ); + toc.appendChild( li ); } - prefform.parentNode.insertBefore(toc, prefform.parentNode.childNodes[0]); - document.getElementById('prefsubmit').id = 'prefcontrol'; + prefform.parentNode.insertBefore( toc, prefform.parentNode.childNodes[0] ); + document.getElementById( 'prefsubmit' ).id = 'prefcontrol'; } function uncoversection() { var oldsecid = this.parentNode.parentNode.selectedid; - var newsec = document.getElementById(this.secid); - if (oldsecid != this.secid) { - var ul = document.getElementById('preftoc'); - document.getElementById(oldsecid).style.display = 'none'; + var newsec = document.getElementById( this.secid ); + if ( oldsecid != this.secid ) { + var ul = document.getElementById( 'preftoc' ); + document.getElementById( oldsecid ).style.display = 'none'; newsec.style.display = 'block'; ul.selectedid = this.secid; - var lis = ul.getElementsByTagName('li'); - for (var i = 0; i< lis.length; i++) { + var lis = ul.getElementsByTagName( 'li' ); + for ( var i = 0; i< lis.length; i++ ) { lis[i].className = ''; } this.parentNode.className = 'selected'; @@ -77,29 +78,29 @@ function uncoversection() { // Timezone stuff // tz in format [+-]HHMM -function checkTimezone(tz, msg) { +function checkTimezone( tz, msg ) { var localclock = new Date(); // returns negative offset from GMT in minutes var tzRaw = localclock.getTimezoneOffset(); - var tzHour = Math.floor( Math.abs(tzRaw) / 60); - var tzMin = Math.abs(tzRaw) % 60; - var tzString = ((tzRaw >= 0) ? "-" : "+") + ((tzHour < 10) ? "0" : "") + tzHour + ((tzMin < 10) ? "0" : "") + tzMin; - if (tz != tzString) { + var tzHour = Math.floor( Math.abs( tzRaw ) / 60 ); + var tzMin = Math.abs( tzRaw ) % 60; + var tzString = ( ( tzRaw >= 0 ) ? '-' : '+' ) + ( ( tzHour < 10 ) ? '0' : '' ) + tzHour + ( ( tzMin < 10 ) ? '0' : '' ) + tzMin; + if ( tz != tzString ) { var junk = msg.split('$1'); - document.write(junk[0] + "UTC" + tzString + junk[1]); + document.write( junk[0] + 'UTC' + tzString + junk[1] ); } } function timezoneSetup() { var tzSelect = document.getElementById( 'mw-input-timecorrection' ); var tzTextbox = document.getElementById( 'mw-input-timecorrection-other' ); - - if (tzSelect && tzTextbox) { - addHandler( tzSelect, 'change', function(e) { updateTimezoneSelection(false); } ); - addHandler( tzTextbox, 'blur', function(e) { updateTimezoneSelection(true); } ); + + if ( tzSelect && tzTextbox ) { + addHandler( tzSelect, 'change', function( e ) { updateTimezoneSelection( false ); } ); + addHandler( tzTextbox, 'blur', function( e ) { updateTimezoneSelection( true ); } ); } - - updateTimezoneSelection(false); + + updateTimezoneSelection( false ); } // in [-]HH:MM format... @@ -109,86 +110,108 @@ function fetchTimezone() { var localclock = new Date(); // returns negative offset from GMT in minutes var tzRaw = localclock.getTimezoneOffset(); - var tzHour = Math.floor( Math.abs(tzRaw) / 60); - var tzMin = Math.abs(tzRaw) % 60; - var tzString = ((tzRaw >= 0) ? "-" : "") + ((tzHour < 10) ? "0" : "") + tzHour + - ":" + ((tzMin < 10) ? "0" : "") + tzMin; + var tzHour = Math.floor( Math.abs( tzRaw ) / 60 ); + var tzMin = Math.abs( tzRaw ) % 60; + var tzString = ( ( tzRaw >= 0 ) ? '-' : '' ) + ( ( tzHour < 10 ) ? '0' : '' ) + tzHour + + ':' + ( ( tzMin < 10 ) ? '0' : '' ) + tzMin; return tzString; } function guessTimezone() { - var textbox = document.getElementById("mw-input-timecorrection-other"); + var textbox = document.getElementById( 'mw-input-timecorrection-other' ); var selector = document.getElementById( 'mw-input-timecorrection' ); - + selector.value = 'other'; textbox.value = fetchTimezone(); textbox.disabled = false; // The changed handler doesn't trip, obviously. - updateTimezoneSelection(true); + updateTimezoneSelection( true ); } -function updateTimezoneSelection(force_offset) { - var selector = document.getElementById("mw-input-timecorrection"); - - if (selector.value == 'guess') { +function updateTimezoneSelection( force_offset ) { + var selector = document.getElementById( 'mw-input-timecorrection' ); + + if ( selector.value == 'guess' ) { return guessTimezone(); } - + var textbox = document.getElementById( 'mw-input-timecorrection-other' ); - var localtimeHolder = document.getElementById("wpLocalTime"); - var servertime = document.getElementsByName("wpServerTime")[0].value; + var localtimeHolder = document.getElementById( 'wpLocalTime' ); + var servertime = document.getElementsByName( 'wpServerTime' )[0].value; var minDiff = 0; - + // Compatibility code. - if (!selector.value) selector.value = selector.options[selector.selectedIndex].value; + if ( !selector.value ) { + selector.value = selector.options[selector.selectedIndex].value; + } // Handle force_offset - if (force_offset) selector.value = 'other'; - + if ( force_offset ) { + selector.value = 'other'; + } + // Get min_diff - if (selector.value == 'other') { + if ( selector.value == 'other' ) { // Grab data from the textbox, parse it. var diffArr = textbox.value.split(':'); - if (diffArr.length == 1) { + if ( diffArr.length == 1 ) { // Specification is of the form [-]XX - minDiff = parseInt(diffArr[0], 10) * 60; + minDiff = parseInt( diffArr[0], 10 ) * 60; } else { // Specification is of the form [-]XX:XX - minDiff = Math.abs(parseInt(diffArr[0], 10))*60 + parseInt(diffArr[1], 10); - if (parseInt(diffArr[0], 10) < 0) minDiff = -minDiff; + minDiff = Math.abs( parseInt( diffArr[0], 10 ) ) * 60 + parseInt( diffArr[1], 10 ); + if ( parseInt( diffArr[0], 10 ) < 0 ) { + minDiff = -minDiff; + } } } else { // Grab data from the selector value var diffArr = selector.value.split('|'); - minDiff = parseInt(diffArr[1], 10); + minDiff = parseInt( diffArr[1], 10 ); } - + // Gracefully handle non-numbers. - if (isNaN(minDiff)) minDiff = 0; - + if ( isNaN( minDiff ) ) { + minDiff = 0; + } + // Determine local time from server time and minutes difference, for display. - var localTime = parseInt(servertime, 10) + minDiff; - + var localTime = parseInt( servertime, 10 ) + minDiff; + // Bring time within the [0,1440) range. - while (localTime < 0) localTime += 1440; - while (localTime >= 1440) localTime -= 1440; + while ( localTime < 0 ) { + localTime += 1440; + } + while ( localTime >= 1440 ) { + localTime -= 1440; + } // Split to hour and minute - var hour = String(Math.floor(localTime/60)); - if (hour.length<2) hour = '0'+hour; + var hour = String( Math.floor( localTime / 60 ) ); + if ( hour.length < 2 ) { + hour = '0' + hour; + } var min = String(localTime%60); - if (min.length<2) min = '0'+min; - changeText(localtimeHolder, hour+':'+min); + if ( min.length < 2 ) { + min = '0' + min; + } + changeText( localtimeHolder, hour + ':' + min ); // If the user selected from the drop-down, fill the offset field. - if (selector.value != 'other') { - hour = String(Math.abs(Math.floor(minDiff/60))); - if (hour.length<2) hour = '0'+hour; - if (minDiff < 0) hour = '-'+hour; + if ( selector.value != 'other' ) { + hour = String( Math.abs( Math.floor( minDiff / 60 ) ) ); + if ( hour.length < 2 ) { + hour = '0' + hour; + } + if ( minDiff < 0 ) { + hour = '-' + hour; + } min = String(minDiff%60); - if (min.length<2) min = '0'+min; - textbox.value = hour+':'+min; + if ( min.length < 2 ) { + min = '0' + min; + } + textbox.value = hour + ':' + min; } } -addOnloadHook(timezoneSetup); -addOnloadHook(tabbedprefs); +addOnloadHook( timezoneSetup ); +addOnloadHook( tabbedprefs ); diff --git a/skins/common/search.js b/skins/common/search.js index ea34270b5b..ff11429112 100644 --- a/skins/common/search.js +++ b/skins/common/search.js @@ -1,40 +1,45 @@ // JS specific to Special:Search // change the search link to what user entered -function mwSearchHeaderClick(obj){ - var searchbox = document.getElementById("searchText"); - if( searchbox == null ) - searchbox = document.getElementById("powerSearchText"); - if( searchbox == null) +function mwSearchHeaderClick( obj ) { + var searchbox = document.getElementById( 'searchText' ); + if( searchbox === null ) { + searchbox = document.getElementById( 'powerSearchText' ); + } + if( searchbox === null ) { return; // should always have either normal or advanced search - + } + var searchterm = searchbox.value; - var parts = obj.href.split("search="); + var parts = obj.href.split( 'search=' ); var lastpart = ''; - var prefix = "search="; - if( parts.length > 1 && parts[1].indexOf('&') >= 0 ) - lastpart = parts[1].substring( parts[1].indexOf('&') ) - else - prefix = "&search="; - obj.href = parts[0] + prefix + encodeURIComponent(searchterm) + lastpart; + var prefix = 'search='; + if( parts.length > 1 && parts[1].indexOf('&') >= 0 ) { + lastpart = parts[1].substring( parts[1].indexOf('&') ); + } else { + prefix = '&search='; + } + obj.href = parts[0] + prefix + encodeURIComponent( searchterm ) + lastpart; } function mwToggleSearchCheckboxes( btn ) { - if( !document.getElementById ) return; - + if( !document.getElementById ) { + return; + } + var nsInputs = document.getElementById( 'powersearch' ).getElementsByTagName( 'input' ); var isChecked = false; - + for ( var i = 0; i < nsInputs.length; i++ ) { var pattern = /^ns/; if ( ( nsInputs[i].type == 'checkbox' ) && ( pattern.test( nsInputs[i].name ) ) ) { switch ( btn ) { - case "none": + case 'none': if ( nsInputs[i].checked ) { nsInputs[i].checked = false; } break; - case "all": + case 'all': if ( !nsInputs[i].checked ) { nsInputs[i].checked = true; } diff --git a/skins/common/wikibits.js b/skins/common/wikibits.js index 0789b6f946..4434315572 100644 --- a/skins/common/wikibits.js +++ b/skins/common/wikibits.js @@ -38,148 +38,147 @@ if (!window.onloadFuncts) { var onloadFuncts = []; } -function addOnloadHook(hookFunct) { +function addOnloadHook( hookFunct ) { // Allows add-on scripts to add onload functions - if(!doneOnloadHook) { + if( !doneOnloadHook ) { onloadFuncts[onloadFuncts.length] = hookFunct; } else { hookFunct(); // bug in MSIE script loading } } - -function hookEvent(hookName, hookFunct) { - addHandler(window, hookName, hookFunct); +function hookEvent( hookName, hookFunct ) { + addHandler( window, hookName, hookFunct ); } -function importScript(page) { +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/ig,'/').replace(/%3A/ig,':') + '&action=raw&ctype=text/javascript'; - return importScriptURI(uri); + return importScriptURI( uri ); } var loadedScripts = {}; // included-scripts tracker -function importScriptURI(url) { - if (loadedScripts[url]) { +function importScriptURI( url ) { + if ( loadedScripts[url] ) { return null; } loadedScripts[url] = true; - var s = document.createElement('script'); - s.setAttribute('src', url); - s.setAttribute('type', 'text/javascript'); - document.getElementsByTagName('head')[0].appendChild(s); + 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 importStylesheet( page ) { + return importStylesheetURI( wgScript + '?action=raw&ctype=text/css&title=' + encodeURIComponent( page.replace(/ /g,'_') ) ); } -function importStylesheetURI(url, media) { - var l = document.createElement('link'); +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); + document.getElementsByTagName('head')[0].appendChild( l ); return l; } -function appendCSS(text) { - var s = document.createElement('style'); +function appendCSS( text ) { + var s = document.createElement( 'style' ); s.type = 'text/css'; s.rel = 'stylesheet'; if ( s.styleSheet ) { - s.styleSheet.cssText = text; //IE + s.styleSheet.cssText = text; // IE } else { - s.appendChild(document.createTextNode(text + '')); //Safari sometimes borks on null + s.appendChild( document.createTextNode( text + '' ) ); // Safari sometimes borks on null } - document.getElementsByTagName('head')[0].appendChild(s); + document.getElementsByTagName('head')[0].appendChild( s ); return s; } // special stylesheet links -if (typeof stylepath != 'undefined' && typeof skin != 'undefined') { +if ( typeof stylepath != 'undefined' && typeof skin != 'undefined' ) { // 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 (opera7_bugs) { - importStylesheetURI(stylepath+'/'+skin+'/Opera7Fixes.css'); - } else if (opera95_bugs) { - importStylesheetURI(stylepath+'/'+skin+'/Opera9Fixes.css'); - } else if (ff2_bugs) { - importStylesheetURI(stylepath+'/'+skin+'/FF2Fixes.css'); + if ( opera6_bugs ) { + importStylesheetURI( stylepath + '/' + skin + '/Opera6Fixes.css' ); + } else if ( opera7_bugs ) { + importStylesheetURI( stylepath + '/' + skin + '/Opera7Fixes.css' ); + } else if ( opera95_bugs ) { + importStylesheetURI( stylepath + '/' + skin + '/Opera9Fixes.css' ); + } else if ( ff2_bugs ) { + importStylesheetURI( stylepath + '/' + skin + '/FF2Fixes.css' ); } } -if (wgBreakFrames) { +if ( wgBreakFrames ) { // Un-trap us from framesets - if (window.top != window) { + if ( window.top != window ) { window.top.location = window.location; } } function showTocToggle() { - if (document.createTextNode) { + if ( document.createTextNode ) { // Uses DOM calls to avoid document.write + XHTML issues - var linkHolder = document.getElementById('toctitle'); - var existingLink = document.getElementById('togglelink'); - if (!linkHolder || existingLink) { + var linkHolder = document.getElementById( 'toctitle' ); + var existingLink = document.getElementById( 'togglelink' ); + if ( !linkHolder || existingLink ) { // Don't add the toggle link twice return; } - var outerSpan = document.createElement('span'); + var outerSpan = document.createElement( 'span' ); outerSpan.className = 'toctoggle'; - var toggleLink = document.createElement('a'); + var toggleLink = document.createElement( 'a' ); toggleLink.id = 'togglelink'; toggleLink.className = 'internal'; toggleLink.href = 'javascript:toggleToc()'; - toggleLink.appendChild(document.createTextNode(tocHideText)); + toggleLink.appendChild( document.createTextNode( tocHideText ) ); - outerSpan.appendChild(document.createTextNode('[')); - outerSpan.appendChild(toggleLink); - outerSpan.appendChild(document.createTextNode(']')); + outerSpan.appendChild( document.createTextNode( '[' ) ); + outerSpan.appendChild( toggleLink ); + outerSpan.appendChild( document.createTextNode( ']' ) ); - linkHolder.appendChild(document.createTextNode(' ')); - linkHolder.appendChild(outerSpan); + linkHolder.appendChild( document.createTextNode( ' ' ) ); + linkHolder.appendChild( outerSpan ); - var cookiePos = document.cookie.indexOf("hidetoc="); - if (cookiePos > -1 && document.cookie.charAt(cookiePos + 8) == 1) { + var cookiePos = document.cookie.indexOf( "hidetoc=" ); + if ( cookiePos > -1 && document.cookie.charAt( cookiePos + 8 ) == 1 ) { toggleToc(); } } } -function changeText(el, newText) { +function changeText( el, newText ) { // Safari work around - if (el.innerText) { + if ( el.innerText ) { el.innerText = newText; - } else if (el.firstChild && el.firstChild.nodeValue) { + } else if ( el.firstChild && el.firstChild.nodeValue ) { el.firstChild.nodeValue = newText; } } function toggleToc() { - var tocmain = document.getElementById('toc'); + var tocmain = document.getElementById( 'toc' ); var toc = document.getElementById('toc').getElementsByTagName('ul')[0]; - var toggleLink = document.getElementById('togglelink'); + var toggleLink = document.getElementById( 'togglelink' ); - if (toc && toggleLink && toc.style.display == 'none') { - changeText(toggleLink, tocHideText); + if ( toc && toggleLink && toc.style.display == 'none' ) { + changeText( toggleLink, tocHideText ); toc.style.display = 'block'; document.cookie = "hidetoc=0"; tocmain.className = 'toc'; } else { - changeText(toggleLink, tocShowText); + changeText( toggleLink, tocShowText ); toc.style.display = 'none'; document.cookie = "hidetoc=1"; tocmain.className = 'toc tochidden'; @@ -189,40 +188,39 @@ function toggleToc() { var mwEditButtons = []; var mwCustomEditButtons = []; // eg to add in MediaWiki:Common.js -function escapeQuotes(text) { - var re = new RegExp("'","g"); - text = text.replace(re,"\\'"); - re = new RegExp("\\n","g"); - text = text.replace(re,"\\n"); - return escapeQuotesHTML(text); +function escapeQuotes( text ) { + var re = new RegExp( "'", "g" ); + text = text.replace( re, "\\'" ); + re = new RegExp( "\\n", "g" ); + text = text.replace( re, "\\n" ); + return escapeQuotesHTML( text ); } -function escapeQuotesHTML(text) { - var re = new RegExp('&',"g"); - text = text.replace(re,"&"); - re = new RegExp('"',"g"); - text = text.replace(re,"""); - re = new RegExp('<',"g"); - text = text.replace(re,"<"); - re = new RegExp('>',"g"); - text = text.replace(re,">"); +function escapeQuotesHTML( text ) { + var re = new RegExp( '&', "g" ); + text = text.replace( re, "&" ); + re = new RegExp( '"', "g" ); + text = text.replace( re, """ ); + re = new RegExp( '<', "g" ); + text = text.replace( re, "<" ); + re = new RegExp( '>', "g" ); + text = text.replace( re, ">" ); return text; } - /** * Set the accesskey prefix based on browser detection. */ var tooltipAccessKeyPrefix = 'alt-'; -if (is_opera) { +if ( is_opera ) { tooltipAccessKeyPrefix = 'shift-esc-'; -} else if (!is_safari_win && is_safari && webkit_version > 526) { +} else if ( !is_safari_win && is_safari && webkit_version > 526 ) { tooltipAccessKeyPrefix = 'ctrl-alt-'; -} else if (!is_safari_win && (is_safari +} else if ( !is_safari_win && ( is_safari || clientPC.indexOf('mac') != -1 - || clientPC.indexOf('konqueror') != -1 )) { + || clientPC.indexOf('konqueror') != -1 ) ) { tooltipAccessKeyPrefix = 'ctrl-'; -} else if (is_ff2) { +} else if ( is_ff2 ) { tooltipAccessKeyPrefix = 'alt-shift-'; } var tooltipAccessKeyRegexp = /\[(ctrl-)?(alt-)?(shift-)?(esc-)?(.)\]$/; @@ -241,28 +239,28 @@ function updateTooltipAccessKeys( nodeList ) { // 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 + '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") ); + updateTooltipAccessKeys( linkContainer.getElementsByTagName( 'a' ) ); } } // these are rare enough that no such optimization is needed - updateTooltipAccessKeys( document.getElementsByTagName("input") ); - updateTooltipAccessKeys( document.getElementsByTagName("label") ); + updateTooltipAccessKeys( document.getElementsByTagName( 'input' ) ); + updateTooltipAccessKeys( document.getElementsByTagName( 'label' ) ); return; } for ( var i = 0; i < nodeList.length; i++ ) { var element = nodeList[i]; - var tip = element.getAttribute("title"); - if ( tip && tooltipAccessKeyRegexp.exec(tip) ) { + var tip = element.getAttribute( 'title' ); + if ( tip && tooltipAccessKeyRegexp.exec( tip ) ) { tip = tip.replace(tooltipAccessKeyRegexp, - "["+tooltipAccessKeyPrefix+"$5]"); - element.setAttribute("title", tip ); + '[' + tooltipAccessKeyPrefix + "$5]"); + element.setAttribute( 'title', tip ); } } } @@ -295,8 +293,8 @@ 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 root = document.getElementById(portlet); +function addPortletLink( portlet, href, text, id, tooltip, accesskey, nextnode ) { + var root = document.getElementById( portlet ); if ( !root ) { return null; } @@ -341,7 +339,7 @@ function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) { return item; } -function getInnerText(el) { +function getInnerText( el ) { if ( typeof el == 'string' ) { return el; } @@ -358,10 +356,10 @@ function getInnerText(el) { var cs = el.childNodes; var l = cs.length; - for (var i = 0; i < l; i++) { - switch (cs[i].nodeType) { + for ( var i = 0; i < l; i++ ) { + switch ( cs[i].nodeType ) { case 1: // ELEMENT_NODE - str += ts_getInnerText(cs[i]); + str += ts_getInnerText( cs[i] ); break; case 3: // TEXT_NODE str += cs[i].nodeValue; @@ -381,11 +379,11 @@ var lastCheckbox; function setupCheckboxShiftClick() { checkboxes = []; lastCheckbox = null; - var inputs = document.getElementsByTagName('input'); - addCheckboxClickHandlers(inputs); + var inputs = document.getElementsByTagName( 'input' ); + addCheckboxClickHandlers( inputs ); } -function addCheckboxClickHandlers(inputs, start) { +function addCheckboxClickHandlers( inputs, start ) { if ( !start ) { start = 0; } @@ -407,14 +405,14 @@ function addCheckboxClickHandlers(inputs, start) { } if ( finish < inputs.length ) { - setTimeout( function () { - addCheckboxClickHandlers(inputs, finish); + setTimeout( function() { + addCheckboxClickHandlers( inputs, finish ); }, 200 ); } } -function checkboxClickHandler(e) { - if (typeof e == 'undefined') { +function checkboxClickHandler( e ) { + if ( typeof e == 'undefined' ) { e = window.event; } if ( !e.shiftKey || lastCheckbox === null ) { @@ -430,7 +428,7 @@ function checkboxClickHandler(e) { start = lastCheckbox; finish = this.index - 1; } - for (var i = start; i <= finish; ++i ) { + for ( var i = start; i <= finish; ++i ) { checkboxes[i].checked = endState; if( i > start && typeof checkboxes[i].onchange == 'function' ) { checkboxes[i].onchange(); // fire triggers @@ -447,25 +445,25 @@ function checkboxClickHandler(e) { Author says "The credit comment is all it takes, no license. Go crazy with it!:-)" From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/ */ -function getElementsByClassName(oElm, strTagName, oClassNames){ +function getElementsByClassName( oElm, strTagName, oClassNames ) { var arrReturnElements = new Array(); - if ( typeof( oElm.getElementsByClassName ) == "function" ) { + if ( typeof( oElm.getElementsByClassName ) == 'function' ) { /* Use a native implementation where possible FF3, Saf3.2, Opera 9.5 */ var arrNativeReturn = oElm.getElementsByClassName( oClassNames ); - if ( strTagName == "*" ) { + if ( strTagName == '*' ) { return arrNativeReturn; } - for ( var h=0; h < arrNativeReturn.length; h++ ) { + for ( var h = 0; h < arrNativeReturn.length; h++ ) { if( arrNativeReturn[h].tagName.toLowerCase() == strTagName.toLowerCase() ) { arrReturnElements[arrReturnElements.length] = arrNativeReturn[h]; } } return arrReturnElements; } - var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName); + var arrElements = ( strTagName == '*' && oElm.all ) ? oElm.all : oElm.getElementsByTagName( strTagName ); var arrRegExpClassNames = new Array(); - if(typeof oClassNames == "object"){ - for(var i=0; i 0) { - if (table.tHead && table.tHead.rows.length > 0) { + if ( table.rows && table.rows.length > 0 ) { + if ( table.tHead && table.tHead.rows.length > 0 ) { firstRow = table.tHead.rows[table.tHead.rows.length-1]; } else { firstRow = table.rows[0]; @@ -562,9 +560,9 @@ function ts_makeSortable(table) { } // We have a first row: assume it's the header, and make its contents clickable links - for (var i = 0; i < firstRow.cells.length; i++) { + for ( var i = 0; i < firstRow.cells.length; i++ ) { var cell = firstRow.cells[i]; - if ((" "+cell.className+" ").indexOf(" unsortable ") == -1) { + if ( (' ' + cell.className + ' ').indexOf(' unsortable ') == -1 ) { cell.innerHTML += '' + '' @@ -574,16 +572,16 @@ function ts_makeSortable(table) { + '" alt="↓"/>'; } } - if (ts_alternate_row_colors) { - ts_alternate(table); + if ( ts_alternate_row_colors ) { + ts_alternate( table ); } } -function ts_getInnerText(el) { +function ts_getInnerText( el ) { return getInnerText( el ); } -function ts_resortTable(lnk) { +function ts_resortTable( lnk ) { // get the span var span = lnk.getElementsByTagName('span')[0]; @@ -592,7 +590,7 @@ function ts_resortTable(lnk) { var column = td.cellIndex; var table = tr.parentNode; - while (table && !(table.tagName && table.tagName.toLowerCase() == 'table')) { + while ( table && !( table.tagName && table.tagName.toLowerCase() == 'table' ) ) { table = table.parentNode; } if ( !table ) { @@ -604,19 +602,19 @@ function ts_resortTable(lnk) { } // Generate the number transform table if it's not done already - if (ts_number_transform_table === null) { + if ( ts_number_transform_table === null ) { ts_initTransformTable(); } // Work out a type for the column // Skip the first row if that's where the headings are - var rowStart = (table.tHead && table.tHead.rows.length > 0 ? 0 : 1); + var rowStart = ( table.tHead && table.tHead.rows.length > 0 ? 0 : 1 ); var itm = ''; - for (var i = rowStart; i < table.rows.length; i++) { - if (table.rows[i].cells.length > column) { + for ( var i = rowStart; i < table.rows.length; i++ ) { + if ( table.rows[i].cells.length > column ) { itm = ts_getInnerText(table.rows[i].cells[column]); - itm = itm.replace(/^[\s\xa0]+/, "").replace(/[\s\xa0]+$/, ""); + itm = itm.replace(/^[\s\xa0]+/, '').replace(/[\s\xa0]+$/, ''); if ( itm != '' ) { break; } @@ -626,82 +624,84 @@ function ts_resortTable(lnk) { // TODO: bug 8226, localised date formats var sortfn = ts_sort_generic; var preprocessor = ts_toLowerCase; - if (/^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/.test(itm)) { + if ( /^\d\d[\/. -][a-zA-Z]{3}[\/. -]\d\d\d\d$/.test( itm ) ) { preprocessor = ts_dateToSortKey; - } else if (/^\d\d[\/.-]\d\d[\/.-]\d\d\d\d$/.test(itm)) { + } else if ( /^\d\d[\/.-]\d\d[\/.-]\d\d\d\d$/.test( itm ) ) { preprocessor = ts_dateToSortKey; - } else if (/^\d\d[\/.-]\d\d[\/.-]\d\d$/.test(itm)) { + } else if ( /^\d\d[\/.-]\d\d[\/.-]\d\d$/.test( itm ) ) { preprocessor = ts_dateToSortKey; // (minus sign)([pound dollar euro yen currency]|cents) - } else if (/(^([-\u2212] *)?[\u00a3$\u20ac\u00a4\u00a5]|\u00a2$)/.test(itm)) { + } else if ( /(^([-\u2212] *)?[\u00a3$\u20ac\u00a4\u00a5]|\u00a2$)/.test( itm ) ) { preprocessor = ts_currencyToSortKey; - } else if (ts_number_regex.test(itm)) { + } else if ( ts_number_regex.test( itm ) ) { preprocessor = ts_parseFloat; } - var reverse = (span.getAttribute("sortdir") == 'down'); + var reverse = ( span.getAttribute( 'sortdir' ) == 'down' ); var newRows = new Array(); var staticRows = new Array(); - for (var j = rowStart; j < table.rows.length; j++) { + for ( var j = rowStart; j < table.rows.length; j++ ) { var row = table.rows[j]; - if((" "+row.className+" ").indexOf(" unsortable ") < 0) { - var keyText = ts_getInnerText(row.cells[column]); - if(keyText === undefined) { + if( (' ' + row.className + ' ').indexOf(' unsortable ') < 0 ) { + var keyText = ts_getInnerText( row.cells[column] ); + if( keyText === undefined ) { keyText = ''; } - var oldIndex = (reverse ? -j : j); - var preprocessed = preprocessor( keyText.replace(/^[\s\xa0]+/, "").replace(/[\s\xa0]+$/, "") ); + var oldIndex = ( reverse ? -j : j ); + var preprocessed = preprocessor( keyText.replace(/^[\s\xa0]+/, '').replace(/[\s\xa0]+$/, '') ); - newRows[newRows.length] = new Array(row, preprocessed, oldIndex); + newRows[newRows.length] = new Array( row, preprocessed, oldIndex ); } else { - staticRows[staticRows.length] = new Array(row, false, j-rowStart); + staticRows[staticRows.length] = new Array( row, false, j-rowStart ); } } - newRows.sort(sortfn); + newRows.sort( sortfn ); var arrowHTML; - if (reverse) { - arrowHTML = '↓'; + if ( reverse ) { + arrowHTML = '↓'; newRows.reverse(); - span.setAttribute('sortdir','up'); + span.setAttribute( 'sortdir', 'up' ); } else { - arrowHTML = '↑'; - span.setAttribute('sortdir','down'); + arrowHTML = '↑'; + span.setAttribute( 'sortdir', 'down' ); } - for (var i = 0; i < staticRows.length; i++) { + for ( var i = 0; i < staticRows.length; i++ ) { var row = staticRows[i]; - newRows.splice(row[2], 0, row); + newRows.splice( row[2], 0, row ); } // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones // don't do sortbottom rows - for (var i = 0; i < newRows.length; i++) { - if ((" "+newRows[i][0].className+" ").indexOf(" sortbottom ") == -1) - table.tBodies[0].appendChild(newRows[i][0]); + for ( var i = 0; i < newRows.length; i++ ) { + if ( ( ' ' + newRows[i][0].className + ' ').indexOf(' sortbottom ') == -1 ) { + table.tBodies[0].appendChild( newRows[i][0] ); + } } // do sortbottom rows only - for (var i = 0; i < newRows.length; i++) { - if ((" "+newRows[i][0].className+" ").indexOf(" sortbottom ") != -1) - table.tBodies[0].appendChild(newRows[i][0]); + for ( var i = 0; i < newRows.length; i++ ) { + if ( ( ' ' + newRows[i][0].className + ' ').indexOf(' sortbottom ') != -1 ) { + table.tBodies[0].appendChild( newRows[i][0] ); + } } // Delete any other arrows there may be showing - var spans = getElementsByClassName(tr, "span", "sortarrow"); - for (var i = 0; i < spans.length; i++) { - spans[i].innerHTML = '↓'; + var spans = getElementsByClassName( tr, 'span', 'sortarrow' ); + for ( var i = 0; i < spans.length; i++ ) { + spans[i].innerHTML = '↓'; } span.innerHTML = arrowHTML; - if (ts_alternate_row_colors) { - ts_alternate(table); + if ( ts_alternate_row_colors ) { + ts_alternate( table ); } } function ts_initTransformTable() { - if ( typeof wgSeparatorTransformTable == "undefined" + if ( typeof wgSeparatorTransformTable == 'undefined' || ( wgSeparatorTransformTable[0] == '' && wgDigitTransformTable[2] == '' ) ) { digitClass = "[0-9,.]"; @@ -731,7 +731,7 @@ function ts_initTransformTable() { digit.replace( /[\\\\$\*\+\?\.\(\)\|\{\}\[\]\-]/, function( s ) { return '\\' + s; } ) ); - if (digit.length > maxDigitLength) { + if ( digit.length > maxDigitLength ) { maxDigitLength = digit.length; } } @@ -757,57 +757,81 @@ function ts_toLowerCase( s ) { return s.toLowerCase(); } -function ts_dateToSortKey(date) { +function ts_dateToSortKey( date ) { // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX - if (date.length == 11) { - switch (date.substr(3,3).toLowerCase()) { - case "jan": var month = "01"; break; - case "feb": var month = "02"; break; - case "mar": var month = "03"; break; - case "apr": var month = "04"; break; - case "may": var month = "05"; break; - case "jun": var month = "06"; break; - case "jul": var month = "07"; break; - case "aug": var month = "08"; break; - case "sep": var month = "09"; break; - case "oct": var month = "10"; break; - case "nov": var month = "11"; break; - case "dec": var month = "12"; break; - // default: var month = "00"; + if ( date.length == 11 ) { + switch ( date.substr( 3, 3 ).toLowerCase() ) { + case 'jan': + var month = '01'; + break; + case 'feb': + var month = '02'; + break; + case 'mar': + var month = '03'; + break; + case 'apr': + var month = '04'; + break; + case 'may': + var month = '05'; + break; + case 'jun': + var month = '06'; + break; + case 'jul': + var month = '07'; + break; + case 'aug': + var month = '08'; + break; + case 'sep': + var month = '09'; + break; + case 'oct': + var month = '10'; + break; + case 'nov': + var month = '11'; + break; + case 'dec': + var month = '12'; + break; + // default: var month = '00'; } - return date.substr(7,4)+month+date.substr(0,2); - } else if (date.length == 10) { - if (ts_europeandate == false) { - return date.substr(6,4)+date.substr(0,2)+date.substr(3,2); + return date.substr( 7, 4 ) + month + date.substr( 0, 2 ); + } else if ( date.length == 10 ) { + if ( ts_europeandate == false ) { + return date.substr( 6, 4 ) + date.substr( 0, 2 ) + date.substr( 3, 2 ); } else { - return date.substr(6,4)+date.substr(3,2)+date.substr(0,2); + return date.substr( 6, 4 ) + date.substr( 3, 2 ) + date.substr( 0, 2 ); } - } else if (date.length == 8) { - yr = date.substr(6,2); - if (parseInt(yr) < 50) { - yr = '20'+yr; + } else if ( date.length == 8 ) { + yr = date.substr( 6, 2 ); + if ( parseInt( yr ) < 50 ) { + yr = '20' + yr; } else { - yr = '19'+yr; + yr = '19' + yr; } - if (ts_europeandate == true) { - return yr+date.substr(3,2)+date.substr(0,2); + if ( ts_europeandate == true ) { + return yr + date.substr( 3, 2 ) + date.substr( 0, 2 ); } else { - return yr+date.substr(0,2)+date.substr(3,2); + return yr + date.substr( 0, 2 ) + date.substr( 3, 2 ); } } - return "00000000"; + return '00000000'; } function ts_parseFloat( s ) { if ( !s ) { return 0; } - if (ts_number_transform_table != false) { + if ( ts_number_transform_table != false ) { var newNum = '', c; for ( var p = 0; p < s.length; p++ ) { c = s.charAt( p ); - if (c in ts_number_transform_table) { + if ( c in ts_number_transform_table ) { newNum += ts_number_transform_table[c]; } else { newNum += c; @@ -815,36 +839,37 @@ function ts_parseFloat( s ) { } s = newNum; } - num = parseFloat(s.replace(/[, ]/g, "").replace("\u2212", "-")); - return (isNaN(num) ? -Infinity : num); + num = parseFloat( s.replace(/[, ]/g, '').replace("\u2212", '-') ); + return ( isNaN( num ) ? -Infinity : num ); } function ts_currencyToSortKey( s ) { return ts_parseFloat(s.replace(/[^-\u22120-9.,]/g,'')); } -function ts_sort_generic(a, b) { +function ts_sort_generic( a, b ) { return a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : a[2] - b[2]; } -function ts_alternate(table) { +function ts_alternate( table ) { // Take object table and get all it's tbodies. - var tableBodies = table.getElementsByTagName("tbody"); + var tableBodies = table.getElementsByTagName( 'tbody' ); // Loop through these tbodies - for (var i = 0; i < tableBodies.length; i++) { + for ( var i = 0; i < tableBodies.length; i++ ) { // Take the tbody, and get all it's rows - var tableRows = tableBodies[i].getElementsByTagName("tr"); + var tableRows = tableBodies[i].getElementsByTagName( 'tr' ); // Loop through these rows // Start at 1 because we want to leave the heading row untouched - for (var j = 0; j < tableRows.length; j++) { + for ( var j = 0; j < tableRows.length; j++ ) { // Check if j is even, and apply classes for both possible results - var oldClasses = tableRows[j].className.split(" "); - var newClassName = ""; - for (var k = 0; k < oldClasses.length; k++) { - if (oldClasses[k] != "" && oldClasses[k] != "even" && oldClasses[k] != "odd") - newClassName += oldClasses[k] + " "; + var oldClasses = tableRows[j].className.split(' '); + var newClassName = ''; + for ( var k = 0; k < oldClasses.length; k++ ) { + if ( oldClasses[k] != '' && oldClasses[k] != 'even' && oldClasses[k] != 'odd' ) { + newClassName += oldClasses[k] + ' '; + } } - tableRows[j].className = newClassName + (j % 2 == 0 ? "even" : "odd"); + tableRows[j].className = newClassName + ( j % 2 == 0 ? 'even' : 'odd' ); } } } @@ -880,7 +905,7 @@ function jsMsg( message, className ) { messageDiv, document.getElementById( 'content' ).firstChild ); - } else if ( document.getElementById('content') + } else if ( document.getElementById( 'content' ) && document.getElementById( 'article' ) ) { // Non-Monobook but still recognizable (old-style) document.getElementById( 'article').insertBefore( @@ -895,15 +920,15 @@ function jsMsg( message, className ) { messageDiv.setAttribute( 'id', 'mw-js-message' ); messageDiv.style.display = 'block'; if( className ) { - messageDiv.setAttribute( 'class', 'mw-js-message-'+className ); + messageDiv.setAttribute( 'class', 'mw-js-message-' + className ); } - if (typeof message === 'object') { - while (messageDiv.hasChildNodes()) // Remove old content - messageDiv.removeChild(messageDiv.firstChild); - messageDiv.appendChild (message); // Append new content - } - else { + if ( typeof message === 'object' ) { + while ( messageDiv.hasChildNodes() ) { // Remove old content + messageDiv.removeChild( messageDiv.firstChild ); + } + messageDiv.appendChild( message ); // Append new content + } else { messageDiv.innerHTML = message; } return true; @@ -916,10 +941,10 @@ function jsMsg( message, className ) { * @param id Identifier string (for use with removeSpinner(), below) */ function injectSpinner( element, id ) { - var spinner = document.createElement( "img" ); - spinner.id = "mw-spinner-" + id; - spinner.src = stylepath + "/common/images/spinner.gif"; - spinner.alt = spinner.title = "..."; + var spinner = document.createElement( 'img' ); + spinner.id = 'mw-spinner-' + id; + spinner.src = stylepath + '/common/images/spinner.gif'; + spinner.alt = spinner.title = '...'; if( element.nextSibling ) { element.parentNode.insertBefore( spinner, element.nextSibling ); } else { @@ -933,7 +958,7 @@ function injectSpinner( element, id ) { * @param id Identifier string */ function removeSpinner( id ) { - var spinner = document.getElementById( "mw-spinner-" + id ); + var spinner = document.getElementById( 'mw-spinner-' + id ); if( spinner ) { spinner.parentNode.removeChild( spinner ); } @@ -941,7 +966,7 @@ function removeSpinner( id ) { function runOnloadHook() { // don't run anything below this for non-dom browsers - if (doneOnloadHook || !(document.getElementById && document.getElementsByTagName)) { + if ( doneOnloadHook || !( document.getElementById && document.getElementsByTagName ) ) { return; } @@ -954,7 +979,7 @@ function runOnloadHook() { sortables_init(); // Run any added-on functions - for (var i = 0; i < onloadFuncts.length; i++) { + for ( var i = 0; i < onloadFuncts.length; i++ ) { onloadFuncts[i](); } } @@ -998,20 +1023,21 @@ function removeHandler( element, remove, handler ) { element.detachEvent( 'on' + remove, handler ); } } -//note: all skins should call runOnloadHook() at the end of html output, +// note: all skins should call runOnloadHook() at the end of html output, // so the below should be redundant. It's there just in case. -hookEvent("load", runOnloadHook); +hookEvent( 'load', runOnloadHook ); if ( ie6_bugs ) { - var isMSIE55 = (window.showModalDialog && window.clipboardData && window.createPopup); + var isMSIE55 = ( window.showModalDialog && window.clipboardData && window.createPopup ); var doneIETransform; var doneIEAlphaFix; - if (document.attachEvent) - document.attachEvent('onreadystatechange', hookit); + if ( document.attachEvent ) { + document.attachEvent( 'onreadystatechange', hookit ); + } function hookit() { - if (!doneIETransform && document.getElementById && document.getElementById('bodyContent')) { + if ( !doneIETransform && document.getElementById && document.getElementById( 'bodyContent' ) ) { doneIETransform = true; relativeforfloats(); fixalpha(); @@ -1021,21 +1047,24 @@ if ( ie6_bugs ) { // png alpha transparency fixes function fixalpha( logoId ) { // bg - if (isMSIE55 && !doneIEAlphaFix) - { + if ( isMSIE55 && !doneIEAlphaFix ) { var plogo = document.getElementById( logoId || 'p-logo' ); - if (!plogo) return; + if ( !plogo ) { + return; + } var logoa = plogo.getElementsByTagName('a')[0]; - if (!logoa) return; + if ( !logoa ) { + return; + } var bg = logoa.currentStyle.backgroundImage; - var imageUrl = bg.substring(5, bg.length-2); + var imageUrl = bg.substring( 5, bg.length - 2 ); doneIEAlphaFix = true; - if (imageUrl.substr(imageUrl.length-4).toLowerCase() == '.png') { - var logospan = logoa.appendChild(document.createElement('span')); + if ( imageUrl.substr( imageUrl.length - 4 ).toLowerCase() == '.png' ) { + var logospan = logoa.appendChild( document.createElement( 'span' ) ); logoa.style.backgroundImage = 'none'; logospan.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + imageUrl + ')'; @@ -1044,20 +1073,17 @@ if ( ie6_bugs ) { logospan.style.width = logoa.currentStyle.width; logospan.style.cursor = 'hand'; // Center image with hack for IE5.5 - if (document.documentElement.dir == "rtl") - { - logospan.style.right = '50%'; - logospan.style.setExpression('marginRight', '"-" + (this.offsetWidth / 2) + "px"'); - } - else - { - logospan.style.left = '50%'; - logospan.style.setExpression('marginLeft', '"-" + (this.offsetWidth / 2) + "px"'); + if ( document.documentElement.dir == 'rtl' ) { + logospan.style.right = '50%'; + logospan.style.setExpression( 'marginRight', '"-" + (this.offsetWidth / 2) + "px"' ); + } else { + logospan.style.left = '50%'; + logospan.style.setExpression( 'marginLeft', '"-" + (this.offsetWidth / 2) + "px"' ); } logospan.style.top = '50%'; - logospan.style.setExpression('marginTop', '"-" + (this.offsetHeight / 2) + "px"'); + logospan.style.setExpression( 'marginTop', '"-" + (this.offsetHeight / 2) + "px"' ); - var linkFix = logoa.appendChild(logoa.cloneNode()); + var linkFix = logoa.appendChild( logoa.cloneNode() ); linkFix.style.position = 'absolute'; linkFix.style.height = '100%'; linkFix.style.width = '100%'; @@ -1067,20 +1093,20 @@ if ( ie6_bugs ) { // fix ie6 disappering float bug function relativeforfloats() { - var bc = document.getElementById('bodyContent'); - if (bc) { - var tables = bc.getElementsByTagName('table'); - var divs = bc.getElementsByTagName('div'); + var bc = document.getElementById( 'bodyContent' ); + if ( bc ) { + var tables = bc.getElementsByTagName( 'table' ); + var divs = bc.getElementsByTagName( 'div' ); } - setrelative(tables); - setrelative(divs); + setrelative( tables ); + setrelative( divs ); } - function setrelative (nodes) { + function setrelative( nodes ) { var i = 0; - while (i < nodes.length) { - if(((nodes[i].style.float && nodes[i].style.float != ('none') || - (nodes[i].align && nodes[i].align != ('none'))) && - (!nodes[i].style.position || nodes[i].style.position != 'relative'))) + while ( i < nodes.length ) { + if( ( ( nodes[i].style.float && nodes[i].style.float != ( 'none' ) || + ( nodes[i].align && nodes[i].align != ( 'none' ) ) ) && + ( !nodes[i].style.position || nodes[i].style.position != 'relative' ) ) ) { nodes[i].style.position = 'relative'; } @@ -1088,14 +1114,14 @@ if ( ie6_bugs ) { } } - // Expand links for printing - - String.prototype.hasClass = function(classWanted) - { + String.prototype.hasClass = function( classWanted ) { var classArr = this.split(/\s/); - for (var i=0; i