Misplaced Pages

:AutoEd/core.js: Difference between revisions - Misplaced Pages

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< Misplaced Pages:AutoEd Browse history interactively← Previous editNext edit →Content deleted Content addedVisualWikitext
Revision as of 22:57, 28 April 2009 view sourceAFigureOfBlue (talk | contribs)Edit filter managers, Administrators53,878 editsm Undid revision 286742590 by Drilnoth (talk)← Previous edit Revision as of 21:15, 29 April 2009 view source AFigureOfBlue (talk | contribs)Edit filter managers, Administrators53,878 edits Copy from User:Plastikspork/AutoEd/core.js per request at WT:AutoEdNext edit →
Line 3: Line 3:
//Please see ] for details on use. //Please see ] for details on use.
// Set default values for any unset variables
if( typeof( autoEdMinor ) == 'undefined' ) { //CONFIGURATION
autoEdMinor = true; if( typeof( autoEdMinor ) == 'undefined' ) {
autoEdMinor = true;
} }


if( typeof( autoEdClick ) == 'undefined' ) {
function AutoEdFromEdit() { //Initiates AutoEd if you are already in edit mode
autoEdClick = true;
autoEdFunctions();
// Add a tag to the summary box
var txt = document.editform.wpSummary;
var summary = "Cleaned up using ]";
if (txt.value.indexOf(summary) == -1) {
if (txt.value.match(/?\s*$/)) {
txt.value += " | ";
}
txt.value += summary;
}
document.editform.wpMinoredit.checked = autoEdMinor;
document.editform.wpDiff.click()
} }

