User:LilDice/flexitags meat.js

// // User:LilDice/flexitags_meat.js // // // Based on tags by Seed 2.0 //requires: //importScript('Wikipedia:WikiProject User scripts/Scripts/Add LI menu'); //importStylesheet('Wikipedia:WikiProject User scripts/Scripts/Add LI menu/css');

var thedate = new Date;

var edFocus = false;

Date.monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; Date.prototype.getMonthName = function { return Date.monthNames[ this.getMonth ]; } Date.prototype.getUTCMonthName = function { return Date.monthNames[ this.getUTCMonth ]; }

function insertAtCursor(myField, myValue) {

if(!edFocus) {   myField.value =  myValue + '\n' + myField.value; return; } //IE support if (document.selection) { myField.focus; sel = document.selection.createRange; sel.text = myValue; } //MOZILLA/NETSCAPE support else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); } else { myField.value = myValue + '\n' + myField.value; } }

function addTab(flexitag) { var tabs = document.getElementById( 'p-cactions' ).getElementsByTagName( 'ul' )[0]; addlimenu(tabs,flexitag.name,flexitag.name); for(j=0;j<flexitag.tagset.length;j++) { mw.util.addPortletLink(flexitag.name, "javascript:doAddTag(" + i + "," + j + ")", flexitag.tagset[j][0],flexitag.tagset[j][0] ,flexitag.tagset[j][0], ""); } }

function parseTag(tagtext) {

var promptmatch = /%prompt\((.+?)\)/i.exec(tagtext); if(promptmatch) { tagtext = tagtext.replace(/%prompt\(.+?\)/,prompt(promptmatch[1])); } if(tagtext.match(/%date/)) { tagtext = tagtext.replace(/%date/,thedate.getUTCMonthName + ' ' + thedate.getUTCFullYear); }

return tagtext; /*if( QueryString.exists( 'vanarticle' ) ) { article = decodeURI(QueryString.get( 'vanarticle' )).replace( /^(Image|Category):/i, ':$1:' ); } else { article = prompt('Which article?').replace( /^(Image|Category):/i, ':$1:' ); }*/ }

function doAddTag(tabindex,tagindex) {

text = document.editform.wpTextbox1.value; tag = "";

insertAtCursor(document.editform.wpTextbox1,tag);

document.editform.wpSummary.value = thetabs[tabindex].tagset[tagindex][1];

if (FlexiTagConfig.minoredit == true) { document.editform.wpMinoredit.checked = true; }

if (FlexiTagConfig.autosubmit == true) { document.editform.submit; } }

$(function { if(document.getElementById('editform')) {

document.getElementById('wpTextbox1').onfocus = function {edFocus=true;}; } if(document.editform) { for(i=0;i<FlexiTagConfig.tabs.length;i++) { tmpTab = FlexiTagConfig.tabs[i]; if('namespace' in tmpTab) {  if ( tmpTab.namespace.match(new RegExp(wgCanonicalNamespace)) ) {   addTab(tmpTab); }    }  else {   addTab(tmpTab); } } } });

// //