User:Cacycle/wikEd dev.js: Difference between revisions

Content deleted Content added
v0.9.2
No edit summary
Line 2:
 
/*
Name: wikEd (wikEd.js)
Version: wikEd 0.9 (beta) (November, 2006). The code is currently under active development and might change rapidly
Update: press SHIFT-Reload to update to the newest version
InfoHomepage: http://en.wikipedia.org/wiki/User:Cacycle/wikEd
CodeHelp: http://en.wikipedia.org/wiki/User:Cacycle/wikEd.jswikEd_Help
AuthorCode: Cacycle ( http://en.wikipedia.org/wiki/User:Cacycle)/wikEd.js
Author: Cacycle (http://en.wikipedia.org/wiki/User:Cacycle)
Bugs: surprisingly functional
Bugs: surprisingly functional
Browsers: The program works ONLY for Mozilla-based browsers (Mozilla, Mozilla Firefox, and Mozilla SeaMonkey)
Browsers: The program works ONLY for Mozilla-based browsers (Mozilla, Mozilla Firefox, and Mozilla SeaMonkey)
License: This code has been released into the public ___domain
License: This code has been released into the public ___domain
What: Comfortable JavaScript editor for Wikipedia and other MediaWikis
What: Comfortable JavaScript editor for Wikipedia and other MediaWikis
Features:
Important: This file might have to be saved as UTF-16 in order to preserve certain Unicode characters
* Pasting of formatted texts from web pages and word processors (e.g. MS Word)
* Conversion of pasted text into wikicode (including tables)
* Syntax highlighting
* Regular expression search and replace
* Find ahead as you type
* Server-independent ''Show preview'' and ''Show changes''
* One-click fixing of common mistakes
* Undo/redo
* Input boxes have a history
* Fullscreen view
Known issues:
* Mozilla replaces tabs with four spaces when pasting text into the iframe
Solution: Disable wikEd, paste the text, and re-enable wikEd by clicking the 'use wikEd' button
* Pasting text from HTML headings (<h1>) generates a whole paragraph containing the pasted text
Solution: Disable wikEd, paste the text, and re-enable wikEd by clicking the 'use wikEd' button
or: press the textify '[T]' button and remove the linebreaks manually
*/
 
var wikEdProgramHomepage = 'http://en.wikipedia.org/wiki/User:Cacycle/wikEd';
var wikEdProgramVersion = '0.9.25 (beta)';
var wikEdProgramDate = 'November 810, 2006';
 
 
//
// configurationuser configurable variables
//
 
Line 128 ⟶ 113:
var wikEdMainCSS = wikEdMainCSS || [];
wikEdMainCSS['.wikEdCombo'] = wikEdMainCSS['.wikEdCombo'] || 'font-size: smaller; padding-left: 0.1em; padding-right: 0.1em; margin-left: 0.1em; margin-right: 0.1em; height: 1.6em; vertical-align: bottom;';
wikEdMainCSS['.wikEdPreviewBox'] = wikEdMainCSS['.wikEdPreviewBox'] || 'background-color: #f9f9f9;';
 
// wikEd button areas
Line 134 ⟶ 118:
wikEdMainCSS['.wikEdButtonsFind'] = wikEdMainCSS['.wikEdButtonsFind'] || 'background: #d4d0cc; border: 1px black solid; padding: 0.1em; margin: 0.2em 0.6em 0 0 ; float: left;';
wikEdMainCSS['.wikEdButtonsFix'] = wikEdMainCSS['.wikEdButtonsFix'] || 'background: #d4d0cc; border: 1px black solid; padding: 0.1em; margin: 0.2em 0.6em 0 0 ; float: left';
wikEdMainCSS['.wikEdButtonsWindowwikEdButtonsControl'] = wikEdMainCSS['.wikEdButtonsWindowwikEdButtonsControl'] || 'background: #d4d0cc; border: 1px black solid; padding: 0.1em; margin: 0.2em 0 0 0 ; float: right;';
wikEdMainCSS['.wikEdButtonsPreview'] = wikEdMainCSS['.wikEdButtonsPreview'] || 'background: #d4d0cc; border: 1px black solid; padding: 0.1em; margin: 0.2em 0 0 0.6em ; float: right;';
wikEdMainCSS['.wikEdButtonsPreviewFull'] = wikEdMainCSS['.wikEdButtonsPreviewFull'] || 'background: #d4d0cc; border: 1px black solid; padding: 0.1em; margin: -2px 0 0 0.6em; float: right;';
Line 152 ⟶ 136:
 
// preview box
wikEdMainCSS['#.wikEdPreviewBoxOuter'] = wikEdMainCSS['#.wikEdPreviewBoxOuter'] || 'clear: both; margin-top: 0.5em; margin-bottom: 0; border-width: 1px; border-style: solid; border-color: #808080 #d0d0d0 #d0d0d0 #808080;';
wikEdMainCSS['#.wikEdPreviewBox'] = wikEdMainCSS['#.wikEdPreviewBox'] || 'background-color: #f9f9f9; padding: 5px; border-width: 1px; border-style: solid; border-color: #404040 #ffffff #ffffff #404040;';
 
// find field
Line 166 ⟶ 150:
 
// summary field
wikEdMainCSS['#summaryComboInputwikEdSummaryComboInput'] = wikEdMainCSS['#summaryComboInputwikEdSummaryComboInput'] || 'position: relative;';
wikEdMainCSS['#wpSummary'] = wikEdMainCSS['#wpSummary'] || 'padding: 0; margin: 0; position: absolute; left: 0; top: 0; z-index: 2; width: auto;';
wikEdMainCSS['#wpSummarySelect'] = wikEdMainCSS['#wpSummarySelect'] || 'border: none; padding: 0; margin: 0; position: relative; vertical-align: middle; z-index: 1;';
Line 177 ⟶ 161:
wikEdMainCSS['#wikEdFrameInner'] = wikEdMainCSS['#wikEdFrameInner'] || 'padding: 0; border-width: 1px; border-style: solid; border-color: #404040 #ffffff #ffffff #404040;';
wikEdMainCSS['#wikEdFrame'] = wikEdMainCSS['#wikEdFrame'] || 'width: 100%; padding: 0; margin: 0; border: none;';
 
// various
wikEdMainCSS['.wikEdHelpSpan'] = wikEdMainCSS['.wikEdHelpSpan'] || '';
 
// textarea (maximal row number, always show vertical scrollbar)
Line 182 ⟶ 169:
 
// summary
wikEdMainCSS['#.wikEdSummaryWrapper'] = wikEdMainCSS['#.wikEdSummaryWrapper'] || 'margin-top: 0.25em 0 0.4em 0;';
wikEdMainCSS['#wpSummaryLabel'] = wikEdMainCSS['#wpSummaryLabel'] || 'margin-right: 0.2em';
wikEdMainCSS['.editOptions'] = wikEdMainCSS['.editOptions'] || 'position: relative; top: 0.1em;';
 
// copywarn
wikEdMainCSS['#editpage-copywarn3'] = wikEdMainCSS['#editpage-copywarn3'] || 'padding-top: 0;';
 
// input wrapper
wikEdMainCSS['.wikEdInputWrapperFull'] = wikEdMainCSS['.wikEdInputWrapperFull'] || 'position: fixed; top: 0; left: 0; right: 0; padding: 4px; background: white;';
wikEdMainCSS['.wikEdInputWrapper'] = wikEdMainCSS['.wikEdInputWrapper'] || '';
 
// textarea and frame wrapper, set up for textarea / frame switch
wikEdMainCSS['.wikEdTextareaWrapper'] = wikEdMainCSS['.wikEdTextareaWrapper'] || '';
wikEdMainCSS['.wikEdFrameWrapper'] = wikEdMainCSS['.wikEdFrameWrapper'] || '';
 
 
Line 197 ⟶ 185:
 
 
// history length for summaryfind, findreplace, and replacesummary fields
var wikEdFindHistoryLengthwikEdHistoryLength = wikEdFindHistoryLengthwikEdHistoryLength || 10[];
wikEdHistoryLength['find'] = 10;
wikEdHistoryLength['replace'] = 10;
wikEdHistoryLength['summary'] = 12;
 
// presets for combo input fields dropdown options, {wikEdUsing} appends a link to this script
var wikEdComboPresetOptions = wikEdComboPresetOptions || [];
wikEdComboPresetOptions['summary'] = wikEdComboPresetOptions['summary'] || [
'copyedit',
'article created',
'reply',
'intro rewrite',
'article created',
'copyedit',
'intro rewrite',
'linkfix',
'linkfix',
'fixing typos',
'fixing typos',
'removing linkspam',
'removing linkspam',
'reverting test',
'reverting vandalismtest',
'reverting vandalism',
'formatting source text',
'formatting source text',
'({wikEdUsing})'
'({wikEdUsing})'
];
 
Line 239 ⟶ 231:
var wikEdImagePath = wikEdImagePath || 'http://upload.wikimedia.org/wikipedia/commons/';
 
// fonttext sizezoom offor edit window (percentage)
var wikEdFontSizewikEdTextZoom = wikEdFontSizewikEdTextZoom || 100;
 
// remove invisible syntax highlighting comments after closing tag
Line 250 ⟶ 242:
// show the text-to-source button for testing purposes
var wikEdShowSourceButton = wikEdShowSourceButton || true;
 
// show the text-to-source button for testing purposes
var wikEdHelpPageLink = wikEdHelpPageLink || ' | <a href="http://en.wikipedia.org/wiki/User:Cacycle/wikEd_Help" target="helpwindow">wikEd_Help</a>';
 
// image filenames
Line 282 ⟶ 277:
wikEdImage['fixPunct'] = wikEdImage['fixPunct'] || wikEdImagePath + 'd/db/WikEd_fix_punct.png';
wikEdImage['fixUnits'] = wikEdImage['fixUnits'] || wikEdImagePath + '6/69/WikEd_fix_units.png';
wikEdImage['fontSizetextZoom'] = wikEdImage['fontSizetextZoom'] || wikEdImagePath + '7/71/WikEd_font_size.png';
wikEdImage['fullScreen'] = wikEdImage['fullScreen'] || wikEdImagePath + 'd/d3/WikEd_fullscreen.png';
wikEdImage['getFind'] = wikEdImage['getFind'] || wikEdImagePath + '9/96/WikEd_get_selection.png';
Line 294 ⟶ 289:
wikEdImage['lastPos'] = wikEdImage['lastPos'] || wikEdImagePath + '5/54/WikEd_jump_next.png';
wikEdImage['logo'] = wikEdImage['logo'] || wikEdImagePath + '6/67/WikEd_logo.png';
wikEdImage['nowiki'] = wikEdImage['nowiki'] || wikEdImagePath + '0/00/WikEd_nowiki.png';
wikEdImage['numberList'] = wikEdImage['numberList'] || wikEdImagePath + '3/3b/WikEd_number_list.png';
wikEdImage['prevPos'] = wikEdImage['prevPos'] || wikEdImagePath + 'c/c7/WikEd_jump_prev.png';
Line 307 ⟶ 303:
wikEdImage['scrollToText'] = wikEdImage['scrollToText'] || wikEdImagePath + '1/13/WikEd_align_top.png';
wikEdImage['source'] = wikEdImage['source'] || wikEdImagePath + '0/02/WikEd_source.png';
wikEdImage['strikethrough'] = wikEdImage['strikethrough'] || wikEdImagePath + '0/00/WikEd_strikethrough.png';
wikEdImage['subscript'] = wikEdImage['subscript'] || wikEdImagePath + '9/9e/WikEd_subscript.png';
wikEdImage['superscript'] = wikEdImage['superscript'] || wikEdImagePath + 'b/bf/WikEd_superscript.png';
Line 321 ⟶ 318:
wikEdImage['wikify'] = wikEdImage['wikify'] || wikEdImagePath + '9/9f/WikEd_wikify.png';
wikEdImage['wikiLink'] = wikEdImage['wikiLink'] || wikEdImagePath + '2/21/WikEd_wikilink.png';
 
 
//
// end of user configurable variables
//
 
 
Line 344 ⟶ 346:
 
// global dom elements
var wikEdTextareaObjwikEdTextarea = {};
var wikEdFrame = {};
var wikEdFrameBody = {};
var wikEdFrameDocument = {};
var wikEdFrameWindow = {};
 
var wikEdLastPosObjwikEdInputWrapper = null{};
var wikEdToolbarWrapper = {};
var wikEdTextareaWrapper = {};
var wikEdFrameWrapper = {};
var wikEdConsoleWrapper = {};
var wikEdButtonsWrapper = {};
var wikEdSummaryWrapper = {};
var wikEdSubmitWrapper = {};
var wikEdPreviewWrapper = {};
var wikEdInsertWrapper = {};
 
var wikEdButtonsFormat = {};
var wikEdButtonsFind = {};
var wikEdButtonsFix = {};
var wikEdButtonsControl = {};
var wikEdButtonsPreview = {};
var wikEdPreviewBox = {};
var wikEdButtonsPreview2 = {};
 
var wikEdCaseSensitive = {};
var wikEdRegExp = {};
var wikEdFindAhead = {};
 
var wikEdFindText = {};
var wikEdReplaceText = {};
var wikEdSummaryText = {};
 
// various
var wikEdFullScreenMode = false;
 
var wikEdTextareaHeight;
var wikEdLastPosObj = null;
 
// counters
Line 360 ⟶ 392:
// add setup routine to addOnloadHook
if (window.addOnloadHook != null) {
addOnloadHook(WikEdSetup);
}
 
Line 382 ⟶ 414:
function insertTags(tagOpen, tagClose, sampleText) {
 
if (useWikEd == true) {
WikEdEditButton('wikEdInsertTags', [tagOpen, tagClose, sampleText]);
}
}
 
// apply tagOpen / tagClose to selection in textarea,
// use sampleText instead of selection if there is none
// taken from wikibits.js
else {
if (wikEdTextareaObjwikEdTextarea.selectionStart || wikEdTextareaObjwikEdTextarea.selectionStart == '0') {
var replaced = false;
var startPos = wikEdTextareaObjwikEdTextarea.selectionStart;
var endPos = wikEdTextareaObjwikEdTextarea.selectionEnd;
if (endPos - startPos) {
replaced = true;
}
}
var scrollTop = wikEdTextareaObjwikEdTextarea.scrollTop;
var myText = (wikEdTextareaObjwikEdTextarea.value).substring(startPos, endPos);
if (! myText) {
myText = sampleText;
}
}
 
// exclude ending space char, if any
if (myText.charAt(myText.length - 1) == ' ') {
subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + ' ';
}
}
else {
subst = tagOpen + myText + tagClose;
}
}
wikEdTextareaObj wikEdTextarea.value = wikEdTextareaObjwikEdTextarea.value.substring(
0, startPos) + subst + wikEdTextareaObjwikEdTextarea.value.substring(endPos, wikEdTextareaObjwikEdTextarea.value.length
);
);
wikEdTextareaObj wikEdTextarea.focus();
 
// set new selection
if (replaced) {
var cPos = startPos+(tagOpen.length + myText.length + tagClose.length);
wikEdTextareaObj wikEdTextarea.selectionStart = cPos;
wikEdTextareaObj wikEdTextarea.selectionEnd = cPos;
}
}
else {
wikEdTextareaObj wikEdTextarea.selectionStart = startPos + tagOpen.length;
wikEdTextareaObj wikEdTextarea.selectionEnd = startPos + tagOpen.length + myText.length;
}
}
wikEdTextareaObj wikEdTextarea.scrollTop = scrollTop;
}
}
 
// reposition cursor if possible
if (wikEdTextareaObjwikEdTextarea.createTextRange) {
wikEdTextareaObj wikEdTextarea.caretPos = document.selection.createRange().duplicate();
}
}
}
}
 
return;
}
 
Line 444 ⟶ 476:
function WikEdSetup() {
 
var html = '';
 
// check if setup was already run
if (document.getElementById('wikEdLogo') != null) {
return;
}
}
 
// insert logo into personal toolbar
var logo = {};
logo.img = document.createElement('img');
logo.lnk = document.createElement('a');
logo.lnk.href = wikEdProgramHomepage;
logo.lnk.alt = 'WikEd Logo';
logo.lnk.appendChild(logo.img);
var listObj = document.createElement('li');
listObj.id = 'wikEdLogo';
listObj.appendChild(logo.lnk);
var personalTools = document.getElementById('p-personal').getElementsByTagName('ul')[0];
personalTools.appendChild(listObj);
 
// set error logo
WikEdSetLogo(logo, false);
 
// at the moment this works only for mozilla browsers (Mozilla, Mozilla Firefox, Mozilla SeaMonkey)
if (navigator.appName == null) {
return;
}
}
var nameMatch = navigator.appName.match(/Netscape/i);
if (nameMatch == null) {
return;
}
}
var name = nameMatch[0];
if ( (name == null) || (name == '') ) {
return;
}
}
var version = navigator.appVersion.match(/\d+(\.\d+)/)[0];
if ( (version == null) || (version < 5.0) ) {
return;
}
}
 
// check if this is an edit page
wikEdTextareaObj wikEdTextarea = document.getElementById('wpTextbox1');
if (wikEdTextareaObjwikEdTextarea == null) {
 
// reset error indicator
WikEdSetLogo(logo);
return;
}
}
 
// get initial textarea height
var textareaHeight wikEdTextareaHeight = wikEdTextareaObjwikEdTextarea.offsetHeight;
 
// setup the undo buffers and getsave the original text for local changes view
wikEdOrigVersion = wikEdTextareaObjwikEdTextarea.value;
 
// add stylesheet definitions
var mainStyle = new WikEdStyleSheet();
for (var rule in wikEdMainCSS) {
mainStyle.addRule(rule, wikEdMainCSS[rule]);
}
}
 
// rewrite image paths to local copies for testing
// create inputWrapper for textarea and buttons
if (wikEdUseLocalImages == true) {
var inputWrapper = document.createElement('div');
inputWrapper.id = 'wikEdInputWrapper';
wikEdTextareaObj.parentNode.insertBefore(inputWrapper, wikEdTextareaObj);
 
// remove MediaWiki upload paths
// move toolbar to textareaWrapper
var regExpStr = '/[0-9a-f]+/[0-9a-f]+(/[\\w\\.]+)$';
var toolbarObj = document.getElementById('toolbar');
var regExp = new RegExp(regExpStr, 'g');
if (toolbarObj != null) {
for (i in wikEdImage) {
inputWrapper.appendChild(toolbarObj);
wikEdImage[i] = wikEdImage[i].replace(regExp, '$1');
}
wikEdImage[i] = wikEdImage[i].replace(wikEdImagePath, wikEdImagePathLocal);
}
}
 
// create wikEd element wrappers
// move wikEdTextareaObj to textareaWrapper
var textareaWrapper = document.createElement('div');
textareaWrapper.id = 'wikEdTextareaWrapper';
 
// create input wrapper, this contains the whole fullscreen content
inputWrapper.appendChild(textareaWrapper);
wikEdInputWrapper = document.createElement('div');
textareaWrapper.appendChild(wikEdTextareaObj);
wikEdInputWrapper.id = 'wikEdInputWrapper';
wikEdInputWrapper.className = 'wikEdInputWrapper';
wikEdTextarea.parentNode.insertBefore(wikEdInputWrapper, wikEdTextarea);
 
// create toolbar wrapper
wikEdToolbarWrapper = document.createElement('div');
wikEdToolbarWrapper.id = 'wikEdToolbarWrapper';
wikEdToolbarWrapper.className = 'wikEdToolbarWrapper';
wikEdInputWrapper.appendChild(wikEdToolbarWrapper);
 
// create textarea wrapper
// add all other buttons and inputs to buttonsWrapper
var buttonsWrapper wikEdTextareaWrapper = document.createElement('div');
wikEdTextareaWrapper.id = 'wikEdTextareaWrapper';
buttonsWrapper.id = 'wikEdButtonsWrapper';
wikEdTextareaWrapper.className = 'wikEdTextareaWrapper';
inputWrapper.appendChild(buttonsWrapper);
wikEdInputWrapper.appendChild(wikEdTextareaWrapper);
 
// create frame wrapper
// rewrite image paths to local copies for testing
wikEdFrameWrapper = document.createElement('div');
if (wikEdUseLocalImages == true) {
wikEdFrameWrapper.id = 'wikEdFrameWrapper';
wikEdFrameWrapper.className = 'wikEdFrameWrapper';
wikEdInputWrapper.appendChild(wikEdFrameWrapper);
 
// create console wrapper for buttons, summary, and submit
// remove MediaWiki upload paths
wikEdConsoleWrapper = document.createElement('div');
var regExpStr = '/[0-9a-f]+/[0-9a-f]+(/[\\w\\.]+)$';
wikEdConsoleWrapper.id = 'wikEdConsoleWrapper';
var regExp = new RegExp(regExpStr, 'g');
wikEdConsoleWrapper.className = 'wikEdConsoleWrapper';
for (i in wikEdImage) {
wikEdInputWrapper.appendChild(wikEdConsoleWrapper);
wikEdImage[i] = wikEdImage[i].replace(regExp, '$1');
wikEdImage[i] = wikEdImage[i].replace(wikEdImagePath, wikEdImagePathLocal);
}
}
 
// addcreate wikEdbuttons editingwrapper for wikEd buttons
var wikEdButtons wikEdButtonsWrapper = document.createElement('div');
wikEdButtonsWrapper.id = 'wikEdButtonsWrapper';
wikEdButtons.id = 'wikEdButtons';
wikEdButtonsWrapper.className = 'wikEdButtonsWrapper';
html = '';
wikEdConsoleWrapper.appendChild(wikEdButtonsWrapper);
 
// create summary wrapper for summary, minor edit, and watch this page
// format buttons
wikEdSummaryWrapper = document.createElement('div');
html += '<div class="wikEdButtonsFormat" id="wikEdButtonsFormat">';
wikEdSummaryWrapper.id = 'wikEdSummaryWrapper';
wikEdSummaryWrapper.className = 'wikEdSummaryWrapper';
wikEdConsoleWrapper.appendChild(wikEdSummaryWrapper);
 
