From 09d9dfda2b3cffe6126e2e6df6159ad9e28e4e84 Mon Sep 17 00:00:00 2001 From: Ori Livneh Date: Sun, 22 Sep 2013 12:30:27 -0700 Subject: [PATCH] Clean-up of skins/common/IEFixes.js - Wrap script code in an IIFE. - Create scope-local bindings for global vars. - Use strict comparisons. - Use single var statement to declare variables. Change-Id: I1ee94b184f5bb2355d01fae554c50ef314147298 --- skins/common/IEFixes.js | 75 +++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/skins/common/IEFixes.js b/skins/common/IEFixes.js index dd999ed420..09f0910cab 100644 --- a/skins/common/IEFixes.js +++ b/skins/common/IEFixes.js @@ -1,10 +1,14 @@ // IE fixes javascript +( function ( mw, $ ) { -window.isMSIE55 = ( window.showModalDialog && window.clipboardData && window.createPopup ); -window.doneIETransform = undefined; -window.doneIEAlphaFix = undefined; +var doneIEAlphaFix, doneIETransform, expandedURLs, fixalpha, isMSIE55, + relativeforfloats, setrelative; -window.hookit = function() { +isMSIE55 = window.isMSIE55 = ( window.showModalDialog && window.clipboardData && window.createPopup ); +doneIETransform = window.doneIETransform = undefined; +doneIEAlphaFix = window.doneIEAlphaFix = undefined; + +window.hookit = function () { if ( !doneIETransform && document.getElementById && document.getElementById( 'bodyContent' ) ) { doneIETransform = true; relativeforfloats(); @@ -17,26 +21,27 @@ if ( document.attachEvent ) { } // png alpha transparency fixes -window.fixalpha = function( logoId ) { +fixalpha = window.fixalpha = function ( logoId ) { // bg if ( isMSIE55 && !doneIEAlphaFix ) { - var plogo = document.getElementById( logoId || 'p-logo' ); + var bg, imageUrl, linkFix, logoa, logospan, plogo; + plogo = document.getElementById( logoId || 'p-logo' ); if ( !plogo ) { return; } - var logoa = plogo.getElementsByTagName('a')[0]; + logoa = plogo.getElementsByTagName('a')[0]; if ( !logoa ) { return; } - var bg = logoa.currentStyle.backgroundImage; - var imageUrl = bg.substring( 5, bg.length - 2 ); + bg = logoa.currentStyle.backgroundImage; + 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' ) { + logospan = logoa.appendChild( document.createElement( 'span' ) ); logoa.style.backgroundImage = 'none'; logospan.style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + imageUrl + ')'; @@ -45,7 +50,7 @@ window.fixalpha = function( logoId ) { logospan.style.width = logoa.currentStyle.width; logospan.style.cursor = 'hand'; // Center image with hack for IE5.5 - if ( document.documentElement.dir == 'rtl' ) { + if ( document.documentElement.dir === 'rtl' ) { logospan.style.right = '50%'; logospan.style.setExpression( 'marginRight', '"-" + (this.offsetWidth / 2) + "px"' ); } else { @@ -55,7 +60,7 @@ window.fixalpha = function( logoId ) { logospan.style.top = '50%'; logospan.style.setExpression( 'marginTop', '"-" + (this.offsetHeight / 2) + "px"' ); - var linkFix = logoa.appendChild( logoa.cloneNode() ); + linkFix = logoa.appendChild( logoa.cloneNode() ); linkFix.style.position = 'absolute'; linkFix.style.height = '100%'; linkFix.style.width = '100%'; @@ -69,22 +74,23 @@ if ( isMSIE55 ) { } // fix ie6 disappering float bug -window.relativeforfloats = function() { - var bc = document.getElementById( 'bodyContent' ); +relativeforfloats = window.relativeforfloats = function () { + var bc, tables, divs; + bc = document.getElementById( 'bodyContent' ); if ( bc ) { - var tables = bc.getElementsByTagName( 'table' ); - var divs = bc.getElementsByTagName( 'div' ); + tables = bc.getElementsByTagName( 'table' ); + divs = bc.getElementsByTagName( 'div' ); setrelative( tables ); setrelative( divs ); } }; -window.setrelative = function( nodes ) { +setrelative = window.setrelative = function ( 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' ) ) ) + 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'; } @@ -93,30 +99,31 @@ window.setrelative = function( nodes ) { }; // Expand links for printing -String.prototype.hasClass = function( classWanted ) { - var classArr = this.split(/\s/); - for ( var i = 0; i < classArr.length; i++ ) { - if ( classArr[i].toLowerCase() == classWanted.toLowerCase() ) { +String.prototype.hasClass = function ( classWanted ) { + var i = 0, classArr = this.split(/\s/); + for ( i = 0; i < classArr.length; i++ ) { + if ( classArr[i].toLowerCase() === classWanted.toLowerCase() ) { return true; } } return false; }; -window.expandedURLs = undefined; +expandedURLs = window.expandedURLs = undefined; -window.onbeforeprint = function() { - expandedURLs = []; +window.onbeforeprint = function () { + var allLinks, contentEl, expandedLink, expandedText, i; - var contentEl = document.getElementById( 'content' ); + expandedURLs = []; + contentEl = document.getElementById( 'content' ); if ( contentEl ) { - var allLinks = contentEl.getElementsByTagName( 'a' ); + allLinks = contentEl.getElementsByTagName( 'a' ); - for ( var i = 0; i < allLinks.length; i++ ) { + for ( i = 0; i < allLinks.length; i++ ) { if ( allLinks[i].className.hasClass( 'external' ) && !allLinks[i].className.hasClass( 'free' ) ) { - var expandedLink = document.createElement( 'span' ); - var expandedText = document.createTextNode( ' (' + allLinks[i].href + ')' ); + expandedLink = document.createElement( 'span' ); + expandedText = document.createTextNode( ' (' + allLinks[i].href + ')' ); expandedLink.appendChild( expandedText ); allLinks[i].parentNode.insertBefore( expandedLink, allLinks[i].nextSibling ); expandedURLs[i] = expandedLink; @@ -132,3 +139,5 @@ window.onafterprint = function() { } } }; + +}( mediaWiki, jQuery ) ); -- 2.20.1