From 8a5a4b200dc89b6dbdc4cd5fd309d84d6c6914fe Mon Sep 17 00:00:00 2001 From: Krinkle Date: Fri, 4 Mar 2011 00:15:03 +0000 Subject: [PATCH] JavaScript clean-up (Code conventions, cross-browser fixes and JSHint validation) ; history.js * Applied whitespace conventions + removed trailing whitespace * Combining var statements ; mediawiki.action.history.js * Calling in document.ready instead of directly (jQuery(fn) is short for jQuery(document).ready(fn)) ** Originally it was a hookEvent('load'), during rewrite in r74397 it was dropped. Restoring now. * Wrapping in jQuery-to-$ * Combining document.ready and wrapper into one (jQuery internally calls the ready-fn with jQuery as first argument) ($(function(){ $(function(){ /* domready */ })(jQuery); --> jQuery( function( $ ) { /* domready */ } ); * (http://jqbug.com/8229) Attributes must be quoted, just like CSS requires that. ; mediawiki.action.view.rightClickEdit.js * Wrapping in jQuery-to-$ ; IEFixes.js * Moving function calls within the if statement since the passed arguments are undefined otherwise --- .../mediawiki.action.history.js | 9 +-- .../mediawiki.action.view.rightClickEdit.js | 2 +- skins/common/IEFixes.js | 4 +- skins/common/history.js | 62 ++++++++++--------- 4 files changed, 40 insertions(+), 37 deletions(-) diff --git a/resources/mediawiki.action/mediawiki.action.history.js b/resources/mediawiki.action/mediawiki.action.history.js index 66f90b0708..3f9634776e 100644 --- a/resources/mediawiki.action/mediawiki.action.history.js +++ b/resources/mediawiki.action/mediawiki.action.history.js @@ -1,7 +1,8 @@ /* * JavaScript for History action */ - -// Replaces histrowinit -$( '#pagehistory li input[name=diff], #pagehistory li input[name=oldid]' ).click( diffcheck ); -diffcheck(); \ No newline at end of file +jQuery( function( $ ) { + // Replaces histrowinit + $( '#pagehistory li input[name="diff"], #pagehistory li input[name="oldid"]' ).click( diffcheck ); + diffcheck(); +}); \ No newline at end of file diff --git a/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js b/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js index 5a7c777f42..caf9a9f2e0 100644 --- a/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js +++ b/resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js @@ -1,7 +1,7 @@ /* * JavaScript to enable right click edit functionality */ -$( function() { +jQuery( function( $ ) { // Select all h1-h6 elements that contain editsection links $( 'h1:has(.editsection a), ' + 'h2:has(.editsection a), ' + diff --git a/skins/common/IEFixes.js b/skins/common/IEFixes.js index ba4dc66b64..7f3b9c0fb7 100644 --- a/skins/common/IEFixes.js +++ b/skins/common/IEFixes.js @@ -69,9 +69,9 @@ window.relativeforfloats = function() { if ( bc ) { var tables = bc.getElementsByTagName( 'table' ); var divs = bc.getElementsByTagName( 'div' ); + setrelative( tables ); + setrelative( divs ); } - setrelative( tables ); - setrelative( divs ); }; window.setrelative = function( nodes ) { diff --git a/skins/common/history.js b/skins/common/history.js index 33845a7587..ee14ac97d9 100644 --- a/skins/common/history.js +++ b/skins/common/history.js @@ -1,8 +1,9 @@ -window.historyRadios = function(parent) { - var inputs = parent.getElementsByTagName('input'); - var radios = []; - for (var i = 0; i < inputs.length; i++) { - if (inputs[i].name == "diff" || inputs[i].name == "oldid") { +window.historyRadios = function( parent ) { + var inputs = parent.getElementsByTagName( 'input' ); + var radios = [], + i = 0; + for ( i = 0; i < inputs.length; i++ ) { + if ( inputs[i].name == 'diff' || inputs[i].name == 'oldid' ) { radios[radios.length] = inputs[i]; } } @@ -11,41 +12,42 @@ window.historyRadios = function(parent) { // check selection and tweak visibility/class onclick window.diffcheck = function() { - var dli = false; // the li where the diff radio is checked - var oli = false; // the li where the oldid radio is checked - var hf = document.getElementById('pagehistory'); - if (!hf) { + var dli = false, // the li where the diff radio is checked + oli = false, // the li where the oldid radio is checked + i = 0; + var hf = document.getElementById( 'pagehistory' ); + if ( !hf ) { return true; } - var lis = hf.getElementsByTagName('li'); - for (var i=0;i