// create submit wrapper for submit buttons and help links
html += '<img class="wikEdButtonInactive" src="' + wikEdImage['undo'] + '" width="16" height="16" alt="Undo" title="Undo" id="wikEdUndo" onClick="javascript:WikEdEditButton(\'wikEdUndo\');">';
wikEdSubmitWrapper = document.createElement('div');
html += '<img class="wikEdButtonInactive" src="' + wikEdImage['redo'] + '" width="16" height="16" alt="Redo" title="Redo" id="wikEdRedo" onClick="javascript:WikEdEditButton(\'wikEdRedo\');">';
wikEdSubmitWrapper.id = 'wikEdSubmitWrapper';
html += '<img class="wikEdButton" src="' + wikEdImage['bold'] + '" width="16" height="16" alt="Bold" title="Bold text" id="wikEdBold" onClick="javascript:WikEdEditButton(\'wikEdBold\');">';
wikEdSubmitWrapper.className = 'wikEdSubmitWrapper';
html += '<img class="wikEdButton" src="' + wikEdImage['italic'] + '" width="16" height="16" alt="Italic" title="Italic text" id="wikEdItalic" onClick="javascript:WikEdEditButton(\'wikEdItalic\');">';
wikEdConsoleWrapper.appendChild(wikEdSubmitWrapper);
html += '<img class="wikEdButton" src="' + wikEdImage['underline'] + '" width="16" height="16" alt="Underline" title="Underline text" id="wikEdUnderline" onClick="javascript:WikEdEditButton(\'wikEdUnderline\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['superscript'] + '" width="16" height="16" alt="Superscript" title="Superscript text" id="wikEdSuperscript" onClick="javascript:WikEdEditButton(\'wikEdSuperscript\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['subscript'] + '" width="16" height="16" alt="Subscript" title="Subscript text" id="wikEdSubscript" onClick="javascript:WikEdEditButton(\'wikEdSubscript\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['case'] + '" width="16" height="16" alt="Casing" title="Toggle between lowercase, uppercase first, and uppercase" id="wikEdCase" onClick="javascript:WikEdEditButton(\'wikEdCase\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['undoAll'] + '" width="16" height="16" alt="Undo all" title="Undo all changes" id="wikEdUndoAll" onClick="javascript:WikEdEditButton(\'wikEdUndoAll\');">';
html += '<img class="wikEdButtonInactive" src="' + wikEdImage['redoAll'] + '" width="16" height="16" alt="Redo all" title="Redo all changes" id="wikEdRedoAll" onClick="javascript:WikEdEditButton(\'wikEdRedoAll\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['redirect'] + '" width="16" height="16" alt="Redirect" title="Redirect" id="wikEdRedirect" onClick="javascript:WikEdEditButton(\'wikEdRedirect\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['updateSyntax'] + '" width="16" height="16" alt="Syntax" title="Update syntax highlighting" id="wikEdUpdateSyntax" onClick="javascript:WikEdEditButton(\'wikEdUpdateSyntax\');">';
html += '<br />';
 
// create preview wrapper for preview and diff box
html += '<img class="wikEdButton" src="' + wikEdImage['wikiLink'] + '" width="16" height="16" alt="Link" title="Wiki link" id="wikEdWikiLink" onClick="javascript:WikEdEditButton(\'wikEdWikiLink\');">';
wikEdPreviewWrapper = document.createElement('div');
html += '<img class="wikEdButton" src="' + wikEdImage['webLink'] + '" width="16" height="16" alt="Weblink" title="External Weblink" id="wikEdWebLink" onClick="javascript:WikEdEditButton(\'wikEdWebLink\');">';
wikEdPreviewWrapper.id = 'wikEdPreviewWrapper';
html += '<img class="wikEdButton" src="' + wikEdImage['decreaseHeading'] + '" width="16" height="16" alt="Heading-" title="Decrease heading levels" id="wikEdDecreaseHeading" onClick="javascript:WikEdEditButton(\'wikEdDecreaseHeading\');">';
wikEdPreviewWrapper.className = 'wikEdPreviewWrapper';
html += '<img class="wikEdButton" src="' + wikEdImage['increaseHeading'] + '" width="16" height="16" alt="Heading+" title="Increase heading levels" id="wikEdIncreaseHeading" onClick="javascript:WikEdEditButton(\'wikEdIncreaseHeading\');">';
wikEdPreviewWrapper.style.display = 'none';
html += '<img class="wikEdButton" src="' + wikEdImage['bulletList'] + '" width="16" height="16" alt="Bullet list" title="Bulleted list" id="wikEdBulletList" onClick="javascript:WikEdEditButton(\'wikEdBulletList\');">';
wikEdInputWrapper.appendChild(wikEdPreviewWrapper);
html += '<img class="wikEdButton" src="' + wikEdImage['numberList'] + '" width="16" height="16" alt="Number list" title="Numbered list" id="wikEdNumberList" onClick="javascript:WikEdEditButton(\'wikEdNumberList\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['indentList'] + '" width="16" height="16" alt="Indent list" title="Indented list" id="wikEdIndentList" onClick="javascript:WikEdEditButton(\'wikEdIndentList\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['definitionList'] + '" width="16" height="16" alt="Def list" title="Definition list" id="wikEdDefinitionList" onClick="javascript:WikEdEditButton(\'wikEdDefinitionList\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['image'] + '" width="16" height="16" alt="Image" title="Image" id="wikEdImage" onClick="javascript:WikEdEditButton(\'wikEdImage\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['table'] + '" width="16" height="16" alt="Table" title="Table" id="wikEdTable" onClick="javascript:WikEdEditButton(\'wikEdTable\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['wikify'] + '" width="16" height="16" alt="Wikify" title="Wikify pasted content" id="wikEdWikify" onClick="javascript:WikEdEditButton(\'wikEdWikify\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['textify'] + '" width="16" height="16" alt="Textify" title="Convert pasted content to plain text" id="wikEdTextify" onClick="javascript:WikEdEditButton(\'wikEdTextify\');">';
html += '</div>';
 
// create insert wrapper for insert special chars links
// window functions: syntax highlighting, classic textarea, align, fullscreen
wikEdInsertWrapper = document.createElement('div');
html += '<div class="wikEdButtonsWindow" id="wikEdButtonsWindow">';
wikEdInsertWrapper.id = 'wikEdInsertWrapper';
html += '<img class="wikEdButton" src="' + wikEdImage['fontSize'] + '" width="16" height="16" alt="Font size" title="Change font size" id="wikEdFontSize" onClick="javascript:WikEdButton(\'wikEdFontSize\');">';
wikEdInsertWrapper.className = 'wikEdInsertWrapper';
html += '<img class="wikEdButton" src="' + wikEdImage['clearHistory'] + '" width="16" height="16" alt="Clear history" title="Clear the find, replace, and summary history" id="wikEdClearHistory" onClick="javascript:WikEdButton(\'wikEdClearHistory\');">';
wikEdInputWrapper.appendChild(wikEdInsertWrapper);
html += '<img class="wikEdButton" src="' + wikEdImage['scrollToButtons'] + '" width="16" height="16" alt="Scroll buttons" title="Scroll to edit buttons" id="wikEdScrollToButtons" onClick="javascript:WikEdButton(\'wikEdScrollToButtons\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['scrollToText'] + '" width="16" height="16" alt="Scroll up" title="Scroll to edit window" id="wikEdScrollToInput" onClick="javascript:WikEdButton(\'wikEdScrollToInput\');">';
html += '<br />';
 
// append input wrapper to document
html += '<img class="wikEdButtonChecked" src="' + wikEdImage['useWikEd'] + '" width="16" height="16" alt="Use wikEd" title="Enable wikEd" id="wikEdUseWikEd" onClick="javascript:WikEdButton(\'wikEdUseWikEd\', true);">';
wpEditform = document.getElementById('editform');
html += '<img class="wikEdButtonUnchecked" src="' + wikEdImage['highlightSyntax'] + '" width="16" height="16" alt="Syntax" title="Highlight syntax" id="wikEdHighlightSyntax" onClick="javascript:WikEdButton(\'wikEdHighlightSyntax\', true);">';
wpEditform.insertBefore(wikEdInputWrapper, wpEditform.firstChild);
if (wikEdShowSourceButton == true) {
html += '<img class="wikEdButton" src="' + wikEdImage['source'] + '" width="16" height="16" alt="Source" title="Show the source code for testing purposes" id="wikEdSource" onClick="javascript:WikEdEditButton(\'wikEdSource\');">';
}
html += '<img class="wikEdButton" src="' + wikEdImage['fullScreen'] + '" width="16" height="16" alt="Fullscreen" title="Fullscreen mode" id="wikEdFullScreen" onClick="javascript:WikEdButton(\'wikEdFullScreen\', true);">';
html += '</div>';
 
// fill the wrappers
// find / replace buttons
 
// add toolbar to toolbar wrapper
html += '<div class="wikEdButtonsFind" id="wikEdButtonsFind">';
wpToolbar = document.getElementById('toolbar');
if (wpToolbar != null) {
wikEdToolbarWrapper.appendChild(wpToolbar);
}
 
// call wikibits:mwSetupToolbar() now because it would terminate with an error after setting textarea to display: none
html += '<img class="wikEdButton" src="' + wikEdImage['getFind'] + '" width="16" height="16" alt="Get find" title="Copy selection to find field (double click: copy selection to find and to replace field)" id="wikEdGetFind" onClick="javascript:WikEdEditButton(\'wikEdGetFind\');" ondblclick="javascript:WikEdEditButton(\'wikEdGetFindReplace\');">';
if (useWikEd == true) {
html += '<img class="wikEdButton" src="' + wikEdImage['findAll'] + '" width="16" height="16" alt="Find all" title="Not yet implemented. Find all matches in whole text or selection" id="wikEdFindAll" onClick="javascript:WikEdEditButton(\'wikEdFindAll\');">';
if (wpToolbar != null) {
html += '<img class="wikEdButton" src="' + wikEdImage['findPrev'] + '" width="16" height="16" alt="Find prev" title="Find previous match" id="wikEdFindPrev" onClick="javascript:WikEdEditButton(\'wikEdFindPrev\');">';
if (wpToolbar.getElementsByTagName('IMG').length == 0) {
if (mwSetupToolbar != null) {
mwSetupToolbar();
}
window.removeEventListener('load', mwSetupToolbar, false);
}
}
}
 
// add textarea to textarea wrapper
html += '<span id="wikEdFindComboInput">';
wikEdTextareaWrapper.appendChild(wikEdTextarea);
html += '<input class="wikEdCombo" id="wikEdFindText" title="" type="text" value="" onfocus="javascript:this.setSelectionRange(0, this.textLength);">';
html += '<select class="wikEdCombo" id="wikEdFindSelect" onfocus="javascript:WikEdSetComboOptions(\'find\')" onChange="javascript:WikEdChangeComboInput(\'find\');">';
html += '</select>';
html += '</span>';
 
// append edit frame to frame wrapper
html += '<img class="wikEdButton" src="' + wikEdImage['findNext'] + '" width="16" height="16" alt="Find next" title="Find next match" id="wikEdFindNext" onClick="javascript:WikEdEditButton(\'wikEdFindNext\');">';
// DOM changes to a starting iframe in designmode may crash the browser, including DOM move, display: none; and position: absolute;
html += '<img class="wikEdButton" src="' + wikEdImage['jumpTopBottom'] + '" width="16" height="16" alt="Jump up/down" title="Jump to the top / bottom" id="wikEdUpdown" onClick="javascript:WikEdEditButton(\'wikEdUpdown\');">';
html += '<img class="wikEdButtonInactive" src="' + wikEdImage['prevPos'] + '" width="16" height="16" alt="Jump prev" title="Jump to previously changed position" id="wikEdPrevPos" onClick="javascript:WikEdEditButton(\'wikEdPrevPos\');">';
html += '<img class="wikEdButtonInactive" src="' + wikEdImage['lastPos'] + '" width="16" height="16" alt="Jump next" title="Jump back to last position" id="wikEdLastPos" onClick="javascript:WikEdEditButton(\'wikEdLastPos\');">';
html += '<br />';
 
// create the iframe
html = '';
html += '<div id="wikEdFrameOuter">';
html += '<div id="wikEdFrameInner">';
html += '</div>';
html += '<iframe id="wikEdFrame" name="wikEdFrame" style="height: ' + wikEdTextareaHeight + 'px;"></iframe>';
html += '</div>';
html += '</div>';
 
wikEdFrameWrapper.innerHTML = html;
//html += '<img class="wikEdButton" src="' + wikEdImage['getFindReplace'] + '" width="16" height="16" alt="Get find + replace" title="Copy selection to find and replace fields" id="wikEdGetFind" onClick="javascript:WikEdEditButton(\'wikEdGetFindReplace\');">';
wikEdInputWrapper.insertBefore(wikEdFrameWrapper, wikEdTextareaWrapper);
html += '<img class="wikEdButton" src="' + wikEdImage['clearFind'] + '" width="16" height="16" alt="Clear find" title="Clear the find field (to search for selected text)" id="wikEdClearFind" onClick="javascript:WikEdButton(\'wikEdClearFind\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['replaceAll'] + '" width="16" height="16" alt="Replace all" title="Not yet mplemented. Replace all matches in whole text or selection" id="wikEdReplaceAll" onClick="javascript:WikEdEditButton(\'wikEdReplaceAll\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['replacePrev'] + '" width="16" height="16" alt="Replace prev" title="Replace previous match" id="wikEdReplacePrev" onClick="javascript:WikEdEditButton(\'wikEdReplacePrev\');">';
 
// fill the frame with content
html += '<span id="wikEdReplaceComboInput">';
html = '';
html += '<input class="wikEdCombo" id="wikEdReplaceText" title="" type="text" value="" onfocus="this.setSelectionRange(0, this.textLength);">';
html += '<html><head></head>';
html += '<select class="wikEdCombo" id="wikEdReplaceSelect" onfocus="WikEdSetComboOptions(\'replace\')" onChange="javascript:WikEdChangeComboInput(\'replace\');">';
html += '<body id="wikEdFrameBody" onload="window.document.designMode = \'on\'; window.document.execCommand(\'styleWithCSS\', false, false);">';
html += '</select>';
html += '</spanbody></html>';
 
wikEdFrame = document.getElementById('wikEdFrame');
html += '<img class="wikEdButton" src="' + wikEdImage['replaceNext'] + '" width="16" height="16" alt="Replace next" title="Replace next match" id="wikEdReplaceNext" onClick="javascript:WikEdEditButton(\'wikEdReplaceNext\');">';
wikEdFrameWindow = wikEdFrame.contentWindow;
html += '<img class="wikEdButtonUnchecked" src="' + wikEdImage['caseSensitive'] + '" width="16" height="16" alt="Case sensitive" title="Search is case sensitive" id="wikEdCaseSensitive" onClick="javascript:WikEdButton(\'wikEdCaseSensitive\', true);">';
wikEdFrameDocument = wikEdFrameWindow.document;
html += '<img class="wikEdButtonUnchecked" src="' + wikEdImage['regExp'] + '" width="16" height="16" alt="RegExp" title="Search field is a regular expression" id="wikEdRegExp" onClick="javascript:WikEdButton(\'wikEdRegExp\', true);">';
wikEdFrameDocument.open();
html += '<img class="wikEdButtonUnchecked" src="' + wikEdImage['findAhead'] + '" width="16" height="16" alt="Find ahead" title="Find ahead as you type (only for non-regexp searches)" id="wikEdFindAhead" onClick="javascript:WikEdButton(\'wikEdFindAhead\', true);">';
wikEdFrameDocument.write(html);
html += '</div>';
wikEdFrameDocument.close();
wikEdFrameBody = wikEdFrameDocument.body;
 
// fixingadd wikEd buttons to buttons wrapper
html += '<div class="wikEdButtonsFix" id="wikEdButtonsFix">';
 
// format buttons
html += '<img class="wikEdButton" src="' + wikEdImage['fixBasic'] + '" width="16" height="16" alt="Fix basic" title="Fix blanks and empty lines, also done by other fixing functions" id="wikEdFixBasic" onClick="javascript:WikEdEditButton(\'wikEdFixBasic\');">';
html = '';
html += '<img class="wikEdButton" src="' + wikEdImage['fixHtml'] + '" width="16" height="16" alt="Fix html" title="Fix html to wikicode" id="wikEdFixHtml" onClick="javascript:WikEdEditButton(\'wikEdFixHtml\');">';
html += '<div class="wikEdButtonsFormat" id="wikEdButtonsFormat">';
html += '<img class="wikEdButton" src="' + wikEdImage['fixCaps'] + '" width="16" height="16" alt="Fix caps" title="Fix caps in headers and lists" id="wikEdFixCaps" onClick="javascript:WikEdEditButton(\'wikEdFixCaps\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['fixUnicode'] + '" width="16" height="16" alt="Fix Unicode" title="Fix Unicode character representations" id="wikEdfixUnicode" onClick="javascript:WikEdEditButton(\'wikEdfixUnicode\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['fixAll'] + '" width="16" height="16" alt="Fix all" title="Fix basic, html, capitalization, and Unicode" id="wikEdFixAll" onClick="javascript:WikEdEditButton(\'wikEdFixAll\');">';
html += '<br />';
 
html += '<img class="wikEdButtonwikEdButtonInactive" src="' + wikEdImage['fixDashundo'] + '" width="16" height="16" alt="Fix dashesUndo" title="Fix dashesUndo" id="wikEdFixDasheswikEdUndo" onClick="javascript:WikEdEditButton(\'wikEdFixDasheswikEdUndo\');">';
html += '<img class="wikEdButtonwikEdButtonInactive" src="' + wikEdImage['fixPunctredo'] + '" width="16" height="16" alt="Fix puntuationRedo" title="FixRedo" spaces before puntuation" id="wikEdFixPunctwikEdRedo" onClick="javascript:WikEdEditButton(\'wikEdFixPunctwikEdRedo\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['fixMathbold'] + '" width="16" height="16" alt="Fix mathBold" title="FixBold mathtext" id="wikEdFixMathwikEdBold" onClick="javascript:WikEdEditButton(\'wikEdFixMathwikEdBold\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['fixChemitalic'] + '" width="16" height="16" alt="Fix chemItalic" title="Fix chemicalItalic formulastext" id="wikEdFixChemwikEdItalic" onClick="javascript:WikEdEditButton(\'wikEdFixChemwikEdItalic\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['fixUnitsunderline'] + '" width="16" height="16" alt="Fix unitsUnderline" title="FixUnderline unitstext" id="wikEdFixUnitswikEdUnderline" onClick="javascript:WikEdEditButton(\'wikEdFixUnitswikEdUnderline\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['strikethrough'] + '" width="16" height="16" alt="Strikethrough" title="Strikethrough text" id="wikEdStrikethrough" onClick="javascript:WikEdEditButton(\'wikEdStrikethrough\');">';
html += '</div>';
html += '<img class="wikEdButton" src="' + wikEdImage['nowiki'] + '" width="16" height="16" alt="Nowiki" title="Nowiki markup text" id="wikEdNowiki" onClick="javascript:WikEdEditButton(\'wikEdNowiki\');">';
html += '<br style="clear: both;">';
html += '<img class="wikEdButton" src="' + wikEdImage['superscript'] + '" width="16" height="16" alt="Superscript" title="Superscript text" id="wikEdSuperscript" onClick="javascript:WikEdEditButton(\'wikEdSuperscript\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['subscript'] + '" width="16" height="16" alt="Subscript" title="Subscript text" id="wikEdSubscript" onClick="javascript:WikEdEditButton(\'wikEdSubscript\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['case'] + '" width="16" height="16" alt="Case" title="Toggle between lowercase, uppercase first, and uppercase" id="wikEdCase" onClick="javascript:WikEdEditButton(\'wikEdCase\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['undoAll'] + '" width="16" height="16" alt="Undo all" title="Undo all changes" id="wikEdUndoAll" onClick="javascript:WikEdEditButton(\'wikEdUndoAll\');">';
html += '<img class="wikEdButtonInactive" src="' + wikEdImage['redoAll'] + '" width="16" height="16" alt="Redo all" title="Redo all changes" id="wikEdRedoAll" onClick="javascript:WikEdEditButton(\'wikEdRedoAll\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['updateSyntax'] + '" width="16" height="16" alt="Syntax" title="Update syntax highlighting" id="wikEdUpdateSyntax" onClick="javascript:WikEdEditButton(\'wikEdUpdateSyntax\');">';
html += '<br />';
 
html += '<img class="wikEdButton" src="' + wikEdImage['wikiLink'] + '" width="16" height="16" alt="Link" title="Wiki link" id="wikEdWikiLink" onClick="javascript:WikEdEditButton(\'wikEdWikiLink\');">';
wikEdButtons.innerHTML = html;
html += '<img class="wikEdButton" src="' + wikEdImage['webLink'] + '" width="16" height="16" alt="Weblink" title="External weblink" id="wikEdWebLink" onClick="javascript:WikEdEditButton(\'wikEdWebLink\');">';
buttonsWrapper.appendChild(wikEdButtons);
html += '<img class="wikEdButton" src="' + wikEdImage['decreaseHeading'] + '" width="16" height="16" alt="Heading-" title="Decrease heading levels" id="wikEdDecreaseHeading" onClick="javascript:WikEdEditButton(\'wikEdDecreaseHeading\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['increaseHeading'] + '" width="16" height="16" alt="Heading+" title="Increase heading levels" id="wikEdIncreaseHeading" onClick="javascript:WikEdEditButton(\'wikEdIncreaseHeading\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['bulletList'] + '" width="16" height="16" alt="Bullet list" title="Bulleted list" id="wikEdBulletList" onClick="javascript:WikEdEditButton(\'wikEdBulletList\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['numberList'] + '" width="16" height="16" alt="Number list" title="Numbered list" id="wikEdNumberList" onClick="javascript:WikEdEditButton(\'wikEdNumberList\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['indentList'] + '" width="16" height="16" alt="Indent list" title="Indented list" id="wikEdIndentList" onClick="javascript:WikEdEditButton(\'wikEdIndentList\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['definitionList'] + '" width="16" height="16" alt="Def list" title="Definition list" id="wikEdDefinitionList" onClick="javascript:WikEdEditButton(\'wikEdDefinitionList\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['image'] + '" width="16" height="16" alt="Image" title="Image" id="wikEdImage" onClick="javascript:WikEdEditButton(\'wikEdImage\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['table'] + '" width="16" height="16" alt="Table" title="Table" id="wikEdTable" onClick="javascript:WikEdEditButton(\'wikEdTable\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['redirect'] + '" width="16" height="16" alt="Redirect" title="Create redirect, deletes whole text" id="wikEdRedirect" onClick="javascript:WikEdEditButton(\'wikEdRedirect\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['wikify'] + '" width="16" height="16" alt="Wikify" title="Wikify pasted content" id="wikEdWikify" onClick="javascript:WikEdEditButton(\'wikEdWikify\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['textify'] + '" width="16" height="16" alt="Textify" title="Convert pasted content to plain text" id="wikEdTextify" onClick="javascript:WikEdEditButton(\'wikEdTextify\');">';
html += '</div>';
 
// set wikEd control buttons
html += '<div class="wikEdButtonsControl" id="wikEdButtonsControl">';
// add elements to buttonsWrapper
html += '<img class="wikEdButton" src="' + wikEdImage['textZoom'] + '" width="16" height="16" alt="Text zoom" title="Text zoom cycling" id="wikEdTextZoom" onClick="javascript:WikEdButton(\'wikEdTextZoom\');">';
var element = document.getElementById('editpage-copywarn');
html += '<img class="wikEdButton" src="' + wikEdImage['clearHistory'] + '" width="16" height="16" alt="Clear history" title="Clear the find, replace, and summary history" id="wikEdClearHistory" onClick="javascript:WikEdButton(\'wikEdClearHistory\');">';
while (element != null) {
html += '<img class="wikEdButton" src="' + wikEdImage['scrollToButtons'] + '" width="16" height="16" alt="Scroll buttons" title="Scroll to edit buttons" id="wikEdScrollToButtons" onClick="javascript:WikEdButton(\'wikEdScrollToButtons\');">';
if (element.id == 'editpage-specialchars') {
html += '<img class="wikEdButton" src="' + wikEdImage['scrollToText'] + '" width="16" height="16" alt="Scroll up" title="Scroll to edit window" id="wikEdScrollToInput" onClick="javascript:WikEdButton(\'wikEdScrollToInput\');">';
break;
html += '<br />';
}
next_element = element.nextSibling;
buttonsWrapper.appendChild(element);
element = next_element;
}
 
html += '<img class="wikEdButtonChecked" src="' + wikEdImage['useWikEd'] + '" width="16" height="16" alt="Use wikEd" title="Toggle between classic text area and wikEd" id="wikEdUseWikEd" onClick="javascript:WikEdButton(\'wikEdUseWikEd\', true);">';
// add preview box upper buttons
html += '<img class="wikEdButtonUnchecked" src="' + wikEdImage['highlightSyntax'] + '" width="16" height="16" alt="Syntax" title="Toggle automatic syntax highlighting" id="wikEdHighlightSyntax" onClick="javascript:WikEdButton(\'wikEdHighlightSyntax\', true);">';
var buttonsPreview = document.createElement('div');
if (wikEdShowSourceButton == true) {
buttonsPreview.id = 'wikEdButtonsPreview';
html += '<img class="wikEdButton" src="' + wikEdImage['source'] + '" width="16" height="16" alt="Source" title="Show the source code for testing purposes" id="wikEdSource" onClick="javascript:WikEdEditButton(\'wikEdSource\');">';
buttonsPreview.className = 'wikEdButtonsPreview';
}
html += '<img class="wikEdButton" src="' + wikEdImage['fullScreen'] + '" width="16" height="16" alt="Fullscreen" title="Toggle the fullscreen mode" id="wikEdFullScreen" onClick="javascript:WikEdButton(\'wikEdFullScreen\', true);">';
html += '</div>';
 
// find / replace buttons
html = '';
html += '<div class="wikEdButtonsFind" id="wikEdButtonsFind">';
html += '<img class="wikEdButton" src="' + wikEdImage['preview'] + '" width="16" height="16" alt="Preview" title="Show preview below" id="wikEdPreview" onClick="javascript:WikEdButton(\'wikEdPreview\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['diff'] + '" width="16" height="16" alt="Changes" title="Show current changes below" id="wikEdDiff" onClick="javascript:WikEdButton(\'wikEdDiff\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['close'] + '" width="16" height="16" alt="Close" title="Close preview box" id="wikEdClose" onClick="javascript:WikEdButton(\'wikEdClose\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['scrollToButtons'] + '" width="16" height="16" alt="Scroll buttons" title="Scroll to edit buttons" id="wikEdScrollToButtons2" onClick="javascript:WikEdButton(\'wikEdScrollToButtons2\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['scrollToText'] + '" width="16" height="16" alt="Scroll up" title="Scroll to edit window" id="wikEdScrollToInput2" onClick="javascript:WikEdButton(\'wikEdScrollToInput2\');">';
 
html += '<img class="wikEdButton" src="' + wikEdImage['getFind'] + '" width="16" height="16" alt="Get find" title="Copy selection to find field (double click: copy selection to find and to replace field)" id="wikEdGetFind" onClick="javascript:WikEdEditButton(\'wikEdGetFind\');" ondblclick="javascript:WikEdEditButton(\'wikEdGetFindReplace\');">';
buttonsPreview.innerHTML = html;
html += '<img class="wikEdButton" src="' + wikEdImage['findAll'] + '" width="16" height="16" alt="Find all" title="Not yet implemented. Find all matches in whole text or selection" id="wikEdFindAll" onClick="javascript:WikEdEditButton(\'wikEdFindAll\');">';
document.getElementById('wpSave').parentNode.insertBefore(buttonsPreview, document.getElementById('wpSave').parentNode.firstChild);
html += '<img class="wikEdButton" src="' + wikEdImage['findPrev'] + '" width="16" height="16" alt="Find prev" title="Find previous match" id="wikEdFindPrev" onClick="javascript:WikEdEditButton(\'wikEdFindPrev\');">';
 
html += '<span id="wikEdFindComboInput">';
// add preview box
html += '<input class="wikEdCombo" id="wikEdFindText" title="" type="text" value="" onfocus="javascript:this.setSelectionRange(0, this.textLength);">';
var previewBox = document.createElement('div');
html += '<select class="wikEdCombo" id="wikEdFindSelect" onfocus="javascript:WikEdSetComboOptions(\'find\')" onChange="javascript:WikEdChangeComboInput(\'find\');">';
previewBox.id = 'customPreviewBox';
html += '</select>';
previewBox.style.display = 'none';
html += '</span>';
 
html += '<img class="wikEdButton" src="' + wikEdImage['findNext'] + '" width="16" height="16" alt="Find next" title="Find next match" id="wikEdFindNext" onClick="javascript:WikEdEditButton(\'wikEdFindNext\');">';
html = '';
html += '<img class="wikEdButton" src="' + wikEdImage['jumpTopBottom'] + '" width="16" height="16" alt="Jump up/down" title="Jump to the top / bottom" id="wikEdUpdown" onClick="javascript:WikEdEditButton(\'wikEdUpdown\');">';
html += '<div id="wikEdPreviewBoxOuter">';
html += '<img class="wikEdButtonInactive" src="' + wikEdImage['prevPos'] + '" width="16" height="16" alt="Jump prev" title="Jump to previously changed position" id="wikEdPrevPos" onClick="javascript:WikEdEditButton(\'wikEdPrevPos\');">';
html += '<div class="wikEdPreviewBox" id="wikEdPreviewBox">';
html += '<img class="wikEdButtonInactive" src="' + wikEdImage['lastPos'] + '" width="16" height="16" alt="Jump next" title="Jump back to last position" id="wikEdLastPos" onClick="javascript:WikEdEditButton(\'wikEdLastPos\');">';
html += '</div>';
html += '<br /div>';
 
//html += '<img class="wikEdButton" src="' + wikEdImage['getFindReplace'] + '" width="16" height="16" alt="Get find + replace" title="Copy selection to find and replace fields" id="wikEdGetFind" onClick="javascript:WikEdEditButton(\'wikEdGetFindReplace\');">';
html += '<div id="wikEdButtonsWindow" class="wikEdButtonsWindow">';
html += '<img class="wikEdButton" src="' + wikEdImage['previewclearFind'] + '" width="16" height="16" alt="PreviewClear find" title="Show preview above" Clear the find field (to search for selected text)" id="wikEdPreview2wikEdClearFind" onClick="javascript:WikEdButton(\'wikEdPreview2wikEdClearFind\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['diffreplaceAll'] + '" width="16" height="16" alt="ChangesReplace all" title="Show current changes above" Not yet mplemented. Replace all matches in whole text or selection" id="wikEdDiff2wikEdReplaceAll" onClick="javascript:WikEdButtonWikEdEditButton(\'wikEdDiff2wikEdReplaceAll\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['closereplacePrev'] + '" width="16" height="16" alt="CloseReplace prev" title="CloseReplace previewprevious boxmatch" id="wikEdClose2wikEdReplacePrev" onClick="javascript:WikEdButtonWikEdEditButton(\'wikEdClose2wikEdReplacePrev\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['scrollToButtons'] + '" width="16" height="16" alt="Scroll buttons" title="Scroll to edit buttons" id="wikEdScrollToButtons3" onClick="javascript:WikEdButton(\'wikEdScrollToButtons3\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['scrollToText'] + '" width="16" height="16" alt="Scroll up" title="Scroll to edit window" id="wikEdScrollToInput3" onClick="javascript:WikEdButton(\'wikEdScrollToInput3\');">';
html += '</div>';
 
html += '<span id="wikEdReplaceComboInput">';
previewBox.innerHTML = html;
html += '<input class="wikEdCombo" id="wikEdReplaceText" title="" type="text" value="" onfocus="this.setSelectionRange(0, this.textLength);">';
inputWrapper.parentNode.insertBefore(previewBox, inputWrapper.nextSibling);
html += '<select class="wikEdCombo" id="wikEdReplaceSelect" onfocus="WikEdSetComboOptions(\'replace\')" onChange="javascript:WikEdChangeComboInput(\'replace\');">';
html += '</select>';
html += '</span>';
 
html += '<img class="wikEdButton" src="' + wikEdImage['replaceNext'] + '" width="16" height="16" alt="Replace next" title="Replace next match" id="wikEdReplaceNext" onClick="javascript:WikEdEditButton(\'wikEdReplaceNext\');">';
// initialize image buttons
html += '<img class="wikEdButtonUnchecked" src="' + wikEdImage['caseSensitive'] + '" width="16" height="16" alt="Case sensitive" title="Search is case sensitive" id="wikEdCaseSensitive" onClick="javascript:WikEdButton(\'wikEdCaseSensitive\', true);">';
WikEdButton('wikEdSource', null, false);
html += '<img class="wikEdButtonUnchecked" src="' + wikEdImage['regExp'] + '" width="16" height="16" alt="RegExp" title="Search field is a regular expression" id="wikEdRegExp" onClick="javascript:WikEdButton(\'wikEdRegExp\', true);">';
WikEdButton('wikEdHighlightSyntax', null, wikEdHighlightSyntax);
html += '<img class="wikEdButtonUnchecked" src="' + wikEdImage['findAhead'] + '" width="16" height="16" alt="Find ahead" title="Find ahead as you type (only for non-regexp searches)" id="wikEdFindAhead" onClick="javascript:WikEdButton(\'wikEdFindAhead\', true);">';
WikEdButton('wikEdUseWikEd', null, useWikEd);
html += '</div>';
WikEdButton('wikEdFullScreen', null, false);
WikEdButton('wikEdCaseSensitive', null, false);
WikEdButton('wikEdRegExp', null, false);
WikEdButton('wikEdFindAhead', null, wikEdFindAheadSelected);
WikEdButton('wikEdPreview', null, false, 'wikEdButton');
WikEdButton('wikEdDiff', null, false, 'wikEdButton');
WikEdButton('wikEdClose', null, false, 'wikEdButton');
WikEdButton('wikEdPreview2', null, false, 'wikEdButton');
WikEdButton('wikEdDiff2', null, false, 'wikEdButton');
WikEdButton('wikEdClose2', null, false, 'wikEdButton');
 
// fixing buttons
// add local preview button next to submit button
html += '<div class="wikEdButtonsFix" id="wikEdButtonsFix">';
var localPreview = document.createElement('button');
localPreview.type = 'button';
localPreview.id = 'wikEdLocalPreview';
localPreview.title = 'Show preview below';
localPreview.className = 'wikEdLocalPreview';
 
html += '<img class="wikEdButton" src="' + wikEdImage['fixBasic'] + '" width="16" height="16" alt="Fix basic" title="Fix blanks and empty lines, also done by other fixing functions" id="wikEdFixBasic" onClick="javascript:WikEdEditButton(\'wikEdFixBasic\');">';
var localPreviewImg = document.createElement('img');
html += '<img class="wikEdButton" src="' + wikEdImage['fixHtml'] + '" width="16" height="16" alt="Fix html" title="Fix html to wikicode" id="wikEdFixHtml" onClick="javascript:WikEdEditButton(\'wikEdFixHtml\');">';
localPreviewImg.id = 'wikEdLocalPreviewImg';
html += '<img class="wikEdButton" src="' + wikEdImage['fixCaps'] + '" width="16" height="16" alt="Fix caps" title="Fix caps in headers and lists" id="wikEdFixCaps" onClick="javascript:WikEdEditButton(\'wikEdFixCaps\');">';
localPreviewImg.src = wikEdImage['preview'];
html += '<img class="wikEdButton" src="' + wikEdImage['fixUnicode'] + '" width="16" height="16" alt="Fix Unicode" title="Fix Unicode character representations" id="wikEdfixUnicode" onClick="javascript:WikEdEditButton(\'wikEdfixUnicode\');">';
localPreviewImg.alt = 'Preview below';
html += '<img class="wikEdButton" src="' + wikEdImage['fixAll'] + '" width="16" height="16" alt="Fix all" title="Fix basic, html, capitalization, and Unicode" id="wikEdFixAll" onClick="javascript:WikEdEditButton(\'wikEdFixAll\');">';
html += '<br />';
 
html += '<img class="wikEdButton" src="' + wikEdImage['fixDash'] + '" width="16" height="16" alt="Fix dashes" title="Fix dashes" id="wikEdFixDashes" onClick="javascript:WikEdEditButton(\'wikEdFixDashes\');">';
localPreview.appendChild(localPreviewImg);
html += '<img class="wikEdButton" src="' + wikEdImage['fixPunct'] + '" width="16" height="16" alt="Fix puntuation" title="Fix spaces before puntuation" id="wikEdFixPunct" onClick="javascript:WikEdEditButton(\'wikEdFixPunct\');">';
var previewButton = document.getElementById('wpPreview');
html += '<img class="wikEdButton" src="' + wikEdImage['fixMath'] + '" width="16" height="16" alt="Fix math" title="Fix math" id="wikEdFixMath" onClick="javascript:WikEdEditButton(\'wikEdFixMath\');">';
previewButton.parentNode.insertBefore(localPreview, previewButton.nextSibling);
html += '<img class="wikEdButton" src="' + wikEdImage['fixChem'] + '" width="16" height="16" alt="Fix chem" title="Fix chemical formulas" id="wikEdFixChem" onClick="javascript:WikEdEditButton(\'wikEdFixChem\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['fixUnits'] + '" width="16" height="16" alt="Fix units" title="Fix units" id="wikEdFixUnits" onClick="javascript:WikEdEditButton(\'wikEdFixUnits\');">';
html += '</div>';
html += '<br style="clear: both;">';
 
// add local diff button nexthtml to submitbuttons buttonwrapper
wikEdButtonsWrapper.innerHTML = html;
var localDiff = document.createElement('button');
wikEdButtonsFormat = document.getElementById('wikEdButtonsFormat');
localDiff.type = 'button';
wikEdButtonsFind = document.getElementById('wikEdButtonsFind');
localDiff.id = 'wikEdLocalDiff';
wikEdButtonsFix = document.getElementById('wikEdButtonsFix');
localDiff.title = 'Show current changes below';
wikEdButtonsControl = document.getElementById('wikEdButtonsControl');
localDiff.className = 'wikEdLocalDiff';
wikEdCaseSensitive = document.getElementById('wikEdCaseSensitive');
wikEdRegExp = document.getElementById('wikEdRegExp');
wikEdFindAhead = document.getElementById('wikEdFindAhead');
wikEdFindText = document.getElementById('wikEdFindText');
wikEdReplaceText = document.getElementById('wikEdReplaceText');
 
// add summary elements to summary wrapper
var localDiffImg = document.createElement('img');
var summaryLabel = document.getElementById('wpSummaryLabel');
localDiffImg.id = 'wikEdLocalDiffImg';
wikEdSummaryWrapper.appendChild(summaryLabel);
localDiffImg.src = wikEdImage['diff'];
localDiffImg.alt = 'Changes below';
 
wikEdSummaryText = document.getElementById('wpSummary');
localDiff.appendChild(localDiffImg);
wikEdSummaryWrapper.appendChild(wikEdSummaryText);
var previewButton = document.getElementById('wpDiff');
previewButton.parentNode.insertBefore(localDiff, previewButton.nextSibling);
 
//crasher: editOptions can't be appended to anything without crash
// move linebreak before checkboxes down
var summaryeditOptions = document.getElementById('wpSummarywpMinoredit').parentNode;
wikEdSummaryWrapper.appendChild(editOptions);
var checkboxSep = document.createTextNode('');
summary.parentNode.replaceChild(checkboxSep, summary.nextSibling);
 
// add submit buttons to submit wrapper
// add summary wrapper before wpSummaryLabel and add all summary elements into it
var summaryWrapperwpEditButtons = document.createElementgetElementById('divwpSave').parentNode;
wikEdSubmitWrapper.appendChild(wpEditButtons);
summaryWrapper.id = 'wikEdSummaryWrapper';
var summaryLabel = document.getElementById('wpSummaryLabel');
summaryLabel.parentNode.insertBefore(summaryWrapper, summaryLabel);
 
// add preview box top bar to submit wrapper
var summary = document.getElementById('wpSummary');
var buttonsPreview = document.createElement('div');
summaryWrapper.appendChild(summaryLabel);
buttonsPreview.id = 'wikEdButtonsPreview';
summaryWrapper.appendChild(summaryLabel);
buttonsPreview.className = 'wikEdButtonsPreview';
var summary = document.getElementById('wpSummary');
summaryWrapper.appendChild(summary);
 
html = '';
var editButtons = document.getElementById('wpSave').parentNode;
html += '<img class="wikEdButton" src="' + wikEdImage['preview'] + '" width="16" height="16" alt="Preview" title="Show preview below" id="wikEdPreview" onClick="javascript:WikEdButton(\'wikEdPreview\');">';
summaryWrapper.parentNode.insertBefore(editButtons, summaryWrapper.nextSibling);
html += '<img class="wikEdButton" src="' + wikEdImage['diff'] + '" width="16" height="16" alt="Changes" title="Show current changes below" id="wikEdDiff" onClick="javascript:WikEdButton(\'wikEdDiff\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['close'] + '" width="16" height="16" alt="Close" title="Close preview box" id="wikEdClose" onClick="javascript:WikEdButton(\'wikEdClose\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['scrollToButtons'] + '" width="16" height="16" alt="Scroll buttons" title="Scroll to edit buttons" id="wikEdScrollToButtons2" onClick="javascript:WikEdButton(\'wikEdScrollToButtons2\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['scrollToText'] + '" width="16" height="16" alt="Scroll up" title="Scroll to edit window" id="wikEdScrollToInput2" onClick="javascript:WikEdButton(\'wikEdScrollToInput2\');">';
 
buttonsPreview.innerHTML = html;
var editOptions = document.getElementById('wpMinoredit').parentNode;
summaryWrapper wikEdSubmitWrapper.appendChild(editOptionsbuttonsPreview);
// var summaryLabel wikEdButtonsPreview = document.getElementById('wpSummaryLabelwikEdButtonsPreview');
// summaryLabel.parentNode.insertBefore(summarySeparator, summaryLabel);
 
// add preview box and its bottom bar to preview wrapper
// add a clear summary button left
html = '';
var summary = document.getElementById('wpSummary');
html += '<div id="wikEdPreviewBoxOuter" class="wikEdPreviewBoxOuter">';
var clearSummary = document.createElement('button');
html += '<div id="wikEdPreviewBox" class="wikEdPreviewBox">';
clearSummary.type = 'button';
html += '</div>';
clearSummary.id = 'wikEdClearSummary';
html += '</div>';
clearSummary.title = 'Clear the summary field';
clearSummary.className = 'wikEdClearSummary';
clearSummary.style.height = (summary.clientHeight + 1) +'px';
clearSummary.onclick = function() {
var summary = document.getElementById('wpSummary');
summary.value = '';
return;
}
var clearSummaryImg = document.createElement('img');
clearSummaryImg.id = 'wikEdClearSummaryImg';
clearSummaryImg.src = wikEdImage['clearSummary'];
clearSummaryImg.alt = 'Clear summary';
 
html += '<div id="wikEdButtonsPreview2" class="wikEdButtonsPreview2">';
clearSummary.appendChild(clearSummaryImg);
html += '<img class="wikEdButton" src="' + wikEdImage['preview'] + '" width="16" height="16" alt="Preview" title="Show preview above" id="wikEdPreview2" onClick="javascript:WikEdButton(\'wikEdPreview2\');">';
summary.parentNode.insertBefore(clearSummary, summary);
html += '<img class="wikEdButton" src="' + wikEdImage['diff'] + '" width="16" height="16" alt="Changes" title="Show current changes above" id="wikEdDiff2" onClick="javascript:WikEdButton(\'wikEdDiff2\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['close'] + '" width="16" height="16" alt="Close" title="Close preview box" id="wikEdClose2" onClick="javascript:WikEdButton(\'wikEdClose2\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['scrollToButtons'] + '" width="16" height="16" alt="Scroll buttons" title="Scroll to edit buttons" id="wikEdScrollToButtons3" onClick="javascript:WikEdButton(\'wikEdScrollToButtons3\');">';
html += '<img class="wikEdButton" src="' + wikEdImage['scrollToText'] + '" width="16" height="16" alt="Scroll up" title="Scroll to edit window" id="wikEdScrollToInput3" onClick="javascript:WikEdButton(\'wikEdScrollToInput3\');">';
html += '</div>';
 
wikEdPreviewWrapper.innerHTML = html;
// make the summary a combo box
wikEdPreviewBox = document.getElementById('wikEdPreviewBox');
wikEdButtonsPreview2 = document.getElementById('wikEdButtonsPreview2');
 
// add insert special chars to insert wrapper
// style needs to be declared here so that it is not overridden by monobook.css
var wpSpecialchars = document.getElementById('editpage-specialchars');
summary.style.width = 'auto';
wikEdInsertWrapper.appendChild(wpSpecialchars);
 
// wrappers filled
var summaryComboInput = document.createElement('span');
summaryComboInput.id = 'summaryComboInput';
 
// display only the textarea or the iframe
var summarySelect = document.createElement('select');
if (useWikEd == true) {
summarySelect.id = 'wpSummarySelect';
WikEdSetEditArea(true);
summarySelect.onchange = function() {
}
WikEdChangeComboInput('summary');
else {
}
WikEdSetEditArea(false);
summarySelect.onfocus = function() {
}
WikEdSetComboOptions('summary');
}
 
// add local preview button next to submit button
summaryComboInput = summary.parentNode.insertBefore(summaryComboInput, summary);
var localPreview = document.createElement('button');
summaryComboInput.appendChild(summary);
localPreview.type = 'button';
summaryComboInput.appendChild(summarySelect);
localPreview.id = 'wikEdLocalPreview';
localPreview.title = 'Show preview below';
localPreview.className = 'wikEdLocalPreview';
 
var localPreviewImg = document.createElement('img');
// move copywarn down
localPreviewImg.id = 'wikEdLocalPreviewImg';
var specialchars = document.getElementById('editpage-specialchars');
localPreviewImg.src = wikEdImage['preview'];
var copywarn = document.getElementById('editpage-copywarn');
localPreviewImg.alt = 'Preview below';
var copywarn2 = document.getElementById('editpage-copywarn2');
var copywarn3 = document.getElementById('editpage-copywarn3');
specialchars.parentNode.insertBefore(copywarn3, specialchars.nextSibling);
specialchars.parentNode.insertBefore(copywarn2, specialchars.nextSibling);
specialchars.parentNode.insertBefore(copywarn, specialchars);
 
localPreview.appendChild(localPreviewImg);
// shorten submit button texts and add onclick handler
var previewButton = document.getElementById('wpPreview').value = 'Preview';
previewButton.parentNode.insertBefore(localPreview, previewButton.nextSibling);
document.getElementById('wpDiff').value = 'Changes';
 
// add local diff button next to submit button
// set up combo input boxes with history
var localDiff = document.createElement('button');
wikEdFieldHist ['find'] = [];
localDiff.type = 'button';
wikEdCookieName['find'] = 'findHistory';
localDiff.id = 'wikEdLocalDiff';
wikEdInputElement['find'] = new Object(document.getElementById('wikEdFindText'));
localDiff.title = 'Show current changes below';
wikEdSelectElement['find'] = new Object(document.getElementById('wikEdFindSelect'));
localDiff.className = 'wikEdLocalDiff';
wikEdSelectElement['find'].style.height = (wikEdInputElement['find'].clientHeight + 1) +'px';
 
var localDiffImg = document.createElement('img');
wikEdFieldHist ['replace'] = [];
localDiffImg.id = 'wikEdLocalDiffImg';
wikEdCookieName['replace'] = 'replaceHistory';
localDiffImg.src = wikEdImage['diff'];
wikEdInputElement['replace'] = new Object(document.getElementById('wikEdReplaceText'));
localDiffImg.alt = 'Changes below';
wikEdSelectElement['replace'] = new Object(document.getElementById('wikEdReplaceSelect'));
wikEdSelectElement['replace'].style.height = (wikEdInputElement['replace'].clientHeight + 1) +'px';
 
localDiff.appendChild(localDiffImg);
wikEdFieldHist ['summary'] = [];
var previewButton = document.getElementById('wpDiff');
wikEdCookieName['summary'] = 'summaryHistory';
previewButton.parentNode.insertBefore(localDiff, previewButton.nextSibling);
wikEdInputElement['summary'] = new Object(document.getElementById('wpSummary'));
wikEdSelectElement['summary'] = new Object(document.getElementById('wpSummarySelect'));
wikEdSelectElement['summary'].style.height = (wikEdInputElement['summary'].clientHeight + 1) +'px';
WikEdResizeComboInput('find');
WikEdResizeComboInput('replace');
WikEdResizeComboInput('summary');
 
// initialize image buttons
// move globalWrapper elements to new subGlobalWrapper
WikEdButton('wikEdSource', null, false);
var globalWrapper = document.getElementById('globalWrapper');
WikEdButton('wikEdHighlightSyntax', null, wikEdHighlightSyntax);
var subGlobalWrapper = document.createElement('div');
WikEdButton('wikEdUseWikEd', null, useWikEd);
subGlobalWrapper.id = 'subGlobalWrapper';
WikEdButton('wikEdFullScreen', null, false);
globalWrapper.appendChild(subGlobalWrapper);
WikEdButton('wikEdCaseSensitive', null, false);
var element = globalWrapper.firstChild;
WikEdButton('wikEdRegExp', null, false);
while (element != null) {
WikEdButton('wikEdFindAhead', null, wikEdFindAheadSelected);
if (element.id == 'subGlobalWrapper') {
WikEdButton('wikEdPreview', null, false, 'wikEdButton');
break;
WikEdButton('wikEdDiff', null, false, 'wikEdButton');
}
WikEdButton('wikEdClose', null, false, 'wikEdButton');
next_element = element.nextSibling;
WikEdButton('wikEdPreview2', null, false, 'wikEdButton');
subGlobalWrapper.appendChild(element);
WikEdButton('wikEdDiff2', null, false, 'wikEdButton');
element = next_element;
WikEdButton('wikEdClose2', null, false, 'wikEdButton');
}
 
// remove linebreak before checkbox
// DOM changes to a starting iframe in designmode may crash the browser including display: none; and position: absolute;
var wpMinoredit = document.getElementById('wpMinoredit');
var node = wpMinoredit.previousSibling;
while (node != null) {
if (node.tagName == 'BR') {
node.parentNode.removeChild(node);
break;
}
node = node.previousSibling;
}
 
// add a clear summary button left to the summary input field
// prepare for the textarea / iframe switch
var frameWrapperclearSummary = document.createElement('divbutton');
clearSummary.type = 'button';
frameWrapper.id = 'frameWrapper';
clearSummary.id = 'wikEdClearSummary';
var textareaWrapper = document.getElementById('wikEdTextareaWrapper');
clearSummary.className = 'wikEdClearSummary';
clearSummary.alt = 'Clear summary';
clearSummary.title = 'Clear the summary field';
clearSummary.style.height = (wikEdSummaryText.clientHeight + 1) +'px';
 
// clear the summary onclick function
// hide textarea or iframe behind anything else in absolute position mode
clearSummary.onclick = function() {
textareaWrapper.style.zIndex = '-100';
frameWrapper.style.zIndex = '-100';
 
// clear the summary if it is only a paragraph name
// display only the textarea or the iframe
if ( /^\/\* .*? \*\/ *$/.test(wikEdSummaryText.value) ) {
if (useWikEd == true) {
wikEdSummaryText.value = '';
textareaWrapper.style.position = 'absolute';
}
frameWrapper.style.position = 'static';
if (document.getElementById('toolbar') != null) {
if (wikEdShowToolbar != true) {
document.getElementById('toolbar').style.display = 'none';
}
}
document.getElementById('wikEdButtonsFormat').style.display = 'block';
document.getElementById('wikEdButtonsFind').style.display = 'block';
document.getElementById('wikEdButtonsFix').style.display = 'block';
document.getElementById('wikEdButtonsWindow').style.display = 'block';
}
else {
frameWrapper.style.position = 'absolute';
textareaWrapper.style.position = 'static';
if (document.getElementById('toolbar') != null) {
document.getElementById('toolbar').style.display = 'block';
}
document.getElementById('wikEdButtonsFormat').style.display = 'none';
document.getElementById('wikEdButtonsFind').style.display = 'none';
document.getElementById('wikEdButtonsFix').style.display = 'none';
document.getElementById('wikEdButtonsWindow').style.display = 'block';
}
 
// clear the summary but leave paragraph names
// create the iframe
else {
html = '';
wikEdSummaryText.value = wikEdSummaryText.value.replace(/^((\/\* .*? \*\/ )?).*/, '$1');
html += '<div id="wikEdFrameOuter">';
}
html += '<div id="wikEdFrameInner">';
return;
html += '</div>';
}
html += '<iframe id="wikEdFrame" name="wikEdFrame" style="height: ' + textareaHeight + 'px;"></iframe>';
var clearSummaryImg = document.createElement('img');
html += '</div>';
clearSummaryImg.id = 'wikEdClearSummaryImg';
html += '</div>';
clearSummaryImg.src = wikEdImage['clearSummary'];
clearSummaryImg.alt = 'Clear summary';
clearSummary.appendChild(clearSummaryImg);
wikEdSummaryText.parentNode.insertBefore(clearSummary, wikEdSummaryText);
 
// make the summary a combo box
frameWrapper.innerHTML = html;
inputWrapper.insertBefore(frameWrapper, textareaWrapper);
 
// style needs to be declared here so that it is not overridden by monobook.css
wikEdFrameWindow = document.getElementById('wikEdFrame').contentWindow;
wikEdSummaryText.style.width = 'auto';
wikEdFrameDocument = wikEdFrameWindow.document;
 
var summaryComboInput = document.createElement('span');
// fill the frame with content
summaryComboInput.id = 'wikEdSummaryComboInput';
html = '';
html += '<html><head></head>';
html += '<body id="wikEdFrameBody" onload="window.document.designMode = \'on\'; window.document.execCommand(\'styleWithCSS\', false, false);">';
html += '</body></html>';
wikEdFrameDocument.open();
wikEdFrameDocument.write(html);
wikEdFrameDocument.close();
wikEdFrameBody = wikEdFrameDocument.body;
 
var summarySelect = document.createElement('select');
// copy the textarea content to the iframe
summarySelect.id = 'wpSummarySelect';
if (useWikEd == true) {
summarySelect.onchange = function() {
WikEdUpdateFrame();
WikEdChangeComboInput('summary');
}
}
summarySelect.onfocus = function() {
WikEdSetComboOptions('summary');
}
 
summaryComboInput = wikEdSummaryText.parentNode.insertBefore(summaryComboInput, wikEdSummaryText);
summaryComboInput.appendChild(wikEdSummaryText);
summaryComboInput.appendChild(summarySelect);
 
// shorten submit button texts and add onclick handler
document.getElementById('wpPreview').value = 'Preview';
document.getElementById('wpDiff').value = 'Changes';
 
// set up combo input boxes with history
wikEdFieldHist ['find'] = [];
wikEdCookieName['find'] = 'findHistory';
wikEdInputElement['find'] = new Object(wikEdFindText);
wikEdSelectElement['find'] = new Object(document.getElementById('wikEdFindSelect'));
wikEdSelectElement['find'].style.height = (wikEdInputElement['find'].clientHeight + 1) +'px';
 
wikEdFieldHist ['replace'] = [];
wikEdCookieName['replace'] = 'replaceHistory';
wikEdInputElement['replace'] = new Object(wikEdReplaceText);
wikEdSelectElement['replace'] = new Object(document.getElementById('wikEdReplaceSelect'));
wikEdSelectElement['replace'].style.height = (wikEdInputElement['replace'].clientHeight + 1) +'px';
 
wikEdFieldHist ['summary'] = [];
wikEdCookieName['summary'] = 'summaryHistory';
wikEdInputElement['summary'] = new Object(wikEdSummaryText);
wikEdSelectElement['summary'] = new Object(document.getElementById('wpSummarySelect'));
wikEdSelectElement['summary'].style.height = (wikEdInputElement['summary'].clientHeight + 1) +'px';
WikEdResizeComboInput('find');
WikEdResizeComboInput('replace');
WikEdResizeComboInput('summary');
 
// add a link to the wikEd help page
var editHelpParent = previewButton;
do {
editHelpParent = editHelpParent.nextSibling;
} while (editHelpParent.tagName != 'SPAN');
 
var editHelp = editHelpParent.lastChild;
while (editHelp.tagName != 'A') {
editHelp = editHelp.previousSibling;
}
 
var wikEdHelpSpan = document.createElement('span');
wikEdHelpSpan.className = 'wikEdHelpSpan';
wikEdHelpSpan.innerHTML = wikEdHelpPageLink;
editHelpParent.insertBefore(wikEdHelpSpan, editHelp.nextSibling);
 
// add frame stylesheet definition
wikEdFrameBody.style.fontSize = parseInt(wikEdFontSizewikEdTextZoom) + '%;';
var frameStyle = new WikEdStyleSheet(wikEdFrameDocument);
for (var ruleName in wikEdFrameCSS) {
var ruleStyle = wikEdFrameCSS[ruleName];
ruleStyle = ruleStyle.replace(/\{wikEdUnknown\}/g, wikEdImage['unknown']);
ruleStyle = ruleStyle.replace(/\{wikEdTab\}/g, wikEdImage['tab']);
ruleStyle = ruleStyle.replace(/\{wikEdCtrl\}/g, wikEdImage['ctrl']);
ruleStyle = ruleStyle.replace(/\{wikEdBlank\}/g, wikEdImage['blank']);
frameStyle.addRule(ruleName, ruleStyle);
}
}
 
// copy the textarea content to the iframe
// set original tree position of input area
if (useWikEd == true) {
wikEdNormalTreePos = inputWrapper.nextSibling;
WikEdUpdateFrame();
}
 
// set frame events
wikEdFrameDocument.addEventListener('keyup', WikEdKeyFrame, true);
wikEdFrameDocument.addEventListener('keypress', WikEdKeyFrame, true);
wikEdFrameDocument.addEventListener('mouseup', WikEdKeyFrame, true);
 
// find ahead events
wikEdFindText.addEventListener('keyup', WikEdFindAhead, true);
var findText = document.getElementById('wikEdFindText');
findText.addEventListener('keyup', WikEdFindAhead, true);
 
// submit button events
var saveButton = document.getElementById('wpSave');
var previewButton = document.getElementById('wpPreview');
var diffButton = document.getElementById('wpDiff');
var localPreview = document.getElementById('wikEdLocalPreview');
var localDiff = document.getElementById('wikEdLocalDiff');
 
// 'Save page' buttononclick function
saveButton.onclick = function() {
if (wikEdFullScreenMode == true) {
WikEdFullScreen(false);
WikEdNormalScreen();
}
}
if (useWikEd == true) {
WikEdUpdateTextarea();
}
}
WikEdAddToHistory('summary');
saveButton.onclick = null;
saveButton.click();
return;
};
 
// 'Show preview' buttononclick function
previewButton.onclick = function() {
if (wikEdFullScreenMode == true) {
WikEdFullScreen(false);
WikEdNormalScreen();
}
}
if (useWikEd == true) {
WikEdUpdateTextarea();
}
}
previewButton.onclick = null;
previewButton.click();
return;
};
 
// 'Show changes' buttononclick function
diffButton.onclick = function() {
if (wikEdFullScreenMode == true) {
WikEdFullScreen(false);
WikEdNormalScreen();
}
}
if (useWikEd == true) {
WikEdUpdateTextarea();
}
}
diffButton.onclick = null;
diffButton.click();
return;
};
 
// 'Show preview' image button onclick function
localPreview.onclick = function() {
WikEdButton('wikEdLocalPreview');
return;
};
 
// 'Show changes' image button onclick function
localDiff.onclick = function() {
WikEdButton('wikEdLocalDiff');
return;
};
 
// disable scrolling to edit window on next preview page
document.getElementById('editform').action += '&noscroll';
 
// scroll to edit window if it is not a preview page
if (window.___location.search.match('noscroll') == null) {
window.scroll(0, WikEdGetOffsetTop(inputWrapperwikEdInputWrapper) - 2);
}
}
 
// focus the edit area
if (useWikEd == true) {
wikEdFrameWindow.focus();
}
}
else {
wikEdTextareaObj wikEdTextarea.setSelectionRange(0, 0);
wikEdTextareaObj wikEdTextarea.focus();
}
}
 
// reset error indicator
WikEdSetLogo(logo);
 
return;
}
 
Line 1,045 ⟶ 1,115:
function WikEdSetLogo(logo, error) {
 
if (error == false) {
logo.img.src = wikEdImage['error'];
logo.img.alt = 'WikEd error';
logo.lnk.title = 'WikEd ' + wikEdProgramVersion + ' (' + wikEdProgramDate + '): Loading error';
}
}
else {
logo.img.src = wikEdImage['logo'];
logo.img.alt = 'WikEd';
logo.lnk.title = 'WikEd ' + wikEdProgramVersion + ' (' + wikEdProgramDate + ')';
}
}
return;
}
 
 
//
// WikEdSetEditArea: apply css changes to switch between classic textarea and rich text frame
//
 
function WikEdSetEditArea(useFrame) {
 
// turn rich text frame on
if (useFrame == true) {
wikEdTextareaWrapper.style.position = 'absolute';
wikEdTextareaWrapper.style.visibility = 'hidden';
wikEdTextarea.style.display = 'none';
 
wikEdFrameWrapper.style.position = 'static';
wikEdFrameWrapper.style.visibility = 'visible';
wikEdFrameBody.style.display = 'block';
 
if (document.getElementById('toolbar') != null) {
if (wikEdShowToolbar == true) {
document.getElementById('toolbar').style.display = 'block';
}
else {
document.getElementById('toolbar').style.display = 'none';
}
}
wikEdButtonsFormat.style.display = 'block';
wikEdButtonsFind.style.display = 'block';
wikEdButtonsFix.style.display = 'block';
wikEdButtonsControl.style.display = 'block';
}
 
// turn classic textarea on
else {
wikEdFrameWrapper.style.position = 'absolute';
wikEdFrameWrapper.style.visibility = 'hidden';
wikEdFrameBody.style.display = 'none';
 
wikEdTextareaWrapper.style.position = 'static';
wikEdTextareaWrapper.style.visibility = 'visible';
wikEdTextarea.style.display = 'block';
 
if (document.getElementById('toolbar') != null) {
document.getElementById('toolbar').style.display = 'block';
}
wikEdButtonsFormat.style.display = 'none';
wikEdButtonsFind.style.display = 'none';
wikEdButtonsFix.style.display = 'none';
wikEdButtonsControl.style.display = 'block';
}
return;
}
 
Line 1,066 ⟶ 1,188:
 
// get the button object
var buttonObj = document.getElementById(whichButton);
if (buttonObj == null) {
alert('Unknown button \'' + whichButton + '\'');
return;
}
}
 
// check if the button is disabled
if (buttonObj.className == 'wikEdButtonInactive') {
return;
}
}
 
// set button to pressed, set cursor to hourglass
buttonObj.style.cursor = 'wait';
 
// init the button
if (setButton != null) {
if (setButton == false) {
buttonObj.checked = false;
if (classButton == null) {
buttonObj.className = 'wikEdButtonUnchecked';
}
}
}
}
else {
buttonObj.checked = true;
if (classButton == null) {
buttonObj.className = 'wikEdButtonChecked';
}
}
}
}
}
}
else if (classButton != null) {
buttonObj.className = classButton;
}
}
 
// toggle the button
if (toggleButton != null) {
if (toggleButton == true) {
if (buttonObj.checked == true) {
buttonObj.checked = false;
buttonObj.className = 'wikEdButtonUnchecked';
}
}
else {
buttonObj.checked = true;
buttonObj.className = 'wikEdButtonChecked';
}
}
}
}
}
}
 
// perform specific actions
if ( ( (setButton == null) && (classButton == null) ) || (doButton == true) ) {
 
// remove active content
WikEdRemoveElements(['script', 'object', 'applet', 'embed']);
 
switch (whichButton) {
 
// switch between syntax highlighting and plain text
case 'wikEdHighlightSyntax':
var obj = {};
obj.html = wikEdFrameBody.innerHTML;
if (buttonObj.checked == true) {
WikEdRemoveHighlighting(obj);
wikEdHighlightSyntax = true;
obj.html = obj.html.replace(/<br\b[^>]*>/g, '\n');
WikEdHighlightSyntax(obj);
obj.html = obj.html.replace(/\n/g, '<br />');
}
}
else {
wikEdHighlightSyntax = false;
WikEdRemoveHighlighting(obj);
obj.html = obj.html.replace(/(\t)/g, '<pre class="wikEdTabPlain">$1</pre><!--wikEdTabPlain-->');
}
}
wikEdFrameBody.innerHTML = obj.html;
break;
 
// align textbox with display top
case 'wikEdScrollToInput':
case 'wikEdScrollToInput2':
case 'wikEdScrollToInput3':
var inputWrapperwikEdInputWrapper = document.getElementById('wikEdInputWrapper');
var inputWrapperTop = WikEdGetOffsetTop(inputWrapperwikEdInputWrapper);
window.scroll(0, inputWrapperTop);
break;
 
// align edit buttons with display top
case 'wikEdScrollToButtons':
case 'wikEdScrollToButtons2':
case 'wikEdScrollToButtons3':
var buttonsWrapperwikEdConsoleWrapper = document.getElementById('wikEdButtonsWrapperwikEdConsoleWrapper');
var buttonsWrapperTopconsoleWrapperTop = WikEdGetOffsetTop(wrapperObjwikEdConsoleWrapper);
window.scroll(0, buttonsWrapperTopconsoleWrapperTop);
break;
 
// cycle through different font sizes
case 'wikEdFontSizewikEdTextZoom':
wikEdTextZoom = wikEdTextZoom / 1.2;
wikEdFontSize = wikEdFontSize / 1.2;
if (wikEdFontSizewikEdTextZoom < 60) {
wikEdFontSize wikEdTextZoom = Math.round(wikEdFontSizewikEdTextZoom * Math.pow(1.2, 4) );
}
}
wikEdFrameBody.style.fontSize = parseInt(wikEdFontSizewikEdTextZoom) + '%;';
break;
 
// display local preview box
case 'wikEdPreview':
case 'wikEdPreview2':
case 'wikEdLocalPreview':
if (wikEdFullScreenMode == true) {
WikEdNormalScreen();
WikEdFullScreen(false);
if (wikEdFullScreenMode == true) {
}
WikEdNormalScreen();
if (useWikEd == true) {
}
WikEdUpdateTextarea();
if (useWikEd == true) {
}
WikEdUpdateTextarea();
wikEdPreviewBox.innerHTML = wiki2html(wikEdTextarea.value);
}
wikEdPreviewWrapper.style.display = 'block';
document.getElementById('wikEdPreviewBox').innerHTML = wiki2html(wikEdTextareaObj.value);
break;
document.getElementById('customPreviewBox').style.display = 'block';
break;
 
// display local diff box
case 'wikEdDiff':
case 'wikEdDiff2':
case 'wikEdLocalDiff':
if (wikEdFullScreenMode == true) {
WikEdFullScreen(false);
WikEdNormalScreen();
}
}
if (useWikEd == true) {
WikEdUpdateTextarea();
}
}
var diffText = wikEdTextareaObjwikEdTextarea.value;
diffText = StringDiff(wikEdOrigVersion, diffText);
document.getElementById(' wikEdPreviewBox').innerHTML = diffText;
document.getElementById('customPreviewBox') wikEdPreviewWrapper.style.display = 'block';
break;
 
// close the preview / diff box
case 'wikEdClose':
case 'wikEdClose2':
document.getElementById('customPreviewBox') wikEdPreviewWrapper.style.display = 'none';
break;
 
// switch between textarea and frame display
// switching an iframe in design mode immediately after initialization between absolute/static may crash mozilla
case 'wikEdUseWikEd':
 
// enble wikEd
if (buttonObj.checked == true) {
WikEdUpdateFrame();
 
document.getElementById('wikEdTextareaWrapper').style.position = 'absolute';
// turn rich text frame on
document.getElementById('frameWrapper').style.position = 'static';
WikEdSetEditArea(true);
if (document.getElementById('toolbar') != null) {
useWikEd = true;
document.getElementById('toolbar').style.display = 'none';
}
}
document.getElementById('wikEdButtonsFormat').style.display = 'block';
document.getElementById('wikEdButtonsFind').style.display = 'block';
document.getElementById('wikEdButtonsFix').style.display = 'block';
document.getElementById('wikEdButtonsWindow').style.display = 'block';
useWikEd = true;
}
 
// disable wikEd
else {
if (wikEdFullScreenMode == true) {
WikEdFullScreen(false);
WikEdNormalScreen();
}
}
WikEdUpdateTextarea();
 
document.getElementById('frameWrapper').style.position = 'absolute';
// turn classic textarea on
document.getElementById('wikEdTextareaWrapper').style.position = 'static';
WikEdSetEditArea(false);
if (document.getElementById('toolbar') != null) {
useWikEd = false;
document.getElementById('toolbar').style.display = 'block';
}
}
break;
document.getElementById('wikEdButtonsFormat').style.display = 'none';
document.getElementById('wikEdButtonsFind').style.display = 'none';
document.getElementById('wikEdButtonsFix').style.display = 'none';
document.getElementById('wikEdButtonsWindow').style.display = 'block';
useWikEd = false;
}
break;
 
// just toggle the case sensitive search button
case 'wikEdCaseSensitive':
break;
 
// just toggle the regexp search button
case 'wikEdRegExp':
break;
 
// just toggle the find-ahead-as-yoyyou-type search button
case 'wikEdFindAhead':
break;
 
// switch to fullscreen edit area
case 'wikEdFullScreen':
if (buttonObj.checked == true) {
WikEdFullScreen(true);
}
}
else {
WikEdFullScreen(false);
WikEdNormalScreen();
}
}
break;
 
// clear the find, replace, and summary history stored in cookies
case 'wikEdClearHistory':
WikEdClearHistory('find');
WikEdClearHistory('replace');
WikEdClearHistory('summary');
break;
 
// clear the search find field to search for the selected text
case 'wikEdClearFind':
wikEdInputElement['find'].value = '';
break;
 
// for testing
case 'wikEdPlaceholder':
break;
}
}
}
}
 
// reset the frame DOM cache because the frame content might have changed
wikEdFrameDOMCache = null;
 
// reset cursor to normal
buttonObj.style.cursor = 'pointer';
 
return;
}
 
Line 1,300 ⟶ 1,409:
 
// get the button object
var buttonObj = document.getElementById(whichButton);
 
// check if button is disabled
if (buttonObj != null) {
if (buttonObj.className == 'wikEdButtonInactive') {
return;
}
}
}
}
 
// remove active content
WikEdRemoveElements(['script', 'object', 'applet', 'embed', 'textarea']);
 
// get ranges to apply the changes to:
// whole text, selection, cursor, word and line under cursor and selection
var obj = {};
 
// setup whole object for the whole text
obj.whole = {};
obj.whole.plainArray = [];
obj.whole.plainNode = [];
obj.whole.plainStart = [];
obj.whole.from = 'whole';
 
// get whole range
obj.whole.range = document.createRange();
obj.whole.range.setStartBefore(wikEdFrameBody.firstChild);
obj.whole.range.setEndAfter(wikEdFrameBody.lastChild);
 
// get whole plain text
WikEdGetInnerHTML(obj.whole, wikEdFrameBody);
obj.whole.code = obj.whole.html;
WikEdRemoveHighlightingWikify(obj.whole);
obj.whole.plain = obj.whole.html;
obj.whole.plain = obj.whole.plain.replace(/<br\b[^>]*>/g, '\n');
obj.whole.range.setStartBefore(wikEdFrameBody.firstChild);
obj.whole.range.setEndAfter(wikEdFrameBody.lastChild);
 
// setup selection object for the selected text
obj.selection = {};
obj.selection.from = 'selection';
 
// set selection range
obj.sel = wikEdFrameWindow.getSelection();
obj.selection.range = obj.sel.getRangeAt(obj.sel.rangeCount - 1);
 
// copy range to document fragment
var documentFragment = obj.selection.range.cloneContents();
 
// get selected text
WikEdGetInnerHTML(obj.selection, documentFragment);
obj.selection.code = obj.selection.html;
WikEdRemoveHighlightingWikify(obj.selection);
obj.selection.plain = obj.selection.html;
obj.selection.plain = obj.selection.plain.replace(/<br\b[^>]*>/g, '\n');
 
// setup cursor object for the cursor position
obj.cursor = {};
obj.cursor.from = 'cursor';
obj.cursor.range = document.createRange();
obj.cursor.range.setStart(obj.sel.focusNode, obj.sel.focusOffset);
obj.cursor.range.setEnd(obj.sel.focusNode, obj.sel.focusOffset);
obj.cursor.plain = '';
 
// setup focusWord object for the word under the cursor
obj.focusWord = {};
obj.focusWord.from = 'focusWord';
obj.focusWord.range = document.createRange();
 
// setup focusLine object for the line under the cursor
obj.focusLine = {};
obj.focusLine.from = 'focusLine';
obj.focusLine.range = document.createRange();
 
// setup selectionWord object for the words under the selection
obj.selectionWord = {};
obj.selectionWord.from = 'selectionWord';
obj.selectionWord.range = document.createRange();
 
// setup selectionLine object for the lines under the selection
obj.selectionLine = {};
obj.selectionLine.from = 'selectionLine';
obj.selectionLine.range = document.createRange();
 
// find the respective word and line boundaries
WikEdFindBoundaries(obj.focusWord, obj.focusLine, obj.whole, obj.cursor);
WikEdFindBoundaries(obj.selectionWord, obj.selectionLine, obj.whole, obj.selection);
 
// get the wikified plain text for the word under the cursor
var documentFragment = obj.focusWord.range.cloneContents();
WikEdGetInnerHTML(obj.focusWord, documentFragment);
obj.focusWord.code = obj.focusWord.html;
WikEdRemoveHighlightingWikify(obj.focusWord);
obj.focusWord.plain = obj.focusWord.html;
obj.focusWord.plain = obj.focusWord.plain.replace(/<br\b[^>]*>/g, '\n');
 
// get the wikified plain text for the line under the cursor
var documentFragment = obj.focusLine.range.cloneContents();
WikEdGetInnerHTML(obj.focusLine, documentFragment);
obj.focusLine.code = obj.focusLine.html;
WikEdRemoveHighlightingWikify(obj.focusLine);
obj.focusLine.plain = obj.focusLine.html;
obj.focusLine.plain = obj.focusLine.plain.replace(/<br\b[^>]*>/g, '\n');
 
// get the wikified plain text for the words under the selection
var documentFragment = obj.selectionWord.range.cloneContents();
WikEdGetInnerHTML(obj.selectionWord, documentFragment);
obj.selectionWord.code = obj.selectionWord.html;
WikEdRemoveHighlightingWikify(obj.selectionWord);
obj.selectionWord.plain = obj.selectionWord.html;
obj.selectionWord.plain = obj.selectionWord.plain.replace(/<br\b[^>]*>/g, '\n');
 
// get the wikified plain text for the lines under the selection
var documentFragment = obj.selectionLine.range.cloneContents();
WikEdGetInnerHTML(obj.selectionLine, documentFragment);
obj.selectionLine.code = obj.selectionLine.html;
WikEdRemoveHighlightingWikify(obj.selectionLine);
obj.selectionLine.plain = obj.selectionLine.html;
obj.selectionLine.plain = obj.selectionLine.plain.replace(/<br\b[^>]*>/g, '\n');
 
// select the appropriate object to change (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine)
obj.changed = {};
switch (whichButton) {
 
// undo: whole
case 'wikEdUndo':
case 'wikEdRedo':
obj.changed = obj.cursor; // dummy
break;
 
// whole text changes: whole
case 'wikEdUndoAll':
case 'wikEdRedoAll':
obj.changed = obj.whole;
break;
 
// basic wiki character formatting: selection / focusWord / cursor
case 'wikEdBold':
case 'wikEdItalic':
case 'wikEdUnderline':
case 'wikEdSuperscript':
case 'wikEdSubscript':
case 'wikEdWikiLink':
case 'wikEdWebLink':
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
}
else if (obj.focusWord.plain != '') {
obj.changed = obj.focusWord;
}
}
else {
obj.changed = obj.cursor;
}
}
break;
 
// character formatting: selection / focusWord
case 'wikEdCase':
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
}
else {
obj.changed = obj.focusWord;
}
}
break;
 
// update syntax highlighting: selection / whole
case 'wikEdUpdateSyntax':
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
}
else {
obj.changed = obj.whole;
}
}
break;
 
