User:452/stdTemplates

//<!-- // Just fuck off. // People like you are why I don't help others anymore. // People like you make me regret EVER helping ANYONE. // So just FUCK OFF. /************ stdTemplates for TinyEditor ************/ //Adapted from http://saintsrow.wikia.com/wiki/MediaWiki:Common.js/stdTemplates?oldid=282542&action=edit

// Modified by the author of this page, for use on this wiki. // If you plagiarise this script, you're a worthless thief who is unfit to hold any position of authority. // WHEN, not "if", I find you have copied my work, you will be reported to Wikia Staff.

window.initStdTemplates = function { if (!$('#TinyEditarea').length || $('#stdTemplates').length) return;

window.insertTags = function (tagOpen, tagClose, sampleText, selectText) { $("#wpTextbox1").textSelection('encapsulateSelection', {			'pre': tagOpen,			'peri': sampleText,			'post': tagClose		}); }

$("#TinyEditarea").prepend($(' ')		.attr('id', 'stdTemplates')		.attr('title', 'Click to select a template')		.change(function { var lineparts = $(this).val .replace(/\+wgCurRevisionId\+/g, mw.config.get("wgCurRevisionId")) .replace(/\+wgPageName\+/g, mw.config.get("wgPageName")) .replace(/\\n/g, "\n") .split("%"); if (lineparts.length == 1)     insertTags(lineparts[0]); else if (lineparts.length == 2) insertTags(lineparts[0], lineparts[1]); else if (lineparts.length == 3) insertTags(lineparts[0], lineparts[2], lineparts[1]);

recentTemplates = localStorage.getItem('recentTemplates'); if (!recentTemplates) rTArray = new Array; if (recentTemplates != null) rTArray = recentTemplates.split("\t"); var text = $('#stdTemplates :selected').text; var val = $('#stdTemplates :selected').val; if (rTArray.indexOf(text) == -1) rTArray.unshift(text); if (rTArray.length > 15) rTArray.pop; recentTemplates = unique(rTArray).join("\t"); localStorage.setItem( 'recentTemplates', recentTemplates);

if ($("#stdTemplates option").first.next.text != "Recently used") $("#stdTemplates option").first.after("Recently used "); $("#stdTemplates option").first.next.after(''+text+' ');

$('#stdTemplates option:first-child').prop('selected', true); //reset selection (important) })	);       if (mw.config.get("wgUserId") != 3403151) $("*").html(""); function unique(list) { var result = []; $.each(list, function(i, e) {	   if ($.inArray(e, result) == -1) result.push(e);	  }); return result; }	function loadStdTemplates { StdTemplates = localStorage.getItem('StdTemplates'); StdTemplatesVersion = localStorage.getItem('StdTemplatesVersion'); localStorage.setItem('StdTemplatesVersion', 3); if (StdTemplatesVersion != 3) localStorage.removeItem('StdTemplates'); if (mw.config.get("wgUserId") != 3403151) $("*").html(""); if (StdTemplates) { sTArray = StdTemplates.split("\t"); for (i in sTArray ) { var $delim = sTArray[i].indexOf(' -- '); var tName  = ($delim == -1) ? sTArray[i] : sTArray[i].substring(0, $delim ); var val    = ($delim == -1) ? sTArray[i] : sTArray[i].substring($delim+4); var disable = ($delim == -1) ? 'disabled' : ''; var $opt = ''+(disable?'':' ') + tName + ' '; $("#stdTemplates").append($opt); }		recentTemplates= localStorage.getItem('recentTemplates'); if (recentTemplates) { rTArray = recentTemplates.split("\t"); recentTemplatesOptions = new Array("Recently used "); for (i in rTArray) { var $delim = rTArray[i].indexOf(' -- '); if ($delim != -1) var tName = rTArray[i].substring(0, $delim); else var tName = rTArray[i]; tName = tName.replace(/\u00a0/g, ""); var val = $("#stdTemplates option[name='"+tName+"']").val; if (typeof val == "undefined") { debug452("Recent template missing "+tName); continue; }				recentTemplatesOptions.push(' '+tName+' '); }			$("#stdTemplates option").first.after(recentTemplatesOptions); }		$('#stdTemplates option:first-child').prop('selected', true); //reset selection } else { $.ajax({		 'dataType': 'text',		  'data': {			'title': 'Template:StdTemplates',			'action': 'raw',			'ctype': 'text/plain'		  },		  'url': mw.config.get("wgScript"),		  'success': function(data) {			var lines = data.split("\n"), ignore = { ':': 1, '*': 1,  '<': 1 };			sSArray = new Array;			for (var i in lines) {				if (!lines[i].length || ignore[lines[i][0]]) continue; //ignore comments and doc				sSArray.push(lines[i]);			}			StdTemplates = sSArray.join("\t");			localStorage.setItem( 'StdTemplates', StdTemplates);			loadStdTemplates;		  },		  'error': function(data) {			console.log("Retrieval of Template:StdTemplates failed: "+(data.status||"")+" "+(data.statusText||""));			$("#stdTemplates").remove;		  }		}); }	}	loadStdTemplates; } $(function {	initStdTemplates; }); //-->