User:Jackmcbarn/advancedtemplatesandbox.js: Difference between revisions

Content deleted Content added
Jackmcbarn (talk | contribs)
Created page with '/* Enables TemplateSandbox on all pages, and allows previewing with a template other than the current page being edited (e.g. preview as Template:Foo when actual...'
 
Jackmcbarn (talk | contribs)
Expand functionality
Line 4:
importScript('User:Jackmcbarn/advancedtemplatesandbox.js'); // Linkback: [[User:Jackmcbarn/advancedtemplatesandbox.js]]
The linkback allows easier tracking of who uses this script.
 
Known issues:
This hardcodes contents of messages, rather than fetching them.
The span is left as a span, rather than being changed to a fieldset.
Tab indexes assume that we're the first thing after "Show changes". If we're not, tab order will be wrong. Also, it relies on non-integer tab indexes working.
*/
 
if($('#wpTemplateSandboxPage').attr('type') == 'hidden') {
(function() { // Begin wrapper to keep variables out of global scope
$('#templatesandbox-editform').prepend('<legend>Preview page with this template</legend>');
 
$('#wpTemplateSandboxPage').before('<span class="mw-templatesandbox-page" id="wpTemplateSandboxPageLabel"><label for="wpTemplateSandboxPage">Page title:</label></span> ').after('<input id="wpTemplateSandboxPreview" name="wpTemplateSandboxPreview" tabindex="' + (0.75 + $('#wpDiff').attr('tabIndex')) + '" value="Show preview" type="submit" />').replaceWith($('#wpTemplateSandboxPage').clone().attr({type: 'text', tabindex: 0.5 + $('#wpDiff').attr('tabIndex'), size: 60, spellcheck: true}));
var editform = $('#templatesandbox-editform');
if(editform.is("fieldset"))
{
// The full form is already loaded; just add the template name option
$('#wpTemplateSandboxTemplate').before("<span class=\"mw-templatesandbox-template\" id=\"wpTemplateSandboxTemplateLabel\"><label for=\"wpTemplateSandboxTemplate\">Template name:</label></span> ").after("<br />").replaceWith($('#wpTemplateSandboxTemplate').clone().attr({type: 'text', tabindex: $('#wpTemplateSandboxPage').attr('tabindex') - 0.5, size: 60, spellcheck: true}));
} else {
// Only a skeleton loaded; reinitialize the whole form
// XXX TODO
}
$('#wpTemplateSandboxTemplate').before("'<span class=\"mw-templatesandbox-template\" id=\"wpTemplateSandboxTemplateLabel\"><label for=\"wpTemplateSandboxTemplate\">Template name:</label></span> "').after("'<br />"').replaceWith($('#wpTemplateSandboxTemplate').clone().attr({type: 'text', tabindex: 0.25 + $('#wpTemplateSandboxPagewpDiff').attr('tabindextabIndex') - 0.5, size: 60, spellcheck: true}));
 
})(); // End wrapper to keep variables out of global scope