// multiple line changes: selectionLine
case 'wikEdDecreaseHeading':
case 'wikEdIncreaseHeading':
case 'wikEdBulletList':
case 'wikEdNumberList':
case 'wikEdIndentList':
case 'wikEdDefinitionList':
if (obj.selection.plain != '') {
obj.changed = obj.selectionLine;
}
}
else {
obj.changed = obj.focusLine;
}
}
break;
 
// image: selectionWord (if text is selected) / cursor
case 'wikEdImage':
//whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine
if (obj.selection.plain != '') {
case 'wikEdImage':
obj.changed = obj.selectionWord;
if (obj.selection.plain != '') {
}
obj.changed = obj.selectionWord;
else {
}
obj.changed = obj.cursor;
else {
}
obj.changed = obj.cursor;
break;
}
break;
 
// table: selectionLine / cursor
case 'wikEdTable':
if (obj.selection.plain != '') {
obj.changed = obj.selectionLine;
}
}
else {
obj.changed = obj.cursor;
}
}
break;
 
// wikify, textify: selection / whole
case 'wikEdWikify':
case 'wikEdTextify':
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
}
else {
obj.changed = obj.whole;
}
}
break;
 
// redirect: whole
case 'wikEdRedirect':
obj.changed = obj.whole;
break;
 
