From: Krinkle Date: Wed, 2 Mar 2011 22:54:12 +0000 (+0000) Subject: Code conventions, cross-browser fixes and JSHint validation X-Git-Tag: 1.31.0-rc.0~31682 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=d73db07ef1909ea8d1c21028b19a8e4820710380;p=lhc%2Fweb%2Fwiklou.git Code conventions, cross-browser fixes and JSHint validation ; edit.js * Creating the 'i' variable only once * Defining winScroll before the if statements. This way when it's referenced later it will never trow an error about it being undefined. * Moving checkSelectedText up. It was called before it's definition. * Removed line with a loose variable on it (added in r59832) --- diff --git a/skins/common/edit.js b/skins/common/edit.js index dd5d13046a..35505f4cdb 100644 --- a/skins/common/edit.js +++ b/skins/common/edit.js @@ -33,7 +33,7 @@ window.mwInsertEditButton = function( parent, item ) { insertTags( item.tagOpen, item.tagClose, item.sampleText, item.selectText ); // click tracking if ( ( typeof $ != 'undefined' ) && ( typeof $.trackAction != 'undefined' ) ) { - $.trackAction( 'oldedit.' + item.speedTip.replace(/ /g, "-") ); + $.trackAction( 'oldedit.' + item.speedTip.replace(/ /g, '-') ); } return false; }; @@ -46,6 +46,7 @@ window.mwInsertEditButton = function( parent, item ) { // we use it to avoid creating the toolbar where javascript is not enabled window.mwSetupToolbar = function() { var toolbar = document.getElementById( 'toolbar' ); + var i = 0; if ( !toolbar ) { return false; } @@ -67,10 +68,10 @@ window.mwSetupToolbar = function() { return false; } } - for ( var i = 0; i < mwEditButtons.length; i++ ) { + for ( i = 0; i < mwEditButtons.length; i++ ) { mwInsertEditButton( toolbar, mwEditButtons[i] ); } - for ( var i = 0; i < mwCustomEditButtons.length; i++ ) { + for ( i = 0; i < mwCustomEditButtons.length; i++ ) { mwInsertEditButton( toolbar, mwCustomEditButtons[i] ); } return true; @@ -96,12 +97,23 @@ window.insertTags = function( tagOpen, tagClose, sampleText, selectText) { } var selText, isSample = false; + function checkSelectedText() { + if ( !selText ) { + selText = sampleText; + isSample = true; + } else if ( selText.charAt(selText.length - 1) == ' ' ) { // exclude ending space char + selText = selText.substring(0, selText.length - 1); + tagClose += ' '; + } + } + if ( document.selection && document.selection.createRange ) { // IE/Opera // save window scroll position + var winScroll = null; if ( document.documentElement && document.documentElement.scrollTop ) { - var winScroll = document.documentElement.scrollTop + winScroll = document.documentElement.scrollTop; } else if ( document.body ) { - var winScroll = document.body.scrollTop; + winScroll = document.body.scrollTop; } // get current selection txtarea.focus(); @@ -153,16 +165,6 @@ window.insertTags = function( tagOpen, tagClose, sampleText, selectText) { txtarea.scrollTop = textScroll; } - function checkSelectedText() { - if ( !selText ) { - selText = sampleText; - isSample = true; - } else if ( selText.charAt(selText.length - 1) == ' ' ) { // exclude ending space char - selText = selText.substring(0, selText.length - 1); - tagClose += ' '; - } - } - }; /** @@ -229,6 +231,4 @@ hookEvent( 'load', function() { } } - editForm -} ); - +} ); \ No newline at end of file