User:Quarenon/templates.js

/* */ /** * templates.js * * Insert various templates from the edit toolbar. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */

$(document).ready(function {	// http://www.netlobo.com/url_query_string_javascript.html	function getParam(name) {		name = name.replace(/[\[]/, '\\\[').replace(/[\]]/, '\\\]');		var regex = new RegExp('[\\?&]' + name + '=([^&#]*)'); 		var results = regex.exec(window.location.href);		if (results == null) {			return '';		} else {			return decodeURIComponent(results[1]);		}	}

var tpls = { 'GEMW 1': { open: '', close: '&mdash;~', sample: '__REFERRER__' }, 'GEMW 2': { open: '', close: '&mdash;~', sample: '__REFERRER__' }, 'Block': { open: , close: , sample: '' }, 'Welcome Notice': { open:  + wgUserName + , close: , sample:  }, // 'No Personal Images': { open: '&mdash~', close: , sample:  }, 'No Personal Images': { open:  + wgUserName + '&mdash;~', close: , sample: '' }, 'No Vandal': { open: '&mdash;~', close: , sample:  }, 'Error 1': { open: '', close: '&mdash;~', sample: '__REFERRER__' }, 'Error 2': { open: '', close: '&mdash;~', sample: '__REFERRER__' }, 'Test 1': { open: '', close: '&mdash;~', sample: '__REFERRER__' }, 'Test 2': { open: '', close: '&mdash;~', sample: '__REFERRER__' }, 'Test 3': { open: '', close: '&mdash;~', sample: '__REFERRER__' }, 'Test 4': { open: '', close: '&mdash;~', sample: '__REFERRER__' }, 'Test 5': { open: '&mdash;~', close: , sample:  }, 'PB': { open: '&mdash;~', close: , sample:  }, 'POV 1': { open: '', close: '&mdash;~', sample: '__REFERRER__' }, 'POV 2': { open: '', close: '&mdash;~', sample: '__REFERRER__' }, 'Vandal': { open: '', close: '&mdash;~', sample: 'number of offense' }, 'User Edit': { open:  + wgUserName + '&mdash;~', close: , sample: '' } };

/* Append a referrer to links going to user talk pages. */	if (wgCanonicalNamespace != 'Special') { $('#bodyContent a').each(function {			var href = $(this).attr('href');			if (href.indexOf('User_talk:') != -1) {				href += (href.indexOf('?') != -1) ? '&' : '?';				href += 'referrer=' + wgPageName;				$(this).attr('href', href);			}		}); }

/* Append template list when editing user talk pages. */	if ((wgAction == 'edit' || wgAction == 'submit') && wgCanonicalNamespace == 'User_talk') { var $select = $(' ').change(function {			var name = $(this).val;

if (name == '') { return; }

var tpl = tpls[name]; insertTags(tpl.open, tpl.close, tpl.sample.replace('__REFERRER__', getParam('referrer')));

$('#wpSummaryEnhanced').val(name); });

$select.append($(' ').val('').text('[Notices]'));

for (var name in tpls) { $select.append($(' ').val(name).text(name)); }

$('#toolbar').prepend($select); } }); /* */