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

Content deleted Content added
m window.document is silly. We should be able to assume a sane browser environment.
add refsDiv directly under #editform, not within .wikiEditor-ui (fixes overlap issue)
 
(10 intermediate revisions by the same user not shown)
Line 27:
*/
 
/*global window, addOnloadHook, SegregateRefsJsL10n, SegregateRefsJsAllowConversion,
wikEdUseWikEd, WikEdUpdateTextarea, WikEdUpdateFrame*/
SegregateRefsJsEmptyRefsWarningGiven, SegregateRefsJsAllowConversion,
 
SegregateRefsJsCompleteSearch, wikEdUseWikEd, WikEdUpdateTextarea,
// <nowiki>
WikEdUpdateFrame*/
 
// Translate the right-hand side of these if necessary.
Line 36:
// var SegregateRefsJsL10n = {
var SegregateRefsJsMsgs = {
version: 1.11,
buttonText: "Segregate refs for editing",
buttonStyle: "background: #dfd;",
buttonConvertText: "Migrate article to LDR",
buttonConvertStyle: "background: #fdd;",
autoWord: "Auto",
convertRefsWarning: "WARNING: You need consensus to migrate an article to list-defined references format (LDR) BEFORE you do so.\n\nClick Cancel now if consensus has not been established in favor of this migration. If there is consensus to make the conversion, click OK to do so.",
emptyRefsWarning: "IMPORTANT: This page includes one or more named " +
groupPrompt: "Please enter the name of a group (as it appears in the wikitext, including any quotes). Leave this blank if unsure.",
"footnotes of which the first occurrence(s) have no contents, which is " +
refsHeader: "Inline footnotes",
"not best practice. This script does not harm such footnotes, however " +
convertHeader: "Generated refs list",
"you should be aware that this script ONLY CHECKS THE FIRST REF TAG " +
refsCommentComplete: "<!-- Converted to LDR format\n using [[User:PleaseStand/References segregator]] -->\n\n",
"it finds for the actual citation or note text, and you must work within " +
convertSummary: "Converted footnotes to LDR format (using [[User:PleaseStand/References segregator|segregate-refs]])",
"this limitation. Any change to the empty ref tag will replace the " +
convertFurther: "This script has done most of the work. However, you still need to do the following:\n\n* Insert the refs list in the new textbox into the proper place in the wikitext.\n* If converting a special group, optionally remove the group attributes.\n* Replace all autogenerated names with human-generated names.\n\nYou can do the above with the Find/Replace command in many text editors. (Always use the quoted form of the attributes.) Then, paste the text back into the edit form and save the page.",
"footnote entirely and leave the old note text hidden.\n\n" +
integrateWarning: "The refs listed below are missing from the text. If you continue, they will be permanently deleted. Are you sure?\n\nUnused refs: "
"BEFORE concluding from the footnotes list that a ref is in fact empty, " +
"please manually check all identically-named ref tags for the contents. " +
"\n\nDo you acknowledge this limitation of the script? DO NOT CLICK OK " +
"UNTIL YOU HAVE READ THE ABOVE INFORMATION.",
convertRefsWarning: "WARNING: You need consensus to migrate an article " +
"to list-defined references format (LDR) BEFORE you do so.\n\nClick " +
"Cancel now if consensus has not been established in favor of this " +
"migration. If there is consensus to make the conversion, click OK to " +
"do so.",
groupPrompt: "Please enter the name of a group (as it appears in the " +
"wikitext, including any quotes). Leave this blank if unsure.",
refsHeader: "Inline footnotes",
convertHeader: "Generated refs list",
refsCommentIncomplete: "<!-- This list of footnotes may be incomplete. " +
"Do not use for conversion purposes. -->\n\n",
refsCommentComplete: "<!-- Converted to LDR format\n" +
" using [[User:PleaseStand/References segregator]] -->\n\n",
convertSummary: "Converted footnotes to LDR format (using " +
"[[User:PleaseStand/References segregator|segregate-refs]])",
convertFurther: "This script has done most of the work. However, you still " +
"need to do the following:\n\n* Insert the refs list in the new textbox " +
"into the proper place in the wikitext.\n* If converting a special " +
"group, optionally remove the group attributes.\n* Replace all " +
"autogenerated names with human-generated names.\n\nYou can do the above " +
"with the Find/Replace command in many text editors. (Always use the " +
"quoted form of the attributes.) Then, paste the text back into the edit " +
"form and save the page.",
integrateWarning: "The refs listed below are missing from the text. If you " +
"continue, they will be permanently deleted. Are you sure?\n\nUnused refs: "
};
 
