From 7e43f640a672e637077b687a57a66072c6a18fba Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Sun, 7 Oct 2012 02:18:42 +0200 Subject: [PATCH] Tweaks and fixes suggested by JSHint/JSLint. Change-Id: Ia2e089dba787fafbd48e27a3da197dec328c5181 --- modules/ext.scribunto.edit.js | 61 ++++++++++++++++++++--------------- modules/ext.scribunto.js | 13 ++++---- 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/modules/ext.scribunto.edit.js b/modules/ext.scribunto.edit.js index 7d7234e4..89b39f24 100644 --- a/modules/ext.scribunto.edit.js +++ b/modules/ext.scribunto.edit.js @@ -41,20 +41,22 @@ function initConsole() function inputKeydown( e ) { // Use onkeydown because IE doesn't support onkeypress for arrow keys - if ( e.shiftKey && e.keyCode == 13 ) { // shift-enter + if ( e.shiftKey && e.keyCode === 13 ) { // shift-enter // don't do anything; allow the shift-enter to insert a line break as normal - } else if ( e.keyCode == 13 ) { // enter + } else if ( e.keyCode === 13 ) { // enter // execute the input on enter go(); - } else if ( e.keyCode == 38 ) { // up + } else if ( e.keyCode === 38 ) { // up // go up in history if at top or ctrl-up - if ( e.ctrlKey || caretInFirstLine( _in ) ) + if ( e.ctrlKey || caretInFirstLine( _in ) ) { hist( 'up' ); - } else if ( e.keyCode == 40 ) { // down + } + } else if ( e.keyCode === 40 ) { // down // go down in history if at end or ctrl-down - if ( e.ctrlKey || caretInLastLine( _in ) ) + if ( e.ctrlKey || caretInLastLine( _in ) ) { hist( 'down' ); - } else { } + } + } setTimeout( recalculateInputHeight, 0 ); @@ -81,19 +83,21 @@ function inputFocus( e ) { function caretInFirstLine( textbox ) { // IE doesn't support selectionStart/selectionEnd - if ( textbox.selectionStart == undefined ) + if ( textbox.selectionStart === undefined ) { return true; + } var firstLineBreak = textbox.value.indexOf( "\n" ); - return ((firstLineBreak == -1) || (textbox.selectionStart <= firstLineBreak)); + return ((firstLineBreak === -1) || (textbox.selectionStart <= firstLineBreak)); } function caretInLastLine( textbox ) { // IE doesn't support selectionStart/selectionEnd - if ( textbox.selectionEnd == undefined ) + if ( textbox.selectionEnd === undefined ) { return true; + } var lastLineBreak = textbox.value.lastIndexOf( "\n" ); @@ -107,8 +111,9 @@ function recalculateInputHeight() + ( window.opera ? 1 : 0 ); // leave room for scrollbar in Opera // without this check, it is impossible to select text in Opera 7.60 or Opera 8.0. - if ( _in.rows != rows ) + if ( _in.rows !== rows ) { _in.rows = rows; + } } function println( s, type ) @@ -148,12 +153,13 @@ function hist( direction ) var L = histList.length; - if ( L == 1 ) + if ( L === 1 ) { return; + } if ( direction === 'up' ) { - if ( histPos == L-1 ) + if ( histPos === L-1 ) { // Save this entry in case the user hits the down key. histList[histPos] = _in.value; @@ -169,8 +175,9 @@ function hist( direction ) _in.value = ''; _in.value = histList[histPos]; var caretPos = _in.value.length; - if (_in.setSelectionRange) + if (_in.setSelectionRange) { _in.setSelectionRange(caretPos, caretPos); + } }, 0 ); @@ -183,7 +190,7 @@ function hist( direction ) histPos++; _in.value = histList[histPos]; } - else if ( histPos == L-1 ) + else if ( histPos === L-1 ) { // Already on the current entry: clear but save if ( _in.value ) @@ -209,12 +216,12 @@ function printError( er ) if ( er.name ) { // lineNumberString should not be "", to avoid a very wacky bug in IE 6. - lineNumberString = (er.lineNumber != undefined) ? (" on line " + er.lineNumber + ": ") : ": "; + lineNumberString = (er.lineNumber !== undefined) ? (" on line " + er.lineNumber + ": ") : ": "; // Because IE doesn't have error.toString. println( er.name + lineNumberString + er.message, "mw-scribunto-error" ); - } - else + } else { println( er, "mw-scribunto-error" ); // Because security errors in Moz /only/ have toString. + } } function setPending() { @@ -238,8 +245,9 @@ function go() question = _in.value; - if ( question == "" ) + if ( question === "" ) { return; + } histList[histList.length-1] = question; histList[histList.length] = ""; @@ -257,8 +265,8 @@ function go() var params = { action: 'scribunto-console', title: mw.config.get( 'wgTitle' ), - question: question, - } + question: question + }; var content = getContent(); if ( !sessionKey || sessionContent !== content ) { @@ -305,14 +313,15 @@ function go() } clearPending(); setTimeout( refocus, 0 ); - }, + } } ); } function getContent() { - var $textarea = $( '#wpTextbox1' ); - var context = $textarea.data( 'wikiEditor-context' ); - if ( context == undefined || context.codeEditor == undefined ) { + var $textarea = $( '#wpTextbox1' ), + context = $textarea.data( 'wikiEditor-context' ); + + if ( context === undefined || context.codeEditor === undefined ) { return $textarea.val(); } else { return $textarea.textSelection( 'getContents' ); @@ -328,7 +337,7 @@ function onClearClick( e ) { mw.scribunto.edit = { 'init': function () { var action = mw.config.get( 'wgAction' ); - if ( action == 'edit' || action == 'submit' || action == 'editredlink' ) { + if ( action === 'edit' || action === 'submit' || action === 'editredlink' ) { this.initEditPage(); } }, diff --git a/modules/ext.scribunto.js b/modules/ext.scribunto.js index 9ebf1299..f0dd5bbd 100644 --- a/modules/ext.scribunto.js +++ b/modules/ext.scribunto.js @@ -8,9 +8,10 @@ mw.scribunto = { }, 'init': function() { - var regex = /^mw-scribunto-error-(\d+)/; - var that = this; - var dialog = $( '
' ); + var regex = /^mw-scribunto-error-(\d+)/, + that = this, + dialog = $( '
' ); + dialog.dialog({ title: mw.msg( 'scribunto-parser-dialog-title' ), autoOpen: false @@ -18,7 +19,7 @@ mw.scribunto = { $('.scribunto-error').each( function( index, span ) { var matches = regex.exec( span.id ); - if ( matches == null ) { + if ( matches === null ) { console.log( "mw.scribunto.init: regex mismatch!" ); return; } @@ -26,7 +27,7 @@ mw.scribunto = { $(span) .css( 'cursor', 'pointer' ) .bind( 'click', function( evt ) { - if ( typeof that.errors[ errorId ] != 'string' ) { + if ( typeof that.errors[ errorId ] !== 'string' ) { console.log( "mw.scribunto.init: error " + matches[1] + " not found, " + "mw.loader.using() callback may not have been called yet." ); return; @@ -39,7 +40,7 @@ mw.scribunto = { .dialog( 'open' ); } ); } ); - }, + } }; $(document).ready( function() {