Content deleted Content added
PleaseStand (talk | contribs) Undid revision 356075499 by PleaseStand (talk) - breaks the script |
PleaseStand (talk | contribs) various changes, including fix for loss of changes when back button used |
||
Line 83:
// Begin encapsulation (prevent interference with other scripts)
(function
// Semi-global variables (private to this script)
var editForm, refsDiv, refsH2, mainTextbox, refsTextbox, randPrefix, messages,
refsButton, convertButton, complete, unloadHandlerRegistered = false;
// Define a (very important) function that is better than hasOwnProperty
function has(obj, key) {
return Object.hasOwnProperty.call(obj, key);
}
// Extend the string object with new methods
Line 135 ⟶ 140:
// Returns the next ref found in the text
getRef: function getRef() {
var results
while(results[1].toString().toLowerCase() != "ref") {▼
results = this.refScanRegex.exec(this.wikiText);
if(!results) {
Line 144 ⟶ 149:
results = [0,0];
}
▲ }
return results[0];
}
Line 168 ⟶ 173:
return null;
}
var attributes = {}, results;
while(
}▼
attributes[results[1].toLowerCase()] = results[2].PsHTMLUnquote();
}
Line 218 ⟶ 219:
// First make sure that the ref is in the right group.
refGroup =
if(group != refGroup) {
continue;
Line 227 ⟶ 228:
// an acceptable ref name to the MediaWiki parser, as verified by
// informal testing.)
if(!
// Bad: it doesn't have one - create a name for it
refStored = false;
Line 240 ⟶ 241:
refLong = ref;
// Check if the ref name has already been seen.
refStored =
// Check if the ref has no contents.
refEmpty = (parser.parsedRef[2].slice(-2) == "/>") ||
Line 328 ⟶ 329:
// First, we build an associative array of all the ref codes
// that we might need to put back into the text.
// NOTE: JavaScript does not actually offer real associative array
// functionality, so we emulate it using objects and the has() function
// we defined earlier that is used to verify a property's existence.
scanner = new RefScanner(argRefText);
while((ref = scanner.getRef())) {
parser = new RefParser(ref);
attributes = parser.getAttributes();
if(
// Only use the first ref with each name
if(!refCodes.hasOwnProperty(attributes.name)) {
Line 347 ⟶ 352:
parser = new RefParser(ref);
attributes = parser.getAttributes();
if(
if(!
// We found a new name
usageFreq[attributes.name] = 1;
Line 370 ⟶ 375:
parser = new RefParser(ref);
attributes = parser.getAttributes();
if(
// Is this name on the replacement list?
if(
// If we are using caseCues, and another ___location is
// preferred, skip to the next ref.
if(caseCues &&
ref.slice(0, 4) != "<REF") {
continue;
Line 424 ⟶ 429:
}
function
// Local variables
var result, refName, unusedRefNamesQuoted = [];
// wikEd compatibility (frame -> textarea)
WikEdUpdateTextarea();
}
// Do the actual integration work
result = integrateRefs(mainTextbox.value, refsTextbox.value,
randPrefix, complete);
// Find all unused ref names
for(refName in result.unusedRefs) {
if(has(result.unusedRefs
unusedRefNamesQuoted.push(refName.PsHTMLQuote());
}
Line 443 ⟶ 454:
unusedRefNamesQuoted.join(", "))) {
// Don't submit form
evt.preventDefault();
return false;
}
Line 449 ⟶ 461:
// Otherwise, update the textbox.
mainTextbox.value = result.wikiText;
// wikEd compatibility (textarea -> frame)
if(typeof wikEdUseWikEd != "undefined" && wikEdUseWikEd) {
WikEdUpdateFrame();
}
// Deactivate this event handler
window.removeEventListener("submit", unloadHandler, false);
window.removeEventListener("unload", unloadHandler, false);
unloadHandlerRegistered = false;
// We can delete the header and refs textbox now
Line 454 ⟶ 476:
refsDiv.removeChild(refsTextbox);
▲ }
return true;
}
Line 524 ⟶ 540:
// Set up the submit handler (to integrate refs when done editing)
window.addEventListener("submit", unloadHandler, false);
▲ if(typeof editForm.onsubmit != "undefined") {
window.addEventListener("unload", unloadHandler, false);
unloadHandlerRegistered = true;
▲ }
// Don't submit form
Line 606 ⟶ 621:
function getEditboxContents() { // ajaxPreview compatibility
if(
// wikEd compatibility (frame -> textarea)
if(typeof wikEdUseWikEd != "undefined" && wikEdUseWikEd) {
WikEdUpdateTextarea();
return integrateRefs(mainTextbox.value, refsTextbox.value,
randPrefix, complete).wikiText;
Line 675 ⟶ 694:
addOnloadHook(loadHandler);
})();
//</nowiki></pre>
|