// character formatting: selection / focusWord
case 'wikEdGetFind':
case 'wikEdGetFindReplace':
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
}
else {
obj.changed = obj.focusWord;
}
}
break;
 
// find and replace: find value / selection / focusWord
case 'wikEdFindPrev':
case 'wikEdFindNext':
case 'wikEdReplacePrev':
case 'wikEdReplaceNext':
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
}
else if (obj.focusWord.plain != '') {
obj.changed = obj.focusWord;
}
}
else {
obj.changed.plain = null;
}
}
break;
 
// replaceall: selection / whole
case 'wikEdFindAll':
case 'wikEdReplaceAll':
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
}
else {
obj.changed = obj.whole;
}
}
break;
 
//////////////////////////////////
case 'wikEdUpdown':
obj.changed = obj.cursor; //dummy
break;
 
// jump to position: dummy
case 'wikEdPrevPos':
case 'wikEdLastPos':
obj.changed = obj.cursor; //dummy
break;
 
// fixing buttons: selection / whole
case 'wikEdFixBasic':
case 'wikEdfixUnicode':
case 'wikEdFixAll':
case 'wikEdFixHtml':
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
}
else {
obj.changed = obj.whole
}
}
break;
 
// fixing buttons: selection / focusLine
case 'wikEdFixPunct':
case 'wikEdFixMath':
case 'wikEdFixUnits':
case 'wikEdFixDashes':
case 'wikEdFixCaps':
case 'wikEdFixChem':
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
}
else {
obj.changed = obj.focusLine;
}
}
break;
 
// fixing buttons: selection / focusWord
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
}
else {
obj.changed = obj.focusWord;
}
}
break;
 
// source: selection / whole
case 'wikEdSource':
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
}
else {
obj.changed = obj.whole;
}
}
break;
 
// insert tags: selection / focusWord / cursor
case 'wikEdInsertTags':
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
}
else if (obj.focusWord.plain != '') {
obj.changed = obj.focusWord;
}
}
else {
obj.changed = obj.cursor;
}
}
break;
 
// unknown edit function
default:
alert('Unknown edit function \'' + whichButton + '\'');
 
// reset button to active, reset cursor
if (buttonObj != null) {
if (buttonObj.className != 'wikEdButtonInactive') {
buttonObj.className = 'wikEdButton';
}
}
}
}
wikEdFrameBody.style.cursor = 'auto';
 
return;
}
}
 
// exit
if (obj.changed == null) {
wikEdFrameWindow.focus();
 
// reset button to active, reset cursor
if (buttonObj != null) {
if (buttonObj.className != 'wikEdButtonInactive') {
buttonObj.className = 'wikEdButton';
}
}
}
}
return;
}
}
 
// set local syntax highlighting flag
var highlightSyntax = wikEdHighlightSyntax;
 
// manipulate the text
var selectChange = true;
switch (whichButton) {
 
// undo
case 'wikEdUndo':
if (wikEdLastVersion == null) {
wikEdLastVersion = obj.changed.plain;
}
}
WikEdFrameExecCommand('undo');
obj.changed.range = obj.sel.getRangeAt(obj.sel.rangeCount - 1);
obj.changed.plain = null;
break;
 
// redo
case 'wikEdRedo':
WikEdFrameExecCommand('redo');
obj.changed.range = obj.sel.getRangeAt(obj.sel.rangeCount - 1);
obj.changed.plain = null;
break;
 
// bold
case 'wikEdBold':
if ( /\'\'\'([^\'].*?)\'\'\'/.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/\'\'\'([^\'].*?)\'\'\'/g, '$1');
}
}
else {
obj.changed.plain = '\'\'\'' + obj.changed.plain + '\'\'\'';
obj.changed.plain = obj.changed.plain.replace(/(\'\'\')( *)(.*?)( *)(\'\'\')/, '$2$1$3$5$4');
}
}
break;
 
// italic
case 'wikEdItalic':
if ( /\'\'([^\'].*?)\'\'/.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/\'\'([^\'].*?)\'\'/g, '$1');
}
}
else {
obj.changed.plain = '\'\'' + obj.changed.plain + '\'\'';
obj.changed.plain = obj.changed.plain.replace(/(\'\')( *)(.*?)( *)(\'\')/, '$2$1$3$5$4');
}
}
break;
 
// underline
case 'wikEdUnderline':
if ( /&lt;u&gt;(.*?)&lt;\/u&gt;/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/&lt;u&gt;(.*?)&lt;\/u&gt;/g, '$1');
}
}
else {
obj.changed.plain = '&lt;u&gt;' + obj.changed.plain + '&lt;\/u&gt;';
obj.changed.plain = obj.changed.plain.replace(/(&lt;u&gt;)( *)(.*?)( *)(&lt;\/u&gt;)/, '$2$1$3$5$4');
}
}
break;
 
// superscript
case 'wikEdSuperscript':
if ( /&lt;sup&gt;(.*?)&lt;\/sup&gt;/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/&lt;sup&gt;(.*?)&lt;\/sup&gt;/g, '$1');
}
}
else {
obj.changed.plain = '&lt;sup&gt;' + obj.changed.plain + '&lt;/sup&gt;';
obj.changed.plain = obj.changed.plain.replace(/(&lt;sup&gt;)( *)(.*?)( *)(&lt;\/sup&gt;)/, '$2$1$3$5$4');
}
}
break;
 
// subscript
case 'wikEdSubscript':
if ( /&lt;sub&gt;(.*?)&lt;\/sub&gt;/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/&lt;sub&gt;(.*?)&lt;\/sub&gt;/g, '$1');
}
}
else {
obj.changed.plain = '&lt;sub&gt;' + obj.changed.plain + '&lt;/sub&gt;';
obj.changed.plain = obj.changed.plain.replace(/(&lt;sub&gt;)( *)(.*?)( *)(&lt;\/sub&gt;)/, '$2$1$3$5$4');
}
}
break;
 
// toggle lowercase / uppercase
case 'wikEdCase':
 
// lowercase all uppercased text
if (obj.changed.plain.toUpperCase() == obj.changed.plain) {
obj.changed.plain = obj.changed.plain.toLowerCase();
}
}
 
// first-letter-uppercase all lowercased text
else if (obj.changed.plain.toLowerCase() == obj.changed.plain) {
obj.changed.plain = obj.changed.plain.replace(/\b(\w)(\w*)/g,
function (p, p1, p2) {
return(p1.toUpperCase() + p2.toLowerCase());
}
}
);
);
}
}
 
// uppercase mixed upper and lowercased text
else {
obj.changed.plain = obj.changed.plain.toUpperCase();
}
}
break;
 
// undo all
case 'wikEdUndoAll':
if (wikEdLastVersion == null) {
wikEdLastVersion = obj.changed.plain;
}
}
obj.changed.plain = wikEdOrigVersion;
obj.changed.plain = obj.changed.plain.replace(/&/g, '&amp;');
obj.changed.plain = obj.changed.plain.replace(/>/g, '&gt;');
obj.changed.plain = obj.changed.plain.replace(/</g, '&lt;');
break;
 
// redo all
case 'wikEdRedoAll':
if (wikEdLastVersion != null) {
obj.changed.plain = wikEdLastVersion;
}
}
break;
 
// update syntax highlighting
case 'wikEdUpdateSyntax':
highlightSyntax = true;
break;
 
// create wikilink
case 'wikEdWikiLink':
if ( /\[\[(.*?)\]\]/.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/\[\[(.*?)\]\]/g, '$1');
}
}
else {
obj.changed.plain = '\[\[' + obj.changed.plain + '\]\]';
obj.changed.plain = obj.changed.plain.replace(/(\[\[)( *)(.*?)( *)(\]\])/, '$2$1$3$5$4');
}
}
break;
 
// create weblink
case 'wikEdWebLink':
if ( /\[(.*?)\]/.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/\[(.*?)\]/g, '$1');
}
}
else {
obj.changed.plain = '\[' + obj.changed.plain + '\]';
obj.changed.plain = obj.changed.plain.replace(/(\[)( *)(.*?)( *)(\])/, '$2$1$3$5$4');
}
}
break;
 
// decrease heading level
case 'wikEdDecreaseHeading':
obj.changed.plain = obj.changed.plain.replace(/(^|\n)=(=+) *([^\n]*?) *=+(?=\n|$)/g, '$1$2 $3 $2'); // decrease heading
obj.changed.plain = obj.changed.plain.replace(/(^|\n)=(?!=) *([^\n]*?) *=+(?=\n|$)/g, '$1$2'); // remove heading
obj.changed.plain = obj.changed.plain.replace(/(^|\n)(=+) *([^\n]*?) *=+(?=\n|$)/g, '$1$2 $3 $2'); // adjust closing tags
break;
 
// increase heading level
case 'wikEdIncreaseHeading':
obj.changed.plain = obj.changed.plain.replace(/(^|\n)(=+) *([^\n]*?) *=+(?=\n|$)/g, '$1=$2 $3 $2='); // increase heading
obj.changed.plain = obj.changed.plain.replace(/(^|\n)([^=\n\s][^\n]*?)(?=\n|$)/g, '$1== $2 =='); // create new heading
obj.changed.plain = obj.changed.plain.replace(/(^|\n)(=+) *([^\n]*?) *=+(?=\n|$)/g, '$1$2 $3 $2'); // adjust closing tags
break;
 
// create bullet list
case 'wikEdBulletList':
obj.changed.plain = obj.changed.plain.replace(/([^\n]+)/g,
function (p, p1) {
p1 = p1.replace(/^ *([\*\#\:\;]*) */g, '*$1 ');
p1 = p1.replace(/^(\*{4,})([\*\#\:\;]*)/g, '$2');
return(p1);
}
}
);
);
break;
 
// create numbered list
case 'wikEdNumberList':
obj.changed.plain = obj.changed.plain.replace(/([^\n]+)/g,
function (p, p1) {
p1 = p1.replace(/^ *([\*\#\:\;]*) */g, '#$1 ');
p1 = p1.replace(/^(\*{4,})([\*\#\:\;]*)/g, '$2');
return(p1);
}
}
);
);
break;
 
// create indented list
case 'wikEdIndentList':
obj.changed.plain = obj.changed.plain.replace(/([^\n]+)/g,
function (p, p1) {
p1 = p1.replace(/^ *([\*\#\:\;]*) */g, ':$1 ');
p1 = p1.replace(/^(\*{4,})([\*\#\:\;]*)/g, '$2');
return(p1);
}
}
);
);
break;
 
// create definition list
case 'wikEdDefinitionList':
obj.changed.plain = obj.changed.plain.replace(/([^\n]+)/g,
function (p, p1) {
p1 = p1.replace(/^ *([^\s\;]+) */g, '; $1 : ');
return(p1);
}
}
);
);
break;
 
// create image
case 'wikEdImage':
if (obj.changed.plain != '') {
obj.changed.plain = '[[Image:<span class="wikEdInsertHere">filename</span>|thumb|<span class="wikEdInsertHere">width</span>px|' + obj.changed.plain + ']]';
}
}
else {
obj.changed.plain = '[[Image:<span class="wikEdInsertHere">filename</span>|thumb|<span class="wikEdInsertHere">width</span>px|<span class="wikEdInsertHere"> </span>]]';
if (obj.focusWord.plain != '') {
obj.changed.plain = ' ' + obj.changed.plain + ' ';
}
}
}
}
break;
 
// create table
case 'wikEdTable':
if (obj.changed.plain != '') {
obj.changed.plain = obj.changed.plain.replace(/(^|\n) */g, '\n|-\n| ');
obj.changed.plain = obj.changed.plain.replace(/^\n\|\-\n/, '\n{| {{Prettytable}}\n');
obj.changed.plain = obj.changed.plain.replace(/$/g, '\n|}\n');
}
}
else {
obj.changed.plain = '\n{| {{Prettytable}}\n|+ <span class="wikEdInsertHere">caption</span>\n! <span class="wikEdinserthere">heading</span> !! <span class="wikEdInsertHere">heading</span>\n|-\n| <span class="wikEdInsertHere">cell</span> || <span class="wikEdInsertHere">cell</span>\n|-\n| <span class="wikEdInsertHere">cell</span> || <span class="wikEdInsertHere">cell</span>\n|}\n';
if (obj.focusLine.plain != '') {
obj.changed.plain = '\n' + obj.changed.plain + '\n';
}
}
}
}
break;
 
// wikify: always done above
case 'wikEdWikify':
break;
 
// textify: strip html from pasted content
case 'wikEdTextify':
var objTextify = {};
 
// get inner html without wikifying
if (obj.changed.from == 'whole') {
WikEdGetInnerHTML(objTextify, wikEdFrameBody);
}
}
else {
obj.selection.range = obj.sel.getRangeAt(obj.sel.rangeCount - 1);
var documentFragment = obj.selection.range.cloneContents();
WikEdGetInnerHTML(objTextify, documentFragment);
}
}
 
WikEdTextify(objTextify);
obj.changed.plain = objTextify.plain;
obj.changed.plain = obj.changed.plain.replace(/\n/g, '<br />');
break;
 
// redirect
case 'wikEdRedirect':
var linkTarget;
if (obj.selectionWord.plain != '') {
linkTarget = obj.selectionWord.plain;
}
}
else {
linkTarget = '<span class="wikEdInsertHere">article link</span>';
}
}
 
// remove leading and trailing spaces
linkTarget = linkTarget.replace(/^\s+|\s+$/g, '');
 
// remove link text
linkTarget = linkTarget.replace(/\|.*?(\]|$)/g, '$1');
 
// remove square brackets
linkTarget = linkTarget.replace(/\[|\]/g, '');
 
// remove link leftovers
linkTarget = linkTarget.replace(/ +\| +/g, ' ');
 
obj.changed.plain = '#redirect [[' + linkTarget + ']]';
 
if (wikEdInputElement['summary'].value == '') {
wikEdInputElement['summary'].value = '#redirect [[' + linkTarget + ']]';
}
}
selectChange = false;
break;
 
// copy selection to find field
case 'wikEdGetFind':
wikEdInputElement['find'].value = obj.changed.plain;
obj.changed.plain = null;
break;
 
// copy selection to find and to replace field
case 'wikEdGetFindReplace':
wikEdInputElement['find'].value = obj.changed.plain;
wikEdInputElement['replace'].value = obj.changed.plain;
obj.changed.plain = null;
break;
 
// find and replace
case 'wikEdFindPrev':
case 'wikEdFindNext':
case 'wikEdReplacePrev':
case 'wikEdReplaceNext':
case 'wikEdFindAll':
case 'wikEdReplaceAll':
 
// get the find text //////////////////
var findText;
if (wikEdInputElement['find'].value != '') {
findText = wikEdInputElement['find'].value;
}
}
else {
if (obj.selection.plain == '') {
obj.changed.plain = null;
break;
}
}
else {
findText = obj.selection.plain;
}
}
}
}
 
// get the replace text
var replaceText = wikEdInputElement['replace'].value;
 
// get the find and replace checkbutton states
var caseSensitiveButton = document.getElementById('wikEdCaseSensitive');
var regExpButton = document.getElementById('wikEdRegExp');
var findAheadButton = document.getElementById('wikEdFindAhead');
 
// format the find and replace texts as regexp or plain text
if (regExpButtonwikEdRegExp.checked == false) {
findText = findText.replace(/([\\^\$\*\+\?\.\(\)\[\]\{\}\:\=\!\|\,\-])/g, '\\$1');
}
}
 
// replace \n with newline character
else {
replaceText = replaceText.replace(/((^|[^\\])(\\\\)*)\\n/g, '$1\n');
}
}
 
// set regexp flags
var regExpFlags = 'g';
if ( ! caseSensitiveButtonwikEdCaseSensitive.checked ) {
regExpFlags += 'i';
}
}
 
// create regexp
var regExpFind = new RegExp(findText, regExpFlags);
 
// replace all
var replacedFlag = false;
if (whichButton == 'wikEdReplaceAll') {
if (regExpFind.test(obj.changed.plain)) {
obj.changed.plain = obj.changed.plain.replace(regExpFind, replaceText);
replacedFlag = true;
}
}
else {
obj.changed.plain = null;
}
}
}
}
 
// find all
if (whichButton == 'wikEdFindAll') {
////////////////////////// set selection with multiple ranges
obj.changed.plain = null;
break;
}
}
 
// replace an existing selection
else if ( (whichButton == 'wikEdReplacePrev') || (whichButton == 'wikEdReplaceNext') ) {
if (regExpFind.test(obj.selection.plain)) {
obj.changed.plain = obj.selection.plain.replace(regExpFind, replaceText);
replacedFlag = true;
}
}
else {
obj.changed.plain = null;
}
}
}
}
else if ( (whichButton == 'wikEdFindNext') || (whichButton == 'wikEdFindPrev') ) {
obj.changed.plain = null;
}
}
 
if ( (whichButton == 'wikEdFindNext') || (whichButton == 'wikEdFindPrev') || (whichButton == 'wikEdReplaceNext') || (whichButton == 'wikEdReplacePrev') ) {
if (replacedFlag == false) {
 
// get direction
var backwards = false;
if ( (whichButton == 'wikEdFindPrev') || (whichButton == 'wikEdReplacePrev') ) {
backwards = true;
}
}
 
// get case sensitive
var caseSensitive = false;
if (caseSensitiveButtonwikEdCaseSensitive.checked == true) {
caseSensitive = true;
}
}
 
// find the text
if (regExpButtonwikEdRegExp.checked) {
WikEdFind(obj, findText, caseSensitive, backwards, regExpFind);
}
}
else {
WikEdFind(obj, findText, caseSensitive, backwards, null);
selectChange = false;
}
}
}
}
}
}
 
// save search history to cookie
if ( (whichButton == 'wikEdFindPrev') || (whichButton == 'wikEdFindNext') ) {
WikEdAddToHistory('find');
}
}
if ( (whichButton == 'wikEdReplacePrev') || (whichButton == 'wikEdReplaceNext') || (whichButton == 'wikEdReplaceAll') ) {
WikEdAddToHistory('find');
WikEdAddToHistory('replace');
}
}
break;
 
