User:Equazcion/UniversalTransclusionPreviews.js

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 = '

';

//Insert the code under the main edit stuff.

$('.editOptions').append(prevCode);

//Insert toggle link

$('.editButtons').append(' | Toggle Transclusion Preview');

// Set link function

$('.transTog').click(function(){

if ($('#templatesandbox-editform').attr('hidden') == "hidden"){

$('#templatesandbox-editform').prop('hidden', false);

} else {

$('#templatesandbox-editform').attr('hidden','');

}

});

}

}