( function ( $ ) {
// Begin encapsulation (prevent interference with other scripts)
(function(){
 
// "Semi-global" variables (function-scoped 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
* Unquote a wikitext tag attribute.
function has(obj, key) {
*
return Object.hasOwnProperty.call(obj, key);
* @param string quotedValue
* @return string
*/
function htmlUnquote( quotedValue ) {
var d = document.createElement( 'div' );
d.innerHTML = '<input value=' + quotedValue + '></input>';
return d.firstChild.value;
}
 
/**
// Setting a slice of a string
* Quote a wikitext tag attribute, choosing single quotes versus
function setSlice(t, replacement, indexFrom, indexTo) {
* double quotes depending on which is shorter.
if(typeof indexTo == "undefined") {
*
return t.slice(0, indexFrom) + replacement;
* @param string value
}
* @return string
return t.slice(0, indexFrom) + replacement + t.slice(indexTo);
*/
}
function htmlQuote( value ) {
var sQ, dQ;
 
value = value.replace( /\&/g, '&amp;' );
// Unquoting from an HTML-quoted form
sQ = "'" + value.replace( /'/g, '&#39;' ) + "'",
function htmlUnquote(t) {
dQ = '"' + value.replace( /"/g, '&quot;' ) + '"';
// Let's use the browser's functionality for the hard work,
// since MediaWiki/PHP supports many different HTML entities.
// (Note: innerHTML is not W3C-standard)
var d = document.createElement("div");
d.innerHTML = "<input value=" + t + "></input>";
return d.firstChild.value;
}
 
return sQ.length < dQ.length ? sQ : dQ;
// Quoting using HTML quotes. Chooses single quotes versus
// double quotes depending on which is shorter.
function htmlQuote(t) {
// Escape ampersands
var s = t.replace(/\&/g, "&amp;");
// Try both kinds of quotes
var sQ = "'" + s.replace(/'/g, "&#39;") + "'",
dQ = '"' + s.replace(/"/g, "&quot;") + '"';
// Choose the shorter, preferring double quotes if equal in length
return (sQ.length < dQ.length ? sQ : dQ);
}
 
// Looks for ref tags in the text, skipping problematic extension tags.
// OBJECTS
// For example, "references" may contain out-of-line refs, which should be skipped.
 
function RefScanner( argWikiText ) {
// RefScanner: Use for identifying ref tags in text. (No nested refs please)
function RefScanner(argWikiText) {
this.wikiText = argWikiText;
// The tags listed below other than "ref" are there for an obvious reason.
// NB: "references" is here to prevent out-of-line refs from being returned.
this.refScanRegex = /(?:<!--[\s\S]*?-->|<(nowiki|source|references|ref)(?:|\s(?:[^"']|"[^"]*"|'[^']*')*?)(?:\/>|(?:>[\s\S]*?<\/\1(?:|\s[^>]*)>)))/gi;
}
RefScanner.prototype = {
// Returns the next ref found in the text
getRef: function getRef() {
var results;
do {
results = this.refScanRegex.exec(this.wikiText);
if(!results) {
return null;
}
if(typeof results[1] == "undefined") {
results = [0,0];
}
} while(results[1].toString().toLowerCase() != "ref");
return results[0];
}
};
 
// RefParser:Get Usethe fornext extracting attributesref from refthe tagstext.
RefScanner.prototype.getRef = function RefParser(argWikiText) {
var results;
this.wikiText = argWikiText;
do {
// The below regex is mostly a copy of the refScanRegex above, except that
results = this.refScanRegex.exec( this.wikiText );
// the whole string must be a ref, and no more, and two parts are extracted:
if ( !results ) {
// $1=attributes, $2=remaining portion of ref
var refParseRegex = /^<ref(|\s(?:[^"']|"[^"]*"|'[^']*')*?)(\/>|(?:>[\s\S]*?<\/ref(?:|\s[^>]*)>))$/i;
this.parsedRef = refParseRegex.exec(this.wikiText);
if(!this.parsedRef) {
throw new Error("invalid ref");
}
}
RefParser.prototype = {
getAttributes: function getAttributes() {
// In this regex, we need to extract a single name-value pair at a time.
var attParseRegex = /\s([^\s=>]+)\s*=\s*("[^"]*"|'[^']*'|[^\s"']*)/g;
if(!this.parsedRef) {
return null;
}
if ( results[1] === undefined ) {
var attributes = {}, results;
while(( results = attParseRegex.exec(this.parsedRef[1])))0, {0];
attributes[results[1].toLowerCase()] = htmlUnquote(results[2]);
}
} while ( results[1].toString().toLowerCase() !== 'ref' );
return attributes;
return results[0];
};
 
// Extracts attributes from ref tags.
function RefParser( argWikiText ) {
// This is mostly a copy of refScanRegex, except that the whole string must be a ref,
// and no more, and two parts are extracted: $1=attributes, $2=remaining portion of ref
var refParseRegex = /^<ref(|\s(?:[^"']|"[^"]*"|'[^']*')*?)(\/>|(?:>[\s\S]*?<\/ref(?:|\s[^>]*)>))$/i;
 
this.wikiText = argWikiText;
this.parsedRef = refParseRegex.exec( this.wikiText );
if ( !this.parsedRef ) {
throw new Error( 'invalid ref' );
}
}
 
// Get all attributes of the tag.
RefParser.prototype.getAttributes = function () {
// In this regex, we need to extract a single name-value pair at a time.
var attParseRegex = /\s([^\s=>]+)\s*=\s*("[^"]*"|'[^']*'|[^\s"']*)/g;
if ( !this.parsedRef ) {
return null;
}
var attributes = Object.create( null ), results;
while ( ( results = attParseRegex.exec( this.parsedRef[1] ) ) ) {
attributes[results[1].toLowerCase()] = htmlUnquote( results[2] );
}
return attributes;
};
 
/**
// FUNCTIONS
* Segregate refs from content.
*
* @param string argWikiText The original wikitext
* @param string group The name of the ref group to process (default group is '')
* @param bool caseCues Mark the original ref code locations using capitalization?
* @return Object
*/
function segregateRefs( argWikiText, group, caseCues ) {
var prefixChars, randNo, randPrefix, refPreferred, scanner, ref, parser, attributes,
refGroup, refName, refStored, refEmpty, refLong, unnamedRefs = 0,
refNames = Object.create( null ), refCodes = [], refShort, outWikiText = '', offset = 0;
 
// Create a random prefix for autogenerated ref names
prefixChars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
randNo = Math.floor( Math.random() * ( prefixChars.length * prefixChars.length ) );
randPrefix = messages.autoWord
+ prefixChars.charAt( Math.floor( randNo / prefixChars.length ) )
+ prefixChars.charAt(randNo % prefixChars.length) +
'-';
 
// segregateRefs: Use for segregating refs from content.
// If completeSearch == true, the function looks in all occurrences for ref
// contents. If completeSearch == false, the function only checks the first.
// group is the reference group to limit the operation to. The empty string
// refers to all ungrouped refs. caseCues is whether or not to use
// capitalization to designate a preferred ref code ___location.
function segregateRefs(argWikiText, completeSearch, group, caseCues) {
// Create a random prefix for autogenerated ref names.
// in theory this has a 1/1296 probability of collision - extremely low
var prefixChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
randNo = Math.floor(Math.random() *
(prefixChars.length * prefixChars.length));
randPrefix = messages.autoWord + prefixChars.charAt(Math.floor(randNo /
prefixChars.length)) + prefixChars.charAt(randNo % prefixChars.length) +
"-";
// Create the beginning of the code for a preferred ref ___location
var refPreferred = caseCues ? "'<REF "' : "'<ref "';
scanner = new RefScanner( argWikiText );
// Variables for the main code
var scanner = new RefScanner(argWikiText), unnamedRefs = 0, refNames = {},
ref, refStored, parser, attributes, refName, refLong, refShort,
refCodes = [], refEmpty, emptyRefsWarningGiven = false, refGroup;
while ( ( ref = scanner.getRef() ) ) {
// Disable the empty refs warning (see below) if the user has disabled it
parser = new RefParser( ref );
if(typeof SegregateRefsJsEmptyRefsWarningGiven != "undefined" &&
SegregateRefsJsEmptyRefsWarningGiven) {
emptyRefsWarningGiven = true;
}
while((ref = scanner.getRef())) {
parser = new RefParser(ref);
attributes = parser.getAttributes();
 
refGroup = attributes.group || '';
// First make sure that the ref is in the right group.
refGroup =if has(attributes, "group") ?!= attributes.grouprefGroup :) "";{
// The ref is in a different group
if(group != refGroup) {
continue;
}
 
if ( attributes.name !== undefined ) {
// Does the ref have a name?
// (Note:The Noref matteralready howhas incorrecta itname seems,(possibly the empty string is)
refName = attributes.name;
// an acceptable ref name to the MediaWiki parser, as verified by
refStored = refName in refNames;
// informal testing.)
refEmpty = parser.parsedRef[2].slice( -2 ) == '/>' ||
if(!has(attributes, "name")) {
parser.parsedRef[2].slice( 0, 3 ) == '></';
// Bad: it doesn't have one - create a name for it
refLong = ref;
 
} else {
// We have to autogenerate one
refName = randPrefix + ( ++unnamedRefs ).toString(10);
refStored = false;
refEmpty = false;
refLong = '<ref name=' + htmlQuote( refName ) +
refName = randPrefix + (++unnamedRefs).toString(10);
// Change the corresponding ref code
refLong = "<ref name=" + htmlQuote(refName) +
parser.parsedRef[1] + parser.parsedRef[2];
} else {
// Good: it has a name.
refName = attributes.name;
refLong = ref;
// Check if the ref name has already been seen.
refStored = has(refNames, refName);
// Check if the ref has no contents.
refEmpty = (parser.parsedRef[2].slice(-2) == "/>") ||
(parser.parsedRef[2].slice(0, 3) == "></");
// Since this script, when not set in complete search mode, checks
// only the first occurrence of a ref for contents, inform the user
// of this limitation if it may pose a problem.
if(!completeSearch && !emptyRefsWarningGiven && !refStored) {
if(refEmpty) {
if(!window.confirm(messages.emptyRefsWarning)) {
return false;
}
emptyRefsWarningGiven = true;
}
}
}
 
if ( !refStored ) {
// Is the ref's name unique?
// Found the first ref of this name
if(!refStored) {
// Unique: add it to the list of refs
refNames[refName] = {
code: refCodes.length,
Line 260 ⟶ 195:
};
refCodes[refNames[refName].code] = refLong;
 
// Make a short code for the ref
if ( refEmpty ) {
refShort = refLong;
} else if (! refGroup.length === '' ) {
refShort = refPreferred + "'name="' + htmlQuote( refName ) + '/>';
htmlQuote(refName) + "/>";
} else {
refShort = refPreferred + "'name="' + htmlQuote( refName ) +
"' " + "group="' + htmlQuote( refGroup ) + "'/>"';
}
 
// Otherwise, is the current longcode not empty?
} else if ( !refEmpty && refNames[refName].empty ) {
// (only when in complete search mode, and when another non-empty,
// Already found an empty ref under this name, yet this one is non-empty
// same-named ref has not been encountered)
// Fill in the long code for the existing entry
} else if (completeSearch && !refEmpty && refNames[refName].empty) {
// Not empty: fill in the long code and make a short code
refCodes[refNames[refName].code] = refLong;
refNames[refName].empty = false;
 
if(!refGroup.length) {
// Make a short code for the ref
refShort = refPreferred + "name=" +
refShort = refPreferred + 'name=' + htmlQuote( refName) + "/>");
}if else( refGroup !== '' ) {
refShort += refPreferred' + "namegroup="' + htmlQuote(refName refGroup ) + '/>';
" " + "group=" + htmlQuote(refGroup) + "/>";
}
refShort += '/>';
 
} else {
// Leave the ref as-is in the original wikitext
refShort = caseCues ? refLong.replace( /^<REF/, "<ref" ) : refLong;
// (except if caseCues apply)
if(caseCues) {
refShort = refLong.replace(/^<REF/, "<ref");
} else {
refShort = refLong;
}
}
 
// Replace the long code with the short code
outWikiText += argWikiText.slice( offset, scanner.refScanRegex.lastIndex - ref.length );
scanner.wikiText = setSlice(scanner.wikiText, refShort,
outWikiText += refShort;
scanner.refScanRegex.lastIndex - ref.length,
offset = scanner.refScanRegex.lastIndex);
// Update lastIndex accordingly
scanner.refScanRegex.lastIndex += refShort.length - ref.length;
}
 
outWikiText += argWikiText.slice( offset );
 
return {
wikiText: scanner.wikiTextoutWikiText,
refCodes: refCodes,
randPrefix: randPrefix
};
}
 
/**
// integrateRefs: Use for inserting ref contents back into text
* Insert ref contents back into the text.
*
* @param string argWikiText The wikitext without ref contents
* @param string argRefText The ref contents
* @param string randPrefix The randPrefix value returned by segregateRefs()
* @param string caseCues The caseCues argument passed to segregateRefs()
*/
function integrateRefs(argWikiText, argRefText, randPrefix, caseCues) {
 
// A function to removeRemove an autogenerated ref name (if possible).
function cleanRefLong(dirtyRef) {
var cleanRegex = /^<(ref) name=(?:"[^"]*"|'[^']*'|[^\s"']*)/i;
return dirtyRef.replace(cleanRegex, "'<$1"');
}
 
var scanner, ref, parser, attributes, refCodes = Object.create( null ), usageFreq = Object.create( null ),
// Variables for the main code
preferredRef = Object.create( null ), refLong, outWikiText = '', offset = 0;
var scanner, ref, parser, attributes, refCodes = {}, usageFreq = {},
 
preferredRef = {}, refLong;
// First, we build an associative array of all the ref codes
// that we might need to put back into the text.
scanner = new RefScanner( argRefText );
while ( ( ref = scanner.getRef() ) ) {
// NOTE: JavaScript does not actually offer real associative array
parser = new RefParser( ref );
// 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 (has(attributes, "attributes.name") !== undefined ) {
// Only use the first ref withhaving each name
if ( !refCodes.hasOwnProperty( attributes.name in refCodes ) ) {
refCodes[attributes.name] = ref;
}
}
}
 
// Next, we build an associative array that holds the usage frequency
// of every ref name used in text, and whether there is a preferred ref,
// if caseCues are selectedenabled.
scanner = new RefScanner( argWikiText );
while ( ( ref = scanner.getRef() ) ) {
parser = new RefParser( ref );
attributes = parser.getAttributes();
if (has(attributes, "attributes.name") !== undefined ) {
if ( !has(usageFreq, attributes.name in usageFreq ) ) {
// We found a new name
usageFreq[attributes.name] = 1;
} else {
// We already found this name
usageFreq[attributes.name]++;
}
if ( caseCues && ref.slice( 0, 4 ) == '<REF' ) {
preferredRef[attributes.name] = true;
if(ref.slice(0, 4) == "<REF") {
preferredRef[attributes.name] = true;
}
}
}
}
 
// Finally, we go through the text again and this time we insert the
// ref codes where we need to, but only in the first place
// a ref name appears (or the first preferred ___location).
scanner = new RefScanner( argWikiText );
while ( ( ref = scanner.getRef() ) ) {
parser = new RefParser( ref );
attributes = parser.getAttributes();
if (has(attributes, "'name")' in attributes ) {
// Is this name on the replacement list?
if (has(refCodes, attributes.name) in refCodes ) {
 
// If we are using caseCues, and another ___location is
// preferred, skip to the next ref.
if ( caseCues && has(preferredRef, attributes.name) in preferredRef &&
ref.slice( 0, 4 ) != "'<REF") {'
) {
continue;
}
// Is this name an autogenerated name?
if ( attributes.name.slice( 0, randPrefix.length ) == randPrefix ) {
// Yes: is the name used multiple times?
if ( usageFreq[attributes.name] > 1 ) {
// Multiple: the replacement code should be the same
// as that stored in the ref textbox.
Line 391 ⟶ 321:
// at least not if the citation was untouched.
// (We don't want to add unnecessary autonames)
refLong = cleanRefLong( refCodes[attributes.name] );
}
} else {
Line 401 ⟶ 331:
// Replace the short code with the long code
outWikiText += argWikiText.slice( offset, scanner.refScanRegex.lastIndex - ref.length );
scanner.wikiText = setSlice(scanner.wikiText, refLong,
outWikiText += refLong;
scanner.refScanRegex.lastIndex - ref.length,
offset = scanner.refScanRegex.lastIndex);
 
// Update lastIndex accordingly
scanner.refScanRegex.lastIndex += refLong.length - ref.length;
// Delete the name from the replacement list
delete refCodes[attributes.name];
Line 412 ⟶ 340:
}
}
 
// Return both the combined output and the ref codes that were not used.
outWikiText += argWikiText.slice( offset );
return {wikiText: scanner.wikiText, unusedRefs: refCodes};
 
return {
wikiText: outWikiText,
unusedRefs: refCodes
};
}
 
/**
// Clears the undo history of a textarea by removing it
* Clear the undo history of a textarea by removing it from the document
// from the DOM and then inserting it again.
* and then inserting it again.
*
* @param HTMLTextareaElement ta The textarea element
*/
function clearUndoHistory(ta) {
var pn = ta.parentNode, ns = ta.nextSibling;
Line 433 ⟶ 370:
// Do the actual integration work
result = integrateRefs(mainTextbox.value, refsTextbox.value, randPrefix, true);
 
randPrefix, complete);
// Find all unused ref names
for(refName in result.unusedRefs) {
unusedRefNamesQuoted.push(htmlQuote(refName));
if(has(result.unusedRefs, refName)) {
unusedRefNamesQuoted.push(htmlQuote(refName));
}
}
// If any refs are unused, warn and allow the user to cancel;
Line 483 ⟶ 416:
refsButton.parentNode.removeChild(refsButton);
}
 
// Allow for disabling usage of the complete search mode
// when segregating refs for editing.
if(typeof SegregateRefsJsCompleteSearch != "undefined" &&
!SegregateRefsJsCompleteSearch) {
complete = false;
} else {
complete = true;
}
// wikEd compatibility (frame -> textarea)
if(typeof wikEdUseWikEd != "undefined" && wikEdUseWikEd) {
Line 499 ⟶ 423:
// Do the actual segregation work and save the random prefix
var segFormat = segregateRefs(mainTextbox.value, complete, "", completetrue);
if(!segFormat) {
return false;
Line 531 ⟶ 455:
refsTextbox = document.createElement("textarea");
refsTextbox.id = "PsRefsTextbox";
refsTextbox.value = segFormat.refCodes.join("\n\n");
if(!complete) {
refsTextbox.valuerows = messages.refsCommentIncomplete +12;
segFormat.refCodes.join("\n\n");
} else {
refsTextbox.value = segFormat.refCodes.join("\n\n");
}
refsTextbox.rows = Math.floor(mainTextbox.rows / 2);
refsTextbox.cols = mainTextbox.cols;
refsTextbox.style.border = "none";
Line 578 ⟶ 496:
// Do the actual segregation work and save the random prefix
var segFormat = segregateRefs(mainTextbox.value, true, group, false);
if(!segFormat) {
return false;
Line 619 ⟶ 537:
refsTextbox.value = messages.refsCommentComplete +
segFormat.refCodes.join("\n");
refsTextbox.rows = Math.floor(mainTextbox.rows / 2)12;
refsTextbox.cols = mainTextbox.cols;
 
refsTextbox.style.border = "none";
Line 647 ⟶ 564:
}
 
function getEditboxContents() { // ajaxPreview compatibility
if(unloadHandlerRegistered) {
// wikEd compatibility (frame -> textarea)
if(typeof wikEdUseWikEd != "undefined" && wikEdUseWikEd) {
WikEdUpdateTextarea();
}
return integrateRefs(mainTextbox.value, refsTextbox.value,
randPrefix, complete).wikiText;
} else {
return mainTextbox.value;
}
}
 
$( function () {
// Leave a global for ajaxPreview to use.
window.getEditboxContents = getEditboxContents;
 
 
function loadHandler() { // This function is called on page load
try {
 
if( !window.addEventListener ) {
return;
}
// Handle message translations
messages = (typeof SegregateRefsJsL10n == "object" &&
Line 697 ⟶ 595:
// Make the "convert" button
convertButton = document.createElement("input");
convertButton.type = "button";
convertButton.value = messages.buttonConvertText;
convertButton.setAttribute("style", messages.buttonConvertStyle);
convertButton.onclick = convertButtonHandler;
if(typeof SegregateRefsJsAllowConversion == "undefined" ||
Line 711 ⟶ 609:
refsDiv.appendChild(refsButton);
refsDiv.appendChild(convertButton);
// Find position within the edit form to insert it at
mainTextbox.parentNode.insertBefore(refsDiv, mainTextbox.nextSibling);
var refsDivPos = mainTextbox, refsDivPosParent = refsDivPos.parentNode;
while (refsDivPosParent !== editForm) {
refsDivPos = refsDivPosParent;
refsDivPosParent = refsDivPos.parentNode;
if (!refsDivPosParent) {
refsDivPos = mainTextbox;
refsDivPosParent = refsDivPos.parentNode;
break;
}
}
refsDivPos = refsDivPos.nextSibling;
if (refsDivPos && refsDivPos.classList.contains("wikiEditor-ui-clear")) {
refsDivPos = refsDivPos.nextSibling;
}
refsDivPosParent.insertBefore(refsDiv, refsDivPos);
} catch(e) {
}
}
 
} );
 
})( jQuery );
// Register document ready handler
$j(loadHandler);
 
// </nowiki>
})();