// jump to top or bottom
case 'wikEdUpdown':
 
// jump to bottom
/////////////////////// also check which is closer!!!!!
if ( (obj.cursor.range.startContainer == wikEdFrameBody) && (obj.cursor.range.startOffset == 0) ) {
obj.changed.range.setEndAfter(wikEdFrameBody.lastChild);
obj.changed.range.collapse(false);
wikEdFrameBody.scrollTop = wikEdFrameBody.scrollHeight;
}
}
 
// jump to top
else {
obj.changed.range.setStartBefore(wikEdFrameBody.firstChild);
obj.changed.range.collapse(true);
wikEdFrameBody.scrollTop = 0;
}
}
obj.changed.plain = null;
break;
 
// jump to previously changed position
case 'wikEdPrevPos':
if (wikEdFrameDocument.queryCommandEnabled('undo') == true) {
WikEdFrameExecCommand('undo');
WikEdFrameExecCommand('redo');
wikEdLastPosObj = obj.cursor;
}
}
obj.changed.plain = null
break;
 
// jump back to last position
case 'wikEdLastPos':
if (wikEdLastPosObj != null) {
obj.changed = wikEdLastPosObj;
wikEdLastPosObj = null;
obj.changed.plain = null;
}
}
else {
obj.changed.plain = null;
}
}
break;
 
// fixbasic: fix characters, spaces, empty lines, certain headings, needed for all fixing functions
// to do: only certain changes in multiline tags: comments, tables, subst
case 'wikEdFixBasic':
WikEdFixBasic(obj.changed);
break;
case 'wikEdFixPunct':
WikEdFixPunct(obj.changed);
break;
case 'wikEdFixMath':
WikEdFixMath(obj.changed);
break;
case 'wikEdFixChem':
WikEdFixChem(obj.changed);
break;
case 'wikEdfixUnicode':
WikEdFixUnicode(obj.changed);
break;
case 'wikEdFixUnits':
WikEdFixUnits(obj.changed);
break;
case 'wikEdFixDashes':
WikEdFixDashes(obj.changed);
break;
case 'wikEdFixHtml':
WikEdFixHTML(obj.changed);
break;
case 'wikEdFixCaps':
WikEdFixCaps(obj.changed);
break;
case 'wikEdFixAll':
WikEdFixAll(obj.changed);
break;
 
// source on
case 'wikEdSource':
obj.changed.plain = obj.changed.code;
obj.changed.plain = obj.changed.plain.replace(/(<(br|p)\b[^>]*>)/g, '$1\n');
obj.changed.plain = obj.changed.plain.replace(/&/g, '&amp;');
obj.changed.plain = obj.changed.plain.replace(/</g, '&lt;');
obj.changed.plain = obj.changed.plain.replace(/>/g, '&gt;');
highlightSyntax = false;
break;
 
// insert tags
case 'wikEdInsertTags':
var tagOpen = parameterArray[0] || '';
var tagClose = parameterArray[1] || '';
var sampleText = parameterArray[2] || '';
tagOpen = tagOpen.replace(/&/g, '&amp;');
tagOpen = tagOpen.replace(/</g, '&lt;');
tagOpen = tagOpen.replace(/>/g, '&gt;');
tagClose = tagClose.replace(/&/g, '&amp;');
tagClose = tagClose.replace(/</g, '&lt;');
tagClose = tagClose.replace(/>/g, '&gt;');
tagsampleText = sampleText.replace(/&/g, '&amp;');
tagsampleText = sampleText.replace(/</g, '&lt;');
tagsampleText = sampleText.replace(/>/g, '&gt;');
if ( (obj.changed.plain == '') && (sampleText.length > 0) ) {
obj.changed.plain = tagOpen + sampleText + tagClose;
}
}
obj.changed.plain = tagOpen + obj.changed.plain + tagClose;
break;
 
// default
default:
alert('Unknown edit function \'' + whichButton + '\'');
}
}
 
// update the selection only, do not change the text
if (obj.changed.plain == null) {
obj.sel.removeAllRanges();
obj.sel.addRange(obj.changed.range);
 
// scroll the selected text into the viewport by using a backwards find
if (selectChange != false) {
 
// get the plain text of the selection
var plainText = obj.sel.getRangeAt(obj.sel.rangeCount - 1).cloneContents().textContent;
 
// collapse the selection to the end and search backwards
if (plainText.length > 0) {
if (plainText.indexOf('\n') < 0) {
obj.changed.range.collapse(false);
 
// function: window.find(string, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog)
wikEdFrameWindow.find(plainText, true, true, false, false, false, false);
}
}
}
}
}
}
}
}
 
// apply text changes
else {
 
// a text change erases the last version for redo all
if ( (whichButton != 'wikEdUndo') && (whichButton != 'wikEdRedo') && (whichButton != 'wikEdUndoAll') ) {
wikEdLastVersion = null;
}
}
 
// highlight the syntax
obj.html = obj.changed.plain;
if (highlightSyntax == true) {
WikEdHighlightSyntax(obj);
}
}
 
// display tabs
else {
obj.html = obj.html.replace(/(\t)/g, '<pre class="wikEdTabPlain">$1</pre><!--wikEdTabPlain-->');
}
}
 
// display multiple blanks as blank-&nbsp;
obj.html = obj.html.replace(/ /g, '&nbsp; ');
obj.html = obj.html.replace(/ /g, '&nbsp; ');
 
// newlines to <br />
obj.html = obj.html.replace(/\n/g, '<br />');
 
// make changed range text the current selection
obj.sel.removeAllRanges();
obj.sel.addRange(obj.changed.range);
 
// get the scroll position
var frameSrollTop;
if (obj.changed.from == 'whole') {
frameSrollTop = wikEdFrameBody.scrollTop
}
}
 
// replace the selection with changed text
if (obj.html != '') {
WikEdFrameExecCommand('inserthtml', obj.html);
}
}
else {
WikEdFrameExecCommand('delete');
}
}
 
// select the whole text after replacing the whole text and scroll to same height
if (obj.changed.from == 'whole') {
wikEdFrameBody.scrollTop = frameSrollTop;
var range = document.createRange();
range.setStartBefore(wikEdFrameBody.firstChild);
range.setEndAfter(wikEdFrameBody.lastChild);
obj.sel.addRange(range);
selectChange = false;
}
}
 
// select the changed text and scroll it into the viewport by using a backwards find
if (selectChange != false) {
 
// get the text content of the changed text
var div = document.createElement('div');
div.innerHTML = obj.changed.plain;
var plainText = div.textContent;
 
// find the text
if (plainText.length > 0) {
if (plainText.indexOf('\n') < 0) {
 
// function: window.find(string, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog)
wikEdFrameWindow.find(plainText, true, true, false, false, false, false);
}
}
}
}
}
}
}
}
 
// reset button to active, reset cursor
if (buttonObj != null) {
if (buttonObj.className != 'wikEdButtonInactive') {
buttonObj.className = 'wikEdButton';
}
}
buttonObj.style.cursor = 'auto';
}
 
// grey out inactive buttons
WikEdInactiveButtons();
InactiveButtons();
 
// reset the frame DOM cache because the frame content has been changed
wikEdFrameDOMCache = null;
 
// focus the frame
if (useWikEd == true) {
wikEdFrameWindow.focus();
}
}
 
return;
}
 
Line 2,315 ⟶ 2,418:
function WikEdFind(obj, findText, caseSensitive, backwards, regExp) {
 
var range = obj.sel.getRangeAt(obj.sel.rangeCount - 1);
 
// empty the range to avoid error messages for reverse direction ranges
obj.changed.range = document.createRange();
 
// use the fast built-in find function for non-regexp searches
if (regExp == null) {
 
// function: window.find(string, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog)
var found = wikEdFrameWindow.find(findText, caseSensitive, backwards, false, false, false, false);
if (found == false) {
obj.changed.range.setStart(range.startContainer, range.startOffset);
obj.changed.range.setEnd(range.endContainer, range.endOffset);
obj.changed.range.collapse(backwards);
}
}
else {
range = obj.sel.getRangeAt(obj.sel.rangeCount - 1);
obj.changed.range.setStart(range.startContainer, range.startOffset);
obj.changed.range.setEnd(range.endContainer, range.endOffset);
}
}
}
}
 
// slow javascript regexp find and replace
else {
 
// perform find
WikEdParseDOM(obj, wikEdFrameBody);
var regExpMatch = [];
 
// find next, search to the right
if (backwards == false) {
 
// set start position for search to right
regExp.lastIndex = obj.plainFocus;
 
// execute the regexp search to the right
regExpMatch = regExp.exec(obj.plain);
 
// collapse the selection to its end for no find
if (regExpMatch == null) {
obj.changed.range.setEnd(range.endContainer, range.endOffset);
obj.changed.range.collapse(false);
}
}
}
}
 
// find previous, search to the left
else {
 
// cycle through the matches to the left
var regExpMatchNext;
do {
regExpMatch = regExpMatchNext;
regExpMatchNext = regExp.exec(obj.plain);
if (regExpMatchNext == null) {
break;
}
}
} while (regExpMatchNext.index < obj.plainAnchor);
 
// collapse the selection to its start for no find
if (regExpMatch == null) {
obj.changed.range.setStart(range.startContainer, range.startOffset);
obj.changed.range.collapse(true);
}
}
}
}
 
// select the find
if (regExpMatch != null) {
i = 0;
while ( (obj.plainStart[i + 1] <= regExpMatch.index) && (obj.plainStart[i + 1] != null) ) {
i ++;
}
}
j = i;
while ( (obj.plainStart[j + 1] <= regExpMatch.index + regExpMatch[0].length) && (obj.plainStart[j + 1] != null) ) {
j ++;
}
}
obj.changed.range.setEnd (obj.plainNode[j], regExpMatch.index + regExpMatch[0].length - obj.plainStart[j]);
obj.changed.range.setStart(obj.plainNode[i], regExpMatch.index - obj.plainStart[i]);
}
}
}
}
return;
}
 
Line 2,405 ⟶ 2,508:
 
// convert html to plain
obj.plain = obj.html;
obj.plain = obj.plain.replace(/\n/g, '');
 
// delete tags
obj.plain = obj.plain.replace(/<(style|script|script|object|applet|embed)\b[^>]*>.*?<\/\1>/g, '');
 
// newlines
obj.plain = obj.plain.replace(/<(br)\b[^>]*>/g, '\n');
 
// remove highlighting pre tags
var isRemove = [];
obj.plain = obj.plain.replace(/(<(\/?)pre\b([^>]*)>)/g,
function (p, p1, p2, p3) {
if (p2 == '') {
if (/\bclass=\"wikEd\w+\"/.test(p3)) {
isRemove.push(true);
return('');
}
}
isRemove.push(false);
return(p1);
}
}
if (isRemove.pop() == true) {
return('');
}
}
return(p1);
}
}
);
 
// blocks
obj.plain = obj.plain.replace(/<\/?(address|blockquote|center|div|h1|h2|h3|h4|h5|h6|hr|isindex|p|pre)\b[^>]*>/g, '\u0000\u0000');
 
// lists
obj.plain = obj.plain.replace(/<\/?(dir|dl|menu|ol|ul)\b[^>]*>/g, '\u0000');
obj.plain = obj.plain.replace(/<\/(dd|dt|li)>/g, '\u0000');
 
// forms
obj.plain = obj.plain.replace(/<\/?(select|textarea)\b[^>]*>/g, '\u0000');
obj.plain = obj.plain.replace(/<\/(option|legend|optgroup)>/g, '\u0000');
 
// table
obj.plain = obj.plain.replace(/<\/?(table|caption)\b[^>]*>/g, '\u0000');
obj.plain = obj.plain.replace(/<\/(tr|th|td)>/g, '\u0000');
 
// finish html to plain conversion
obj.plain = obj.plain.replace(/<[^>]*>/g, '');
 
// remove trailing spaces
obj.plain = obj.plain.replace(/[ \t\u00a0]+([\n\u0000])/g, '$1');
 
// trim down \u0000 and \n
obj.plain = obj.plain.replace(/\u0000+/g, '\n');
obj.plain = obj.plain.replace(/^\n+/g, '');
obj.plain = obj.plain.replace(/\n{2,}$/g, '\n');
 
return;
}
 
 
//
// InactiveButtonsWikEdInactiveButtons: grey out inactive buttons, called after every change and click ////////////////////
//
 
function InactiveButtonsWikEdInactiveButtons() {
 
// undo, prevpos
if (wikEdFrameDocument.queryCommandEnabled('undo') == true ) {
document.getElementById('wikEdUndo').className = 'wikEdButton';
document.getElementById('wikEdPrevPos').className = 'wikEdButton';
document.getElementById('wikEdUndoAll').className = 'wikEdButton';
}
}
else {
document.getElementById('wikEdUndo').className = 'wikEdButtonInactive';
document.getElementById('wikEdPrevPos').className = 'wikEdButtonInactive';
document.getElementById('wikEdUndoAll').className = 'wikEdButtonInactive';
}
}
 
// redo
if (wikEdFrameDocument.queryCommandEnabled('redo') == true ) {
document.getElementById('wikEdRedo').className = 'wikEdButton';
}
}
else {
document.getElementById('wikEdRedo').className = 'wikEdButtonInactive';
}
}
 
// redo all
if (wikEdLastVersion != null) {
document.getElementById('wikEdRedoAll').className = 'wikEdButton';
}
}
else {
document.getElementById('wikEdRedoAll').className = 'wikEdButtonInactive';
}
}
 
// lastpos
if (wikEdLastPosObj != null) {
document.getElementById('wikEdLastPos').className = 'wikEdButton';
}
}
else {
document.getElementById('wikEdLastPos').className = 'wikEdButtonInactive';
}
}
 
return;
}
 
Line 2,517 ⟶ 2,620:
 
// non-breaking space character to normal space
obj.plain = obj.plain.replace(/(\u00a0)/g, ' ');
 
// remove trailing spaces
obj.plain = obj.plain.replace(/( |&nbsp;)+\n/g, '\n');
 
// empty line before and after headings, spaces around word (lookahead)
obj.plain = obj.plain.replace(/\n+(={2,}) *([^\n]*?) *(={2,})(?=\n)\n*/g, '\n\n$1 $2 $3\n\n');
 
// uppercase well known headings
obj.plain = obj.plain.replace(/\n== external links? ==\n/ig, '\n== External links ==\n');
obj.plain = obj.plain.replace(/\n== see also ==\n/ig, '\n== See also ==\n');
obj.plain = obj.plain.replace(/\n== references? ==\n/ig, '\n== References ==\n');
 
// add space after * # : ; (list) and after {| |- | (table)
obj.plain = obj.plain.replace(/(^|\n)([\*\#\:\;]+|\{\||\|\-|\|\}|\|) */g, '$1$2 ');
obj.plain = obj.plain.replace(/ +\n/g, '\n');
 
// empty line before and after tables
obj.plain = obj.plain.replace(/\n+(\{\|)/g, '\n\n$1');
obj.plain = obj.plain.replace(/(\n\|\}) *([^\n]*)[\n|$]+/g, '$1\n\n$2\n\n');
 
// empty line before and after lists
obj.plain = obj.plain.replace(/(^|\n)([^\*\#\:\;].*?)\n+([\*\#\:\;])/g, '$1$2\n\n$3');
obj.plain = obj.plain.replace(/(^|\n)([\*\#\:\;].*?)\n+([^\*\#\:\;])/g, '$1$2\n\n$3');
 
// split into lines and change single lines, used to handle tables
var lines = obj.plain.split('\n');
obj.plain = '';
var tableflag = false;
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
 
// do not change lines starting with a blank
if ( ! line.match(/^ /) ) {
 
// detect table
if ( line.match(/^(\{\||\!|\|[^}])/) ) {
tableflag = true;
}
}
else if ( line.match(/^\|\}/) ) {
tableflag = false;
}
}
 
// changes only to be done in tables
if (tableflag) {
 
// add spaces around ||
line = line.replace(/ *\|\| */g, ' || ');
}
}
 
// changes not to be done in tables
if ( ! tableflag) {
 
// empty line before and after images
line = line.replace(/^(\[\[image:.*?\]\])/ig, '\n$1');
line = line.replace(/(\[\[image:.*?(\[\[.*?\]\].*?)*\]\])$/ig, '$1\n');
 
// empty line before and after includes
line = line.replace(/^(\{\{.*?\}\})/g, '\n$1');
line = line.replace(/(\{\{.*?\}\})$/g, '$1\n');
 
// to be done: convert single newlines into spaces
// line = line.replace(/(\n[^\n \*\#\:\;\|\{].*?)\n([^\n \*\#\:\;\|\{])/g, '$1 $2');
}
}
}
}
 
// concatenate the lines
obj.plain += line;
if (i < lines.length - 1) {
obj.plain += '\n';
}
}
}
}
 
// remove spaces in wikilinks
obj.plain = obj.plain.replace(/\[\[ *([^\n]*?) *\]\]/g, '[[$1]]');
 
// remove spaces in external links
obj.plain = obj.plain.replace(/\[ *([^\n]*?) *\]/g, '[$1]');
 
// no space around pipes before brackets
obj.plain = obj.plain.replace(/ +\| +\]\]/g, '|]]');
 
// no space around pipes before curly brackets
obj.plain = obj.plain.replace(/ +\| +\}\}/g, '|}}');
 
// no empty line between headings and includes
obj.plain = obj.plain.replace(/\n(==+ [^\n]*? ==+\n)\n+(\{\{.*?\}\})/g, '\n$1$2');
 
// spaces in comments
obj.plain = obj.plain.replace(/(&lt;!--) *([^\n]*?) *(--&gt;)/g, '$1 $2 $3');
 
 
/* ????
// empty lines around html comments
obj.plain = obj.plain.replace(/\n+(&lt;!--.*?--&gt;)\n+/g, '\n$1\n\n');
obj.plain = obj.plain.replace(/^(&lt;!--.*?--&gt;)\n+/g, '$1\n');
obj.plain = obj.plain.replace(/\n+(&lt;!--.*?--&gt;)$/g, '\n$1');
*/
 
// empty line before and after categories
obj.plain = obj.plain.replace(/( |\n)*(\[\[category:[^\n]*?\]\])( |\n)*/gi, '\n\n$2\n\n');
 
// categories not separated by empty lines (lookahead)
obj.plain = obj.plain.replace(/(\[\[category:[^\n]*?\]\])\n*(?=\[\[category:[^\n]*?\]\])/gi, '$1\n');
 
// single empty lines only
obj.plain = obj.plain.replace(/\n{3,}/g, '\n\n');
 
// remove leading and trailing newlines
obj.plain = obj.plain.replace(/^\n+/, '');
obj.plain = obj.plain.replace(/\n{2,}$/, '\n');
 
return;
}
 
Line 2,638 ⟶ 2,741:
 
function WikEdFixPunct(obj) {
WikEdFixBasic(obj);
 
obj.plain = obj.plain.replace(/([\w\'\"\”\]\}\)]) +([\.\,\:\;])(\s+|$)/g, '$1$2 ');
obj.plain = obj.plain.replace(/\s+$/g, '');
 
return;
}
 
Line 2,654 ⟶ 2,757:
 
// replace supported chars: change decimal, hex, and character entities into actual char
for (i = 0; i < wikEdSupportedChars.length; i ++) {
var replaceChar = String.fromCharCode(parseInt(wikEdSupportedChars[i][0], 16));
 
// decimal representation
var regExpStr = '&#0*' + parseInt(wikEdSupportedChars[i][0], 16) + ';|';
 
// hex representation
regExpStr += '&#x0*' + wikEdSupportedChars[i][0] + ';';
 
// case insensitive replace
var regExp = new RegExp(regExpStr, 'gi');
obj.plain = obj.plain.replace(regExp, replaceChar);
 
// character entity representation
regExpStr = '&amp;' + wikEdSupportedChars[i][1] + ';';
 
// case sensitive replace
regExp = new RegExp(regExpStr, 'g');
obj.plain = obj.plain.replace(regExp, replaceChar);
}
}
 
// replace unsupported chars (IE6): change decimal, hex, and chars into character entities
for (i = 0; i < wikEdProblemChars.length; i ++) {
replaceChar = '&' + wikEdProblemChars[i][1] + ';';
 
// decimal representation
regExpStr = '&#0*' + parseInt(wikEdProblemChars[i][0], 16) + ';|';
 
// hex representation
regExpStr += '&#x0*' + wikEdProblemChars[i][0] + ';';
 
// case insensitive replace
regExp = new RegExp(regExpStr, 'gi');
obj.plain = obj.plain.replace(regExp, replaceChar);
 
// actual character representation
regExpStr = '\\u' + wikEdProblemChars[i][0];
 
// case sensitive replace
regExp = new RegExp(regExpStr, 'g');
obj.plain = obj.plain.replace(regExp, replaceChar);
}
}
 
// replace special chars (spaces and invisible characters): change decimal, hex, and chars into character entities
for (i = 0; i < wikEdSpecialChars.length; i ++) {
var replaceChar = '&amp;' + wikEdSpecialChars[i][1] + ';';
 
// decimal representation
var regExpStr = '&#0*' + parseInt(wikEdSpecialChars[i][0], 16) + ';|';
 
// hex representation
regExpStr += '&#x0*' + wikEdSpecialChars[i][0] + ';';
 
// case insensitive replace
var regExp = new RegExp(regExpStr, 'gi');
obj.plain = obj.plain.replace(regExp, replaceChar);
 
// actual character representation
regExpStr = '\\u' + wikEdSpecialChars[i][0];
 
// case sensitive replace
var regExp = new RegExp(regExpStr, 'g');
obj.plain = obj.plain.replace(regExp, replaceChar);
}
}
 
// unicode line separator and paragraph separator
obj.plain = obj.plain.replace(/\u2028/g, '\n');
obj.plain = obj.plain.replace(/\u2029/g, '\n\n');
 
return;
}
 
Line 2,733 ⟶ 2,836:
function WikEdFixMath(obj) {
 
WikEdFixBasic(obj);
 
// change only outside <math> </math> wikicode
obj.plain = obj.plain.replace(/(.*?)((&lt;math(\b.*?)&gt;.*?&lt;\/math&gt;)|$)/gi,
function (p, p1, p2) {
 
// convert html entities into actual dash characters
p1 = p1.replace(/&plus;/g, '+');
p1 = p1.replace(/&minus;/g, '\u2212');
p1 = p1.replace(/&middot;/g, '·');
 
// convert dash next to a number into a minus sign character
p1 = p1.replace(/([^\w\,\{])-(\d)/g, '$1\u2212$2');
 
// changes 2x3 to 2×3
p1 = p1.replace(/(\d *)x( *\d)/g, '$1\u00d7$2');
 
// changes 10^3 to 10<sup>3</sup>
p1 = p1.replace(/(\d*\.?\d+)\^(\u2212?\d+\.?\d*)/g, '$1&lt;sup&gt;$2&lt;/sup&gt;');
 
// change x^3 to x<sup>3</sup>
p1 = p1.replace(/([\w])\^(\u2212?\d+\.?\d*) /g, '$1&lt;sup&gt;$2&lt;/sup&gt;');
 
// change +/- to ±
p1 = p1.replace(/( |\d)\+\/(-|\u2212)( |\d)/g, '$1\u00b1$3');
 
// htmlize single char superscripts
p1 = p1.replace(/(\u00b9|&sup1;)/g, '&lt;sup&gt;1&lt;/sup&gt;');
p1 = p1.replace(/(\u00b2|&sup2;)/g, '&lt;sup&gt;2&lt;/sup&gt;');
p1 = p1.replace(/(\u00b3|&sup3;)/g, '&lt;sup&gt;3&lt;/sup&gt;');
 
return(p1 + p2);
}
}
);
return;
}
 
Line 2,777 ⟶ 2,880:
function WikEdFixChem(obj) {
 
WikEdFixBasic(obj);
 
var realElements = 'H|He|Li|Be|B|C|N|O|F|Ne|Na|Mg|Al|Si|P|S|Cl|Ar|K|Ca|Sc|Ti|V|Cr|Mn|Fe|Co|Ni|Cu|Zn|Ga|Ge|As|Se|Br|Kr|Rb|Sr|Y|Zr|Nb|Mo|Tc|Ru|Rh|Pd|Ag|Cd|In|Sn|Sb|Te|I|Xe|Cs|Ba|Hf|Ta|W|Re|Os|Ir|Pt|Au|Hg|Tl|Pb|Bi|Po|At|Rn|Fr|Ra|Rf|Db|Sg|Bh|Hs|Mt|Ds|Rg|La|Ce|Pr|Nd|Pm|Sm|Eu|Gd|Tb|Dy|Ho|Er|Tm|Yb|Lu|Ac|Th|Pa|U|Np|Pu|Am|Cm|Bk|Cf|Es|Fm|Md|No|Lr';
var pseudoElements = '|Me|Et|Pr|Bu|e';
 
// fix common typos
obj.plain = obj.plain.replace(/([^a-z])h2o([^a-z])/g, '$1H2O$2');
obj.plain = obj.plain.replace(/([^a-z])h3o+/g, '$1H3O+');
obj.plain = obj.plain.replace(/([^a-z])oh-/g, '$1OH+');
 
// uppercase lowercased elements
var regExp = new RegExp('(^|[^a-zA-Z])(' + realElements.toLowerCase() + pseudoElements.toLowerCase() + ')([^a-zA-Z]|$)', 'g');
obj.plain = obj.plain.replace(regExp,
function (p, p1, p2, p3) {
if (p2 != 'e') {
p2 = p2.substr(0, 1).toUpperCase() + p2.substr(1).toLowerCase();
}
}
return(p1 + p2 + p3);
}
}
);
 
// fix superscripts
obj.plain = obj.plain.replace(/&plus;/g, '+');
obj.plain = obj.plain.replace(/&minus;/g, '\u2212');
obj.plain = obj.plain.replace(/&middot;/g, '·');
regExp = new RegExp('(' + realElements + pseudoElements + '|\\))(\\d*(\\+|-|\\u2212))', 'g');
obj.plain = obj.plain.replace(regExp,
function (p, p1, p2, p3) {
p2 = p2.replace(/-/g, '\u2212');
return(p1 + '&lt;sup&gt;' + p2 + '&lt;/sup&gt;');
}
}
);
 
// fix indices
regExp = new RegExp('(' + realElements + pseudoElements + '|\\))(\\d+)', 'g');
obj.plain = obj.plain.replace(regExp, '$1&lt;sub&gt;$2&lt;/sub&gt;');
 
// fix prefixes
regExp = new RegExp('(\\d+) *(\\(|' + realElements + pseudoElements + ')', 'g');
obj.plain = obj.plain.replace(regExp, '$1$2');
 
// fix arrows
obj.plain = obj.plain.replace(/ *-+&gt; */g, ' \u2192 ');
obj.plain = obj.plain.replace(/ *&lt;-+ */g, ' \u2190 ');
 
// &hdarr; and "leftwards harpoon over rightwards harpoon" not yet supported in IE
// obj.plain = obj.plain.replace(/ *(&lt;=+&gt;|&hdarr;|&harr;|\u2190 *\u2192) */g, ' \u21cc ');
obj.plain = obj.plain.replace(/ *(&lt;==+&gt;|&hdarr;|&harr;|\u21cc|\u2190 *\u2192) */g, ' <=> ');
 
// fix -
obj.plain = obj.plain.replace(/(\w|\)|&gt;) +(-|\u2212) +(\w|\()/g, '$1 \u2212 $3');
 
return;
}
 
Line 2,839 ⟶ 2,942:
 
