User:PleaseStand/segregate-refs-dev.js: Difference between revisions

Content deleted Content added
m writing the code a bit more concisely
adding a compatibility function for use by scripts like ajaxPreview
Line 86:
 
// Semi-global variables (private to this script)
var editForm; var, refsDiv; var, refsH2; var, mainTextbox;, varrefsTextbox, refsTextbox;randPrefix, messages,
var randPrefix; var messages; var refsButton; var, convertButton; var, complete;
 
// Extend the string object with new methods
Line 117:
var s = this.replace(/\&/g, "&");
// Try both kinds of quotes
var sQ = "'" + s.replace(/'/g, "'") + "'";,
var dQ = '"' + s.replace(/"/g, """) + '"';
// Choose the shorter, preferring double quotes if equal in length
return (sQ.length < dQ.length ? sQ : dQ);
Line 192:
// Create a random prefix for autogenerated ref names.
// in theory this has a 1/1296 probability of collision - extremely low
var prefixChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";,
var randNo = Math.floor(Math.random() *
(prefixChars.length * prefixChars.length));
randPrefix = messages.autoWord + prefixChars.charAt(Math.floor(randNo /
Line 203:
// Variables for the main code
var scanner = new RefScanner(argWikiText);, unnamedRefs = 0, refNames = {},
ref, refStored, parser, attributes, refName, refLong, refShort,
var unnamedRefs = 0; var refNames = {}; var ref; var refStored;
var refCodes = []; var, refEmpty; var, emptyRefsWarningGiven = false, refGroup;
var parser; var attributes; var refName; var refLong; var refShort;
var refCodes = []; var refEmpty; var emptyRefsWarningGiven = false;
var refGroup;
// Disable the empty refs warning (see below) if the user has disabled it
Line 325 ⟶ 323:
// Variables for the main code
var scanner; var, ref; var, parser; var, attributes; var, refCodes = {};, usageFreq = {},
var usageFreq = {}; var preferredRef = {}; var, refLong;
// First, we build an associative array of all the ref codes
Line 422 ⟶ 420:
// from the DOM and then inserting it again.
function clearUndoHistory(ta) {
var pn = ta.parentNode, ns = ta.nextSibling;
var ns = ta.nextSibling;
pn.insertBefore(pn.removeChild(ta), ns);
}
Line 429 ⟶ 426:
function submitHandler() {
// Local variables
var result; var, refName; var, unusedRefNamesQuoted = [];
// Do the actual integration work
Line 607 ⟶ 604:
return false;
}
 
function getEditboxContents() { // ajaxPreview compatibility
if(editForm.onsubmit == submitHandler) {
return integrateRefs(mainTextbox.value, refsTextbox.value,
randPrefix, complete).wikiText;
} else {
return mainTextbox.value;
}
}
 
// Leave a global for ajaxPreview to use.
window.getEditboxContents = getEditboxContents;
 
 
function loadHandler() { // This function is called on page load
Line 660 ⟶ 670:
}
}
 
 
// Register load handler