User:Equazcion/UniversalTransclusionPreviews.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Equazcion/UniversalTransclusionPreviews. |
if (mw.config.get('wgNamespaceNumber') != 10) { //It's already in Template space, so do nothing there.
if ((mw.config.get('wgAction') == "edit") || (mw.config.get('wgAction') == "submit")){
var hidden = '';
$("#templatesandbox-editform").remove();
//Determine if we're on a transclusion preview page already.
//If so, fill in transclusion preview input line with host page title and unhide preview line
var prevTitle = $('div.previewnote a').attr('title');
if (typeof prevTitle == "undefined"){
prevTitle = '';
hidden = ' hidden="hidden"';
} else {
hidden = '';
}
//Code to add:
var prevCode = '<fieldset id="templatesandbox-editform"' + hidden + '><legend>Preview a page with this page transcluded</legend>' +
'<span class="mw-templatesandbox-page" id="wpTemplateSandboxPageLabel">' +
'<label for="wpTemplateSandboxPage">Page title:</label></span> ' +
'<input id="wpTemplateSandboxPage" tabindex="8" size="60" spellcheck="true" name="wpTemplateSandboxPage" ' +
'value="' + prevTitle + '">' +
'<input id="wpTemplateSandboxPreview" name="wpTemplateSandboxPreview" tabindex="9" value="Show preview" type="submit">' +
'</fieldset>';
//Insert the code under the main edit stuff.
$('.editOptions').append(prevCode);
//Insert toggle link
$('.editButtons').append(' | <a class="transTog" href="#azb">Toggle Transclusion Preview</a>');
// Set link function
$('.transTog').click(function(){
if ($('#templatesandbox-editform').attr('hidden') == "hidden"){
$('#templatesandbox-editform').prop('hidden', false);
} else {
$('#templatesandbox-editform').attr('hidden','');
}
});
}
}