function WikEdFixUnits(obj) {
WikEdFixBasic(obj);
 
// convert all &deg; into actual ° symbol
obj.plain = obj.plain.replace(/&deg;/g, '°');
 
// convert the word ohm(s) or the html entity into the actual Omega symbol (not the actual ohm symbol &#8486;) and make sure it's spaced
obj.plain = obj.plain.replace(/(\d) ?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|&mu;|µ|&micro;|n|p|f|a|z|y)? ?(&Omega;|&#8486;|(ohm|Ohm)s?)([\s.,:;\'\"\/\)])/g, '$1 $2\u03a9$5');
 
// convert various micro symbols into the actual micro symbol, make sure it's spaced
obj.plain = obj.plain.replace(/(\d) ?(&mu;|&micro;)(g|s|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|O|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|M)([\s.,:;\'\"\/\)])/g, '$1 µ$3$4');
 
// convert capital K to lowercase k in units
obj.plain = obj.plain.replace(/(\d) ?K(g|s|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|O|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|M)([\s.,:;\'\"\/\)])/g, '$1 k$2$3');
 
// capitalize units correctly
obj.plain = obj.plain.replace(/(\d) ?(khz)([ ,.])/gi, '$1 kHz$3');
obj.plain = obj.plain.replace(/(\d) ?(mhz)([ ,.])/gi, '$1 MHz$3');
obj.plain = obj.plain.replace(/(\d) ?(ghz)([ ,.])/gi, '$1 GHz$3');
obj.plain = obj.plain.replace(/(\d) ?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|&mu;|µ|&micro;|n|p|f|a|z|y)?(hz|HZ)([\s.,:;\'\"\/\)])/g, '$1 $2Hz$4');
obj.plain = obj.plain.replace(/(\d) ?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|&mu;|µ|&micro;|n|p|f|a|z|y)?(pa|PA)([\s.,:;\'\"\/\)])/g, '$1 $2Pa$4');
 
// add a space before dB
obj.plain = obj.plain.replace(/(\d) ?(dB)([\s.,:;\'\"\/\)])/g, '$1 $2$3');
 
// add a space before any units that were missed before
obj.plain = obj.plain.replace(/(\d) ?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|&mu;|µ|&micro;|n|p|f|a|z|y)?(g|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|O|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|M)([\s.,:;\'\"\/\)])/g, '$1 $2$3$4');
 
// separate one for seconds since they give a lot of false positives like "1970s". Only difference is mandatory prefix.
obj.plain = obj.plain.replace(/(\d) ?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|&mu;|µ|&micro;|n|p|f|a|z|y)(s)([\s.,:;\'\"\/\)])/g, '$1 $2$3$4');
 
// bps or b/s or bits/s --> bit/s
obj.plain = obj.plain.replace(/([KkMmGgTtPpEeYyZz])(bps|bits?\/s|b\/s)/g, '$1bit/s');
 
// Bps or byte/s or bytes/s --> B/s
obj.plain = obj.plain.replace(/([KkMmGgTtPpEeYyZz])(Bps|bytes?\/s)/g, '$1B/s');
 
// after that, make capitalization correct
obj.plain = obj.plain.replace(/K(bit|B)\/s/g, 'k$1/s');
obj.plain = obj.plain.replace(/m(bit|B)\/s/g, 'M$1/s');
obj.plain = obj.plain.replace(/g(bit|B)\/s/g, 'G$1/s');
obj.plain = obj.plain.replace(/t(bit|B)\/s/g, 'T$1/s');
obj.plain = obj.plain.replace(/e(bit|B)\/s/g, 'E$1/s');
obj.plain = obj.plain.replace(/y(bit|B)\/s/g, 'Y$1/s');
obj.plain = obj.plain.replace(/z(bit|B)\/s/g, 'Z$1/s');
 
// fix a common error
obj.plain = obj.plain.replace(/mibi(bit|byte)/g, 'mebi$1');
 
return;
}
 
Line 2,897 ⟶ 3,000:
 
function WikEdFixDashes(obj) {
WikEdFixBasic(obj);
 
// convert html entities into actual dash characters
obj.plain = obj.plain.replace(/&mdash;/g, '—');
obj.plain = obj.plain.replace(/&ndash;/g, '–');
obj.plain = obj.plain.replace(/&minus;/g, '\u2212');
 
// convert -- and em dashes with or without spaces to em dash surrounded by spaces
obj.plain = obj.plain.replace(/([a-zA-Z\'\"”\]\}\)]) *(--|—|&mdash;) *([a-zA-Z\'\"“\[\{\(])/g, '$1 — $3');
 
// convert - or en dashes with spaces to em dash character surrounded by spaces
obj.plain = obj.plain.replace(/([a-zA-Z\'\"”\]\}])( |&nbsp;)+(\u2212|–|&ndash;) +([a-zA-Z\'\"“\[\{])/g, '$1$2— $4');
 
// convert hyphen next to lone number into a minus sign character
obj.plain = obj.plain.replace(/([a-zA-Z\'\"”\]\>] )-(\d)/g, '$1\u2212$2');
 
// convert dashes to en dashes in dates
obj.plain = obj.plain.replace(/([ \(][12]\d\d\d) ?(--?|—|&mdash;) ?([12]\d\d\d|\d\d)([ \),.;])/g, '$1–$3$4');
 
return;
}
 
Line 2,925 ⟶ 3,028:
 
function WikEdFixHTML(obj) {
WikEdFixBasic(obj);
 
// remove syntax highlighting
obj.html = obj.plain;
obj.html = obj.html.replace(/\n/g, '<br />');
WikEdRemoveHighlighting(obj);
 
// turn visible html code into real html, exclude comments
obj.html = obj.html.replace(/&lt;(\/?\w.*?)&gt;/g, '<$1>');
 
// wikify
WikEdWikifyHTML(obj);
 
// turn real html into visible html code
obj.html = obj.html.replace(/<br\b[^>]*>/g, '\n');
obj.html = obj.html.replace(/</g, '&lt;');
obj.html = obj.html.replace(/>/g, '&gt;');
obj.plain = obj.html;
 
return;
}
 
Line 2,953 ⟶ 3,056:
 
function WikEdFixCaps(obj) {
WikEdFixBasic(obj);
 
// uppercase lists
// start (listcode (char-ent|tag|category..|digit|non-word,non-ret))(word,non-digit..) end
obj.plain = obj.plain.replace(/^([\*\#\:\;]+ (\&\w+\;|&lt;[^\n]*?&gt;|\{\{.*?\}\}[^\n]*|\d|[^\w\n])*)([^\W\d].*?)?$/gm,
function (p, p1, p2, p3) {
if ( ! p3.match(/^(http|ftp|alpha|beta|gamma|delta|epsilon|kappa|lambda|$)/) ) {
p3 = p3.substr(0, 1).toUpperCase() + p3.substr(1);
}
}
return(p1 + p3);
}
}
);
 
// uppercase link lists (link)
obj.plain = obj.plain.replace(/^([\*\#\:\;]+ \[\[)([^\n]*?)(\]\])/gm,
function (p, p1, p2, p3) {
 
// uppercase link
p2 = p2.replace(/^((\&\w+\;|\W|\d)*)([^\W\d].*)$/,
function (p, p1, p2, p3) {
if ( ! p3.match(/^(http|ftp|alpha|beta|gamma|delta|epsilon|kappa|lambda)/) ) {
p3 = p3.substr(0, 1).toUpperCase() + p3.substr(1);
}
}
return(p1 + p3);
}
}
);
);
 
// uppercase comment
p2 = p2.replace(/(\| *(\&\w+\;|&lt;[^\n]*?&gt;|\W|\d)*)([^\W\d].*)$/,
function (p, p1, p2, p3) {
if ( ! p3.match(/^(http|ftp|alpha|beta|gamma|delta|epsilon|kappa|lambda)/) ) {
p3 = p3.substr(0, 1).toUpperCase() + p3.substr(1);
}
}
return(p1 + p3);
}
}
);
);
return(p1 + p2 + p3);
}
}
);
 
// uppercase headings
obj.plain = obj.plain.replace(/^(==+ (\&\w+\;|&lt;[^\n]*?&gt;|\d|[^\w\n])*)([^\W\d].*? ==+)$/gm,
function (p, p1, p2, p3) {
if ( ! p3.match(/^(http|ftp|alpha|beta|gamma|delta|epsilon|kappa|lambda)/) ) {
p3 = p3.substr(0, 1).toUpperCase() + p3.substr(1);
}
}
return(p1 + p3);
}
}
);
 
// uppercase images
obj.plain = obj.plain.replace(/(\[\[)image:(\w)([^\n]*\]\])/igm,
function (p, p1, p2, p3) {
return(p1 + 'Image:' + p2.toUpperCase() + p3);
}
}
);
 
return;
}
 
Line 3,018 ⟶ 3,121:
 
function WikEdFixAll(obj) {
WikEdFixBasic(obj);
WikEdFixUnicode(obj);
WikEdFixHTML(obj);
WikEdFixCaps(obj);
return;
}
 
Line 3,033 ⟶ 3,136:
 
// cycle through the element names
for each (var tagNameStr in tagNameArray) {
var elementArray = wikEdFrameDocument.getElementsByTagName(tagNameStr);
for (i = 0; i < elementArray.length; i ++) {
elementArray[i].parentNode.removeChild(elementArray[i]);
}
}
}
}
return;
}
 
Line 3,050 ⟶ 3,153:
 
// get the start node and offset
var startNode = selection.range.startContainer;
var startNodeOffset = selection.range.startOffset;
 
// get the end node and offset
var endNode = selection.range.endContainer;
var endNodeOffset = selection.range.endOffset;
 
if (startNode.nodeType == 1) {
startNode = startNode.childNodes[startNodeOffset];
startNodeOffset = 0;
}
}
if (endNode.nodeType == 1) {
endNode = endNode.childNodes[endNodeOffset];
endNodeOffset = 0;
}
}
 
// find the start and end nodes in the whole plain text arrays
var startNodeIndex;
var endNodeIndex;
for (i = 0; i < whole.plainNode.length; i ++) {
if (startNode == whole.plainNode[i]) {
startNodeIndex = i;
}
}
if (endNode == whole.plainNode[i]) {
endNodeIndex = i;
break;
}
}
}
}
 
// find last previous word and line boundary
var foundWord = false;
var foundLine = false;
var regExp = new RegExp('.*[^\\w\\-]', 'g');
var plain = '';
 
// check text nodes left-wise for a boundary
for (i = startNodeIndex; i >= 0; i --) {
plain = whole.plainArray[i];
 
plain = plain.replace(/&amp;/g, '&');
plain = plain.replace(/&lt;/g, '<');
plain = plain.replace(/&gt;/g, '>');
 
// boundary is a newline
if (plain == '\n') {
 
// current newline is the start node
if (i == startNodeIndex) {
if (! foundWord) {
word.range.setStartBefore(whole.plainNode[i]);
foundWord = true;
}
}
line.range.setStartBefore(whole.plainNode[i]);
}
}
else {
if (! foundWord) {
word.range.setStartAfter(whole.plainNode[i]);
foundWord = true;
}
}
line.range.setStartAfter(whole.plainNode[i]);
}
}
foundLine = true;
break;
}
}
 
// check text node for a word boundary
else if (! foundWord) {
if (i == startNodeIndex) {
plain = plain.substr(0, startNodeOffset);
 
plain = plain.replace(/&amp;/g, '&');
plain = plain.replace(/&lt;/g, '<');
plain = plain.replace(/&gt;/g, '>');
}
}
regExp.lastIndex = 0;
if (regExp.exec(plain) != null) {
word.range.setStart(whole.plainNode[i], regExp.lastIndex); /////
foundWord = true;
}
}
}
}
}
}
 
// boundary is start of text
if (! foundLine) {
line.range.setStartBefore(whole.plainNode[0]);
if (! foundWord) {
word.range.setStartBefore(whole.plainNode[0]);
}
}
}
}
 
// find next word and line boundary
regExp = new RegExp('[^\\w\\-]', 'g');
foundWord = false;
foundLine = false;
 
// check text nodes right-wise for a boundary
for (i = endNodeIndex; i < whole.plainArray.length; i ++) {
plain = whole.plainArray[i];
 
plain = plain.replace(/&amp;/g, '&');
plain = plain.replace(/&lt;/g, '<');
plain = plain.replace(/&gt;/g, '>');
 
// boundary is a newline
if (plain == '\n') {
if (! foundWord) {
word.range.setEndBefore(whole.plainNode[i]);
foundWord = true;
}
}
line.range.setEndBefore(whole.plainNode[i]);
foundLine = true;
break;
}
}
 
// check text node for a word boundary
else if (! foundWord) {
if (i == endNodeIndex) {
regExp.lastIndex = endNodeOffset;
}
}
else {
regExp.lastIndex = 0;
}
}
var regExpArray = regExp.exec(plain);
if (regExpArray != null) {
word.range.setEnd(whole.plainNode[i], regExpArray.index);
foundWord = true;
}
}
}
}
}
}
 
// boundary is end of text
if (! foundLine) {
line.range.setEndAfter(whole.plainNode[whole.plainArray.length - 1]);
if (! foundWord) {
word.range.setEndAfter(whole.plainNode[whole.plainArray.length - 1]);
}
}
}
}
return;
}
 
Line 3,197 ⟶ 3,300:
function WikEdRemoveHighlightingWikify(obj) {
 
if (obj.html != '') {
 
// remove syntax highlighting
WikEdRemoveHighlighting(obj);
 
// wikify
if (obj.htmlCode == true) {
WikEdWikifyHTML(obj);
}
}
}
}
return;
}
 
Line 3,217 ⟶ 3,320:
 
/*
allowed and converted tags:
br|p
h1|h2|h3|h4|h5|h6
hr
hr
i|dfn|cite|em|var
b|strong
table|caption|col|thead|tfoot|tbody|tr|td|th
dl|dt|dd|li|ol|ul
a
a
not allowed yet:
bdo|q|kbd|samp|abbr|acronym|label
other allowed tags:
big|blockquote|colgroup|center|code|del|div|font|ins|pre|s|small|span|strike|sub|sup|tt|u|rb|rp|rt|ruby
mediawiki tags:
nowiki|math|gallery|noinclude|includeonly|ref|references
*/
 
function WikEdWikifyHTML(obj) {
 
var regExpStr;
var regExp;
var regExpMatch;
 
// delete tags: <style>
obj.html = obj.html.replace(/<(style)\b[^>]*>.*?<\/\1>/g, '');
 
// sanitize attributes in opening html tags
obj.html = obj.html.replace(/<(\w+)(.*?) *(\/?)>/g,
function (p, p1, p2, p3) {
if (p3 != '') {
p3 = ' ' + p3;
}
}
return('<' + p1 + WikEdSanitizeAttributes(p1, p2) + p3 + '>');
}
}
);
 
// remove <span> ... </span> pairs withhout attributes
var isRemove = [];
obj.html = obj.html.replace(/(<(\/?)span\b([^>]*)>)/g,
function (p, p1, p2, p3) {
if (p2 == '') {
if (p3 == '') {
isRemove.push(true);
return('');
}
}
isRemove.push(false);
return(p1);
}
}
if (isRemove.pop() == true) {
return('');
}
}
return(p1);
}
}
);
 
// remove <p> ... </p> pairs withhout attributes
var isRemove = [];
obj.html = obj.html.replace(/(<(\/?)p\b([^>]*)>)/g,
function (p, p1, p2, p3) {
if (p2 == '') {
if (p3 == '') {
isRemove.push(true);
return('\n\n');
}
}
isRemove.push(false);
return(p1);
}
}
if (isRemove.pop() == true) {
return('\n\n');
}
}
return(p1);
}
}
);
 
// remove trailing spaces
obj.html = obj.html.replace(/[ \t]+\n/g, '\n');
 
// escape character entities
obj.html = obj.html.replace(/&(?!(amp;|lt;|gt;))/g, '&amp;');
 
// remove MediaWiki table of contents
obj.html = obj.html.replace(/<table\b[^>]*?\bid=\"toc\"[^>]*>.*?<\/table>/g, '');
 
// remove MediaWiki print footer
obj.html = obj.html.replace(/<div\b[^>]*?\bclass=\"printfooter\"[^>]*>[^<>\"]+\"<a\b[^>]*>[^<]+<\/a>\"<\/div> */g, '');
 
// remove MediaWiki category list tags
regExp = /<div\b[^>]*\bid=\"catlinks\"[^>]*>(.*?)<\/div>/g;
while(regExp.test(obj.html) == true) {
obj.html = obj.html.replace(regExp, '$1');
}
}
regExp = /<p\b[^>]*?\bclass=\"catlinks\"[^>]*>(.*?)<a\b[^>]*>[^<>]+<\/a>: (.*?)<\/p>/g;
while(regExp.test(obj.html) == true) {
obj.html = obj.html.replace(regExp, '$1$2');
}
}
 
// remove comments
obj.html = obj.html.replace(/<!--.*?-->/g, '');
 
// <hr> horizontal rule
obj.html = obj.html.replace(/\s*<hr\b[^>]*>\s*/i, '\n----\n');
 
// <i> <em> <dfn> <var> <cite> italic
obj.html = obj.html.replace(/<(i|em|dfn|var|cite)\b[^>]*>/g, '\'\'');
obj.html = obj.html.replace(/<\/(i|em|dfn|var|cite)\b[^>]*>/g, '\'\'');
 
// <b> <strong> bold
obj.html = obj.html.replace(/<(b|strong)\b[^>]*>/g, '\'\'\'');
obj.html = obj.html.replace(/<\/(b|strong)\b[^>]*>/g, '\'\'\'');
 
// <h1> .. <h6> headings
obj.html = obj.html.replace(/<span class=\"editsection\">.*?<\/span> */g, '');
 
obj.html = obj.html.replace(/\s*<h1\b[^>]*>(.*?)<\/h1>\s*/g, '\n\n= $1 =\n\n');
obj.html = obj.html.replace(/\s*<h2\b[^>]*>(.*?)<\/h2>\s*/g, '\n\n== $1 ==\n\n');
obj.html = obj.html.replace(/\s*<h3\b[^>]*>(.*?)<\/h3>\s*/g, '\n\n=== $1 ===\n\n');
obj.html = obj.html.replace(/\s*<h4\b[^>]*>(.*?)<\/h4>\s*/g, '\n\n==== $1 ====\n\n');
obj.html = obj.html.replace(/\s*<h5\b[^>]*>(.*?)<\/h5>\s*/g, '\n\n===== $1 =====\n\n');
obj.html = obj.html.replace(/\s*<h6\b[^>]*>(.*?)<\/h6>\s*/g, '\n\n====== $1 ======\n\n');
 
obj.html = obj.html.replace(/<span\b[^>]*\bclass=\"mw-headline\">(.*?)<\/span> */g, '$1');
 
// sanitize <span> <div>
obj.html = obj.html.replace(/<(span|div) ([^>]*)>/g,
function (p, p1, p2) {
return('<' + p1 + WikEdSanitizeAttributes(p1, p2) + '>');
}
}
);
 
// remove <thead> <tbody> <tfoot>
obj.html = obj.html.replace(/\s*<(thead|tbody|tfoot)\b[^>]*>\s*/g, '');
 
// line breaks in table cells
obj.html = obj.html.replace(/(<(td|th)\b[^>]*>)\s*([^]*?)(<\/\2>)/g,
function(p, p1, p2, p3, p4) {
p3 = p3.replace(/\n/g, '&lt;br /&gt;\n');
return(p1 + '<br />' + p3 + p4);
}
}
);
 
// remove table closing tags
obj.html = obj.html.replace(/(<\/(td|th|tr|caption|thead|tbody|tfoot)>)/g, '');
 
// <td> table cells
obj.html = obj.html.replace(/\s*<td>/g, '\n| ');
obj.html = obj.html.replace(/\s*<(td) ([^>]*)>\s*/g,
function (p, p1, p2) {
return('\n|' + WikEdSanitizeAttributes(p1, p2) + ' | ');
}
}
);
 
// <th> table cells
obj.html = obj.html.replace(/\s*<th>\s*/g, '\n| ');
obj.html = obj.html.replace(/\s*<(th) ([^>]*)>\s*/g,
function (p, p1, p2) {
return('\n!' + WikEdSanitizeAttributes(p1, p2) + ' | ');
}
}
);
 
// line breaks in table cells continued
obj.html = obj.html.replace(/<br\b[^>]*>/g, '\n');
 
// <tr> table rows
obj.html = obj.html.replace(/\s*<tr>\s*/g, '\n|-\n');
obj.html = obj.html.replace(/\s*<(tr) ([^>]*)>\s*/g,
function (p, p1, p2) {
return('\n|-' + WikEdSanitizeAttributes(p1, p2) + '\n');
}
}
);
 
// <caption> captionCaption
obj.html = obj.html.replace(/\s*<caption>\s*/g, '\n|+ ');
obj.html = obj.html.replace(/\s*<(caption) ([^>]*)>\s*/g,
function (p, p1, p2) {
return('\n|+' + WikEdSanitizeAttributes(p1, p2) + ' | ');
}
}
);
 
// <table> tables
obj.html = obj.html.replace(/\s*<table>\s*(\|-\n)?/g, '\n\n{|\n');
obj.html = obj.html.replace(/\s*<(table) ([^>]*)>\s*(\|-\n)?/g,
function (p, p1, p2) {
return('\n{|' + WikEdSanitizeAttributes(p1, p2) + '\n');
}
}
);
obj.html = obj.html.replace(/\s*<\/table>\s*/g, '\n|}\n\n');
 
// convert links
var regExpMatch = [];
var regExpStr = '(<a(\\b[^>]*)>(.*?)</a>)';
var regExp = new RegExp(regExpStr, 'gi');
obj.html = obj.html.replace(regExp,
function (p, p1, p2, p3) {
var linkPar = p2;
var linkText = p3;
var linkArticle = '';
var linkTitle = '';
var imgWidth = '';
 
// internal wiki links
 
// get the title="" parameter
regExpStr = ' href=\\"' + wikEdServer + '(' + wikEdArticlePath + '|' + wikEdScriptPath + ')([^\\">]*)\\"';
regExp = new RegExp(regExpStr);
regExpMatch = regExp.exec(linkPar);
if (regExpMatch != null) {
regExpStr = ' title=\\"([^\\">]*)\\"';
regExp = new RegExp(regExpStr);
regExpMatch = regExp.exec(linkPar);
if (regExpMatch != null) {
linkTitle = regExpMatch[1];
}
}
}
}
 
// get wiki article name from url parameter list
regExpStr = ' href=\\"' + wikEdServer + wikEdScriptPath + 'index\\.php\\?[^\\"]*?\\btitle=([^\\"]*?)(&amp;|\\")';
regExp = new RegExp(regExpStr);
regExpMatch = regExp.exec(linkPar);
if (regExpMatch != null) {
linkArticle = regExpMatch[1];
if (linkArticle != '') {
linkArticle = linkArticle.replace(/_/g, ' ');
linkArticle = decodeURIComponent(linkArticle);
 
// ISBN links
regExpStr = ' href=\\"' + wikEdServer + wikEdScriptPath + 'index\\.php\\?[^\\"]*?\\bisbn=(\\d+)(&amp;|\\")';
regExp = new RegExp(regExpStr);
regExpMatch = regExp.exec(linkPar);
if (regExpMatch != null) {
return('ISBN ' + regExpMatch[1]);
}
}
}
}
}
}
 
// get wiki article name from url
if (linkArticle == '') {
regExpStr = ' href=\\"' + wikEdServer + wikEdArticlePath + '([^\\"]*)\\"';
regExp = new RegExp(regExpStr);
regExpMatch = regExp.exec(linkPar);
if (regExpMatch != null) {
linkArticle = regExpMatch[1];
if (linkArticle != '') {
linkArticle = linkArticle.replace(/_/g, ' ');
linkArticle = decodeURIComponent(linkArticle);
}
}
}
}
}
}
 
// format wiki link
if (linkArticle != '') {
 
// check for wiki image
regExpStr = '^<img\\b[^>]*?\\bwidth=\\"(\\d+)\\"[^>]*?>$';
regExp = new RegExp(regExpStr);
regExpMatch = regExp.exec(linkText);
if (regExpMatch != null) {
imgWidth = regExpMatch[1];
imgWidth = '|' + imgWidth + 'px';
if ( (linkTitle != '') && (linkTitle != 'Enlarge') ) {
linkTitle = '|' + linkTitle;
return('[[' + linkArticle + imgWidth + linkTitle + ']]');
}
}
else {
return('[[' + linkArticle + imgWidth + ']]');
}
}
}
}
 
// ISBN link
regExpStr = '^' + wikEdServer + wikEdScriptPath + 'index\\.php\\?.*?\\btitle=.*?&amp;isbn=(\d+)';
regExp = new RegExp(regExpStr);
regExpMatch = regExp.exec(linkAddr);
if (regExpMatch != null) {
return('ISBN ' + regExpMatch[1]);
}
}
 
// category link
regExpMatch = /^category:(.*)/i.exec(linkArticle);
if (regExpMatch != null) {
return('[[Category:' + regExpMatch[1].substr(0, 1).toUpperCase() + linkText.substr(1) + ']]');
}
}
 
// wiki link
if (linkArticle == linkText.substr(0, 1).toUpperCase() + linkText.substr(1)) {
return('[[' + linkText + ']]');
}
}
 
// date link (English only)
regExpMatch = /^(January|February|March|April|May|June|July|August|September|October|November|December) (\d{1,2})$/.exec(linkArticle);
if (regExpMatch != null) {
var month = regExpMatch[1];
var day = regExpMatch[2];
if (linkText == (day + ' ' + month) ) {
return('[[' + linkArticle + ']]');
}
}
}
}
 
// lowercase the article name if the first char of the link text can exist in lower/uppercase and is lowercase
if ( linkText.substr(0, 1).toLowerCase() != linkText.substr(0, 1).toUpperCase() ) {
if ( linkText.substr(0, 1) == linkText.substr(0, 1).toLowerCase() ) {
linkArticle = linkArticle.substr(0, 1).toLowerCase() + linkArticle.substr(1);
}
}
}
}
 
// suffix links
regExpStr = '^' + linkArticle.replace(/(\W)/, '\\$1') + '(\\w+)$';
regExp = new RegExp(regExpStr);
regExpMatch = regExp.exec(linkText);
if (regExpMatch != null) {
return('[[' + linkText + ']]' + regExpMatch[1]);
}
}
return('[[' + linkArticle + '|' + linkText + ']]');
}
}
 
// external link
regExpMatch = linkPar.match(/ href=\"([^\">]*)\"/);
if (regExpMatch != null) {
var linkAddr = regExpMatch[1];
if (linkAddr != '') {
 
// PubMed link
regExpMatch = /^http:\/\/www\.ncbi\.nlm\.nih\.gov\/entrez\/query\.fcgi\?cmd=Retrieve&amp;db=pubmed&amp;.*?&amp;list_uids=(\d+)/.exec(linkAddr);
if (regExpMatch != null) {
return('PMID ' + regExpMatch[1]);
}
}
 
// DOI link
regExpMatch = /^http:\/\/dx\.doi\.org\/(.*)/.exec(linkAddr);
if (regExpMatch != null) {
return('{{doi|' + regExpMatch[1] + '}}');
}
}
 
// other external link
return('[' + linkAddr + ' ' + linkText + ']');
}
}
}
}
 
// return unchanged text
return(p1);
}
}
);
 
// clean up MediaWiki category list
obj.html = obj.html.replace(/<span\b[^>]*>(\[\[Category:[^\]]+\]\])<\/span>[\s\|]*/gi, '$1\n');
 
// clean up DOI
obj.html = obj.html.replace(/\[\[Digital object identifier\|DOI\]\]:(\{\{doi\|[^\}\s]+\}\})/gi, '$1');
 
// convert images
obj.html = obj.html.replace(/<img\b([^>]*)>/g,
function (p, p1) {
 
// get and format parameters
var address = '';
var regExpMatch = /\bsrc\s*=\s*(\'|\")([^\'\"]*)(\'|\")/i.exec(p1);
if (regExpMatch != null) {
address = regExpMatch[2].replace(/^ +| +$/g, '');
}
}
 
var imgAlt = '';
regExpMatch = /\balt\s*=\s*(\'|\")([^\'\"]*)(\'|\")/i.exec(p1);
if (regExpMatch != null) {
imgAlt = regExpMatch[2].replace(/^ +| +$/g, '');
imgAlt = imgAlt.replace(/&amp;nbsp;|\n/g, ' ');
imgAlt = imgAlt.replace(/ {2,}/g, ' ');
imgAlt = imgAlt.replace(/^ | $/g, '');
if (imgAlt != '') {
imgAlt = '|' + imgAlt;
}
}
}
}
 
var imgWidth = '';
regExpMatch = /\bwidth\s*=\s*(\'|\")([^\'\"]*)(\'|\")/i.exec(p1);
if (regExpMatch != null) {
imgWidth = '|' + regExpMatch[2].replace(/^ +| +$/g, '') + 'px';
}
}
 
var imgLink = '';
regExpMatch = /([^\/]+)$/.exec(address);
if (regExpMatch != null) {
imgLink = regExpMatch[1];
if (imgLink != '') {
return('[[Image:' + imgLink + imgWidth + imgAlt + ']]');
}
}
}
}
return('');
}
}
);
 
// convert lists: * # : ;
var listObj = {};
listObj.prefix = '';
obj.html = obj.html.replace(/ *<(\/?(ol|ul|li|dl|dd|dt))\b[^>]*> */g,
function (p, p1, p2, p3, p4) {
switch (p1.toLowerCase()) {
case 'ol':
listObj.prefix += '#';
return('\u0000');
case 'ul':
listObj.prefix += '*';
return('\u0000');
case 'dl':
listObj.prefix += ':';
return('\u0000');
case '/ol':
case '/ul':
case '/dl':
listObj.prefix = listObj.prefix.substr(0, listObj.prefix.length - 1);
return('\u0000');
case 'li':
case 'dd':
return('\u0000' + listObj.prefix + ' ');
case 'dt':
return('\u0000' + listObj.prefix.replace(/:$/, ';') + ' ');
case '/li':
case '/dt':
case '/dd':
return('');
}
}
}
}
);
obj.html = obj.html.replace(/\u0000+[#\*:\;]+ (?=\u0000)/g, '');
obj.html = obj.html.replace(/\u0000+/g, '\n');
 
// <> remove not allowed tags
obj.html = obj.html.replace(/(<\/?)(\/?)(\w+)(.*?>)/g,
function (p, p1, p2, p3, p4) {
if ( /^(big|blockquote|colgroup|center|code|del|div|font|ins|p|pre|s|small|span|strike|sub|sup|tt|u|rb|rp|rt|ruby|nowiki|math|gallery|noinclude|includeonly|ref|references)$/i.test(p3) ) {
return(p1 + p2 + p3 + p4);
}
}
else {
return('');
}
}
}
}
);
 
// remove empty inline and block tag pairs
obj.html = obj.html.replace(/<(big|colgroup|code|del|font|ins|pre|s|small|span|strike|sub|sup|tt|u|rb|rp|rt|ruby|nowiki)\b[^>]*><\/\1>/g, '');
obj.html = obj.html.replace(/<(blockquote|center|div|math|gallery|noinclude|includeonly|ref|references)\b[^>]*><\/\1>/g, '\n');
 