if( typeof( autoEdTag ) == 'undefined' ) {
if(queryString('AutoEdFromView')) addOnloadHook(function() { AutoEdFromView(); }) //Part of next function
autoEdTag = "Cleaned up using ]";
function AutoEdFromView() { //Initiates AutoEd if you are viewing the article without currently editing it
}
var txt = document.getElementById('wpTextbox1');

if(!txt) return;
if( typeof( autoEdHover ) == 'undefined' ) {
autoEdFunctions();
autoEdLinkHover = "Run AutoEd";
document.getElementById('wpSummary').value += 'Cleaned up using ]';
}

if( typeof( autoEdLink ) == 'undefined' ) {
autoEdLinkName = "auto ed";
}

if( typeof( autoEdLinkLocation ) == 'undefined' ) {
autoEdLinkLocation = "p-cactions";
}

if( typeof( autoEdFunctions ) == 'undefined' ) {
function autoEdFunctions() { alert('AutoEd/core.js: autoEdFunctions is undefined'); }
autoEdTag = "";
autoEdClick = false;
autoEdMinor = false;
}

//Initiates AutoEd
function autoEdExecute() {
if(!document.getElementById('wpTextbox1')) return;
autoEdFunctions();
autoEdEditSummary();
}

//Adds Tag to edit summary textbox
function autoEdEditSummary() {
var txt = document.editform.wpSummary;
var tag = autoEdTag;

// Is the tag blank?
if( tag.match(//) ) {
// Has it already been tagged?
if( txt.value.indexOf(tag) == -1 ) {
// Append a pipe if necessary
if( txt.value.match(/?\s*$/) ) {
txt.value += " | ";
}
// Append our tag
txt.value += tag;
}
}

// Check 'This is a minor edit'
if( autoEdMinor ) {
document.editform.wpMinoredit.checked = autoEdMinor; document.editform.wpMinoredit.checked = autoEdMinor;
}
document.editform.wpDiff.click()

// Click 'Show changes'
if( autoEdClick ) {
document.editform.wpDiff.click();
}
} }

function queryString(p) { //Allows URI to be properly decoded so that AutoEdFromView() works properly //Allows URI to be properly decoded for AutoEd in View Mode
function autoEdQueryString(p) {
var re = RegExp('' + p + '=(*)');
var re = RegExp('' + p + '=(*)');
var matches;
if (matches = re.exec(document.location)) { var matches;
if (matches = re.exec(document.location)) {
try { try {
return decodeURI(matches); return decodeURI(matches);
} catch (e) { } catch (e) {
}
} }
return null; }
return null;
} }


addOnloadHook(function () { //Adds "auto ed" tabs to page.
//Execute AutoEd after call from View Mode
if(wgCanonicalNamespace == "" || wgCanonicalNamespace == "Image" || wgCanonicalNamespace == "File" || wgCanonicalNamespace == "User" || wgCanonicalNamespace == "Template" || wgCanonicalNamespace == "Project" || wgCanonicalNamespace == "Portal"){
if( autoEdQueryString('AutoEd') ) {
if(document.forms.editform) {
addOnloadHook(function() {
addPortletLink('p-cactions', 'javascript:AutoEdFromEdit()', 'auto ed', 'ca-AutoEd', 'Run AutoEd', '', document.getElementById('ca-move'));
autoEdExecute();
} //End editform if
});
if(wgAction == "view"){
}
var url = wgServer + wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=edit';

addPortletLink('p-cactions',url + '&AutoEdFromView=true', 'auto ed','ca-AutoEd', 'Run AutoEd', '', document.getElementById('ca-move'));
// Add "auto ed" tabs and associate with actions
} //End pageview if
addOnloadHook(function () {
}//End namespace if
if(wgCanonicalNamespace == "" || wgCanonicalNamespace == "Image" || wgCanonicalNamespace == "File" || wgCanonicalNamespace == "User"
|| wgCanonicalNamespace == "Template" || wgCanonicalNamespace == "Project" || wgCanonicalNamespace == "Portal") {
if(document.forms.editform) {
addPortletLink( autoEdLinkLocation, 'javascript:autoEdExecute()', autoEdLinkName, 'ca-AutoEd', autoEdLinkHover, '', document.getElementById('ca-move'));
} //End editform if
if(wgAction == "view"){
var url = wgServer + wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=edit';
addPortletLink( autoEdLinkLocation, url + '&AutoEd=true', autoEdLinkName, 'ca-AutoEd', autoEdLinkHover, '', document.getElementById('ca-move'));
} //End pageview if
} //End namespace if
}); });



Revision as of 21:15, 29 April 2009

//

//This script does not function without additional "helper" modules!
//Please see ] for details on use.
// Set default values for any unset variables
if( typeof( autoEdMinor ) == 'undefined' ) {
  autoEdMinor = true;
}
if( typeof( autoEdClick ) == 'undefined' ) {
  autoEdClick = true;
}
if( typeof( autoEdTag ) == 'undefined' ) {
  autoEdTag = "Cleaned up using ]";
}
if( typeof( autoEdHover ) == 'undefined' ) {
  autoEdLinkHover = "Run AutoEd";
}
if( typeof( autoEdLink ) == 'undefined' ) {
  autoEdLinkName = "auto ed";
}
if( typeof( autoEdLinkLocation ) == 'undefined' ) {
  autoEdLinkLocation = "p-cactions";
}
if( typeof( autoEdFunctions ) == 'undefined' ) {
  function autoEdFunctions() { alert('AutoEd/core.js: autoEdFunctions is undefined'); }
  autoEdTag = "";
  autoEdClick = false;
  autoEdMinor = false;
}
//Initiates AutoEd
function autoEdExecute() {
  if(!document.getElementById('wpTextbox1')) return;
  autoEdFunctions();
  autoEdEditSummary();
}
//Adds Tag to edit summary textbox
function autoEdEditSummary() {
  var txt = document.editform.wpSummary;
  var tag = autoEdTag;
  // Is the tag blank?
  if( tag.match(//) ) {
    // Has it already been tagged?
    if( txt.value.indexOf(tag) == -1 ) {
    // Append a pipe if necessary
    if( txt.value.match(/?\s*$/) ) {
      txt.value += " | ";
    }
    // Append our tag
    txt.value += tag;
    }
  }
  // Check 'This is a minor edit'
  if( autoEdMinor ) {
    document.editform.wpMinoredit.checked = autoEdMinor;
  }
  // Click 'Show changes'
  if( autoEdClick ) {
    document.editform.wpDiff.click();
  }
}
//Allows URI to be properly decoded for AutoEd in View Mode 
function autoEdQueryString(p) {
  var re = RegExp('' + p + '=(*)');
  var matches;
  if (matches = re.exec(document.location)) {
    try {
      return decodeURI(matches);
    } catch (e) {
    }
  }
  return null;
}
//Execute AutoEd after call from View Mode
if( autoEdQueryString('AutoEd') ) {
  addOnloadHook(function() { 
    autoEdExecute();
  });
}
// Add "auto ed" tabs and associate with actions
addOnloadHook(function () {
  if(wgCanonicalNamespace == "" || wgCanonicalNamespace == "Image" ||  wgCanonicalNamespace == "File" || wgCanonicalNamespace == "User"
       || wgCanonicalNamespace == "Template" || wgCanonicalNamespace == "Project" || wgCanonicalNamespace == "Portal") {
    if(document.forms.editform) {
      addPortletLink( autoEdLinkLocation, 'javascript:autoEdExecute()', autoEdLinkName, 'ca-AutoEd', autoEdLinkHover, '', document.getElementById('ca-move'));
    } //End editform if
    if(wgAction == "view"){
      var url = wgServer + wgScript + '?title=' + encodeURIComponent(wgPageName) + '&action=edit';
      addPortletLink( autoEdLinkLocation, url + '&AutoEd=true', autoEdLinkName, 'ca-AutoEd', autoEdLinkHover, '', document.getElementById('ca-move'));
    } //End pageview if
  } //End namespace if
});
//