mediawiki-extensions-Scribunto/modules/ext.scribunto.edit.js

403 lines
9.5 KiB
JavaScript
Raw Normal View History

( function ( $, mw ) {
/**
* Debug console
* Based on JavaScript Shell 1.4 by Jesse Ruderman (GPL/LGPL/MPL tri-license)
*
* TODO:
* * Refactor, more jQuery, etc.
* * Spinner?
* * A prompt in front of input lines and the textarea
* * Collapsible backtrace display
*/
var
histList = [ '' ],
histPos = 0,
question,
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
input,
output,
$spinner,
lastError = null,
sessionContent = null,
sessionKey = null,
pending = false,
clearNextRequest = false;
function refocus() {
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
// Needed for Mozilla to scroll correctly
input.blur();
input.focus();
}
function initConsole() {
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
input = document.getElementById( 'mw-scribunto-input' );
output = document.getElementById( 'mw-scribunto-output' );
$spinner = $.createSpinner( { size: 'small', type: 'block' } );
recalculateInputHeight();
println( mw.msg( 'scribunto-console-intro' ), 'mw-scribunto-message' );
}
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
/**
* Use onkeydown because IE doesn't support onkeypress for arrow keys
*
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
* @param {jQuery.Event} e
*/
function inputKeydown( e ) {
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
/*jshint noempty:false */
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
if ( e.shiftKey && e.keyCode === 13 ) {
// shift-enter
// don't do anything; allow the shift-enter to insert a line break as normal
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
} else if ( e.keyCode === 13 ) {
// enter
// execute the input on enter
go();
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
} else if ( e.keyCode === 38 ) {
// up
// go up in history if at top or ctrl-up
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
if ( e.ctrlKey || caretInFirstLine( input ) ) {
hist( 'up' );
}
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
} else if ( e.keyCode === 40 ) {
// down
// go down in history if at end or ctrl-down
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
if ( e.ctrlKey || caretInLastLine( input ) ) {
hist( 'down' );
}
}
setTimeout( recalculateInputHeight, 0 );
}
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
function inputFocus() {
if ( sessionContent === null ) {
// No previous state to clear
return;
}
if ( clearNextRequest ) {
// User already knows
return;
}
if ( getContent() !== sessionContent ) {
printClearBar( 'scribunto-console-cleared' );
clearNextRequest = true;
}
}
function caretInFirstLine( textbox ) {
var firstLineBreak;
// IE doesn't support selectionStart/selectionEnd
if ( textbox.selectionStart === undefined ) {
return true;
}
firstLineBreak = textbox.value.indexOf( '\n' );
return ( ( firstLineBreak === -1 ) || ( textbox.selectionStart <= firstLineBreak ) );
}
function caretInLastLine( textbox ) {
var lastLineBreak;
// IE doesn't support selectionStart/selectionEnd
if ( textbox.selectionEnd === undefined ) {
return true;
}
lastLineBreak = textbox.value.lastIndexOf( '\n' );
return ( textbox.selectionEnd > lastLineBreak );
}
function recalculateInputHeight() {
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
var rows = input.value.split( /\n/ ).length +
// prevent scrollbar flickering in Mozilla
1 +
// leave room for scrollbar in Opera
( window.opera ? 1 : 0 );
// without this check, it is impossible to select text in Opera 7.60 or Opera 8.0.
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
if ( input.rows !== rows ) {
input.rows = rows;
}
}
function println( s, type ) {
var newdiv;
if ( ( s = String( s ) ) ) {
newdiv = document.createElement( 'div' );
newdiv.appendChild( document.createTextNode( s ) );
newdiv.className = type;
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
output.appendChild( newdiv );
return newdiv;
}
}
function printClearBar( msg ) {
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
$( '<div>' )
.attr( 'class', 'mw-scribunto-clear' )
.text( mw.msg( msg ) )
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
.appendTo( output );
}
function hist( direction ) {
// histList[0] = first command entered, [1] = second, etc.
// type something, press up --> thing typed is now in "limbo"
// (last item in histList) and should be reachable by pressing
// down again.
var L = histList.length;
if ( L === 1 ) {
return;
}
if ( direction === 'up' ) {
if ( histPos === L - 1 ) {
// Save this entry in case the user hits the down key.
histList[ histPos ] = input.value;
}
if ( histPos > 0 ) {
histPos--;
// Use a timeout to prevent up from moving cursor within new text
// Set to nothing first for the same reason
setTimeout(
function () {
var caretPos;
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
input.value = '';
input.value = histList[ histPos ];
caretPos = input.value.length;
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
if ( input.setSelectionRange ) {
input.setSelectionRange( caretPos, caretPos );
}
},
0
);
}
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
} else {
// direction down
if ( histPos < L - 1 ) {
histPos++;
input.value = histList[ histPos ];
} else if ( histPos === L - 1 ) {
// Already on the current entry: clear but save
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
if ( input.value ) {
histList[ histPos ] = input.value;
++histPos;
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
input.value = '';
}
}
}
}
function printQuestion( q ) {
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
println( q, 'mw-scribunto-input' );
}
function printError( er ) {
var lineNumberString;
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
// for debugging the shell
lastError = er;
if ( er.name ) {
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
// lineNumberString should not be '', to avoid a very wacky bug in IE 6.
lineNumberString = ( er.lineNumber !== undefined ) ? ( ' on line ' + er.lineNumber + ': ' ) : ': ';
// Because IE doesn't have error.toString.
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
println( er.name + lineNumberString + er.message, 'mw-scribunto-error' );
} else {
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
// Because security errors in Moz /only/ have toString.
println( er, 'mw-scribunto-error' );
}
}
function setPending() {
pending = true;
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
input.readOnly = true;
$spinner.insertBefore( input );
}
function clearPending() {
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
$spinner.remove();
pending = false;
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
input.readOnly = false;
}
function go() {
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
var params, api, content, sentContent;
if ( pending ) {
// If there is an XHR request pending, don't send another one
// We set readOnly on the textarea to give a UI indication, this is
// just for paranoia.
return;
}
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
question = input.value;
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
if ( question === '' ) {
return;
}
histList[ histList.length - 1 ] = question;
histList[ histList.length ] = '';
histPos = histList.length - 1;
// Unfortunately, this has to happen *before* the script is run, so that
// print() output will go in the right place.
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
input.value = '';
// can't preventDefault on input, so also clear it later
setTimeout( function () {
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
input.value = '';
}, 0 );
recalculateInputHeight();
printQuestion( question );
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
params = {
action: 'scribunto-console',
title: mw.config.get( 'wgPageName' ),
question: question
};
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
content = getContent();
sentContent = false;
if ( !sessionKey || sessionContent !== content ) {
params.clear = true;
params.content = content;
sentContent = true;
}
if ( sessionKey ) {
params.session = sessionKey;
}
if ( clearNextRequest ) {
params.clear = true;
clearNextRequest = false;
}
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
api = new mw.Api();
setPending();
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
api.post( params )
.done( function ( result ) {
if ( result.sessionIsNew === '' && !sentContent ) {
// Session was lost. Resend query, with content
printClearBar( 'scribunto-console-cleared-session-lost' );
sessionContent = null;
clearPending();
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
input.value = params.question;
go();
return;
}
sessionKey = result.session;
sessionContent = content;
if ( result.type === 'error' ) {
$( '<div>' ).addClass( 'mw-scribunto-error' ).html( result.html ).appendTo( output );
} else {
if ( result.print !== '' ) {
println( result.print, 'mw-scribunto-print' );
}
if ( result[ 'return' ] !== '' ) {
println( result[ 'return' ], 'mw-scribunto-normalOutput' );
}
}
clearPending();
setTimeout( refocus, 0 );
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
} )
.fail( function ( code, result ) {
if ( result.error && result.error.info ) {
printError( result.error.info );
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
} else if ( result.exception ) {
printError( 'Error sending API request: ' + result.exception );
} else {
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
mw.log( result );
printError( 'error' );
}
clearPending();
setTimeout( refocus, 0 );
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
} );
}
function getContent() {
var $textarea = $( '#wpTextbox1' ),
context = $textarea.data( 'wikiEditor-context' );
if ( context === undefined || context.codeEditor === undefined ) {
return $textarea.val();
} else {
return $textarea.textSelection( 'getContents' );
}
}
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
function onClearClick() {
$( '#mw-scribunto-output' ).empty();
clearNextRequest = true;
refocus();
}
function initEditPage() {
var $wpTextbox1,
$console = $( '#mw-scribunto-console' );
if ( !$console.length ) {
// There is no console in the DOM; on read-only (protected) pages,
// we need to add it here, because the hook does not insert
// it server-side.
$wpTextbox1 = $( '#wpTextbox1' );
if ( !$wpTextbox1.length || !$wpTextbox1.prop( 'readonly' ) ) {
return;
}
$console = $( '<div>' ).attr( { id: 'mw-scribunto-console' } );
$wpTextbox1.after( $console );
}
$( '<fieldset>' )
.attr( 'class', 'mw-scribunto-console-fieldset' )
.append( $( '<legend>' ).text( mw.msg( 'scribunto-console-title' ) ) )
.append( $( '<div id="mw-scribunto-output"></div>' ) )
.append(
$( '<div>' ).append(
$( '<textarea>' )
.attr( {
id: 'mw-scribunto-input',
'class': 'mw-scribunto-input',
wrap: 'off',
rows: 1,
dir: 'ltr',
lang: 'en'
} )
.bind( 'keydown', inputKeydown )
.bind( 'focus', inputFocus )
)
)
.append(
$( '<div>' ).append(
$( '<input>' )
.attr( {
type: 'button',
value: mw.msg( 'scribunto-console-clear' )
} )
.bind( 'click', onClearClick )
)
)
.wrap( '<form>' )
.appendTo( $console );
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
initConsole();
}
Clean up existing code and pass jshint Coding style: * Avoid meaningless '_' in variable names, especially when used inconsistently. * Avoid trailing line comments. * Consistent if/else curly brace position. * Consistently use single quotes (there are no magic quotes in js). * Consistently use $ in variable names of jQuery-wrapped elements (as opposed to plain node references). * Avoid using variable names like '_this' or 'that', instead name them after the object. * Too many var statements. * Hoist var statement. * Fix alignment of closing parentheses in initEditPage. Code quality: * Remove commented out code. * Add missing radix parameter for parseInt. * Remove unused private function "printWithRunin". * Remove unused parameters. * Don't call "console.log" in production client-side code because the console doesn't always exist in normal browser modes (and would result in an Uncaught ReferenceError, aborting the script unexpectedly and leaving the user interface in a likely unresponsive state). * Use the Promise.done and Promise.fail handlers of mw.Api, instead of the deprecated 'ok' and 'err' parameters. * Use jQuery#on instead of the deprecated jQuery#bind. * Use a local shared reference to the singleton instead of relying on 'this' context, this way the methods can be called regardless of context. Such as in the $(document).ready(), or when passing around setErrors callback. * Avoid using invalid html shortcuts like <div/>, use <tag> for creation, and <tag>..</tag> for parsing (per style guide). * Document inputKeydown parameter being jQuery.Event (as oppposed to native Event). Misc: * Renamed '_in' to 'in', and renamed again to 'input' ('in' is an illegal variable name and would've crashed). Change-Id: I283fda1409b1e76db56a939183bdaefc95e60961
2013-12-10 23:05:26 +00:00
$( function () {
var action = mw.config.get( 'wgAction' );
if ( action === 'edit' || action === 'submit' || action === 'editredlink' ) {
initEditPage();
}
} );
}( jQuery, mediaWiki ) );