// escape < >
obj.html = obj.html.replace(/</g, '&lt;');
obj.html = obj.html.replace(/>/g, '&gt;');
 
// newlines to <br />
obj.html = obj.html.replace(/[ \t]+\n/g, '\n');
obj.html = obj.html.replace(/\n{3,}/g, '\n\n');
obj.html = obj.html.replace(/\n/g, '<br />');
 
return;
}
 
Line 3,675 ⟶ 3,778:
function WikEdSanitizeAttributes(tag, attributes) {
 
var common = 'lang|dir|style|class'; // not needed: id|title
var tablealign = '|align|char|charoff|valign';
var tablecell = '|abbr|axis|headers|scope|rowspan|colspan|nowrap|width|height|bgcolor';
tag = tag.toLowerCase();
var sanitized = '';
var regExp = /(\w+)\s*=\s*(\'|\")([^\'\"]*)(\'|\")/g;
var regExpMatch;
while (regExpMatch = regExp.exec(attributes)) {
var attrib = regExpMatch[1];
var attribValue = regExpMatch[3];
if (attribValue == '') {
continue;
}
}
var valid = false;
if ('center|em|strong|cite|code|var|sub|supdl|dd|dt|tt|b|i|big|small|strike|s|u|rb|rp|ruby'.indexOf(tag) >= 0) {
if (common.indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('div|span|h1|h2|h3|h4|h5|h6|p'.indexOf(tag) >= 0) {
if ((common + '|align').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('blockquote'.indexOf(tag) >= 0) {
if ((common + '|cite').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('br'.indexOf(tag) >= 0) {
if ('style|clear'.indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('pre'.indexOf(tag) >= 0) {
if ((common + '|width').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('ins|del'.indexOf(tag) >= 0) {
if ((common + '|cite|datetime').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('ul'.indexOf(tag) >= 0) {
if ((common + '|type').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('ol'.indexOf(tag) >= 0) {
if ((common + '|type|start').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('li'.indexOf(tag) >= 0) {
if ((common + '|type|value').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('table'.indexOf(tag) >= 0) {
if ((common + '|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor|frame|rules|border').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('caption'.indexOf(tag) >= 0) {
if ((common + '|align').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('thead|tfoot|tbody'.indexOf(tag) >= 0) {
if ((common + tablealign).indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('colgroup|col'.indexOf(tag) >= 0) {
if ((common + '|span|width' + tablealign).indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('tr'.indexOf(tag) >= 0) {
if ((common + '|bgcolor' + tablealign).indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('td|th'.indexOf(tag) >= 0) {
if ((common + tablecell + tablealign).indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('font'.indexOf(tag) >= 0) {
if ((common + '|size|color|face').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('hr'.indexOf(tag) >= 0) {
if ((common + '|noshade|size|width').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('rt'.indexOf(tag) >= 0) {
if ((common + '|rbspan').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('ref'.indexOf(tag) >= 0) {
if (('name').indexOf(attrib) >= 0) { valid = true; }
}
}
else if ('references'.indexOf(tag) >= 0) {
}
}
if (valid == true) {
 
// remove non-standard styles and clean up
if (attrib == 'style') {
attribValue = attribValue.replace(/(^| )(-moz-[\w\-]+): [\w\-]+; */g, '$1');
attribValue = attribValue.replace(/(^| )([\w\-]+): (-moz-[\w\-]+|windowtext); */g, '$1');
attribValue = attribValue.replace(/\b0(%|in|cm|mm|em|ex|pt|pc|px)\b/g, '0');
attribValue = attribValue.replace(/[\w\-]+ *\: *\; */g, '');
attribValue = attribValue.replace(/ *(;|:) */g, '$1 ');
attribValue = attribValue.replace(/( |;)+$/g, ';');
}
}
sanitized += ' ' + attrib + '="' + attribValue + '"';
}
}
}
}
return(sanitized);
}
 
Line 3,774 ⟶ 3,877:
 
// remove highlighting and atttribute-free span tags
var isRemove = [];
obj.html = obj.html.replace(/(<(\/?)span\b([^>]*)>)/g,
function (p, p1, p2, p3) {
if (p2 == '') {
if (/\bclass=\"wikEd\w+\"/.test(p3)) {
isRemove.push(true);
return('');
}
}
isRemove.push(false);
return(p1);
}
}
if (isRemove.pop() == true) {
return('');
}
}
return(p1);
}
}
);
 
// remove highlighting div tags
var isRemove = [];
obj.html = obj.html.replace(/(<(\/?)div\b([^>]*)>)/g,
function (p, p1, p2, p3) {
if (p2 == '') {
if (/\bclass=\"wikEd\w+\"/.test(p3)) {
isRemove.push(true);
return('');
}
}
isRemove.push(false);
return(p1);
}
}
if (isRemove.pop() == true) {
return('');
}
}
return(p1);
}
}
);
 
// remove highlighting and pre tags
var isRemove = [];
obj.html = obj.html.replace(/(<(\/?)pre\b([^>]*)>)/g,
function (p, p1, p2, p3) {
if (p2 == '') {
if (/\bclass=\"wikEd\w+\"/.test(p3)) {
isRemove.push(true);
return('');
}
}
isRemove.push(false);
return(p1);
}
}
if (isRemove.pop() == true) {
return('');
}
}
return(p1);
}
}
);
 
// comments
obj.html = obj.html.replace(/<!--wikEd\w+-->/g, '');
obj.html = obj.html.replace(/\n|\r/g, '');
 
// check for pasted html content
if (obj.html.match(/<(?!br\b)/)) {
obj.htmlCode = true;
}
}
else {
obj.htmlCode = false;
}
}
 
return;
}
//
Line 3,854 ⟶ 3,957:
 
// various blocks
if (singleLine != true) {
obj.html = obj.html.replace(/(&lt;(blockquote|center|div|pre)\b.*?&gt;)/gi, '<span class="wikEdBlock">$1');
obj.html = obj.html.replace(/(&lt;\/(blockquote|center|div|pre)\b.*?&gt;)/gi, '$1</span><!--wikEdBlock-->');
}
}
 
// lists * # : ;
obj.html = obj.html.replace(/^([\*\#\:\;]+)(.*?)$/gm, '<span class="wikEdListLine"><span class="wikEdListTag">$1</span><!--wikEdListTag-->$2</span><!--wikEdListLine-->');
if (singleLine != true) {
obj.html = obj.html.replace(/((<span class=\"wikEdListLine\">[^\n]*\n)+)/g, '<span class="wikEdListBlock">$1');
obj.html = obj.html.replace(/(<span class=\"wikEdListLine\">[^\n]*)(\n)(?!<span class=\"wikEdListLine\">)/g, '$1</span><!--wikEdListBlock-->$2');
}
}
 
// #redirect (finish)
obj.html = obj.html.replace(/(<span class=\"wikEdWikiRedir\">)(.*?<\/span><!--wikEdWikiRedir-->)/g, '$1#$2');
 
// space-pre
if (singleLine != true) {
obj.html = obj.html.replace(/^ ( *)(.*?)$/gm, '<span class="wikEdSpaceLine"><span class="wikEdSpaceTag">&nbsp;$1</span><!--wikEdSpaceTag-->$2</span><!--wikEdSpaceLine-->');
obj.html = obj.html.replace(/((<span class=\"wikEdSpaceLine\">[^\n]*\n)+)/g, '<span class="wikEdSpaceBlock">$1');
obj.html = obj.html.replace(/(<span class=\"wikEdSpaceLine\">[^\n]*)(\n)(?!<span class="wikEdSpaceLine">)/g, '$1</span><!--wikEdSpaceBlock-->$2');
}
}
 
// ---- <hr> horizontal rule
obj.html = obj.html.replace(/(^|\n|<[^>]*>)(----)(\n|<[^>]*>|$)/g, '$1<span class="wikEdHR">$2</span><!--wikEdHR-->$3');
obj.html = obj.html.replace(/(&lt;hr&gt;)/g, '<span class="wikEdHRInline">$1</span><!--wikEdHRInline-->');
 
// == headings
obj.html = obj.html.replace(/(^|\n|<[^>]*>)(=+ *)([^\n]*?)( *=+ *)(\n|<[^>]*>|$)/g,
function (p, p1, p2, p3, p4, p5) {
p2 = p2.replace(/(=+)/g, '<span class="wikEdWiki">$1</span><!--wikEdWiki-->');
p4 = p4.replace(/(=+)/g, '<span class="wikEdWiki">$1</span><!--wikEdWiki-->');
if ( /^(external links?|see also|references?)$/i.test(p3) ) {
p1 = p1 + '<span class="wikEdHeadingWp">';
p5 = '</span><!--wikEdHeadingWp-->' + p5;
}
}
else {
p1 = p1 + '<span class="wikEdHeading">';
p5 = '</span><!--wikEdHeading-->' + p5;
}
}
return(p1 + p2 + p3 + p4 + p5);
}
}
);
 
// tables {| |+ |- ! |} |
obj.html = obj.html.replace(/^(\{\||\|\+|\|\-|\!|\|\}|\|)(.*?)$/gm, '<span class="wikEdTableLine"><span class="wikEdTableTag">$1</span><!--wikEdTableTag-->$2</span><!--wikEdTableLine-->');
if (singleLine != true) {
obj.html = obj.html.replace(/(^|\n)((<[^>]*>)*\{\|)/g, '$1<span class="wikEdTableBlock">$2');
obj.html = obj.html.replace(/(^|\n)((<[^>]*>)*\|\}(<[^>]*>)*)/g, '$1$2</span><!--wikEdTableBlock-->');
obj.html = obj.html.replace(/(&lt;table\b.*?&gt;)/gi, '<span class="wikEdTableBlock">$1');
obj.html = obj.html.replace(/(&lt;\/table\b.*?&gt;)/gi, '$1</span><!--wikEdTableBlock-->');
}
}
 
// <gallery> wiki markup
if (singleLine != true) {
obj.html = obj.html.replace(/(&lt;(gallery)\b.*?&gt;)/gi, '$1<span class="wikEdWiki">$1');
obj.html = obj.html.replace(/(&lt;\/(gallery)\b.*?&gt;)/gi, '$1</span><!--wikEdWiki-->');
}
}
 
// various block tags
obj.html = obj.html.replace(/(&lt;\/?(blockquote|center|div|pre)\b.*?&gt;)/gi, '<span class="wikEdBlockTag">$1</span><!--wikEdBlockTag-->');
 
// <p> ... </p> pairs with (wikEdBlockTag) and withhout attributes (wikEdUnknown)
var isRemove = [];
obj.html = obj.html.replace(/(&lt;(\/?)p\b(.*?)&gt;)/g,
function (p, p1, p2, p3) {
if (p2 == '') {
if (p3 == '') {
isRemove.push(true);
return('<span class="wikEdUnknown">' + p1 + '</span><!--wikEdUnknown-->');
}
}
if (/\/$/.test(p3)) {
return('<span class="wikEdUnknown">' + p1 + '</span><!--wikEdUnknown-->');
}
}
isRemove.push(false);
return('<span class="wikEdBlockTag">' + p1 + '</span><!--wikEdBlockTag-->');
}
}
if (isRemove.pop() == true) {
return('<span class="wikEdUnknown">' + p1 + '</span><!--wikEdUnknown-->');
}
}
return('<span class="wikEdBlockTag">' + p1 + '</span><!--wikEdBlockTag-->');
}
}
);
 
// inline elements
 
// <sup> </sub> <ins> <del>
obj.html = obj.html.replace(/((&lt;)sup\b.*?(&gt;)(.*?)(&lt;)\/sup\b.*?(&gt;))/gi, '<span class="wikEdSuperscript">$1</span><!--wikEdSuperscript-->');
obj.html = obj.html.replace(/((&lt;)sub\b.*?(&gt;)(.*?)(&lt;)\/sub\b.*?(&gt;))/gi, '<span class="wikEdSubscript">$1</span><!--wikEdSubscript-->');
obj.html = obj.html.replace(/((&lt;)(ins|u)\b.*?(&gt;)(.*?)(&lt;)\/(ins|u)\b.*?(&gt;))/gi, '<span class="wikEdIns">$1</span><!--wikEdIns-->');
obj.html = obj.html.replace(/((&lt;)(del|s|strike)\b.*?(&gt;)(.*?)(&lt;)\/(del|s|strike)\b.*?(&gt;))/gi, '<span class="wikEdDel">$1</span><!--wikEdDel-->');
 
// various inline tags
obj.html = obj.html.replace(/(&lt;\/?(sub|sup|ins|u|del|s|strike|big|br|colgroup|code|font|small|span|tt|rb|rp|rt|ruby)\b.*?&gt;)/gi, '<span class="wikEdInlineTag">$1</span><!--wikEdInlineTag-->');
 
// unsupported or not needed <> tags
obj.html = obj.html.replace(/(&lt;\/?)(\w+)(.*?\/?&gt;)/g,
function (p, p1, p2, p3) {
if ( ! /^(col|thead|tfoot|tbody|big|br|blockquote|colgroup|center|code|del|div|font|ins|p|pre|s|small|span|strike|sub|sup|tt|u|rb|rp|rt|ruby|nowiki|math|gallery|noinclude|includeonly|ref|references)$/i.test(p2) ) {
p1 = '<span class="wikEdUnknown">' + p1;
p3 = p3 + '</span><!--wikEdUnknown-->';
}
}
return(p1 + p2 + p3);
}
}
);
 
// comments
obj.html = obj.html.replace(/(&lt;!--[^]*?--&gt;)/g, '<span class="wikEdComment">$1</span><!--wikEdComment-->');
 
// <nowiki> <math> <noinclude> <includeonly> <ref> <references> wiki markup
obj.html = obj.html.replace(/((&lt;)(nowiki|math|gallery|noinclude|includeonly|ref|references)\b.*?(&gt;)(.*?)(&lt;)\/(nowiki|math|gallery|noinclude|includeonly|ref|references)\b.*?(&gt;))/gi, '<span class="wikEdWiki">$1</span><!--wikEdWiki-->');
 
// URLs, allowed chars: \w / . & ? = - @ # % ~ + (; allowed because of &amp; and common misuse)
obj.html = obj.html.replace(/((http:\/\/|https:\/\/|ftp:\/\/|irc:\/\/|gopher:\/\/|news:|mailto:)[^\u0000-\u0020\!\"\$\'\(\)\*\,\:\<\>\[\\\]\^\`\{-\|\}\u007f-\uffff]*)/gi,
function (p, p1, p2) {
p1 = p1.replace(/(.*)/, '<span class="wikEdURLLink">$1</span><!--wikEdURLLink-->');
return(p1);
}
}
);
 
// URLs with text
obj.html = obj.html.replace(/(\[)( *<span class=\"wikEdURLLink\">.*?<\!--wikEdURLLink--> *)([^\]\n]*?)( *\])/gi,
function (p, p1, p2, p3, p4) {
 
// link text
p3 = p3.replace(/(.*)/, '<span class="wikEdURLText">$1</span><!--wikEdURLText-->');
 
// link tags
p1 = p1.replace(/(\[)/, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
p4 = p4.replace(/(\])/, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
 
return(p1 + p2 + p3 + p4);
}
}
);
 
// [[ ]] links, images, categories
obj.html = obj.html.replace(/(\[\[)([^\]]*)(\]\])/g,
function (p, p1, p2, p3) {
 
// image
if ( /^\s*image\s*:/i.test(p2) ) {
if (p2.match(/\s*\w+\s*:\s*image\s*:/i)) {
p1 = '<span class="wikEdImageInter">' + p1;
p3 = p3 + '</span><!--wikEdImageInter-->';
}
}
else {
p1 = '<span class="wikEdImage">' + p1;
p3 = p3 + '</span><!--wikEdImage-->';
}
}
p2 = p2.replace(/^(\s*)(.*:)+/, '$1<span class="wikEdInter">$2</span><!--wikEdInter-->');
p2 = p2.replace(/(\s*)([^>:\|]+)(\s*\|\s*|$)/, '$1<span class="wikEdImageName">$2</span><!--wikEdImageName-->$3');
p2 = p2.replace(/(\|\s*)(.*)/,
function (p, p1, p2) {
p2 = p2.replace(/(.*?)(\s*(\||$))/g, '<span class="wikEdImageText">$1</span><!--wikEdImageText-->$2');
return(p1 + p2);
}
}
);
);
}
}
 
// category
else if ( /^\s*category\s*:/i.test(p2) ) {
if (p2.match(/\s*\w+\s*:\s*category\s*:/i)) {
p1 = '<span class="wikEdCatInter">' + p1;
p3 = p3 + '</span><!--wikEdCatInter-->';
}
}
else {
p1 = '<span class="wikEdCat">' + p1;
p3 = p3 + '</span><!--wikEdCat-->';
}
}
p2 = p2.replace(/^(\s*)(.*:)+/, '$1<span class="wikEdInter">$2</span><!--wikEdInter-->');
p2 = p2.replace(/(\s*)([^>:\|]+)(\s*\|\s*|$)/, '$1<span class="wikEdCatName">$2</span><!--wikEdCatName-->$3');
p2 = p2.replace(/(\|\s*)(.*)/,
function (p, p1, p2) {
p2 = p2.replace(/(.*?)(\s*(\||$))/g, '<span class="wikEdCatText">$1</span><!--wikEdCatText-->$2');
return(p1 + p2);
}
}
);
);
}
}
 
// wikilink
else {
if (p2.match(/^\s*\w+\s*:/)) {
p1 = '<span class="wikEdLinkInter">' + p1;
p3 = p3 + '</span><!--wikEdLinkInter-->';
}
}
else {
p1 = '<span class="wikEdLink">' + p1;
p3 = p3 + '</span><!--wikEdLink-->';
}
}
p2 = p2.replace(/^(\s*)(.*:)+/, '$1<span class="wikEdInter">$2</span><!--wikEdInter-->');
p2 = p2.replace(/(\s*)([^>:\|]+)(\s*\|\s*|$)/, '$1<span class="wikEdLinkName">$2</span><!--wikEdLinkName-->$3');
p2 = p2.replace(/(\|\s*)(.*)/,
function (p, p1, p2) {
p2 = p2.replace(/(.*?)(\s*(\||$))/g, '<span class="wikEdLinkText">$1</span><!--wikEdLinkText-->$2');
return(p1 + p2);
}
}
);
);
}
}
 
// link tags
p1 = p1.replace(/(\[+)/, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
p2 = p2.replace(/(\|)/gi, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
p3 = p3.replace(/(\]+)/, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
return(p1 + p2 + p3);
}
}
);
 
// {{ }}, {{{ }}} templates
obj.html = obj.html.replace(/(\{\{+)([^\}]*)(\}\}+)/g,
function (p, p1, p2, p3) {
if (p2.match(/^\s*\w+\s*:/)) {
p1 = '<span class="wikEdTemplInter">' + p1;
p3 = p3 + '</span><!--wikEdTemplInter-->';
}
}
else {
p1 = '<span class="wikEdTempl">' + p1;
p3 = p3 + '</span><!--wikEdTempl-->';
}
}
p2 = p2.replace(/^(\s*)(.*:)+/, '$1<span class="wikEdInter">$2</span><!--wikEdInter-->');
p2 = p2.replace(/(\s*)([^>:\|]+)(\s*\|\s*|$)/, '$1<span class="wikEdTemplName">$2</span><!--wikEdTemplName-->$3');
p2 = p2.replace(/(\|\s*)(.*)/,
function (p, p1, p2) {
p2 = p2.replace(/(.*?)(\s*(\||$))/g, '<span class="wikEdTemplText">$1</span><!--wikEdTemplText-->$2');
return(p1 + p2);
}
}
);
);
 
// template tags
p1 = p1.replace(/(\{+)/, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
p2 = p2.replace(/(\|)/g, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
p3 = p3.replace(/(\}+)/, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
return(p1 + p2 + p3);
}
}
);
 
// #redirect
obj.html = obj.html.replace(/(^|\n)(#)(redirect\b)/g, '$1<span class="wikEdWikiRedir">$3</span><!--wikEdWikiRedir-->');
 
 
Line 4,095 ⟶ 4,198:
 
// <b> <i>
obj.html = obj.html.replace(/(\'\'\')(\'*)(.*?)(\'*)(\'\'\')/g, '<span class="wikEdBold">$2$3$4</span><!--wikEdBold-->');
obj.html = obj.html.replace(/(\'\')(.*?)(\'\')/g, '<span class="wikEdItalic">$1$2$3</span><!--wikEdItalic-->');
obj.html = obj.html.replace(/(<span class=\"wikEdBold\">)/g, '$1\'\'\'');
obj.html = obj.html.replace(/(<\/span><!--wikEdBold-->)/g, '\'\'\'$1');
obj.html = obj.html.replace(/(\'{2,})/g, '<span class="wikEdWiki">$1</span><!--wikEdWiki-->');
 
// named colors
obj.html = obj.html.replace(/(\b(red|orange|yellow|fuchsia|white|lime|aqua|silver)\b)/g, '<span style="background-color: $1;" class="wikEdColors">$1</span><!--wikEdColors-->');
obj.html = obj.html.replace(/(\b(maroon|olive|purple|green|navy|teal|blue|black|gray)\b)/g, '<span style="color: white; background-color: $1;" class="wikEdColors">$1</span><!--wikEdColors-->');
 
// RGB colors
obj.html = obj.html.replace(/(#[0-9a-fA-F]{6})([\s\'\";])/g, '<span style="background-color: $1;" class="wikEdColors">$1</span><!--wikEdColors-->$2');
obj.html = obj.html.replace(/(rgb\(\s*\d+,\s*\d+,\s*\d+\s*\))/gi, '<span style="background-color: $1;" class="wikEdColors">$1</span><!--wikEdColors-->');
 
// display control chars with popup title
var regExpStr = '';
for (var decimalValue in wikEdControlChars) {
regExpStr += String.fromCharCode(decimalValue);
}
}
var regExp = new RegExp('([' + regExpStr + '])', 'g');
obj.html = obj.html.replace(regExp,
function (p, p1) {
if (p1 == '\u0009') {
p1 = '<pre class="wikEdTab" title="' + wikEdControlChars[p1.charCodeAt(0).toString()] + '">' + p1 + '</pre><!--wikEdTab-->';
}
}
else if (p1 != '\u000a') {
p1 = '<pre class="wikEdCtrl" title="' + wikEdControlChars[p1.charCodeAt(0).toString()] + '">' + p1 + '</pre><!--wikEdCtrl-->';
}
}
return(p1);
}
}
);
 
// display strange spaces with popup title
var regExpStr = '';
for (var decimalValue in wikEdStrangeSpaces) {
regExpStr += String.fromCharCode(decimalValue);
}
}
var regExp = new RegExp('([' + regExpStr + '])', 'g');
obj.html = obj.html.replace(regExp,
function (p, p1) {
if (p1 != '\u000a') {
p1 = '<pre class="wikEdBlank" title="' + wikEdStrangeSpaces[p1.charCodeAt(0).toString()] + '">' + p1 + '</pre><!--wikEdBlank-->';
}
}
return(p1);
}
}
);
 
// remove comments
if (wikEdRemoveHighlightComments == true) {
obj.html = obj.html.replace(/<!--wikEd\w+-->/g, '');
}
}
 
return;
}
 
Line 4,159 ⟶ 4,262:
 
// get frame content
var obj = {};
obj.html = wikEdFrameBody.innerHTML;
 
// textify so that no html formatting is submitted
WikEdTextify(obj);
obj.plain = obj.plain.replace(/&nbsp;/g, ' ');
obj.plain = obj.plain.replace(/&lt;/g, '<');
obj.plain = obj.plain.replace(/&gt;/g, '>');
obj.plain = obj.plain.replace(/&amp;/g, '&');
 
// copy to textarea
wikEdTextareaObj wikEdTextarea.value = obj.plain;
 
return;
}
 
Line 4,183 ⟶ 4,286:
 
// get frame content
var obj = {};
obj.html = wikEdTextareaObjwikEdTextarea.value;
obj.html = obj.html.replace(/&/g, '&amp;');
obj.html = obj.html.replace(/>/g, '&gt;');
obj.html = obj.html.replace(/</g, '&lt;');
 
// highlight the syntax
if (wikEdHighlightSyntax == true) {
WikEdHighlightSyntax(obj);
}
}
 
// display tabs
else {
obj.html = obj.html.replace(/(\t)/g, '<pre class="wikEdTabPlain">$1</pre><!--wikEdTabPlain-->');
}
}
 
// multiple blanks to blank-&nbsp;
obj.html = obj.html.replace(/ /g, '&nbsp; ');
obj.html = obj.html.replace(/ /g, '&nbsp; ');
 
// newlines to <br />
obj.html = obj.html.replace(/\n/g, '<br />');
 
// set frame content
wikEdFrameBody.innerHTML = obj.html;
 
return;
}
 
Line 4,220 ⟶ 4,323:
 
// grey out inactive buttons
WikEdInactiveButtons();
InactiveButtons();
 
// reset the frame DOM cache
wikEdFrameDOMCache = null;
 
return;
}
 
Line 4,235 ⟶ 4,338:
function WikEdFrameExecCommand(command, option) {
 
wikEdFrameDocument.execCommand(command, false, option);
return;
}
 
Line 4,246 ⟶ 4,349:
function WikEdFindAhead() {
 
if (document.getElementById('wikEdFindAhead').checked == true) {
 
// get the find text
var findText = document.getElementById('wikEdFindText').value;
if (findText == '') {
return;
}
}
 
// function: window.find(string, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog)
var found = wikEdFrameWindow.find(findText, false, false, true, false, false, false);
if (found == false) {
var sel = wikEdFrameWindow.getSelection();
sel.collapse(sel.anchorNode, sel.anchorOffset);
}
}
}
}
return;
}
 
 
//
// WikEdFullScreen: change to fullscreen edit area or back to normal view
//
 
function WikEdFullScreen(fullscreen) {
 
// get dom nodes
var inputWrapperwikEdButtonsPreview = document.getElementById('wikEdInputWrapperwikEdButtonsPreview');
var frame = document.getElementById('wikEdFrame');
var frameWrapper = document.getElementById('frameWrapper');
var buttonsWrapper = document.getElementById('wikEdButtonsWrapper');
var buttonsPreview = document.getElementById('wikEdButtonsPreview');
// hide divs to remove the vertical scrollbar
wikEdTextareaObj.style.display = 'none';
 
// hide allor divsshow aboveelements
var displayStyle;
var node = document.getElementById('editform').previousSibling;
while if (nodefullscreen !== nulltrue) {
displayStyle = 'none';
if (node.nodeName == 'DIV') {
}
node.style.display = 'none';
else {
}
displayStyle = 'block';
node = node.previousSibling;
}
}
 
// elements above input wrapper
// hide all divs below
var node = document.getElementById('editform').previousSibling;
var node = inputWrapper.parentNode.nextSibling;
while (node != null) {
if ( (node.nodeName == 'DIV') if|| (node.nodeName == 'DIVH3') ) {
node.style.display = 'none'displayStyle;
}
}
node = node.nextSiblingpreviousSibling;
}
}
document.getElementsByTagName('H1')[0].style.display = displayStyle;
 
// hide all divs below, one levelinput abovewrapper
var node = document.getElementById('column-content')wikEdInputWrapper.nextSibling;
while (node != null) {
if (node.nodeName == 'DIV') {
node.style.display = 'none'displayStyle;
}
}
node = node.nextSibling;
}
}
 
// styledivs thebelow input wrapper, some levels up
var node = document.getElementById('column-one');
inputWrapper.className = 'wikEdInputWrapperFull';
while (node != null) {
buttonsPreview.className = 'wikEdButtonsPreviewFull';
if (node.nodeName == 'DIV') {
node.style.display = displayStyle;
}
node = node.nextSibling;
}
 
// resizeinsert the framewrapper
document.getElementById('wikEdInsertWrapper').style.display = displayStyle;
var buttonsTop = WikEdGetOffsetTop(buttonsWrapper);
var buttonsHeight = buttonsWrapper.offsetHeight;
var frameHeight = frame.offsetHeight;
var windowHeight = window.innerHeight;
var windowWidth = window.innerWidth;
var frameHeightNew = frameHeight + (windowHeight - (buttonsTop + buttonsHeight) ) - 2;
frame.style.height = frameHeightNew + 'px';
 
// set the fullscreen button state
WikEdButton('wikEdFullScreen', null, true);
 
// grey out scroll-to buttons
document.getElementById('wikEdScrollToInput').className = 'wikEdButtonInactive';
document.getElementById('wikEdScrollToInput2').className = 'wikEdButtonInactive';
document.getElementById('wikEdScrollToButtons').className = 'wikEdButtonInactive';
document.getElementById('wikEdScrollToButtons2').className = 'wikEdButtonInactive';
 
wikEdFullScreenMode = true;
 
return;
}
 
 
//
// WikEdNormalScreen: change back to normal page view
//
 
