Bureaucrats, editor, Interface administrators, Administrators (Semantic MediaWiki), Curators (Semantic MediaWiki), Editors (Semantic MediaWiki), Administrators
47,327
edits
No edit summary Tag: Manual revert |
No edit summary |
||
Line 1:
"use strict";
/**
* Gadget that loads a couple of snippets for the console on module pages
Line 8 ⟶ 10:
* The scribunto console is run by ext.scribunto.edit - https://github.com/wikimedia/mediawiki-extensions-Scribunto/blob/master/modules/ext.scribunto.edit.js
*/
var FRAME_TEST = ["local frame = {}", "function frame.getParent()", " local args = {", " -- Args go here as ['name'] = value,", " }", " return { args = args }", "end", "mw.log( p.main(frame) )"],
FRAME_TEST_TEXT = FRAME_TEST.join('\n');
var $clearBtn,
$inp;
function addButtons() {
var $prevHistory = $('<input class="console-control console-prevHist" type="button" value="History ˄" title="Load the previous input in your console history, if any">');
// send the appropriate keydown events to the input element
// (ctrl+up / ctrl+down scrolls history)
$prevHistory.on('click', function () {
$inp.trigger({
type: 'keydown',
keyCode: 38,
//DOWN arrow
ctrlKey: true
});
// don't actually need to have an event attached to this, we're just gonna check is(:checked)
// BUT we are adding an event to save state to localStorage
$allowEnter.prop('checked', window.localStorage.getItem('rsw-scribunto-console-allowEnter') === "true"); // do this before attaching event, just to be sure we don't fire it
$allowEnter.on('change', function () {
window.localStorage.setItem('rsw-scribunto-console-allowEnter', $allowEnter.is(':checked'));
});
// attach this to the parent element
// capture=true => this runs before the innermost element's event
document.getElementById('mw-scribunto-input').parentElement.addEventListener('keydown', function (e) {
if (e.target.id !== 'mw-scribunto-input') return;
if (!(e.keyCode === 13)) return; // enter
if (e.ctrlKey || e.shiftKey) return;
if ($allowEnter.is(':checked')) {
e.stopImmediatePropagation();
$inp.attr('rows', $inp.val().split(/\r?\n/).length + 1);
return;
}
}, true);
// enter runs the code
// ctrl+enter runs it too, and we're explicitly excluding ctrl+enter from allowEnter
var $run = $('<input class="console-control console-runButton" type="button" value="Run" title="Run the current input">');
$run.on('click', function () {
$inp.trigger({
type: 'keydown',
keyCode: 13,
ctrlKey: true
});
});
$clearBtn.parent().prepend($run).append($addTextBtn, $prevHistory, $nextHistory, $allowEnterWrapper);
}
function init() {
}
init();
|