Content deleted Content added
PleaseStand (talk | contribs) m still not good enough |
PleaseStand (talk | contribs) enabled save button on keypress and removed whitespace from empty lines |
||
Line 42:
return value != null ? value : (fallback != null ? fallback : null);
},
/**
* Sets a key/value pair in localStorage.
Line 55:
}
}
};
Line 64:
dependencies: ["mediawiki.util", "jquery.ui.tabs"],
/**
* Shows the user interface for the sandbox editor.
Line 74:
rows: mw.user.options.get("rows")
};
// CSS to add
mw.util.addCSS( "#sandbox-tabs { font-size: 1em; } " +
"#sandbox-wrapper textarea { font-family: monospace, sans-serif; }" );
// Elements to add
editor.$wrapper = $("#sandbox-wrapper");
Line 86:
editor.$cssArea = $("<textarea id='sandbox-css-area'></textarea>").prop( textareaProps );
editor.$saveLocal = $("<button id='sandbox-save-local'></button>");
// Modifications to wiki page
$("#sandbox-enabled-placeholder").replaceWith( editor.$enabled );
Line 95:
$("#sandbox-js-area-placeholder").replaceWith( editor.$jsArea );
$("#sandbox-css-area-placeholder").replaceWith( editor.$cssArea );
// .wrapAll() does not suffice because it clones the the wrapping element.
$("#sandbox-save-local-text")
.replaceWith( editor.$saveLocal )
.appendTo( editor.$saveLocal );
// Event handling functions
editor.loadSandbox();
editor.$saveLocal.click( editor.saveSandbox );
editor.$wrapper.delegate( ":input", "change keypress", editor.handleChange);
$("#sandbox-loading").hide();
editor.$wrapper.show();
},
/**
* Called when a form field's value changes or a key is pressed.
*/
handleChange: function(event) {
// Ignore arrow keys in Firefox.
if ( event.type === "keypress" && !event.which ) {
return;
▲ }
editor.$saveLocal.prop( "disabled", false );
},
Line 139 ⟶ 146:
storage.set( "css", editor.$cssArea.val() );
}
};
Line 148 ⟶ 155:
var enabled, css, js, dependencies;
enabled = +storage.get( "enabled", "0" );
if ( !enabled ) {
return;
}
css = storage.get( "css", "" );
js = storage.get( "js", "" );
dependencies = $.trim( storage.get("dependencies", "") ).split( /\s*,\s*/ );
mw.loader.using( "mediawiki.util", function() {
mw.util.addCSS( css );
});
mw.loader.using( dependencies, function() {
$.globalEval( js + "\n//@ sourceURL=localSandbox.js" );
});
}
Line 191 ⟶ 198:
runSandbox();
}
}
|