function WikEdNormalScreen() {
 
// get dom nodes
var inputWrapper = document.getElementById('wikEdInputWrapper');
var frame = document.getElementById('wikEdFrame');
var buttonsPreview = document.getElementById('wikEdButtonsPreview');
 
// show hidden divs
wikEdTextareaObj.style.display = 'block';
 
// show all divs above
var node = document.getElementById('editform').previousSibling;
while (node != null) {
if (node.nodeName == 'DIV') {
node.style.display = 'block';
}
node = node.previousSibling;
}
 
// show all divs below
var node = inputWrapper.parentNode.nextSibling;
while (node != null) {
if (node.nodeName == 'DIV') {
node.style.display = 'block';
}
node = node.nextSibling;
}
 
// show all divs below, one level above
var node = document.getElementById('column-content').nextSibling;
while (node != null) {
if (node.nodeName == 'DIV') {
node.style.display = 'block';
}
node = node.nextSibling;
}
 
// change styles
// reset the input wrapper style
if (fullscreen) {
inputWrapper.className = 'wikEdInputWrapper';
buttonsPreview wikEdInputWrapper.className = 'wikEdButtonsPreviewwikEdInputWrapperFull';
wikEdButtonsPreview.className = 'wikEdButtonsPreviewFull';
}
else {
wikEdInputWrapper.className = 'wikEdInputWrapper';
wikEdButtonsPreview.className = 'wikEdButtonsPreview';
}
 
// resize the frame
if (fullscreen) {
frame.style.height = wikEdTextareaObj.offsetHeight + 'px';
var consoleTop = WikEdGetOffsetTop(wikEdConsoleWrapper);
var consoleHeight = wikEdConsoleWrapper.offsetHeight;
var frameHeight = wikEdFrame.offsetHeight;
var windowHeight = window.innerHeight;
var windowWidth = window.innerWidth;
var frameHeightNew = frameHeight + (windowHeight - (consoleTop + consoleHeight) ) - 2;
wikEdFrame.style.height = frameHeightNew + 'px';
}
else {
wikEdFrame.style.height = wikEdTextareaHeight + 'px';
}
 
// scroll to edit frame
if (fullscreen == false) {
window.scroll(0, WikEdGetOffsetTop(inputWrapper) - 2);
window.scroll(0, WikEdGetOffsetTop(wikEdInputWrapper) - 2);
}
 
// set the fullscreen button state
WikEdButton('wikEdFullScreen', null, falsefullscreen);
 
// grey out or re-activate scroll-to buttons
var buttonClass;
document.getElementById('wikEdScrollToInput').className = 'wikEdButton';
if (fullscreen) {
document.getElementById('wikEdScrollToInput2').className = 'wikEdButton';
buttonClass = 'wikEdButtonInactive';
document.getElementById('wikEdScrollToButtons').className = 'wikEdButton';
}
document.getElementById('wikEdScrollToButtons2').className = 'wikEdButton';
else {
buttonClass = 'wikEdButton';
}
document.getElementById('wikEdScrollToInput').className = buttonClass;
document.getElementById('wikEdScrollToInput2').className = buttonClass;
document.getElementById('wikEdScrollToButtons').className = buttonClass;
document.getElementById('wikEdScrollToButtons2').className = buttonClass;
 
wikEdFullScreenMode = falsefullscreen;
 
return;
}
 
Line 4,408 ⟶ 4,475:
 
// add a dummy option
var dummy;
if (wikEdSelectElement[field].options.length == 0) {
wikEdSelectElement[field].options[0] = new Option('');
dummy = true;
}
}
 
// set option widths to 0
for (i = 0; i < wikEdSelectElement[field].options.length; i ++) {
wikEdSelectElement[field].options[i].style.width = '0';
}
}
 
// calculate select width
var inputWidth = wikEdInputElement[field].clientWidth;
var selectWidth = wikEdSelectElement[field].clientWidth;
var optionWidth = wikEdSelectElement[field].options[0].offsetWidth;
var border = wikEdInputElement[field].offsetWidth - wikEdInputElement[field].clientWidth;
wikEdSelectElement[field].style.width = (selectWidth - optionWidth + inputWidth - border) + 'px';
 
// delete dummy option
if (dummy) {
wikEdSelectElement[field].options[0] = null;
}
}
 
// set option widths to auto
for (i = 0; i < wikEdSelectElement[field].options.length; i ++) {
wikEdSelectElement[field].options[i].style.width = 'auto';
}
}
return;
}
 
Line 4,446 ⟶ 4,513:
 
// get selection index (-1 for unselected)
var selected = wikEdSelectElement[field].selectedIndex;
if (selected >= 0) {
 
// get selected option
var option = wikEdSelectElement[field].options[selected];
if (option.text != '') {
 
// add a tag to the summary box
if (field == 'summary') {
var text = wikEdInputElement[field].value;
if ( (text != '') && (!text.match(/ \*\/ $/) ) ) {
if (option.text.match(/^\w/)) {
text += ', ';
}
}
else {
text += ' ';
}
}
}
}
text += option.text;
wikEdInputElement[field].value = text;
}
}
 
// add case and regexp checkboxes to find / replace fields
else if (option.value == 'setcheck') {
WikEdButton('wikEdCaseSensitive', null, (option.text.charAt(0) == wikEdCheckMarker[true]) );
WikEdButton('wikEdRegExp', null, (option.text.charAt(1) == wikEdCheckMarker[true]) );
wikEdInputElement[field].value = option.text.substr(3);
}
}
 
// add option text
else {
wikEdInputElement[field].value = option.text;
}
}
}
}
}
}
return;
}
 
Line 4,491 ⟶ 4,558:
function WikEdAddToHistory(field) {
 
if (wikEdInputElement[field].value != '') {
 
// load history from cookie
WikEdLoadHistoryFromCookie(field);
 
// add current value to history
wikEdFieldHist[field].unshift(wikEdInputElement[field].value);
 
// add case and regexp checkboxes to find / replace value
if ( (field == 'find') || (field == 'replace') ) {
wikEdFieldHist[field][0] =
wikEdCheckMarker[ document.getElementById('wikEdCaseSensitive').checked ] +
wikEdCheckMarker[ document.getElementById('wikEdRegExp').checked ] +
' ' + wikEdFieldHist[field][0];
}
}
 
// remove paragraph names from summary
if (field == 'summary') {
wikEdFieldHist[field][0] = wikEdFieldHist[field][0].replace(/^\/\* .*? \*\/ */, '');
}
 
// remove multiple old copies from history
i = 1;
while (i < wikEdFieldHist[field].length) {
if (wikEdFieldHist[field][i] == wikEdFieldHist[field][0]) {
wikEdFieldHist[field].splice(i, 1);
}
}
else {
i ++;
}
}
}
}
 
// remove new value if it is a preset value
if (wikEdComboPresetOptions[field] != null) {
i = 0;
while (i < wikEdComboPresetOptions[field].length) {
if (wikEdComboPresetOptions[field][i] == wikEdFieldHist[field][0]) {
wikEdFieldHist[field].shift;
break;
}
}
else {
i ++;
i ++;
}
}
}
}
}
}
 
// cut history to maximal history length
wikEdFieldHist[field] = wikEdFieldHist[field].slice(0, wikEdFindHistoryLengthwikEdHistoryLength[field]);
 
// saved history to cookie
WikEdSaveHistoryToCookie(field);
}
}
return;
}
 
Line 4,549 ⟶ 4,621:
 
// load history from cookie
WikEdLoadHistoryFromCookie(field);
 
var option = {};
var selected = null;
j = 0;
 
// delete options
var options = wikEdSelectElement[field].options;
for (i = 0; i > options.length; i ++) {
wikEdSelectElement[field].remove(i);
}
}
 
// delete optgroup
option = document.getElementById(field + 'Optgroup');
if (option != null) {
wikEdSelectElement[field].removeChild(option);
}
}
 
// workaround for onchange not firing when selecting first option from unselected dropdown
option = document.createElement('option');
option.style.display = 'none';
wikEdSelectElement[field].options[j++] = option;
 
// add history entries
for (i = 0; i < wikEdFieldHist[field].length; i ++) {
if (wikEdFieldHist[field][i] != null) {
if (wikEdFieldHist[field][i] == wikEdInputElement[field].value) {
selected = j;
}
}
option = document.createElement('option');
option.text = wikEdFieldHist[field][i];
if ( (field == 'find') || (field == 'replace') ) {
option.value = 'setcheck';
}
}
wikEdSelectElement[field].options[j++] = option;
}
}
}
}
 
// add preset entries
if (wikEdComboPresetOptions[field] != null) {
var startPreset = j;
for (i = 0; i < wikEdComboPresetOptions[field].length; i ++) {
if (wikEdComboPresetOptions[field][i] != null) {
if (wikEdComboPresetOptions[field][i] == wikEdInputElement[field].value) {
selected = j;
}
}
option = document.createElement('option');
option.text = wikEdComboPresetOptions[field][i];
if (field == 'summary') {
option.text = option.text.replace(/\{wikEdUsing\}/g, wikEdSummaryUsing);
}
}
wikEdSelectElement[field].options[j++] = option;
}
}
}
}
 
// add a blank separator
if (startPreset > 1) {
option = document.createElement('optgroup');
option.label = '\u00a0';
option.id = field + 'Optgroup';
wikEdSelectElement[field].insertBefore(option, wikEdSelectElement[field].options[startPreset]);
}
}
}
}
 
// set the selection
wikEdSelectElement[field].selectedIndex = selected;
return;
}
 
Line 4,624 ⟶ 4,696:
 
function WikEdClearHistory(field) {
var cookieExpire = new Date();
cookieExpire.setTime( cookieExpire.getTime() + wikEdCookieExpireSec * 1000 );
WikEdSetCookie(wikEdCookieName[field], '', cookieExpire.toGMTString());
WikEdSetComboOptions(field);
return;
}
 
Line 4,637 ⟶ 4,709:
 
function WikEdLoadHistoryFromCookie(field) {
var cookie = WikEdGetCookie(wikEdCookieName[field]);
if (cookie != '') {
cookie = decodeURIComponent(cookie);
wikEdFieldHist[field] = cookie.split('\n');
}
}
else {
wikEdFieldHist[field] = [];
}
}
return;
}
 
Line 4,654 ⟶ 4,726:
 
function WikEdSaveHistoryToCookie(field) {
var cookieExpire = new Date();
cookieExpire.setTime( cookieExpire.getTime() + wikEdCookieExpireSec * 1000 );
var cookie = '';
cookie = wikEdFieldHist[field].join('\n')
cookie = cookie.replace(/\n$/, '');
cookie = encodeURIComponent(cookie);
WikEdSetCookie(wikEdCookieName[field], cookie, cookieExpire.toGMTString());
return;
}
 
Line 4,667 ⟶ 4,739:
// WikEdGetStyle: get computed style properties for non-inline css definitions
function WikEdGetStyle(element, styleProperty) {
var style;
if (element != null) {
style = document.defaultView.getComputedStyle(element, null).getPropertyValue(styleProperty);
}
}
return(style);
}
 
Line 4,680 ⟶ 4,752:
 
function WikEdGetCookie(name) {
var cookie = ' ' + document.cookie;
var search = ' ' + name + '=';
var setStr = '';
var offset = 0;
var end = 0;
offset = cookie.indexOf(search);
if (offset != -1) {
offset += search.length;
end = cookie.indexOf(';', offset)
if (end == -1) {
end = cookie.length;
}
}
setStr = cookie.substring(offset, end);
setStr = setStr.replace(/\\+/g, ' ');
setStr = decodeURIComponent(setStr);
}
}
return(setStr);
}
 
Line 4,705 ⟶ 4,777:
 
function WikEdSetCookie(name, value, expires, path, ___domain, secure) {
var cookie = name + '=' + encodeURIComponent(value);
if (expires != null) {
cookie += '; expires=' + expires
}
}
if (path != null) {
cookie += '; path=' + path;
}
}
if (___domain != null) {
cookie += '; ___domain=' + ___domain;
}
}
if (secure != null) {
cookie += '; secure';
}
}
document.cookie = cookie;
}
 
Line 4,727 ⟶ 4,799:
 
function WikEdGetOffsetTop(element) {
var offset = 0;
do {
offset += element.offsetTop;
} while ( (element = element.offsetParent) != null );
return(offset);
}
 
Line 4,740 ⟶ 4,812:
 
function WikEdGetOffsetLeft(element) {
var offset = 0;
do {
offset += element.offsetLeft;
} while ( (element = element.offsetParent) != null );
return(offset);
}
 
Line 4,763 ⟶ 4,835:
 
/* problematic because of obj.changed //////////////////////
if (wikEdFrameDOMCache != null) {
obj = wikEdFrameDOMCache;
return;
}
}
*/
 
obj.plainLength = 0;
obj.plainArray = [];
obj.plainNode = [];
obj.plainStart = [];
obj.plainPos = [];
WikEdParseDOMRecursive(obj, topNode);
obj.plain = obj.plainArray.join('');
wikEdFrameDOMCache = obj;
return;
}
 
Line 4,788 ⟶ 4,860:
 
// cycle through the child nodes of currentNode
for each (var childNode in currentNode.childNodes) {
 
if (childNode == null) {
break;
}
}
 
// check for selection
if (childNode == obj.sel.focusNode) {
obj.plainFocus = obj.plainLength + obj.sel.focusOffset;
}
}
if (childNode == obj.sel.anchorNode) {
obj.plainAnchor = obj.plainLength + obj.sel.anchorOffset;
}
}
var value = null;
 
// get text of child node
switch (childNode.nodeType) {
case 1:
if ( (childNode.childNodes.length == 0) && (wikEdLeafElements[childNode.nodeName] == true) ) {
if (childNode.nodeName == 'BR') {
value = '\n';
}
}
}
}
else {
WikEdParseDOMRecursive(obj, childNode);
}
}
break;
case 3:
value = childNode.nodeValue;
value = value.replace(/\n/g, ' ');
break;
case 5:
value = '&' + childNode.nodeName + ';';
break;
}
}
 
// add text to text object
if (value != null) {
 
// array of text fragments
obj.plainArray.push(value);
 
// array of text fragment node references
obj.plainNode.push(childNode);
 
// array of text fragment text positions
obj.plainStart.push(obj.plainLength);
 
// node references containing text positions
obj.plainPos[childNode] = obj.plainLength;
 
// current text length
obj.plainLength += value.length;
}
}
}
}
return;
}
 
Line 4,854 ⟶ 4,926:
 
// initialize string
if (obj.html == null) {
obj.html = '';
}
}
if (obj.plain == null) {
obj.plain = '';
}
}
if (obj.plainArray == null) {
obj.plainArray = [];
obj.plainNode = [];
obj.plainStart = [];
}
}
 
for (var i = 0; i < currentNode.childNodes.length; i ++) {
var childNode = currentNode.childNodes.item(i);
switch (childNode.nodeType) {
case 1:
obj.html += '<' + childNode.nodeName.toLowerCase();
for (var j = 0; j < childNode.attributes.length; j ++) {
if (childNode.attributes.item(j).nodeValue != null) {
obj.html += ' ' + childNode.attributes.item(j).nodeName + '="' + childNode.attributes.item(j).nodeValue.replace(/</g, '&lt;').replace(/>/g, '&gt;') + '"';
}
}
}
}
if ( (childNode.childNodes.length == 0) && wikEdLeafElements[childNode.nodeName] ) {
obj.html += '>';
if (childNode.nodeName == 'BR') {
obj.plainArray.push('\n');
obj.plainNode.push(childNode);
obj.plainStart.push(obj.plain.length);
obj.plain += '\n';
}
}
}
}
else {
obj.html += '>';
WikEdGetInnerHTML(obj, childNode);
obj.html += '</' + childNode.nodeName.toLowerCase() + '>'
}
}
break;
case 3:
var value = childNode.nodeValue;
value = value.replace(/\n/g, ' '); // important for pasted page content
obj.plainArray.push(value); // plain array contains & < > instead of &amp; &lt; &gt;
obj.plainNode.push(childNode);
obj.plainStart.push(obj.plain.length);
value = value.replace(/&/g, '&amp;');
value = value.replace(/</g, '&lt;');
value = value.replace(/>/g, '&gt;');
obj.html += value;
obj.plain += value;
break;
case 4: obj.html += '<![CDATA[' + childNode.nodeValue + ']]>';
break;
case 5:
var value = '&' + childNode.nodeName + ';';
obj.plainArray.push(value);
obj.plainNode.push(childNode);
obj.plainStart.push(obj.plain.length);
value = value.replace(/&/g, '&amp;');
obj.html += value;
obj.plain += value;
break;
case 8: obj.html += '<!--' + childNode.nodeValue + '-->';
break;
}
}
}
}
return;
}
 
Line 4,925 ⟶ 4,997:
function WikEdStyleSheet(documentObject) {
 
this.styleElement = null;
if (documentObject == null) {
documentObject = document;
}
}
 
// IE
if (documentObject.createStyleSheet) {
this.styleElement = documentObject.createStyleSheet();
}
}
 
// standards compliant browsers
else {
this.styleElement = documentObject.createElement('style');
this.styleElement.from = 'text/css';
var insert = documentObject.getElementsByTagName('head')[0];
if (insert != null) {
insert.appendChild(this.styleElement);
}
}
}
}
 
// add-a-rule method
 
// IE
this.addRule = function(selector, declaration) {
if (this.styleElement.addRule) {
this.styleElement.addRule(selector, declaration);
}
}
 
// standards compliant browsers
else {
if (this.styleElement.sheet != null) {
if (this.styleElement.sheet.insertRule != null) {
this.styleElement.sheet.insertRule(selector + ' { ' + declaration + ' } ', 0);
}
}
}
}
}
}
};
return;
}
 
Line 4,969 ⟶ 5,041:
function WED(objectName, object) {
 
WikEdDebug(objectName, object);
return;
}
 
Line 4,978 ⟶ 5,050:
function WikEdDebug(objectName, object) {
 
document.getElementById('wikEdTextareaWrapper').style.position = 'static';
// document.getElementById('frameWrapperwikEdTextareaWrapper').style.positionvisibility = 'staticvisible';
wikEdTextarea.style.display = 'block';
if (objectName == null) {
if (objectName == null) {
wikEdTextareaObj.value = '';
wikEdTextarea.value = '';
wikEdTextareaObj.style.height = '25em';
wikEdTextarea.style.height = '25em';
}
}
else {
else {
wikEdTextareaObj.value += objectName + ': ' + object + '\n';
wikEdTextarea.value += objectName + ': ' + object + '\n';
}
}
return;
return;
}
 
Line 4,999 ⟶ 5,072:
// supported chars in Mozilla and IE
var wikEdSupportedChars = [
['00a1', 'iexcl'], // ¡
['00a2', 'cent'], // ¢
['00a3', 'pound'], // £
['00a4', 'curren'], // ¤
['00a5', 'yen'], // ¥
['00a6', 'brvbar'], // ¦
['00a7', 'sect'], // §
['00a8', 'uml'], // ¨
['00a9', 'copy'], // ©
['00aa', 'ordf'], // ª
['00ab', 'laquo'], // «
['00ac', 'not'], // ¬
['00ae', 'reg'], // ®
['00af', 'macr'], // ¯
['00b0', 'deg'], // °
['00b1', 'plusmn'], // ±
['00b2', 'sup2'], // ²
['00b3', 'sup3'], // ³
['00b4', 'acute'], // ´
['00b5', 'micro'], // µ
['00b6', 'para'], // ¶
['00b7', 'middot'], // ·
['00b8', 'cedil'], // ¸
['00b9', 'sup1'], // ¹
['00ba', 'ordm'], // º
['00bb', 'raquo'], // »
['00bc', 'frac14'], // ¼
['00bd', 'frac12'], // ½
['00be', 'frac34'], // ¾
['00bf', 'iquest'], // ¿
['00c0', 'Agrave'], // À
['00c1', 'Aacute'], // Á
['00c2', 'Acirc'], // Â
['00c3', 'Atilde'], // Ã
['00c4', 'Auml'], // Ä
['00c5', 'Aring'], // Å
['00c6', 'AElig'], // Æ
['00c7', 'Ccedil'], // Ç
['00c8', 'Egrave'], // È
['00c9', 'Eacute'], // É
['00ca', 'Ecirc'], // Ê
['00cb', 'Euml'], // Ë
['00cc', 'Igrave'], // Ì
['00cd', 'Iacute'], // Í
['00ce', 'Icirc'], // Î
['00cf', 'Iuml'], // Ï
['00d0', 'ETH'], // Ð
['00d1', 'Ntilde'], // Ñ
['00d2', 'Ograve'], // Ò
['00d3', 'Oacute'], // Ó
['00d4', 'Ocirc'], // Ô
['00d5', 'Otilde'], // Õ
['00d6', 'Ouml'], // Ö
['00d7', 'times'], // ×
['00d8', 'Oslash'], // Ø
['00d9', 'Ugrave'], // Ù
['00da', 'Uacute'], // Ú
['00db', 'Ucirc'], // Û
['00dc', 'Uuml'], // Ü
['00dd', 'Yacute'], // Ý
['00de', 'THORN'], // Þ
['00df', 'szlig'], // ß
['00e0', 'agrave'], // à
['00e1', 'aacute'], // á
['00e2', 'acirc'], // â
['00e3', 'atilde'], // ã
['00e4', 'auml'], // ä
['00e5', 'aring'], // å
['00e6', 'aelig'], // æ
['00e7', 'ccedil'], // ç
['00e8', 'egrave'], // è
['00e9', 'eacute'], // é
['00ea', 'ecirc'], // ê
['00eb', 'euml'], // ë
['00ec', 'igrave'], // ì
['00ed', 'iacute'], // í
['00ee', 'icirc'], // î
['00ef', 'iuml'], // ï
['00f0', 'eth'], // ð
['00f1', 'ntilde'], // ñ
['00f2', 'ograve'], // ò
['00f3', 'oacute'], // ó
['00f4', 'ocirc'], // ô
['00f5', 'otilde'], // õ
['00f6', 'ouml'], // ö
['00f7', 'divide'], // ÷
['00f8', 'oslash'], // ø
['00f9', 'ugrave'], // ù
['00fa', 'uacute'], // ú
['00fb', 'ucirc'], // û
['00fc', 'uuml'], // ü
['00fd', 'yacute'], // ý
['00fe', 'thorn'], // þ
['00ff', 'yuml'], // ÿ
['0027', 'apos'], // '
['0022', 'quot'], // "
['0152', 'OElig'], // Œ
['0153', 'oelig'], // œ
['0160', 'Scaron'], // Š
['0161', 'scaron'], // š
['0178', 'Yuml'], // Ÿ
['02c6', 'circ'], // ˆ
['02dc', 'tilde'], // ˜
['2013', 'ndash'], // –
['2014', 'mdash'], // —
['2018', 'lsquo'], // ‘
['2019', 'rsquo'], // ’
['201a', 'sbquo'], // ‚
['201c', 'ldquo'], // “
['201d', 'rdquo'], // ”
['201e', 'bdquo'], // „
['2020', 'dagger'], // †
['2021', 'Dagger'], // ‡
['2030', 'permil'], // ‰
['2039', 'lsaquo'], // ‹
['203a', 'rsaquo'], // ›
['20ac', 'euro'], // €
['0192', 'fnof'], // ƒ
['0391', 'Alpha'], // Α
['0392', 'Beta'], // Β
['0393', 'Gamma'], // Γ
['0394', 'Delta'], // Δ
['0395', 'Epsilon'],// Ε
['0396', 'Zeta'], // Ζ
['0397', 'Eta'], // Η
['0398', 'Theta'], // Θ
['0399', 'Iota'], // Ι
['039a', 'Kappa'], // Κ
['039b', 'Lambda'], // Λ
['039c', 'Mu'], // Μ
['039d', 'Nu'], // Ν
['039e', 'Xi'], // Ξ
['039f', 'Omicron'],// Ο
['03a0', 'Pi'], // Π
['03a1', 'Rho'], // Ρ
['03a3', 'Sigma'], // Σ
['03a4', 'Tau'], // Τ
['03a5', 'Upsilon'],// Υ
['03a6', 'Phi'], // Φ
['03a7', 'Chi'], // Χ
['03a8', 'Psi'], // Ψ
['03a9', 'Omega'], // Ω
['03b1', 'alpha'], // α
['03b2', 'beta'], // β
['03b3', 'gamma'], // γ
['03b4', 'delta'], // δ
['03b5', 'epsilon'],// ε
['03b6', 'zeta'], // ζ
['03b7', 'eta'], // η
['03b8', 'theta'], // θ
['03b9', 'iota'], // ι
['03ba', 'kappa'], // κ
['03bb', 'lambda'], // λ
['03bc', 'mu'], // μ
['03bd', 'nu'], // ν
['03be', 'xi'], // ξ
['03bf', 'omicron'],// ο
['03c0', 'pi'], // π
['03c1', 'rho'], // ρ
['03c2', 'sigmaf'], // ς
['03c3', 'sigma'], // σ
['03c4', 'tau'], // τ
['03c5', 'upsilon'],// υ
['03c6', 'phi'], // φ
['03c7', 'chi'], // χ
['03c8', 'psi'], // ψ
['03c9', 'omega'], // ω
['2022', 'bull'], // •
['2026', 'hellip'], // …
['2032', 'prime'], // ′
['2033', 'Prime'], // ″
['203e', 'oline'], // ‾
['2044', 'frasl'], // ⁄
['2122', 'trade'], // ™
['2190', 'larr'], // ←
['2191', 'uarr'], // ↑
['2192', 'rarr'], // →
['2193', 'darr'], // ↓
['2194', 'harr'], // ↔
['21d2', 'rArr'], // ⇒
['21d4', 'hArr'], // ⇔
['2200', 'forall'], // ∀
['2202', 'part'], // ∂
['2203', 'exist'], // ∃
['2207', 'nabla'], // ∇
['2208', 'isin'], // ∈
['220b', 'ni'], // ∋
['220f', 'prod'], // ∏
['2211', 'sum'], // ∑
['2212', 'minus'], // −
['221a', 'radic'], // √
['221d', 'prop'], // ∝
['221e', 'infin'], // ∞
['2220', 'ang'], // ∠
['2227', 'and'], // ∧
['2228', 'or'], // ∨
['2229', 'cap'], // ∩
['222a', 'cup'], // ∪
['222b', 'int'], // ∫
['2234', 'there4'], // ∴
['223c', 'sim'], // ∼
['2248', 'asymp'], // ≈
['2260', 'ne'], // ≠
['2261', 'equiv'], // ≡
['2264', 'le'], // ≤
['2265', 'ge'], // ≥
['2282', 'sub'], // ⊂
['2283', 'sup'], // ⊃
['2286', 'sube'], // ⊆
['2287', 'supe'], // ⊇
['2295', 'oplus'], // ⊕
['22a5', 'perp'], // ⊥
['25ca', 'loz'], // ◊
['2660', 'spades'], // ♠
['2663', 'clubs'], // ♣
['2665', 'hearts'], // ♥
['2666', 'diams'] // ♦
];
 
Line 5,221 ⟶ 5,294:
//
var wikEdSpecialChars = [
['2002', 'ensp'], //   en space
['00ad', 'shy'], // ­ soft hyphen
['2003', 'emsp'], //   em space
['2009', 'thinsp'], //   thin space
['200c', 'zwnj'], // ‌ zero width non-joiner
['200d', 'zwj'], // ‍ zero width joiner
['200e', 'lrm'], // ‎ left-to-right mark
['200f', 'rlm'] // ‏ right-to-left mark
];
 
// unsupported chars in IE6
var wikEdProblemChars = [
['03d1', 'thetasym'], // ϑ
['03d2', 'upsih'], // ϒ
['03d6', 'piv'], // ϖ
['2118', 'weierp'], // ℘
['2111', 'image'], // ℑ
['211c', 'real'], // ℜ
['2135', 'alefsym'], // ℵ
['21b5', 'crarr'], // ↵
['21d0', 'lArr'], // ⇐
['21d1', 'uArr'], // ⇑
['21d3', 'dArr'], // ⇓
['2205', 'empty'], // ∅
['2209', 'notin'], // ∉
['2217', 'lowast'], // ∗
['2245', 'cong'], // ≅
['2284', 'nsub'], // ⊄
['22a5', 'perp'], // ⊥
['2297', 'otimes'], // ⊗
['22c5', 'sdot'], // ⋅
['2308', 'lceil'], // ⌈
['2309', 'rceil'], // ⌉
['230a', 'lfloor'], // ⌊
['230b', 'rfloor'], // ⌋
['2329', 'lang'], // 〈
['232a', 'rang'] // 〉
];
 
// ASCII control characters and invisibles, used for syntax highlighting
var wikEdControlChars = {
'0': 'null',
'1': 'start of heading',
'2': 'start of text',
'3': 'end of text',
'4': 'end of transmission',
'5': 'enquiry',
'6': 'acknowledge',
'7': 'bell',
'8': 'backspace',
'9': 'horizontal tab',
'10': 'line feed, new line',
'11': 'vertical tab',
'12': 'form feed, new page',
'13': 'carriage return',
'14': 'shift out',
'15': 'shift in',
'16': 'data link escape',
'17': 'device control 1',
'18': 'device control 2',
'19': 'device control 3',
'20': 'device control 4',
'21': 'negative acknowledge',
'22': 'synchronous idle',
'23': 'end of trans. block',
'24': 'cancel',
'25': 'end of medium',
'25': 'substitute',
'26': 'escape',
'27': 'file separator',
'28': 'group separator',
'29': 'record separator',
'30': 'unit separator',
'173' : 'soft hyphen', // \u00ad
'8204': 'zero width non-joiner', // \u200c
'8205': 'zero width joiner', // \u200d
'8206': 'left-to-right mark', // \u200e
'8207': 'right-to-left mark', // \u200f
'8232': 'line separator', // \u2028
'8233': 'paragraph separator' // \u2028
};
 
// strange spaces, used for syntax highlighting
var wikEdStrangeSpaces = {
'31': 'non-breaking space', // \u00a0
'8194': 'en space', // \u2002
'8195': 'em space', // \u2003
'8201': 'thin space', // \u2009
};