r83123 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83122‎ | r83123 | r83124 >
Date:22:54, 2 March 2011
Author:krinkle
Status:ok
Tags:
Comment:
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)
Modified paths:
  • /trunk/phase3/skins/common/edit.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/edit.js
@@ -33,7 +33,7 @@
3434 insertTags( item.tagOpen, item.tagClose, item.sampleText, item.selectText );
3535 // click tracking
3636 if ( ( typeof $ != 'undefined' ) && ( typeof $.trackAction != 'undefined' ) ) {
37 - $.trackAction( 'oldedit.' + item.speedTip.replace(/ /g, "-") );
 37+ $.trackAction( 'oldedit.' + item.speedTip.replace(/ /g, '-') );
3838 }
3939 return false;
4040 };
@@ -46,6 +46,7 @@
4747 // we use it to avoid creating the toolbar where javascript is not enabled
4848 window.mwSetupToolbar = function() {
4949 var toolbar = document.getElementById( 'toolbar' );
 50+ var i = 0;
5051 if ( !toolbar ) {
5152 return false;
5253 }
@@ -67,10 +68,10 @@
6869 return false;
6970 }
7071 }
71 - for ( var i = 0; i < mwEditButtons.length; i++ ) {
 72+ for ( i = 0; i < mwEditButtons.length; i++ ) {
7273 mwInsertEditButton( toolbar, mwEditButtons[i] );
7374 }
74 - for ( var i = 0; i < mwCustomEditButtons.length; i++ ) {
 75+ for ( i = 0; i < mwCustomEditButtons.length; i++ ) {
7576 mwInsertEditButton( toolbar, mwCustomEditButtons[i] );
7677 }
7778 return true;
@@ -96,12 +97,23 @@
9798 }
9899 var selText, isSample = false;
99100
 101+ function checkSelectedText() {
 102+ if ( !selText ) {
 103+ selText = sampleText;
 104+ isSample = true;
 105+ } else if ( selText.charAt(selText.length - 1) == ' ' ) { // exclude ending space char
 106+ selText = selText.substring(0, selText.length - 1);
 107+ tagClose += ' ';
 108+ }
 109+ }
 110+
100111 if ( document.selection && document.selection.createRange ) { // IE/Opera
101112 // save window scroll position
 113+ var winScroll = null;
102114 if ( document.documentElement && document.documentElement.scrollTop ) {
103 - var winScroll = document.documentElement.scrollTop
 115+ winScroll = document.documentElement.scrollTop;
104116 } else if ( document.body ) {
105 - var winScroll = document.body.scrollTop;
 117+ winScroll = document.body.scrollTop;
106118 }
107119 // get current selection
108120 txtarea.focus();
@@ -153,16 +165,6 @@
154166 txtarea.scrollTop = textScroll;
155167 }
156168
157 - function checkSelectedText() {
158 - if ( !selText ) {
159 - selText = sampleText;
160 - isSample = true;
161 - } else if ( selText.charAt(selText.length - 1) == ' ' ) { // exclude ending space char
162 - selText = selText.substring(0, selText.length - 1);
163 - tagClose += ' ';
164 - }
165 - }
166 -
167169 };
168170
169171 /**
@@ -229,6 +231,4 @@
230232 }
231233 }
232234
233 - editForm
234 -} );
235 -
 235+} );
\ No newline at end of file

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r59832Fixes for comments on r59655...dantman17:17, 8 December 2009

Status & tagging log