/* {{no:Bruker:Dvyjones/wikEd_mal}} <pre clear="all"><nowiki> */
// version info
var wikEdProgramVersion = '0.9.24b';
var wikEdProgramDate = '4 Februar, 2007';
/*
Teksten under sakl oversettes
== wikEd ==
A full-featured JavaScript in-browser editor for Wikipedia and other MediaWiki edit pages
The program works currently ONLY for Mozilla-based browsers (Mozilla, Mozilla Firefox, and Mozilla SeaMonkey)
Homepage: http://no.wikipedia.orghttps://wiki95.com/no/Bruker:Dvyjones/wikEd
Author: Cacycle (http://en.wikipedia.orghttps://wiki95.com/no/User:Cacycle)
License: This code has been released into the public domain
This file might have to be saved as UTF-16 in your editor to preserve Unicode characters, e.g. ·±×♥ (. +/- x heart)
== Installation ==
* Copy the following block of code to ]
* Press SHIFT-Reload to update to the newest version
* PLEASE DO NOT COPY THE WHOLE PROGRAM
* See http://en.wikipedia.orghttps://wiki95.com/no/User:Cacycle/wikEd for detailed instructions
// ---- START INSTALLATION CODE ----
// install ] in-browser text editor
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
// ---- END INSTALLATION CODE ----
*/
/* {{en:User:Cacycle/wikEd_template}} <pre clear="all"><nowiki> */
// version info
var wikEdProgramVersion = '0.9.38a';
var wikEdProgramDate = 'July 18, 2007';
//
// user configurable variables
//
// user readable texts, copy changes to http://en.wikipedia.orghttps://wiki95.com/no/User:Cacycle/wikEd_international_en.js, also defined in wikEdDiff.js
var wikEdText = wikEdText || ;
// WikedInitText: define built-in user interface texts
function WikedInitText() {
WikEdInitObject(wikEdText, {
// logo
'wikEdLogo alt': 'wikEd',
'wikEdLogo title': 'wikEd {wikEdProgramVersion} ({wikEdProgramDate}) Click to disable',
'wikEdLogo error alt': 'wikEd error',
'wikEdLogo error title': 'Loading error - wikEd {wikEdProgramVersion} ({wikEdProgramDate}) Click to disable',
'wikEdLogo browser alt': '(wikEd)',
'wikEdLogo browser title': 'Browser not supported - wikEd {wikEdProgramVersion} ({wikEdProgramDate})',
'wikEdLogo disabled alt': '(wikEd)',
'wikEdLogo disabled title': 'Disabled - wikEd {wikEdProgramVersion} ({wikEdProgramDate}) Click to enable',
// top jumper
'wikEdScrollToEdit4 alt': 'Scroll to edit',
'wikEdScrollToEdit4 title': 'Scroll to edit field',
// button bar grip titles
'wikEdGripFormat title': 'Formatting buttons (click to hide or show)',
'wikEdGripCustom1 title': 'Custom buttons (click to hide or show)',
'wikEdGripFind title': 'Find buttons (click to hide or show)',
'wikEdGripFix title': 'Fixing buttons (click to hide or show)',
'wikEdGripCustom2 title': 'Custom buttons (click to hide or show)',
'wikEdGripControl title': 'wikEd control buttons (click to hide or show)',
// formatting buttons, top row
'wikEdUndo alt': 'Undo',
'wikEdUndo title': 'Undo',
'wikEdRedo alt': 'Redo',
'wikEdRedo title': 'Redo',
'wikEdBold title': 'Bold text',
'wikEdItalic alt': 'Italic',
'wikEdItalic title': 'Italic text',
'wikEdUnderline alt': 'Underline',
'wikEdUnderline title': 'Underline text',
'wikEdStrikethrough alt': 'Strikethrough',
'wikEdStrikethrough title': 'Strikethrough text',
'wikEdNowiki alt': 'Nowiki',
'wikEdNowiki title': 'Nowiki markup text',
'wikEdSuperscript alt': 'Superscript',
'wikEdSuperscript title': 'Superscript text',
'wikEdSubscript alt': 'Subscript',
'wikEdSubscript title': 'Subscript text',
'wikEdRef alt': 'Ref',
'wikEdRef title': 'In-text reference',
'wikEdCase alt': 'Case',
'wikEdCase title': 'Toggle between lowercase, uppercase first, and uppercase',
'wikEdRedirect alt': 'Redirect',
'wikEdRedirect title': 'Create redirect, deletes whole text',
'wikEdUndoAll alt': 'Undo all',
'wikEdUndoAll title': 'Undo all changes',
'wikEdRedoAll alt': 'Redo all',
'wikEdRedoAll title': 'Redo all changes',
// formatting buttons, bottom row
'wikEdWikiLink alt': 'Link',
'wikEdWikiLink title': 'Wiki link',
'wikEdWebLink alt': 'Weblink',
'wikEdWebLink title': 'External weblink',
'wikEdHeading alt': 'Heading',
'wikEdHeading title': 'Increase heading levels (shift-click: decrease)',
'wikEdBulletList alt': 'Bullet list',
'wikEdBulletList title': 'Increase bulleted list level (shift-click: decrease)',
'wikEdNumberList alt': 'Number list',
'wikEdNumberList title': 'Increase numbered list level (shift-click: decrease)',
'wikEdIndentList alt': 'Indent list',
'wikEdIndentList title': 'Increase indention (shift-click: decrease)',
'wikEdDefinitionList alt': 'Def list',
'wikEdDefinitionList title': 'Definition list',
'wikEdImage alt': 'Image',
'wikEdImage title': 'Image',
'wikEdTable alt': 'Table',
'wikEdTable title': 'Table',
'wikEdReferences alt': 'References',
'wikEdReferences title': 'References location (shift-click: small Wikipedia style)',
'wikEdWikify alt': 'Wikify',
'wikEdWikify title': 'Convert pasted content to wiki code, update highlighting',
'wikEdTextify alt': 'Textify',
'wikEdTextify title': 'Convert pasted content to plain text, update highlighting',
// find and replace buttons, top row
'wikEdFindAll alt': 'Find all',
'wikEdFindAll title': 'Find all matches',
'wikEdFindPrev alt': 'Find prev',
'wikEdFindPrev title': 'Find previous match',
'wikEdFindSelect title': 'Select a previous search or jump to a heading',
'wikEdFindNext alt': 'Find next',
'wikEdFindNext title': 'Find next match (shift-click: get selection)',
'wikEdJumpPrev alt': 'Selected prev',
'wikEdJumpPrev title': 'Find the selected text backwards',
'wikEdJumpNext alt': 'Selected next',
'wikEdJumpNext title': 'Find the selected text forwards',
// find and replace buttons, bottom row
'wikEdReplaceAll alt': 'Replace all',
'wikEdReplaceAll title': 'Replace all matches in whole text or selection',
'wikEdReplacePrev alt': 'Replace prev',
'wikEdReplacePrev title': 'Replace previous match',
'wikEdReplaceSelect title': 'Select a previous replacement',
'wikEdReplaceNext alt': 'Replace next (shift-click: get selection)',
'wikEdReplaceNext title': 'Replace next match',
'wikEdCaseSensitive alt': 'Case sensitive',
'wikEdCaseSensitive title': 'Search is case sensitive',
'wikEdRegExp alt': 'RegExp',
'wikEdRegExp title': 'Search field is a regular expression',
'wikEdFindAhead alt': 'Find ahead',
'wikEdFindAhead title': 'Find ahead as you type (case-insensitive non-regexp search)',
// fix buttons, top row
'wikEdFixBasic alt': 'Fix basic',
'wikEdFixBasic title': 'Fix blanks and empty lines, also done by other fixing functions',
'wikEdFixHtml alt': 'Fix html',
'wikEdFixHtml title': 'Fix html to wikicode',
'wikEdFixCaps alt': 'Fix caps',
'wikEdFixCaps title': 'Fix caps in headers and lists',
'wikEdfixUnicode alt': 'Fix Unicode',
'wikEdfixUnicode title': 'Fix Unicode character representations',
'wikEdFixAll alt': 'Fix all',
'wikEdFixAll title': 'Fix basic, html, capitalization, and Unicode',
'wikEdFixRegExTypo alt': 'Fix typos',
'wikEdFixRegExTypo title': 'Fix typos using the AutoWikiBrowser RegExTypoFixer rules',
// fix buttons, bottom row
'wikEdFixDashes alt': 'Fix dashes',
'wikEdFixDashes title': 'Fix dashes',
'wikEdFixPunct alt': 'Fix punctuation',
'wikEdFixPunct title': 'Fix spaces before punctuation',
'wikEdFixMath alt': 'Fix math',
'wikEdFixMath title': 'Fix math',
'wikEdFixChem alt': 'Fix chem',
'wikEdFixChem title': 'Fix chemical formulas',
'wikEdFixUnits alt': 'Fix units',
'wikEdFixUnits title': 'Fix units',
// wikEd control buttons, top row
'wikEdRefHide alt': 'Hide <ref>',
'wikEdRefHide title': 'Toggle <ref> tag hiding',
'wikEdTextZoom alt': 'Text zoom',
'wikEdTextZoom title': 'Text zoom cycling (shift-click: reverse)',
'wikEdClearHistory alt': 'Clear history',
'wikEdClearHistory title': 'Clear the find, replace, and summary history',
'wikEdScrollToPreview alt': 'Scroll to preview',
'wikEdScrollToPreview title': 'Scroll to preview field',
'wikEdScrollToEdit alt': 'Scroll to edit',
'wikEdScrollToEdit title': 'Scroll to edit field',
// wikEd control buttons, bottom row
'wikEdUseWikEd alt': 'Use wikEd',
'wikEdUseWikEd title': 'Toggle between classic text area and wikEd',
'wikEdHighlightSyntax alt': 'Syntax',
'wikEdHighlightSyntax title': 'Toggle automatic syntax highlighting',
'wikEdSource alt': 'Source',
'wikEdCloseToolbar title': 'Close the standard non-wikEd toolbar',
'wikEdCloseToolbar alt': 'Close toolbar',
'wikEdSource title': 'Show the source code for testing purposes',
'wikEdUsing alt': 'Using',
'wikEdUsing title': 'Automatically add \'\'…using wikEd\'\' to summaries',
'wikEdDiff alt': 'wikEdDiff',
'wikEdDiff title': 'Toggle automatic improved diff view',
'wikEdFullScreen alt': 'Fullscreen',
'wikEdFullScreen title': 'Toggle the fullscreen mode',
// summary buttons
'wikEdClearSummary alt': 'Clear summary',
'wikEdClearSummary title': 'Clear the summary field',
'wikEdSummarySelect title': 'Select a previous summary',
'wikEdPresetSummary': [
'/* */ ', 'copyedit', 'reply', 'article created', 'intro rewrite',
'linkfix', 'fixing typos', 'removing linkspam', 'reverting test',
'reverting vandalism', 'formatting source text', '{wikEdUsing}'
],
'wikEdSummaryUsing': '…using ]',
// submit buttons
'wikEdLocalPreviewImg alt': 'Preview below',
'wikEdLocalPreview title': 'Show preview below',
'wikEdLocalDiffImg alt': 'Changes below',
'wikEdLocalDiff title': 'Show current changes below',
'wikEdHelpPageLink': ' | <a target="_blank" href="http://en.wikipedia.orghttps://wiki95.com/no/User:Cacycle/wikEd_help" target="helpwindow">wikEd help</a>',
// preview and changes buttons, top
'wikEdClose alt': 'Close',
'wikEdClose title': 'Close preview box',
'wikEdScrollToPreview2 alt': 'Scroll to preview',
'wikEdScrollToPreview2 title': 'Scroll to preview field',
'wikEdScrollToEdit2 alt': 'Scroll to edit',
'wikEdScrollToEdit2 title': 'Scroll to edit field',
// preview and changes buttons, bottom
'wikEdClose alt': 'Close',
'wikEdClose title': 'Close preview box',
'wikEdScrollToPreview3 alt': 'Scroll to preview',
'wikEdScrollToPreview3 title': 'Scroll to preview field',
'wikEdScrollToEdit3 alt': 'Scroll to edit',
'wikEdScrollToEdit3 title': 'Scroll to edit field',
// formatting functions
'image filename': 'filename',
'image width': 'width',
'table caption': 'caption',
'table heading': 'heading',
'table cell': 'cell',
'redirect article link': 'article link',
// fixing functions
'External links': 'External links',
'See also': 'See also',
'References': 'References',
// language specific wiki code
'wikicode Image': 'Image',
'wikicode Category': 'Category',
'wikicode Template': 'Template',
'wikEdReferencesSection': '\n== References ==\n\n<div class="references-small">\n<references/>\n</div>\n',
// shortened button texts
'shortenedPreview': 'Preview',
'shortenedChanges': 'Changes',
// follow link popup
'followLink': '(Ctrl-click)'
});
}
// use local copies of images for testing (set to true in local copy of edit page), also defined in wikEdDiff.js
if (typeof(wikEdUseLocalImages) == 'undefined') { var wikEdUseLocalImages = false; }
// path to local images for testing, also defined in wikEdDiff.js
var wikEdImagePathLocal = wikEdImagePathLocal || 'file:///D:/wikEd/images/';
// path to images, also defined in wikEdDiff.js
var wikEdImagePath = wikEdImagePath || 'http://upload.wikimedia.org/wikipedia/commons/';
// image filenames, also defined in wikEdDiff.js
var wikEdImage = wikEdImage || ;
// WikedInitImage: define built-in image URLs
function WikedInitImage() {
WikEdInitImage(wikEdImage, {
'blank': '5/51/WikEd_blank.png',
'bold': '5/59/WikEd_bold.png',
'browser': '0/07/WikEd_disabled.png',
'bulletList': '6/62/WikEd_bullet_list.png',
'case': 'a/aa/WikEd_case.png',
'caseSensitive': '0/0d/WikEd_case_sensitive.png',
'clearHistory': 'c/c8/WikEd_clear_history.png',
'clearSummary': '2/2c/WikEd_clear_summary.png',
'close': '9/97/WikEd_close.png',
'closeToolbar': '1/1d/WikEd_close_toolbar.png',
'ctrl': '1/10/WikEd_ctrl.png',
'definitionList': 'f/f5/WikEd_definition_list.png',
'diff': 'd/db/WikEd_diff.png',
'disabled': '0/07/WikEd_disabled.png',
'dummy': 'c/c5/WikEd_dummy.png',
'error': '3/3e/WikEd_error.png',
'findAhead': '3/34/WikEd_find_ahead.png',
'findAll': '7/75/WikEd_find_all.png',
'findNext': 'a/ad/WikEd_find_next.png',
'findPrev': 'f/f5/WikEd_find_prev.png',
'fixAll': '8/86/WikEd_fix_all.png',
'fixBasic': '3/30/WikEd_fix_basic.png',
'fixCaps': '0/00/WikEd_fix_caps.png',
'fixUnicode': 'd/d4/WikEd_fix_unicode.png',
'fixChem': 'e/e7/WikEd_fix_chem.png',
'fixDash': 'e/e5/WikEd_fix_dash.png',
'fixHtml': '0/05/WikEd_fix_html.png',
'fixMath': '3/3f/WikEd_fix_math.png',
'fixPunct': 'd/db/WikEd_fix_punct.png',
'fixRegExTypo': '9/94/WikEd_fix_reg-ex-typo.png',
'fixUnits': '6/69/WikEd_fix_units.png',
'textZoom': '7/71/WikEd_font_size.png',
'fullScreen': 'd/d3/WikEd_fullscreen.png',
'getFind': '9/96/WikEd_get_selection.png',
'grip': 'a/ad/WikEd_grip.png',
'heading': '0/07/WikEd_heading.png',
'highlightSyntax': '6/67/WikEd_syntax.png',
'image': '3/37/WikEd_image.png',
'indentList': '7/7a/WikEd_indent_list.png',
'italic': 'd/d4/WikEd_italic.png',
'jumpNext': '5/54/WikEd_jump_next.png',
'logo': '6/67/WikEd_logo.png',
'nowiki': '5/5a/WikEd_nowiki.png',
'numberList': '3/3b/WikEd_number_list.png',
'jumpPrev': 'c/c7/WikEd_jump_prev.png',
'preview': '3/31/WikEd_preview.png',
'redirect': 'f/fa/WikEd_redirect.png',
'redo': 'd/d7/WikEd_redo.png',
'ref': 'b/ba/WikEd_ref.png',
'refHide': '0/0b/WikEd_ref_hide.png',
'references': '6/66/WikEd_references.png',
'redoAll': '2/2d/WikEd_redo_all.png',
'regExp': '6/6a/WikEd_regexp.png',
'replaceAll': '2/2a/WikEd_replace_all.png',
'replaceNext': 'b/b0/WikEd_replace_next.png',
'replacePrev': 'a/a1/WikEd_replace_prev.png',
'scrollToEdit': '1/13/WikEd_align_top.png',
'scrollToPreview': '3/37/WikEd_align_preview.png',
'scrollToEditDown': 'a/a8/WikEd_align_down.png',
'scrollToPreviewDown': '5/58/WikEd_align_preview_down.png',
'source': '0/02/WikEd_source.png',
'strikethrough': '0/06/WikEd_strikethrough.png',
'subscript': '9/9e/WikEd_subscript.png',
'superscript': 'b/bf/WikEd_superscript.png',
'tab': 'e/e7/WikEd_tab.png',
'table': 'b/bd/WikEd_table.png',
'textify': 'c/cd/WikEd_textify.png',
'underline': '2/21/WikEd_underline.png',
'undo': 'e/e6/WikEd_undo.png',
'undoAll': '0/08/WikEd_undo_all.png',
'unknown': '8/8a/WikEd_unknown.png',
'useWikEd': '6/67/WikEd_logo.png',
'using': 'e/e0/WikEd_using.png',
'webLink': '1/16/WikEd_weblink.png',
'wikEdDiff': 'c/c6/WikEdDiff.png',
'wikify': '9/9f/WikEd_wikify.png',
'wikiLink': '2/21/WikEd_wikilink.png'
});
}
// edit-frame css rules
var wikEdFrameCSS = wikEdFrameCSS || ;
// WikedInitFrameCSS: define built-in edit frame css
function WikedInitFrameCSS() {
WikEdInitObject(wikEdFrameCSS, {
// frame body
'.wikedFrameBody': 'background: #FFFFFF; margin: 0px; padding: 0.2em; overflow: -moz-scrollbars-vertical; overflow-x: auto; font-family: monospace;',
// syntax highlighting
'.wikEdBlock': 'background-color: #e8e8e8;',
'.wikEdBlockTag': 'color: #0000e0;',
'.wikEdInlineTag': 'color: #0000e0;',
'.wikEdUnknown': 'background-image: url({wikEdUnknown});',
'.wikEdSubscript': 'position: relative; top: 0.3em;',
'.wikEdSuperscript': 'position: relative; top: -0.3em;',
'.wikEdBold': 'font-weight: bold;',
'.wikEdRef': 'color: #808080; background-color: #e8e8e8;',
'.wikEdRefHide': 'color: #c0c0c0;',
'.wikEdComment': 'background-color: #fff0d0;',
'.wikEdDel': 'text-decoration: line-through;',
'.wikEdIns': 'text-decoration: underline;',
'.wikEdItalic': 'font-style: italic;',
'.wikEdNowiki': 'background-color: #e8e8e8;',
'.wikEdRGB': '',
// horizontal rule
'.wikEdHR': 'background-color: #d0d0d0;',
'.wikEdHRInline': 'background-color: #d0d0d0;',
// wiki code
'.wikEdWiki': 'color: #0000e0;',
'.wikEdWikiRedir': 'color: #0000e0; background-color: #ffffff; font-weight: bold;',
'.wikEdMagic': 'color: #0000e0; background-color: #e0e0e0; font-weight: bold;',
// headings
'.wikEdHeading': 'background-color: #e0e0e0; font-weight: bold;',
'.wikEdHeadingWp': 'background-color: #d8e0ff; font-weight: bold;',
// tables
'.wikEdTableBlock': 'background-color: #e8e8e8;',
'.wikEdTableLine': 'background-color: #e8e8e8;',
'.wikEdTableTag': 'background-color: #e8e8e8; color: #0000e0;',
// list
'.wikEdListBlock': 'background-color: #e8e8e8;',
'.wikEdListLine': 'background-color: #f0f0f0',
'.wikEdListTag': 'background-color: #e8e8e8; color: #0000e0; font-weight: bold;',
// space-pre
'.wikEdSpaceBlock': 'background-color: #e8e8e8;',
'.wikEdSpaceLine': 'background-color: #e8e8e8;',
'.wikEdSpaceTag': 'color: #0000e0; font-weight: bold;',
// wiki links, images, categories, templates
'.wikEdLinkTag': 'color: #0000e0;',
'.wikEdLink': '',
'.wikEdImage': 'background-color: #d5ffaa;',
'.wikEdCat': 'background-color: #d0d8ff;',
'.wikEdTemplTag': 'color: #0000e0;',
'.wikEdTempl': 'background-color: #e0e8ff;',
// interlanguage
'.wikEdInter': 'color: #000000;',
'.wikEdLinkInter': 'background-color: #c8c8ff;',
'.wikEdImageInter': 'background-color: #c8c8ff;',
'.wikEdCatInter': 'background-color: #c8c8ff;',
'.wikEdTemplInter': 'background-color: #c8c8ff;',
// name
'.wikEdLinkName': 'color: #f00000; font-weight: bold;',
'.wikEdImageName': 'color: #000000; font-weight: bold;',
'.wikEdCatName': 'color: #f00000; font-weight: bold;',
'.wikEdTemplName': 'color: #f00000; font-weight: bold;',
'.wikEdURLLink': 'color: #f00000; font-weight: bold;',
// links
'.wikEdHighlightLink': 'text-decoration: none; color: #909090;',
':hover.wikEdHighlightLink': 'text-decoration: underline; color: #909090;',
// pasted html
'.wikEdPastedHtml': 'background-color: #ffc080;',
// text and parameters
'.wikEdLinkText': 'color: #000000; font-weight: bold;',
'.wikEdImageParam': 'color: #0000e0;',
'.wikEdImageCaption': 'color: #000000;',
'.wikEdCatText': 'color: #000000;',
'.wikEdTemplText': 'color: #000000;',
'.wikEdURLText': 'color: #000000; font-weight: bold;',
// insert wikicode here
'.wikEdInsertHere': 'background-color: orange; font-style: italic;',
// colors
'.wikEdColorsLight': 'color: black;',
'.wikEdColorsDark': 'color: white;',
// invisibles, control chars, and strange spaces
'.wikEdTab': 'white-space: pre; background-image: url({wikEdTab}); background-position: right bottom; background-repeat: no-repeat;',
'.wikEdTabPlain': 'white-space: pre;',
'.wikEdCtrl': 'white-space: pre; background-image: url({wikEdCtrl}); background-position: left center; background-repeat: repeat-x; background-color: white;',
'.wikEdCtrl:before': 'content: \'\u00a0\'',
'.wikEdBlank': 'white-space: -moz-pre-wrap; background-image: url({wikEdBlank}); background-position: left center; background-repeat: repeat-x; background-color: white;'
});
}
// main window css rules
var wikEdMainCSS = wikEdMainCSS || ;
// WikedInitMainCSS: define built-in main window css
function WikedInitMainCSS() {
WikEdInitObject(wikEdMainCSS, {
// combo input box
'.wikEdCombo': 'font-size: smaller; padding-left: 0.1em; padding-right: 0.1em; margin: 0 0.1em 0 0.1em; height: 1.6em; vertical-align: bottom;',
// wikEd button areas
// button bar margins
'.wikEdButtonBarFormat': 'margin: 0 8px 3px 0; float: left;',
'.wikEdButtonBarCustom1': 'margin: 0 8px 3px 0; float: left;',
'.wikEdButtonBarFind': 'margin: 0 8px 3px 0; float: left;',
'.wikEdButtonBarFix': 'margin: 0 8px 3px 0; float: left;',
'.wikEdButtonBarCustom2': 'margin: 0 8px 3px 0; float: left;',
'.wikEdButtonBarControl': 'margin: 0 0 3px 0; float: right;',
'.wikEdButtonBarPreview': 'margin: 0 0 0.15em 0.6em; float: right;',
'.wikEdButtonBarPreviewFull': 'margin: -0.2em 0 0 0.6em; float: right;',
'.wikEdButtonBarPreview2': 'margin: 0.2em 0 0.4em 0; float: right;',
'.wikEdButtonBarJump': 'margin: 0 0 0 0.6em; float: right;',
// button bar inner wrapper: border (hidden: invisible)
'.wikedButtonBarInnerWrapperVisible': 'border: 1px solid; border-color: #e0e0e0 #808080 #808080 #e0e0e0;',
'.wikedButtonBarInnerWrapperHidden': '',
// button bar grip wrapper: invisible (hidden: border)
'.wikedButtonBarGripWrapperVisible': 'float: left;',
'.wikedButtonBarGripWrapperHidden': 'float: left; border: 1px solid; border-color: #e0e0e0 #808080 #808080 #e0e0e0;',
// button bar buttons wrapper: invisible (hidden: border)
'.wikedButtonBarButtonsWrapperVisible': 'float: left; background: #d4d0cc; ',
'.wikedButtonBarButtonsWrapperHidden': 'float: left; background: #d4d0cc; border: 1px solid; border-color: #e0e0e0 #808080 #808080 #e0e0e0; z-index: 4;',
// button bar grip
'.wikedButtonBarGrip': 'background: #d4d0cc; padding: 0; background-image: url({wikEdGrip}); background-repeat: repeat-y; cursor: pointer;',
// button bar buttons
'.wikEdButtonsFormat': 'background: #d4d0cc; padding: 2px 2px 0 0px;',
'.wikEdButtonsCustom1': 'background: #d4d0cc; padding: 2px 2px 0 0px;',
'.wikEdButtonsFind': 'background: #d4d0cc; padding: 0px 2px 0 0px;',
'.wikEdButtonsFix': 'background: #d4d0cc; padding: 2px 2px 0 0px;',
'.wikEdButtonsCustom2': 'background: #d4d0cc; padding: 2px 2px 0 0px;',
'.wikEdButtonsControl': 'background: #d4d0cc; padding: 2px 2px 0 1px;',
'.wikEdButtonsPreview': 'background: #d4d0cc; padding: 2px; border: 1px solid; border-color: #e0e0e0 #808080 #808080 #e0e0e0;',
'.wikEdButtonsPreviewFull': 'background: #d4d0cc; padding: 2px; border: 1px solid; border-color: #e0e0e0 #808080 #808080 #e0e0e0;',
'.wikEdButtonsPreview2': 'background: #d4d0cc; padding: 2px; border: 1px solid; border-color: #e0e0e0 #808080 #808080 #e0e0e0;',
'.wikEdButtonsJump': 'background: #d4d0cc; padding: 2px; border: 1px solid; border-color: #e0e0e0 #808080 #808080 #e0e0e0;',
// wikEd buttons
'.wikEdButton': 'vertical-align: text-top; font-size: small; text-decoration: underline; margin: 1px 2px; padding: 0; background: #d4d0cc; border: 1px #d4d0cc solid; cursor: pointer;',
'.wikEdButton:hover': 'background: #e4e0dd; border: 1px outset; cursor: pointer;',
'.wikEdButton:active': 'background: #e4e0dc; border: 1px inset; cursor: pointer;',
'.wikEdButtonSolo': 'vertical-align: text-top; font-size: small; text-decoration: underline; margin: 1px 2px; padding: 0; background: #d4d0cc; border: 1px #d4d0cc solid; cursor: pointer;',
'.wikEdButtonSolo:hover': 'background: #e4e0dd; border: 1px outset; cursor: pointer;',
'.wikEdButtonChecked': 'vertical-align: text-top; font-size: small; text-decoration: none; margin: 1px 2px; padding: 0; background: #ccc8c3; border: 1px solid; border-color: black white white black; cursor: pointer;',
'.wikEdButtonUnchecked': 'vertical-align: text-top; font-size: small; text-decoration: none; margin: 1px 2px; padding: 0; background: #ddd8d3; border: 1px solid; border-color: white black black white; cursor: pointer;',
'.wikEdButtonPressed': 'vertical-align: text-top; font-size: small; text-decoration: none; margin: 1px 2px; padding: 0; background: #ccc8c3; border: 1px solid; border-color: black white white black; cursor: wait;',
'.wikEdButtonInactive': 'vertical-align: text-top; font-size: small; text-decoration: underline; margin: 1px 2px; padding: 0; background: #c0c0c0; border: 1px #b0b0b0 solid; cursor: not-allowed',
'.wikEdLocalPreview': 'vertical-align: top; margin: 0 0.33em 0 0.15em; padding: 0;',
'.wikEdLocalDiff': 'vertical-align: top; margin: 0 0.33em 0 -0.18em; padding: 0;',
'.wikEdButtonDummy': 'vertical-align: text-top; margin: 1px 2px; padding: 1px; background: #d4d0cc;',
// preview box
'.wikEdPreviewBoxOuter': 'clear: both; margin: 0; border-width: 1px; border-style: solid; border-color: #808080 #d0d0d0 #d0d0d0 #808080;',
'.wikEdPreviewBox': 'background-color: #faf8f6; padding: 5px; border-width: 1px; border-style: solid; border-color: #404040 #ffffff #ffffff #404040;',
// find field
'.wikEdFindComboInput': 'position: relative; padding: 0; margin: 0 0.2em; font-style: normal; white-space: nowrap;',
'#wikEdFindText': 'height: 1.4em; font-family: monospace; padding: 0; margin: 0; position: absolute; width: 170px; left: 0; top: 0; z-index: 2;',
'#wikEdFindSelect': 'height: 1.5em; font-family: monospace; padding: 0; margin: 0; position: relative; border: none; vertical-align: baseline; z-index: 1;',
// replace field
'.wikEdReplaceComboInput': 'position: relative; padding: 0; margin: 0 0.2em; font-style: normal; white-space: nowrap;',
'#wikEdReplaceText': 'height: 1.4em; font-family: monospace; padding: 0; margin: 0; position: absolute; width: 170px; left: 0; top: 0; z-index: 2;',
'#wikEdReplaceSelect': 'height: 1.5em; font-family: monospace; padding: 0; margin: 0; position: relative; border: none; vertical-align: baseline; z-index: 1;',
// summary field
'.wikEdSummaryComboInput': 'position: relative; white-space: nowrap; margin: 0 0 0 0.1em;',
'.wikEdSummaryText': 'padding: 0; margin: 0; position: absolute; left: 0; top: 0; z-index: 2;',
'.wikEdSummarySelect': 'border: none; padding: 0; margin: 0; position: relative; vertical-align: middle; z-index: 1;',
// space around submit buttons
'.editButtons': 'margin: 0;',
// frame
'.wikEdFrameOuter': 'width: 100%; margin: 0; border-width: 1px; border-style: solid; border-color: #808080 #d0d0d0 #d0d0d0 #808080;',
'.wikEdFrameInner': 'padding: 0; border-width: 1px; border-style: solid; border-color: #404040 #ffffff #ffffff #404040;',
'.wikEdFrame': 'width: 100%; padding: 0; margin: 0; border: none;',
// summary
'.wikEdSummaryWrapper': 'margin: 0 0 0.4em 0;',
'.wikEdSummaryWrapperTop': 'margin: 0.1em 0 0.4em 0;',
'#wpSummaryLabel': 'margin: 0 0.2em 0 0;',
'.editOptions': 'position: relative; top: 0.1em;',
'.wikEdClearSummaryForm': 'display: inline;',
'.wikEdClearSummary': 'vertical-align: middle; margin: 0 0.1em 0 0.5em; padding: 0 0 0.2em 0;',
// input wrapper
'.wikEdInputWrapper': 'z-index: 100; clear: both; margin-top: 0.5em;',
'.wikEdInputWrapperFull': 'position: fixed; top: 0; left: 0; right: 0; padding: 4px; background: white; z-index: 100;',
// other wrappers
'.wikEdToolbarWrapper': 'margin: 0 0 0.25em 0;',
'.wikEdTextareaWrapper': 'margin: 0 0 0.35em 0;',
'.wikEdFrameWrapper': 'margin: 0 0 0.35em 0;',
'.wikEdConsoleWrapper': '',
'.wikEdButtonsWrapper': '',
'.wikEdSummaryInputWrapper': 'display: inline; white-space: nowrap;',
'.wikEdSummaryOptions': 'display: inline;',
'.wikEdSubmitWrapper': 'margin: 0 0 0.25em 0;',
'.wikEdSubmitButtonsWrapper': '',
'.wikEdLocalPrevWrapper': '',
'.wikEdInsertWrapper': '',
// various
'.wikEdEditOptions': 'display: inline; vertical-align: baseline; margin-right: 0.75em; white-space: nowrap;',
'.wikEdEditHelp': 'vertical-align: baseline; margin-right: 0.5em; white-space: nowrap;',
'#editpage-specialchars': 'clear: both;'
});
}
// buttons (id, class, popup title, image src, width, height, alt text, onClick and parameters)
var wikEdButton = wikEdButton || ;
// WikedInitButton: define built-in buttons (id, class, popup title, image src, width, height, alt text, onClick and parameters)
function WikedInitButton() {
WikEdInitObject(wikEdButton, {
// format top
1: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
2: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
3: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
4: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
5: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
6: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
7: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
8: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
9: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
10: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
12: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
25: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
13: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
14: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
// format bottom
15: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
16: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
17: , wikEdImage, '16', '16', wikEdText, 'if (!event.shiftKey) { javascript:WikEdEditButton(this, \'wikEdIncreaseHeading\'); } else { javascript:WikEdEditButton(this, \'wikEdDecreaseHeading\'); }' ],
19: , wikEdImage, '16', '16', wikEdText, 'if (!event.shiftKey) { javascript:WikEdEditButton(this, \'wikEdIncreaseBulletList\'); } else { javascript:WikEdEditButton(this, \'wikEdDecreaseBulletList\'); }' ],
20: , wikEdImage, '16', '16', wikEdText, 'if (!event.shiftKey) { javascript:WikEdEditButton(this, \'wikEdIncreaseNumberList\'); } else { javascript:WikEdEditButton(this, \'wikEdDecreaseNumberList\'); }' ],
21: , wikEdImage, '16', '16', wikEdText, 'if (!event.shiftKey) { javascript:WikEdEditButton(this, \'wikEdIncreaseIndentList\'); } else { javascript:WikEdEditButton(this, \'wikEdDecreaseIndentList\'); }' ],
22: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
23: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
24: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
11: , wikEdImage, '16', '16', wikEdText, 'if (!event.shiftKey) { javascript:WikEdEditButton(this, this.id); } else { javascript:WikEdEditButton(this, \'wikEdReferencesSection\'); }' ],
26: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
27: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
// control top
77: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id, true);' ],
29: , wikEdImage, '16', '16', wikEdText, 'if (!event.shiftKey) { javascript:WikEdButton(this, \'wikEdTextZoomDown\'); } else { javascript:WikEdButton(this, \'wikEdTextZoomUp\'); }' ],
30: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id);' ],
31: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id);' ],
32: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id);' ],
// control bottom
33: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id, true);' ],
34: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id, true);' ],
35: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
75: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id, true);' ],
36: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id, true);' ],
37: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id, true);' ],
// find top
39: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
40: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
41: , wikEdImage, '16', '16', wikEdText, 'if (event.shiftKey) { javascript:WikEdEditButton(this, this.id, \'shift\'); } else { javascript:WikEdEditButton(this, this.id); }' ],
43: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
44: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
// find bottom
46: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
47: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
48: , wikEdImage, '16', '16', wikEdText, 'if (event.shiftKey) { javascript:WikEdEditButton(this, this.id, \'shift\'); } else { javascript:WikEdEditButton(this, this.id); }' ],
49: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id, true);' ],
50: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id, true);' ],
51: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id, true);' ],
// fix top
52: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
53: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
54: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
55: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
56: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
57: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
// fix bottom
58: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
59: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
60: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
61: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
62: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdEditButton(this, this.id);' ],
// preview top
65: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id);' ],
66: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id);' ],
67: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id);' ],
// preview bottom
70: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id);' ],
71: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id);' ],
72: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id);' ],
// jump
78: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id, true);' ],
74: , wikEdImage, '16', '16', wikEdText, 'javascript:WikEdButton(this, this.id);' ],
// dummy
76: , '16', '16', '', '' ]
});
}
// button bars (id, class, button numbers)
var wikEdButtonBar = wikEdButtonBar || ;
// WikedInitButtonBar: define built-in button bars (id outer, class outer, id inner, class inner, height, grip title, button numbers)
function WikedInitButtonBar() {
WikEdInitObject(wikEdButtonBar, {
'format': , ],
'custom1': , ],
'find': , ],
'fix': , ],
'custom2': , ],
'control': , ],
'preview': ],
'preview2': ],
'jump': ]
});
}
// history length for find, replace, and summary fields
var wikEdHistoryLength = wikEdHistoryLength || ;
wikEdHistoryLength = 10;
wikEdHistoryLength = 10;
wikEdHistoryLength = 10;
// presets for combo input fields dropdown options, {wikEdUsing} appends a link to this script
var wikEdComboPresetOptions = wikEdComboPresetOptions || ;
wikEdComboPresetOptions = wikEdComboPresetOptions || wikEdText;
// text for summary link to this script
var wikEdSummaryUsing = wikEdSummaryUsing || wikEdText;
// expiration time span for permanent cookies in seconds
var wikEdCookieExpireSec = wikEdCookieExpireSec || (30 * 24 * 60 * 60);
// find ahead as you type checkbox preset
if (typeof(wikEdHighlightSyntaxPreset) == 'undefined') { var wikEdFindAheadSelected = true; }
// highlight syntax preset
var wikEdHighlightSyntaxPreset = wikEdHighlightSyntaxPreset || true;
// enable wikEd preset
if (typeof(wikEdUseWikEdPreset) == 'undefined') { var wikEdUseWikEdPreset = true; }
// add '...using wikEd' to summary preset (set to true by single-session cookie wikEdSummaryUsing)
if (typeof(wikEdUsingPreset) == 'undefined') { var wikEdUsingPreset = false; }
// wikEdDiff preset
if (typeof(wikEdDiffPreset) == 'undefined') { var wikEdDiffPreset = false; }
// fullscreen mode preset
if (typeof(wikEdFullScreenModePreset) == 'undefined') { var wikEdFullScreenModePreset = false; }
// show MediaWiki toolbar preset
if (typeof(wikEdCloseToolbarPreset) == 'undefined') { var wikEdCloseToolbarPreset = false; }
// hide ref tags preset
if (typeof(wikEdRefHidePreset) == 'undefined') { var wikEdRefHidePreset = false; }
// initial text zoom for edit window (percentage)
var wikEdTextZoom = wikEdTextZoom || 100;
// remove invisible syntax highlighting comments after closing tag
if (typeof(wikEdRemoveHighlightComments) == 'undefined') { var wikEdRemoveHighlightComments = true; }
// show the text-to-source button for testing purposes
if (typeof(wikEdShowSourceButton) == 'undefined') { var wikEdShowSourceButton = false; }
// show the using-wiked button
if (typeof(wikEdShowUsingButton) == 'undefined') { var wikEdShowUsingButton = false; }
// the wikEd help page link to be displayed after the editing help link, an empty string disables the link
var wikEdHelpPageLink = wikEdHelpPageLink || wikEdText;
// display the wikEd button bars on top of the edit box
if (typeof(wikEdButtonsOnTop) == 'undefined') { var wikEdButtonsOnTop = true; }
// enable external diff script
if (typeof(wikEdLoadDiffScript) == 'undefined') { var wikEdLoadDiffScript = true; }
// diff script URL
var wikEdDiffScriptSrc = wikEdDiffScriptSrc || 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/diff.js&action=raw&ctype=text/javascript';
// enable external wikEdDiff script
if (typeof(wikEdLoadDiff) == 'undefined') { var wikEdLoadDiff = true; }
// wikEdDiff script URL, also defined in wikEdDiff.js
var wikEdDiffSrc = wikEdDiffSrc || 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEdDiff.js&action=raw&ctype=text/javascript';
// enable external InstaView script
if (typeof(wikEdLoadInstaView) == 'undefined') { var wikEdLoadInstaView = true; }
// InstaView script URL
var wikEdInstaViewSrc = wikEdInstaViewSrc || 'http://en.wikipedia.org/w/index.php?title=User:Pilaf/include/instaview.js&action=raw&ctype=text/javascript';
// enable external RegExTypoFix script
if (typeof(wikEdLoadRegExTypoFix) == 'undefined') { var wikEdLoadRegExTypoFix = false; }
// RegExTypoFix script URL
var wikEdRegExTypoFixSrc = wikEdRegExTypoFixSrc || 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEdTypoFix.js&action=raw&ctype=text/javascript';
// enable RegExTypoFix (http://en.wikipedia.orghttps://wiki95.com/no/User:Mboverload/RegExTypoFix), needs User:Cacycle/wikEdTypoFix.js or translation
if (typeof(wikEdRegExTypoFix) == 'undefined') { var wikEdRegExTypoFix = true; }
// enable highlighting as links
if (typeof(wikEdFollowHighlightedLinks) == 'undefined') { var wikEdFollowHighlightedLinks = false; }
// skip the browser detection to run wikEd under IE and Opera
if (typeof(wikEdSkipBrowserTest) == 'undefined') { var wikEdSkipBrowserTest = false; }
// set the button bar grip width in px
var wikEdButtonBarGripWidth = wikEdButtonBarGripWidth || 8;
// enable local preview (Pilaf's InstaView)
if (typeof(wikEdUseLocalPreview) == 'undefined') { var wikEdUseLocalPreview = true; }
// allow ajax requests from local copy for testing, also defined in wikEdDiff.js
if (typeof(wikEdAllowLocalAjax) == 'undefined') { var wikEdAllowLocalAjax = false; }
// enable server preview (Ajax)
if (typeof(wikEdUseAjaxPreview) == 'undefined') { var wikEdUseAjaxPreview = true; }
// enable auto update (Ajax)
if (typeof(wikEdAutoUpdate) == 'undefined') { var wikEdAutoUpdate = true; }
// hours between update check
var wikEdAutoUpdateHours = wikEdAutoUpdateHours || 20;
// auto update version url (ajax)
var wikEdAutoUpdateUrl = wikEdAutoUpdateUrl || 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd_current_version&action=raw&maxage=0';
// show complete unshortened article text for local diff, also defined in wikEdDiff.js
if (typeof(wikEdFullDiff) == 'undefined') { var wikEdFullDiff = false; }
// make links ctrl-clickable
if (typeof(wikEdFollowLinks) == 'undefined') { var wikEdFollowLinks = true; }
// correct tab order between check boxes and submit buttons
if (typeof(wikEdSubmitTabOrder) == 'undefined') { var wikEdSubmitTabOrder = false; }
//
// end of user configurable variables
//
// global variables
var wikEdLoaded;
var wikEdDisabled = false;
// history
var wikEdFieldHist = ;
var wikEdCookieName = ;
var wikEdInputElement = ;
var wikEdSelectElement = ;
var wikEdCheckMarker = ;
wikEdCheckMarker = '\u2022';
wikEdCheckMarker = '\u22c5';
// cache the parsed DOM object
var wikEdFrameDOMCache;
// undo all, redo all
var wikEdOrigVersion = '';
var wikEdLastVersion;
// global dom elements
var wikEdLogo;
var wikEdLogoList;
var wikEdTextarea;
var wikEdFrame;
var wikEdFrameBody;
var wikEdFrameDocument;
var wikEdFrameWindow;
var wikEdInputWrapper;
var wikEdToolbarWrapper;
var wikEdTextareaWrapper;
var wikEdFrameWrapper;
var wikEdConsoleWrapper;
var wikEdButtonsWrapper;
var wikEdSummaryWrapper;
var wikEdSummaryInputWrapper;
var wikEdSummaryOptions;
var wikEdSubmitWrapper;
var wikEdSubmitButtonsWrapper;
var wikEdLocalPrevWrapper;
var wikEdInsertWrapper;
var wikEdButtonBarFormat;
var wikEdButtonBarCustom1;
var wikEdButtonBarFind;
var wikEdButtonBarFix;
var wikEdButtonBarCustom2;
var wikEdButtonBarControl;
var wikEdButtonBarPreview;
var wikEdButtonBarPreview2;
var wikEdButtonBarJump;
var wikEdPreviewBox;
var wikEdClearSummary;
var wikEdClearSummaryImg;
var wikEdCaseSensitive;
var wikEdRegExp;
var wikEdFindAhead;
var wikEdFindText;
var wikEdReplaceText;
var wikEdSummaryText;
var wikEdSummarySelect;
var wikEdEditOptions;
var wikEdEditHelp;
var wikEdSaveButton;
var wikEdPreviewButton;
var wikEdLDiffButton;
var wikEdLocalPreview;
var wikEdLocalDiff;
var wikEdDiffPreviewButton;
var wikEdSummaryLabel;
// various
var wikEdTextareaHeight;
var wikEdClearSummaryWidth;
var wikEdFullScreenMode = false;
var wikeEdInsertTagsOriginal;
var wikEdAddNewSection;
var wikEdBrowserNotSupported
var wikEdFrameScrollTop;
var wikEdTextareaUpdated;
// wikEd settings
var wikEdRefHide;
var wikEdUsing;
var wikEdUseWikEd;
var wikEdCloseToolbar;
var wikEdHighlightSyntax;
var wikEdDiff;
// unicode fixing
var wikEdControlCharsStr = '';
var wikEdSupportedChars;
var wikEdSpecialChars;
var wikEdProblemChars;
var wikEdControlChars;
var wikEdStrangeSpaces;
// debugging time measurement, usage: wikEdDebugTimer.push(); WikEdDebugTimer();
var wikEdDebugTimer = ;
// MediaWiki file paths for use in regexps
var wikEdServer = '';
var wikEdArticlePath = '';
var wikEdScriptPath = '';
var wikEdArticlePrefix = '';
// hash of loaded scripts, also defined in wikEdDiff.js
var wikEdExternalScripts = wikEdExternalScripts || ;
// check for updates
WikEdAutoUpdate();
// call the setup routine
if (typeof(addOnloadHook) == 'function') {
addOnloadHook(WikEdSetup);
}
else {
window.onload = WikEdSetup;
}
//
// WikEdInitObject: initialize object, keep pre-defined values
//
function WikEdInitObject(array, preset) {
for (var key in preset) {
if (array == null) {
array = preset;
}
}
return;
}
//
// WikEdInitImage: initialize images, keep pre-defined values
//
function WikEdInitImage(array, preset) {
for (var key in preset) {
if (array == null) {
// remove MediaWiki path prefixes and add local path
if (wikEdUseLocalImages == true) {
array = wikEdImagePathLocal + preset.replace(/^+\/+\//, '');
}
// add path
else {
array = wikEdImagePath + preset;
}
}
}
return;
}
//
// WikEdSetup: setup routine, called on page load
//
function WikEdSetup(scrollToText) {
// initialize texts and images (needed here for logo)
WikedInitText();
WikedInitImage();
// add image path to image filename
if (wikEdLogo == null) {
// insert logo into personal toolbar
wikEdLogo = document.createElement('img');
wikEdLogo.id = 'wikEdLogoImg';
wikEdLogo.onclick = WikEdMainSwitch;
wikEdLogoList = document.createElement('li');
wikEdLogoList.id = 'wikEdLogoList';
wikEdLogoList.appendChild(wikEdLogo);
var personalTools = document.getElementById('p-personal');
if (personalTools != null) {
personalTools.getElementsByTagName('ul').appendChild(wikEdLogoList);
}
}
// detect already loaded external scripts
if (wikEdExternalScripts == null) {
var pageScripts = document.getElementsByTagName('script');
for (var i = 0; i < pageScripts.length; i ++) {
var nameMatch = pageScripts.src.match(/\/(*?)($|\?)/);
if (nameMatch != null) {
var scriptName = nameMatch;
if (scriptName != '') {
wikEdExternalScripts = true;
}
}
}
}
// load the external diff script
var head = document.getElementsByTagName('head');
if ( (wikEdLoadDiffScript == true) && (wikEdExternalScripts == null) ) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = wikEdDiffScriptSrc;
head.appendChild(script);
wikEdExternalScripts = true;
}
// load the external wikEdDiff script
if ( (wikEdLoadDiff == true) && (wikEdExternalScripts == null) ) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = wikEdDiffSrc;
head.appendChild(script);
wikEdExternalScripts = true;
}
// check if disabled
var cookie = WikEdGetCookie('wikEdDisabled');
if (cookie != '') {
wikEdDisabled = true;
wikEdUseWikEd = false;
WikEdSetLogo();
return;
}
// check if setup was already run
if (wikEdLoaded == true) {
return;
}
// set error logo
WikEdSetLogo('error');
// at the moment this works only for Mozilla browsers (Mozilla, Mozilla Firefox, Mozilla SeaMonkey)
if (wikEdSkipBrowserTest != true) {
// no id no wikEd
if (navigator.appName == null) {
wikEdBrowserNotSupported = true;
}
else {
// check if it is a Netscape descendant
var origin = navigator.appName.match(/Netscape/i);
if ( (origin == null) || (origin == '') ) {
wikEdBrowserNotSupported = true;
}
// check the generation
var generation = navigator.appVersion.match(/\d+(\.\d+)/);
if ( (generation == null) || (generation < 5.0) ) {
wikEdBrowserNotSupported = true;
}
// check if it is a Gecko browser
var geckoDate = navigator.userAgent.match(/\bGecko\/(\d+)/i);
if (geckoDate != null) {
if ( (geckoDate != '') && (geckoDate < 20050000) ) {
wikEdBrowserNotSupported = true;
}
}
// check browser and version
var agent = navigator.userAgent.match(/(Firefox|Netscape|SeaMonkey)\/(\d+\.\d+)/i);
if (agent != null) {
var browser = agent;
var version = agent;
if (
(browser == 'Firefox') && (version < 1.5) ||
(browser == 'Netscape') && (version < 8.0) ||
(browser == 'SeaMonkey') && (version < 1.0)
) {
wikEdBrowserNotSupported = true;
}
}
}
// browser not supported, set error message
if (wikEdBrowserNotSupported == true) {
WikEdSetLogo('browser');
return;
}
}
// check if this is an edit page
wikEdTextarea = document.getElementsByName('wpTextbox1');
var wpEditform = document.getElementById('editform');
wikEdSaveButton = document.getElementById('wpSave');
if ( (wikEdTextarea == null) || (wpEditform == null) || (wikEdSaveButton == null) ) {
// reset error indicator
WikEdSetLogo();
return;
}
// initialize frame css, main css, buttons, and button bars
WikedInitFrameCSS();
WikedInitMainCSS();
WikedInitButton();
WikedInitButtonBar();
// define Unicode characters for fixing function
WikEdInitUnicode();
// detect if we add a new section (+ tab)
if (/(\?|&)section=new\b/.test(window.location.search) == true) {
wikEdAddNewSection = true;
}
// load the external InstaView script
if ( (wikEdLoadInstaView == true) && (wikEdExternalScripts == null) ) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = wikEdInstaViewSrc;
head.appendChild(script);
wikEdExternalScripts = true;
}
else if (wikEdLoadInstaView != true) {
wikEdUseLocalPreview = false;
}
// load the external RegExTypoFix script
if ( (wikEdLoadRegExTypoFix == true) && (wikEdExternalScripts == null) ) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = wikEdRegExTypoFixSrc;
head.appendChild(script);
wikEdExternalScripts = true;
}
else if (wikEdLoadRegExTypoFix != true) {
wikEdRegExTypoFix = false;
}
// get initial textarea height
wikEdTextareaHeight = wikEdTextarea.offsetHeight;
// setup the undo buffers and save the original text for local changes view
wikEdOrigVersion = wikEdTextarea.value;
// add stylesheet definitions
var mainStyle = new WikEdStyleSheet();
var rules = '';
for (var ruleName in wikEdMainCSS) {
var ruleStyle = wikEdMainCSS;
if (typeof(ruleStyle) != 'string') {
continue;
}
ruleStyle = ruleStyle.replace(/\{wikEdGrip\}/g, wikEdImage);
rules += ruleName + ' {' + ruleStyle + '}\n';
}
mainStyle.addRules(rules);
// get button settings from cookies
wikEdUsing = WikEdGetCookieSetting('wikEdSummaryUsing', wikEdUsingPreset);
wikEdUseWikEd = WikEdGetCookieSetting('wikEdUseClassic', wikEdUseWikEdPreset);
wikEdHighlightSyntax = WikEdGetCookieSetting('wikEdSyntaxOff', wikEdHighlightSyntaxPreset);
wikEdFullScreenMode = WikEdGetCookieSetting('wikEdFullscreen', wikEdFullScreenModePreset);
wikEdCloseToolbar = WikEdGetCookieSetting('wikEdCloseToolbar', wikEdCloseToolbarPreset);
wikEdRefHide = WikEdGetCookieSetting('wikEdRefHide', wikEdRefHidePreset);
wikEdDiff = WikEdGetCookieSetting('wikEdDiff', wikEdDiffPreset);
// no fullscreen for preview pages
if (window.location.search.match(/(\?|&)action=submit\b/) != null) {
wikEdFullScreenMode = false;
}
// disable wikEd for js pages
if ( (typeof(wgTitle) == 'string') && (typeof(wgCanonicalNamespace) == 'string') ) {
if (/\.js$/.test(wgTitle) == true) {
if ( (wgCanonicalNamespace != 'User_talk') && (wgCanonicalNamespace != 'Talk') ) {
if (wikEdOrigVersion.length > 20000) {
wikEdUseWikEd = false;
}
else {
wikEdHighlightSyntax = false;
}
}
}
}
// preset frame related styles to avoid browser crashes
var styleFrameBody;
var styleFrameWrapperPosition;
var styleFrameWrapperVisibility;
var styleTextareaWrapperPosition;
var styleTextareaWrapperVisibility;
if (wikEdUseWikEd == true) {
styleFrameBody = 'style="display: block;" ';
styleFrameWrapperPosition = 'static';
styleFrameWrapperVisibility = 'visible';
styleTextareaWrapperPosition = 'absolute';
styleTextareaWrapperVisibility = 'hidden';
}
else {
styleFrameBody = 'style="display: none;" ';
styleFrameWrapperPosition = 'absolute';
styleFrameWrapperVisibility = 'hidden';
styleTextareaWrapperPosition = 'static';
styleTextareaWrapperVisibility = 'visible';
}
var wikEdInputWrapperClass;
if (wikEdFullScreenMode == true) {
wikEdInputWrapperClass = 'wikEdInputWrapperFull';
}
else {
wikEdInputWrapperClass = 'wikEdInputWrapper';
}
// create wikEd element wrappers
// create input wrapper, this contains the whole fullscreen content
wikEdInputWrapper = document.createElement('div');
wikEdInputWrapper.id = 'wikEdInputWrapper';
wikEdInputWrapper.className = wikEdInputWrapperClass;
wikEdTextarea.parentNode.insertBefore(wikEdInputWrapper, wikEdTextarea);
// create toolbar wrapper
wikEdToolbarWrapper = document.createElement('div');
wikEdToolbarWrapper.id = 'wikEdToolbarWrapper';
wikEdToolbarWrapper.className = 'wikEdToolbarWrapper';
wikEdInputWrapper.appendChild(wikEdToolbarWrapper);
// create textarea wrapper
wikEdTextareaWrapper = document.createElement('div');
wikEdTextareaWrapper.id = 'wikEdTextareaWrapper';
wikEdTextareaWrapper.className = 'wikEdTextareaWrapper';
wikEdTextareaWrapper.style.position = styleTextareaWrapperPosition;
wikEdTextareaWrapper.style.visibility = styleTextareaWrapperVisibility;
wikEdInputWrapper.appendChild(wikEdTextareaWrapper);
// create frame wrapper
wikEdFrameWrapper = document.createElement('div');
wikEdFrameWrapper.id = 'wikEdFrameWrapper';
wikEdFrameWrapper.className = 'wikEdFrameWrapper';
wikEdFrameWrapper.style.position = styleFrameWrapperPosition;
wikEdFrameWrapper.style.visibility = styleFrameWrapperVisibility;
wikEdInputWrapper.appendChild(wikEdFrameWrapper);
// create console wrapper for buttons, summary, and submit
wikEdConsoleWrapper = document.createElement('div');
wikEdConsoleWrapper.id = 'wikEdConsoleWrapper';
wikEdConsoleWrapper.className = 'wikEdConsoleWrapper';
wikEdInputWrapper.appendChild(wikEdConsoleWrapper);
// create buttons wrapper for wikEd buttons
wikEdButtonsWrapper = document.createElement('div');
wikEdButtonsWrapper.id = 'wikEdButtonsWrapper';
wikEdButtonsWrapper.className = 'wikEdButtonsWrapper';
if (wikEdButtonsOnTop == true) {
wikEdInputWrapper.insertBefore(wikEdButtonsWrapper, wikEdTextareaWrapper);
}
else {
wikEdConsoleWrapper.appendChild(wikEdButtonsWrapper);
}
// create summary wrapper for summary, minor edit, and watch this page
wikEdSummaryWrapper = document.createElement('div');
wikEdSummaryWrapper.id = 'wikEdSummaryWrapper';
// add summary above the edit field if we add a new section (+ tab)
if (wikEdAddNewSection == true) {
wikEdSummaryWrapper.className = 'wikEdSummaryWrapperTop';
wikEdInputWrapper.insertBefore(wikEdSummaryWrapper, wikEdFrameWrapper);
}
else {
wikEdSummaryWrapper.className = 'wikEdSummaryWrapper';
wikEdConsoleWrapper.appendChild(wikEdSummaryWrapper);
}
// create summary input wrapper
wikEdSummaryInputWrapper = document.createElement('div');
wikEdSummaryInputWrapper.id = 'wikEdSummaryInputWrapper';
wikEdSummaryInputWrapper.className = 'wikEdSummaryInputWrapper';
wikEdSummaryWrapper.appendChild(wikEdSummaryInputWrapper);
// create minor edit and watch page wrapper
wikEdSummaryOptions = document.createElement('div');
wikEdSummaryOptions.id = 'wikEdSummaryOptions';
wikEdSummaryOptions.className = 'wikEdSummaryOptions';
wikEdSummaryWrapper.appendChild(wikEdSummaryOptions);
// create submit wrapper for submit elements
wikEdSubmitWrapper = document.createElement('div');
wikEdSubmitWrapper.id = 'wikEdSubmitWrapper';
wikEdSubmitWrapper.className = 'wikEdSubmitWrapper';
wikEdConsoleWrapper.appendChild(wikEdSubmitWrapper);
// create submit buttons wrapper for submit buttons and help links
wikEdSubmitButtonsWrapper = document.createElement('div');
wikEdSubmitButtonsWrapper.id = 'wikEdSubmitButtonsWrapper';
wikEdSubmitButtonsWrapper.className = 'wikEdSubmitButtonsWrapper';
wikEdSubmitWrapper.appendChild(wikEdSubmitButtonsWrapper);
// create preview wrapper for preview and diff box
wikEdLocalPrevWrapper = document.createElement('div');
wikEdLocalPrevWrapper.id = 'wikEdLocalPrevWrapper';
wikEdLocalPrevWrapper.className = 'wikEdLocalPrevWrapper';
wikEdLocalPrevWrapper.style.display = 'none';
wikEdInputWrapper.appendChild(wikEdLocalPrevWrapper);
// create insert wrapper for insert special chars links
wikEdInsertWrapper = document.createElement('div');
wikEdInsertWrapper.id = 'wikEdInsertWrapper';
wikEdInsertWrapper.className = 'wikEdInsertWrapper';
wikEdInputWrapper.appendChild(wikEdInsertWrapper);
// append input wrapper to document
wpEditform.insertBefore(wikEdInputWrapper, wpEditform.firstChild);
// fill the wrappers
// wikEdDiff enhanced ajax diff
if (typeof(wikEdDiffTable) == 'object') {
if ( (wikEdDiffTable != null) && (wikEdDiff == true) ) {
if (typeof(WikEdDiff) == 'function') {
WikEdDiff();
}
}
}
// add toolbar to toolbar wrapper
var wpToolbar = document.getElementById('toolbar');
if (wikEdCloseToolbar == true) {
wikEdToolbarWrapper.style.display = 'none';
}
else {
wikEdToolbarWrapper.style.display = 'block';
}
if (wpToolbar != null) {
wikEdToolbarWrapper.appendChild(wpToolbar);
}
// call wikibits:mwSetupToolbar() now because it would terminate with an error after setting textarea to display: none
if (wpToolbar != null) {
if (wpToolbar.getElementsByTagName('IMG').length == 0) {
if (typeof(mwSetupToolbar) == 'function') {
mwSetupToolbar();
window.removeEventListener('load', mwSetupToolbar, false);
}
}
}
wikEdEditOptions = document.getElementsByName('wpSummary').parentNode;
wikEdEditOptions.className = 'wikEdEditOptions';
// add summary elements to summary input wrapper
wikEdSummaryLabel = document.getElementById('wpSummaryLabel');
if (wikEdSummaryLabel != null) {
wikEdSummaryInputWrapper.appendChild(wikEdSummaryLabel);
}
wikEdSummaryText = document.getElementsByName('wpSummary');
wikEdSummaryInputWrapper.appendChild(wikEdSummaryText);
// move editpage-copywarn out of summary wrapper
// needs to be done before appending editOptions to summary wrapper otherwise a linebreak stays (Mozilla bug)
var copywarn = document.getElementById('editpage-copywarn');
if (copywarn != null) {
wikEdInputWrapper.parentNode.insertBefore(copywarn, wikEdInputWrapper.nextSibling);
}
// add submit buttons to submit wrapper
var wpEditButtons = wikEdSaveButton.parentNode;
wikEdSubmitWrapper.insertBefore(wpEditButtons, wikEdSubmitButtonsWrapper);
// move edit options after submit buttons; crashes Mozilla when appended after filling the iframe
var previewButton = document.getElementById('wpDiff');
previewButton.parentNode.insertBefore(wikEdEditOptions, previewButton.nextSibling);
// remove linebreak before minor edit checkbox
var node = wikEdEditOptions.firstChild;
while (node != null) {
if (node.tagName != null) {
if (node.tagName == 'BR') {
node.parentNode.removeChild(node);
break;
}
}
node = node.nextSibling;
}
// correct tab order between check boxes and submits
wikEdPreviewButton = document.getElementById('wpPreview');
wikEdDiffPreviewButton = document.getElementById('wpDiff');
if (wikEdSubmitTabOrder == true) {
var wpMinoredit = document.getElementById('wpMinoredit');
var wpWatchthis = document.getElementById('wpWatchthis');
if ( (wpMinoredit != null) && (wpWatchthis != null) ) {
var tabIndex = ;
tabIndex.push(wpMinoredit.tabIndex, wpWatchthis.tabIndex, wikEdSaveButton.tabIndex, wikEdPreviewButton.tabIndex, wikEdDiffPreviewButton.tabIndex);
wikEdSaveButton.tabIndex = tabIndex.shift();
wikEdPreviewButton.tabIndex = tabIndex.shift();
wikEdDiffPreviewButton.tabIndex = tabIndex.shift();
wpMinoredit.tabIndex = tabIndex.shift();
wpWatchthis.tabIndex = tabIndex.shift();
}
}
// add textarea to textarea wrapper
wikEdTextareaWrapper.appendChild(wikEdTextarea);
// add edit-frame to frame wrapper
// any DOM changes to a starting iframe in designmode may crash mozilla, including DOM move, display: none; and position: absolute;
// create the iframe
var html = '';
html += '<div id="wikEdFrameOuter" class="wikEdFrameOuter">';
html += '<div id="wikEdFrameInner" class="wikEdFrameInner">';
html += '<iframe id="wikEdFrame" class="wikEdFrame" name="wikEdFrame" style="height: ' + wikEdTextareaHeight + 'px;"></iframe>';
html += '</div>';
html += '</div>';
wikEdFrameWrapper.innerHTML = html;
wikEdInputWrapper.insertBefore(wikEdTextareaWrapper, wikEdFrameWrapper);
// fill the frame with content
html = '';
html += '<html><head></head>';
html += '<body id="wikEdFrameBody" class="wikedFrameBody"' + styleFrameBody + 'onload="window.document.designMode = \'on\'; window.document.execCommand(\'styleWithCSS\', false, false);">';
html += '</body></html>';
wikEdFrame = document.getElementById('wikEdFrame');
wikEdFrameWindow = wikEdFrame.contentWindow;
wikEdFrameDocument = wikEdFrameWindow.document;
wikEdFrameDocument.open();
wikEdFrameDocument.write(html);
wikEdFrameDocument.close();
wikEdFrameBody = wikEdFrameDocument.body;
// generate button bars and add them to the buttons wrapper
// form wrapper has been added against summary input submit defaulting to this button
wikEdButtonBarFormat = MakeButtonBar(wikEdButtonBar);
wikEdButtonsWrapper.appendChild(wikEdButtonBarFormat);
wikEdButtonBarControl = MakeButtonBar(wikEdButtonBar);
wikEdButtonsWrapper.appendChild(wikEdButtonBarControl);
if (wikEdButtonBar.length > 0) {
wikEdButtonBarCustom1 = MakeButtonBar(wikEdButtonBar);
wikEdButtonsWrapper.appendChild(wikEdButtonBarCustom1);
}
wikEdButtonBarFind = MakeButtonBar(wikEdButtonBar);
wikEdButtonsWrapper.appendChild(wikEdButtonBarFind);
wikEdButtonBarFix = MakeButtonBar(wikEdButtonBar);
wikEdButtonsWrapper.appendChild(wikEdButtonBarFix);
if (wikEdButtonBar.length > 0) {
wikEdButtonBarCustom2 = MakeButtonBar(wikEdButtonBar);
wikEdButtonsWrapper.appendChild(wikEdButtonBarCustom2);
}
var br = document.createElement('br');
br.style.clear = 'both';
wikEdButtonsWrapper.appendChild(br);
wikEdCaseSensitive = document.getElementById('wikEdCaseSensitive');
wikEdRegExp = document.getElementById('wikEdRegExp');
wikEdFindAhead = document.getElementById('wikEdFindAhead');
wikEdFindText = document.getElementById('wikEdFindText');
wikEdReplaceText = document.getElementById('wikEdReplaceText');
// add preview box top bar to submit wrapper
wikEdButtonBarPreview = MakeButtonBar(wikEdButtonBar);
wikEdSubmitWrapper.insertBefore(wikEdButtonBarPreview, wikEdSubmitWrapper.firstChild);
// add preview box and its bottom bar to preview wrapper
var div = document.createElement('div');
div.id = 'wikEdPreviewBoxOuter';
div.className = 'wikEdPreviewBoxOuter';
wikEdLocalPrevWrapper.appendChild(div);
wikEdPreviewBox = document.createElement('div');
wikEdPreviewBox.id = 'wikEdPreviewBox';
wikEdPreviewBox.className = 'wikEdPreviewBox';
div.appendChild(wikEdPreviewBox);
wikEdButtonBarPreview2 = MakeButtonBar(wikEdButtonBar);
wikEdLocalPrevWrapper.appendChild(wikEdButtonBarPreview2);
// add jump box to standard preview
var wikiPreview = document.getElementById('wikiPreview');
if (wikiPreview != null) {
if (wikiPreview.firstChild != null) {
wikEdButtonBarJump = MakeButtonBar(wikEdButtonBar);
wikiPreview.insertBefore(wikEdButtonBarJump, wikiPreview.firstChild);
}
}
// add insert special chars to insert wrapper
var wpSpecialchars = document.getElementById('editpage-specialchars');
if (wpSpecialchars != null) {
wikEdInsertWrapper.appendChild(wpSpecialchars);
}
// wrappers filled
// add local preview button next to submit button
wikEdLocalPreview = document.createElement('button');
wikEdLocalPreview.id = 'wikEdLocalPreview';
wikEdLocalPreview.title = wikEdText;
wikEdLocalPreview.className = 'wikEdLocalPreview';
var localPreviewImg = document.createElement('img');
localPreviewImg.id = 'wikEdLocalPreviewImg';
localPreviewImg.src = wikEdImage;
localPreviewImg.alt = wikEdText;
localPreviewImg.title = wikEdText;
wikEdLocalPreview.appendChild(localPreviewImg);
wikEdPreviewButton.parentNode.insertBefore(wikEdLocalPreview, wikEdPreviewButton.nextSibling);
// add local diff button next to submit button
wikEdLocalDiff = document.createElement('button');
wikEdLocalDiff.id = 'wikEdLocalDiff';
wikEdLocalDiff.title = wikEdText;
wikEdLocalDiff.className = 'wikEdLocalDiff';
var localDiffImg = document.createElement('img');
localDiffImg.id = 'wikEdLocalDiffImg';
localDiffImg.src = wikEdImage;
localDiffImg.alt = wikEdText;
localDiffImg.title = wikEdText;
wikEdLocalDiff.appendChild(localDiffImg);
wikEdDiffPreviewButton.parentNode.insertBefore(wikEdLocalDiff, wikEdDiffPreviewButton.nextSibling);
// initialize image buttons
WikEdButton(document.getElementById('wikEdDiff'), 'wikEdDiff', null, wikEdDiff);
WikEdButton(document.getElementById('wikEdRefHide'), 'wikEdRefHide', null, wikEdRefHide);
WikEdButton(document.getElementById('wikEdHighlightSyntax'), 'wikEdHighlightSyntax', null, wikEdHighlightSyntax);
WikEdButton(document.getElementById('wikEdUseWikEd'), 'wikEdUseWikEd', null, wikEdUseWikEd);
WikEdButton(document.getElementById('wikEdCloseToolbar'), 'wikEdCloseToolbar', null, wikEdCloseToolbar);
WikEdButton(document.getElementById('wikEdFullScreen'), 'wikEdFullScreen', null, wikEdFullScreenMode);
WikEdButton(document.getElementById('wikEdUsing'), 'wikEdUsing', null, wikEdUsing);
WikEdButton(document.getElementById('wikEdCaseSensitive'), 'wikEdCaseSensitive', null, false);
WikEdButton(document.getElementById('wikEdRegExp'), 'wikEdRegExp', null, false);
WikEdButton(document.getElementById('wikEdFindAhead'), 'wikEdFindAhead', null, wikEdFindAheadSelected);
WikEdButton(document.getElementById('wikEdClose'), 'wikEdClose', null, false, 'wikEdButton');
WikEdButton(document.getElementById('wikEdClose2'), 'wikEdClose2', null, false, 'wikEdButton');
if (wikEdRegExTypoFix == false) {
document.getElementById('wikEdFixRegExTypo').style.display = 'none';
}
// add a clear summary button left to the summary input field
var clearSummaryForm = document.createElement('form');
clearSummaryForm.id = 'wikEdClearSummaryForm';
clearSummaryForm.className = 'wikEdClearSummaryForm';
wikEdSummaryText.parentNode.insertBefore(clearSummaryForm, wikEdSummaryText);
wikEdClearSummary = document.createElement('button');
wikEdClearSummary.id = 'wikEdClearSummary';
wikEdClearSummary.className = 'wikEdClearSummary';
wikEdClearSummary.alt = wikEdText;
wikEdClearSummary.title = wikEdText;
wikEdClearSummary.style.height = (wikEdSummaryText.clientHeight + 1) +'px';
clearSummaryForm.appendChild(wikEdClearSummary);
wikEdClearSummaryImg = document.createElement('img');
wikEdClearSummaryImg.id = 'wikEdClearSummaryImg';
wikEdClearSummaryImg.src = wikEdImage;
wikEdClearSummaryImg.alt = 'Clear summary';
wikEdClearSummary.appendChild(wikEdClearSummaryImg);
// remember button width, might be without image
wikEdClearSummaryWidth = wikEdClearSummary.offsetWidth;
// make the summary a combo box
var summaryComboInput = document.createElement('span');
summaryComboInput.id = 'wikEdSummaryComboInput';
summaryComboInput.className = 'wikEdSummaryComboInput';
summaryComboInput = wikEdSummaryText.parentNode.insertBefore(summaryComboInput, wikEdSummaryText);
wikEdSummaryText = wikEdSummaryText.parentNode.removeChild(wikEdSummaryText);
wikEdSummaryText.className = 'wikEdSummaryText';
var wikEdSummaryTextWidth = wikEdSummaryWrapper.offsetWidth - wikEdSummaryInputWrapper.offsetWidth;
if (wikEdSummaryTextWidth < 150) {
wikEdSummaryTextWidth = 150;
}
wikEdSummaryText.style.width = wikEdSummaryTextWidth + 'px';
wikEdSummarySelect = document.createElement('select');
wikEdSummarySelect.id = 'wikEdSummarySelect';
wikEdSummarySelect.className = 'wikEdSummarySelect';
wikEdSummarySelect.onchange = function() {
WikEdChangeComboInput('summary');
}
wikEdSummarySelect.onfocus = function() {
WikEdSetComboOptions('summary');
}
summaryComboInput.appendChild(wikEdSummaryText);
summaryComboInput.appendChild(wikEdSummarySelect);
// shorten submit button texts
wikEdPreviewButton.value = wikEdText;
wikEdDiffPreviewButton.value = wikEdText;
// set up combo input boxes with history
wikEdFieldHist = ;
wikEdCookieName = 'wikEdFindHistory';
wikEdInputElement = new Object(wikEdFindText);
wikEdSelectElement = new Object(document.getElementById('wikEdFindSelect'));
wikEdSelectElement.style.height = (wikEdInputElement.clientHeight + 1) +'px';
wikEdSelectElement.title = wikEdText;
wikEdFieldHist = ;
wikEdCookieName = 'wikEdReplaceHistory';
wikEdInputElement = new Object(wikEdReplaceText);
wikEdSelectElement = new Object(document.getElementById('wikEdReplaceSelect'));
wikEdSelectElement.style.height = (wikEdInputElement.clientHeight + 1) +'px';
wikEdSelectElement.title = wikEdText;
wikEdFieldHist = ;
wikEdCookieName = 'wikEdSummaryHistory';
wikEdInputElement = new Object(wikEdSummaryText);
wikEdSelectElement = new Object(document.getElementById('wikEdSummarySelect'));
wikEdSelectElement.style.height = (wikEdInputElement.clientHeight + 1) +'px';
wikEdSelectElement.title = wikEdText;
// adjust the select field widths to that of the text input fields
WikEdResizeComboInput('find');
WikEdResizeComboInput('replace');
WikEdResizeComboInput('summary');
// hide the button bars per cookie setting
WikEdButtonBarInit(wikEdButtonBarFormat);
WikEdButtonBarInit(wikEdButtonBarControl);
if (wikEdButtonBarCustom1 != null) {
WikEdButtonBarInit(wikEdButtonBarCustom1);
}
WikEdButtonBarInit(wikEdButtonBarFind);
WikEdButtonBarInit(wikEdButtonBarFix);
if (wikEdButtonBarCustom2 != null) {
WikEdButtonBarInit(wikEdButtonBarCustom2);
}
// display only the textarea or the iframe, dont change the frame
if (wikEdUseWikEd == true) {
WikEdSetEditArea(true, true);
}
else {
WikEdSetEditArea(false, true);
}
// add a link to the wikEd help page
if ( (wikEdHelpPageLink != '') && (wikEdHelpPageLink != null) ) {
var editHelpParent = previewButton;
do {
editHelpParent = editHelpParent.nextSibling;
} while (editHelpParent.tagName != 'SPAN');
var editHelp = editHelpParent.lastChild;
while (editHelp.tagName != 'A') {
editHelp = editHelp.previousSibling;
}
wikEdHelpSpan = document.createElement('span');
wikEdHelpSpan.id = 'wikEdHelpSpan';
wikEdHelpSpan.className = 'wikEdHelpSpan';
wikEdHelpSpan.innerHTML = wikEdHelpPageLink;
editHelpParent.insertBefore(wikEdHelpSpan, editHelp.nextSibling);
wikEdEditHelp = wikEdHelpSpan.parentNode;
wikEdEditHelp.id = 'wikEdEditHelp';
wikEdEditHelp.className = 'wikEdEditHelp';
}
// add frame stylesheet definition
wikEdFrameBody.style.fontSize = parseInt(wikEdTextZoom) + '%;';
var frameStyle = new WikEdStyleSheet(wikEdFrameDocument);
var rules = '';
for (var ruleName in wikEdFrameCSS) {
var ruleStyle = wikEdFrameCSS;
if (typeof(ruleStyle) != 'string') {
continue;
}
ruleStyle = ruleStyle.replace(/\{wikEdUnknown\}/g, wikEdImage);
ruleStyle = ruleStyle.replace(/\{wikEdTab\}/g, wikEdImage);
ruleStyle = ruleStyle.replace(/\{wikEdCtrl\}/g, wikEdImage);
ruleStyle = ruleStyle.replace(/\{wikEdBlank\}/g, wikEdImage);
ruleStyle = ruleStyle.replace(/\{wikEdGrip\}/g, wikEdImage);
rules += ruleName + ' {' + ruleStyle + '}\n';
}
frameStyle.addRules(rules);
// copy the textarea content to the iframe
if (wikEdUseWikEd == true) {
WikEdUpdateFrame();
}
// set the summary shrinking event after loading the 'Clear summary' image handler
wikEdClearSummaryImg.addEventListener('load', WikEdShrinkSummaryHandler, true);
// set the summary resize event for window resizing
window.addEventListener('resize', WikEdResizeSummaryHandler, true);
// set frame events
wikEdFrameDocument.addEventListener('keydown', WikEdKeyFrame, true);
wikEdFrameDocument.addEventListener('keyup', WikEdKeyFrame, true);
wikEdFrameDocument.addEventListener('keypress', WikEdKeyFrame, true);
wikEdFrameDocument.addEventListener('mouseup', WikEdKeyFrame, true);
// set find ahead events
wikEdFindText.addEventListener('keyup', WikEdFindAhead, true);
// set submit button events
wikEdSaveButton.addEventListener('click', WikEdSaveButtonHandler, true);
wikEdPreviewButton.addEventListener('click', WikEdPreviewButtonHandler, true);
wikEdDiffPreviewButton.addEventListener('click', wikEdDiffPreviewButtonHandler, true);
wikEdLocalPreview.addEventListener('click', WikEdLocalPreviewHandler, true);
wikEdLocalDiff.addEventListener('click', WikEdLocalDiffHandler, true);
// unload (leaving page) events
window.addEventListener('unload', WikEdUnloadHandler, false);
// set button bar grip area events
wikEdButtonBarFormat.firstChild.firstChild.addEventListener('click', WikEdButtonBarGripHandler, false);
wikEdButtonBarControl.firstChild.firstChild.addEventListener('click', WikEdButtonBarGripHandler, false);
if (wikEdButtonBarCustom1 != null) {
if (wikEdButtonBarCustom1.firstChild.firstChild != null) {
wikEdButtonBarCustom1.firstChild.firstChild.addEventListener('click', WikEdButtonBarGripHandler, false);
}
}
wikEdButtonBarFind.firstChild.firstChild.addEventListener('click', WikEdButtonBarGripHandler, false);
wikEdButtonBarFix.firstChild.firstChild.addEventListener('click', WikEdButtonBarGripHandler, false);
if (wikEdButtonBarCustom2 != null) {
if (wikEdButtonBarCustom2.firstChild.firstChild != null) {
wikEdButtonBarCustom2.firstChild.firstChild.addEventListener('click', WikEdButtonBarGripHandler, false);
}
}
// set the clear summary onclick handler
wikEdClearSummary.addEventListener('click', WikEdClearSummaryHandler, true);
// select the text on focus for find and replace fields
wikEdFindText.addEventListener('focus', WikEdFindReplaceHandler, true);
wikEdReplaceText.addEventListener('focus', WikEdFindReplaceHandler, true);
// tab / shift-tab between find and replace fields
wikEdFindText.addEventListener('keydown', WikEdFindReplaceHandler, true);
wikEdReplaceText.addEventListener('keydown', WikEdFindReplaceHandler, true);
// scroll to edit window if it is not a preview page
if (scrollToText != false) {
if (window.location.search.match(/(\?|&)action=submit\b/) == null) {
window.scroll(0, WikEdGetOffsetTop(wikEdInputWrapper) - 2);
}
// focus the edit area
if (wikEdUseWikEd == true) {
wikEdFrameWindow.focus();
}
else {
wikEdTextarea.setSelectionRange(0, 0);
wikEdTextarea.focus();
}
}
// init MediaWiki file paths for use in regexps
if (typeof(wgServer) == 'string') {
wikEdServer = wgServer.replace(/(\W)/g, '\\$1');
}
if (typeof(wgArticlePath) == 'string') {
wikEdArticlePath = wgArticlePath.replace(wgServer, '');
wikEdArticlePrefix = wgArticlePath.replace(/\$1$/, '');
}
if (typeof(wgScriptPath) == 'string') {
wikEdScriptPath = wgScriptPath.replace(wgServer, '');
}
wikEdArticlePath = wikEdArticlePath.replace(/\$1$/, '');
wikEdScriptPath = wikEdScriptPath.replace(/\/?$/, '/');
wikEdArticlePath = wikEdArticlePath.replace(/(\W)/g, '\\$1');
wikEdScriptPath = wikEdScriptPath.replace(/(\W)/g, '\\$1');
// fullscreen mode
if (wikEdFullScreenMode == true) {
WikEdFullScreen(wikEdFullScreenMode, true);
}
// overwrite the insertTags function in wikibits.js used by the standard button toolbar and the editpage special chars
if (typeof(insertTags) == 'function') {
wikeEdInsertTagsOriginal = insertTags;
insertTags = WikEdInsertTags;
}
// reset error indicator
WikEdSetLogo();
wikEdLoaded = true;
return;
}
//
// WikEdAutoUpdate: check for the latest version
//
function WikEdAutoUpdate() {
// check if autoupdate is enabled
if (wikEdAutoUpdate != true) {
return;
}
// check only on non-interaction pages
if (/(\?|&)action=/.test(window.location.search) == true) {
return;
}
// check cookie for last update check date
var cookie = WikEdGetCookie('wikEdAutoUpdate');
var lastCheck = new Date(cookie);
// fix missing or corrupt cookie
if (isNaN(lastCheck.valueOf()) == true) {
WikEdSetCookie('wikEdAutoUpdate', 'January 1, 1970', 0, '/');
return;
}
// get the hours since last update check
var currentDate = new Date();
var diffHours = (currentDate - lastCheck) / 1000 / 60 / 60;
if (diffHours < wikEdAutoUpdateHours) {
return;
}
// save current update check date to cookie
WikEdSetCookie('wikEdAutoUpdate', currentDate.toUTCString(), 0, '/');
// allow ajax request from local copy for testing
if (wikEdAllowLocalAjax == true) {
if (typeof(netscape) == 'object') {
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
}
}
// make the ajax request
var ajax = WikEdAjaxInitObject();
if (ajax == null) {
return;
}
ajax.open('GET', wikEdAutoUpdateUrl, true);
ajax.send(null);
// ajax response handler function
ajax.onreadystatechange = function() {
if (ajax.readyState != 4) {
return;
}
// get response
var html = ajax.responseText;
// get current version number from string
var ver = wikEdProgramVersion.match(/(\d+)\.(\d+)\.(\d+)(\w?)/);
if (ver == null) {
return;
}
var currentVersion = ((Number(ver) * 1000 + Number(ver)) * 1000 + Number(ver)) * 100 + (ver + '0').charCodeAt(0);
// get new version number from string
var ver = html.match(/(\d+)\.(\d+)\.(\d+)(\w?)/);
if (ver == null) {
return;
}
var newVersion = ((Number(ver) * 1000 + Number(ver)) * 1000 + Number(ver)) * 100 + (ver + '0').charCodeAt(0);
// compare the versions
if (currentVersion >= newVersion) {
return;
}
// update wikEd by reloading the page with cache bypassing (equivalent to Shift-Reload or Shift-F5)
window.location.reload(true);
}
return;
}
//
// WikEdShrinkSummaryHandler: shrink the summary after loading the 'Clear summary' image
//
function WikEdShrinkSummaryHandler(event) {
var diffWidth = wikEdClearSummary.offsetWidth - wikEdClearSummaryWidth;
wikEdInputElement.style.width = (wikEdInputElement.clientWidth - diffWidth) + 'px';
wikEdSelectElement.style.width = (wikEdSelectElement.clientWidth - diffWidth) + 'px';
wikEdClearSummaryWidth = wikEdClearSummary.offsetWidth;
return;
}
//
// WikEdResizeSummaryHandler: adjust the summary width after resizing the window
//
function WikEdResizeSummaryHandler(event) {
WikEdResizeSummary();
return;
}
//
// WikEdUnloadHandler: save editing frame to cached textarea
//
function WikEdUnloadHandler(event) {
// update textarea if not already done in submit handlers
if (wikEdUseWikEd == true) {
if (wikEdTextareaUpdated != true) {
WikEdUpdateTextarea();
}
}
return;
}
//
// WikEdSaveButtonHandler: 'Save page' onclick handler
//
function WikEdSaveButtonHandler(event) {
wikEdSaveButton.removeEventListener('click', WikEdSaveButtonHandler, true);
// update textarea
if (wikEdUseWikEd == true) {
WikEdUpdateTextarea();
wikEdTextareaUpdated = true;
}
// add "using wikEd" to summary, not for adding a new section (+ tab)
var text = wikEdSummaryText.value;
text = text.replace(/^+/, '');
text = text.replace(/+$/, '');
WikEdAddToHistory('summary');
if ( (wikEdUsing == true) && (text != '') ) {
if (text.lastIndexOf(wikEdSummaryUsing) < 0) {
if (wikEdAddNewSection != true) {
text += ' ' + wikEdSummaryUsing;
}
}
}
wikEdSummaryText.value = text;
// submit
wikEdSaveButton.click();
// reinstate handler in case the browser back button will be used
wikEdSaveButton.addEventListener('click', WikEdSaveButtonHandler, true);
return;
}
//
// WikEdPreviewButtonHandler: 'Show preview' onclick handler
//
function WikEdPreviewButtonHandler(event) {
if (wikEdUseWikEd == true) {
WikEdUpdateTextarea();
wikEdTextareaUpdated = true;
}
return;
}
//
// wikEdDiffPreviewButtonHandler: 'Show changes' onclick handler
//
function wikEdDiffPreviewButtonHandler(event) {
if (wikEdFullScreenMode == true) {
WikEdFullScreen(false);
}
if (wikEdUseWikEd == true) {
WikEdUpdateTextarea();
wikEdTextareaUpdated = true;
}
return;
}
//
// WikEdFollowLinkHandler: open highlighted link in new window/tab
//
function WikEdFollowLinkHandler(event) {
if (event.ctrlKey == true) {
if (event.currentTarget.onclick != null) {
event.stopPropagation();
var onClickCode = event.currentTarget.onclick.toString();
var linkMatch = onClickCode.match(/\svar linkUrl *= *(.*)/);
if (linkMatch != null) {
var linkUrl = linkMatch;
window.open(linkUrl);
window.focus();
}
}
}
return;
}
//
// WikEdLocalPreviewHandler: local 'Show preview' image button onclick handler
//
function WikEdLocalPreviewHandler(event) {
event.preventDefault();
WikEdButton(wikEdLocalPreview, 'wikEdLocalPreview');
return;
}
//
// WikEdLocalDiffHandler: local 'Show changes' image button onclick handler
//
function WikEdLocalDiffHandler(event) {
event.preventDefault();
WikEdButton(wikEdLocalDiff, 'wikEdLocalDiff');
return;
}
//
// WikEdButtonBarGripHandler: click, mouseover handler, see also WikEdButtonBarInit()
//
function WikEdButtonBarGripHandler(event) {
event.stopPropagation();
var grip = event.target;
var gripWrapper = grip.parentNode;
var buttonsWrapper = gripWrapper.nextSibling;
var buttons = buttonsWrapper.firstChild;
var barInnerWrapper = gripWrapper.parentNode;
var bar = barInnerWrapper.parentNode;
if (event.type == 'click') {
buttonsWrapper.style.position = 'static';
// hide the buttons bar
if (buttonsWrapper.minimized != true) {
barInnerWrapper.className = 'wikedButtonBarInnerWrapperHidden';
gripWrapper.className = 'wikedButtonBarGripWrapperHidden';
buttonsWrapper.className = 'wikedButtonBarButtonsWrapperHidden';
buttonsWrapper.widthOriginal = buttonsWrapper.offsetWidth;
buttonsWrapper.style.display = 'none';
buttonsWrapper.minimized = true;
grip.addEventListener('mouseover', WikEdButtonBarGripHandler, false);
WikEdSetCookie(bar.id + 'Hidden', '1', null, '/');
}
// unhide the buttons bar
else {
barInnerWrapper.className = 'wikedButtonBarInnerWrapperVisible';
gripWrapper.className = 'wikedButtonBarGripWrapperVisible';
buttonsWrapper.className = 'wikedButtonBarButtonsWrapperVisible';
buttonsWrapper.style.display = 'block';
buttonsWrapper.minimized = false;
grip.removeEventListener('mouseover', WikEdButtonBarGripHandler, false);
WikEdSetCookie(bar.id + 'Hidden', '', -1, '/');
}
}
// show the buttons bar on mouseover
else if (event.type == 'mouseover') {
if (buttonsWrapper.minimized == true) {
bar.addEventListener('mouseout', WikEdButtonBarHandler, false);
// show buttons to the right
if (bar.offsetParent.clientWidth > grip.offsetLeft + grip.offsetWidth + buttonsWrapper.widthOriginal) {
buttonsWrapper.style.left = (grip.offsetLeft + grip.offsetWidth) + 'px';
}
// show buttons to the left
else {
buttonsWrapper.style.left = (gripWrapper.offsetLeft - buttonsWrapper.widthOriginal) + 'px';
}
// a mozilla bug sometimes gives offsetTop - 1 when the wikEdToolbarWrapper is hidden
buttonsWrapper.style.top = gripWrapper.offsetTop + 'px';
buttonsWrapper.style.position = 'absolute';
buttonsWrapper.style.display = 'block';
}
}
return;
}
//
// WikEdButtonBarGripHandler: mouseout handler
//
function WikEdButtonBarHandler(event) {
event.stopPropagation();
var bar = event.currentTarget;
var barInnerWrapper = bar.firstChild;
var gripWrapper = barInnerWrapper.firstChild;
var grip = gripWrapper.firstChild;
var buttonsWrapper = gripWrapper.nextSibling;
var buttons = buttonsWrapper.firstChild;
// hide the buttons
if (event.type == 'mouseout') {
if (buttonsWrapper.minimized == true) {
// filter the events for mouseouts actually leaving the bar
if (
(
( (event.target == grip) || (event.target == gripWrapper) ) &&
(event.relatedTarget != gripWrapper) && (event.relatedTarget != buttonsWrapper) && (event.relatedTarget != buttons) && (event.relatedTarget.parentNode != buttons)
) ||
(
( (event.target.parentNode.parentNode == buttons) || (event.target.parentNode == buttons) || (event.target == buttons) || (event.target == buttonsWrapper) ) &&
(event.relatedTarget.parentNode.parentNode != buttons) && (event.relatedTarget.parentNode != buttons) && (event.relatedTarget != buttons) && (event.relatedTarget != buttonsWrapper) && (event.relatedTarget != gripWrapper) && (event.relatedTarget != grip)
)
) {
bar.removeEventListener('mouseout', WikEdButtonBarHandler, false);
buttonsWrapper.style.display = 'none';
buttonsWrapper.style.position = 'static';
}
}
}
return;
}
//
// clear the summary onclick handler
//
function WikEdClearSummaryHandler(event) {
event.preventDefault();
// clear the summary if it is only a paragraph name
if ( /^\/\* .*? \*\/ *$/.test(wikEdSummaryText.value) ) {
wikEdSummaryText.value = '';
}
// clear the summary but leave paragraph names
else {
wikEdSummaryText.value = wikEdSummaryText.value.replace(/^((\/\* .*? \*\/ *)?).*/,
function (p, p1, p2) {
if (p1.length > 0) {
p1 = p1 + ' ';
}
return(p1);
}
);
}
wikEdSummaryText.focus();
return;
}
//
// WikEdFindReplaceHandler: find and replace: tab and shift-tab between fields, select on focus
//
function WikEdFindReplaceHandler(event) {
// tab / shift-tab between fields
if (event.type == 'keydown') {
if (event.keyCode == 9) {
if (event.target == wikEdFindText) {
event.preventDefault();
wikEdReplaceText.removeEventListener('focus', WikEdFindReplaceHandler, true);
wikEdReplaceText.focus();
wikEdReplaceText.addEventListener('focus', WikEdFindReplaceHandler, true);
}
else if (event.target == wikEdReplaceText) {
event.preventDefault();
wikEdFindText.removeEventListener('focus', WikEdFindReplaceHandler, true);
wikEdFindText.focus();
wikEdFindText.addEventListener('focus', WikEdFindReplaceHandler, true);
}
}
}
// select on focus
else if (event.type == 'focus') {
event.target.setSelectionRange(0, this.textLength);
}
return;
}
//
// WikEdSetLogo: set the logo on top of the page
//
function WikEdSetLogo(state) {
if (state == 'error') {
wikEdLogo.src = wikEdImage;
wikEdLogo.alt = wikEdText;
wikEdLogo.title = wikEdText;
}
else if (state == 'browser') {
wikEdLogo.src = wikEdImage;
wikEdLogo.alt = wikEdText;
wikEdLogo.title = wikEdText;
}
else {
if (wikEdDisabled == true) {
wikEdLogo.src = wikEdImage;
wikEdLogo.alt = wikEdText;
wikEdLogo.title = wikEdText;
}
else {
wikEdLogo.src = wikEdImage;
wikEdLogo.alt = wikEdText;
wikEdLogo.title = wikEdText;
}
}
wikEdLogo.title = wikEdLogo.title.replace(/\{wikEdProgramVersion\}/g, wikEdProgramVersion);
wikEdLogo.title = wikEdLogo.title.replace(/\{wikEdProgramDate\}/g, wikEdProgramDate);
return;
}
//
// MakeButtonBar: generate button bar div element
//
function MakeButtonBar(bar) {
// id outer, class outer, id inner, class inner, alt, button numbers
var barId = bar;
var barClass = bar;
var buttonsId = bar;
var buttonsClass = bar;
var barHeight = bar;
var gripTitle = bar;
var buttonNumbers = bar;
// collect the buttons
var buttons = '';
for (var property in buttonNumbers) {
if ( (typeof(buttonNumbers) != 'string') && (typeof(buttonNumbers) != 'number') ) {
continue;
}
switch (buttonNumbers) {
case 'br':
buttons += '<br />';
break;
case 'find':
buttons += '<span class="wikEdFindComboInput" id="wikEdFindComboInput">';
buttons += '<input class="wikEdCombo" id="wikEdFindText" type="text" value="">';
buttons += '<select class="wikEdCombo" id="wikEdFindSelect" onfocus="javascript:WikEdSetComboOptions(\'find\')" onChange="javascript:WikEdChangeComboInput(\'find\');">';
buttons += '</select>';
buttons += '</span>';
break;
case 'replace':
buttons += '<span class="wikEdReplaceComboInput" id="wikEdReplaceComboInput">';
buttons += '<input class="wikEdCombo" id="wikEdReplaceText" type="text" value="">';
buttons += '<select class="wikEdCombo" id="wikEdReplaceSelect" onfocus="WikEdSetComboOptions(\'replace\')" onChange="javascript:WikEdChangeComboInput(\'replace\');">';
buttons += '</select>';
buttons += '</span>';
break;
default:
var currButton = wikEdButton];
if (typeof(currButton) != 'object') {
alert('Loading error: The button "' + buttonNumbers + '" is not defined.');
}
if ( (currButton == 'wikEdSource') && (wikEdShowSourceButton != true) ) {
break;
}
if ( (currButton == 'wikEdUsing') && (wikEdShowUsingButton != true) ) {
break;
}
buttons += '<img id="' + currButton + '" class="' + currButton + '" title="' + currButton + '" src="' + currButton + '" width="' + currButton + '" height="' + currButton + '" alt="' + currButton + '" onClick="' + currButton + '">';
}
}
// create the button bar div
var div = document.createElement('div');
div.id = barId;
div.className = barClass;
var buttonsStyle = '';
if (barHeight > 0) {
buttonsStyle = ' style="height: ' + barHeight + 'px;"';
}
// make a grip bar
var html = '';
if (gripTitle != null) {
var gripStyle = 'width: ' + wikEdButtonBarGripWidth + 'px; ';
if (barHeight > 0) {
gripStyle += 'height: ' + barHeight + 'px; ';
}
if (gripStyle.length > 0){
gripStyle = ' style="' + gripStyle + '"';
}
html += '<div class="wikedButtonBarInnerWrapperVisible" style="height: ' + barHeight + 'px;">';
html += '<div class="wikedButtonBarGripWrapperVisible">';
html += '<div class="wikedButtonBarGrip"' + gripStyle + ' title="' + gripTitle + '">';
html += ' ';
html += '</div>';
html += '</div>';
html += '<div class="wikedButtonBarButtonsWrapperVisible"' + buttonsStyle + '>';
html += '<div id="' + buttonsId + '" class="' + buttonsClass + '" style="">';
html += buttons;
html += '</div>';
html += '</div>';
html += '</div>';
}
// make a standard no-grip bar
else {
html += '<div id="' + buttonsId + '" class="' + buttonsClass + '"' + buttonsStyle + '">';
html += buttons;
html += '</div>';
}
div.innerHTML = html;
return(div);
}
//
// WikEdButtonBarInit: hide buttons bar, see also WikEdButtonBarGripHandler()
//
function WikEdButtonBarInit(bar) {
var cookie = WikEdGetCookie(bar.id + 'Hidden');
if (cookie != '') {
var barInnerWrapper = bar.firstChild;
var gripWrapper = barInnerWrapper.firstChild;
var grip = gripWrapper.firstChild;
var buttonsWrapper = gripWrapper.nextSibling;
var buttons = buttonsWrapper.firstChild;
barInnerWrapper.className = 'wikedButtonBarInnerWrapperHidden';
gripWrapper.className = 'wikedButtonBarGripWrapperHidden';
buttonsWrapper.className = 'wikedButtonBarButtonsWrapperHidden';
buttonsWrapper.widthOriginal = buttonsWrapper.offsetWidth;
buttonsWrapper.style.display = 'none';
buttonsWrapper.minimized = true;
grip.addEventListener('mouseover', WikEdButtonBarGripHandler, true);
}
return;
}
//
// WikEdSetEditArea: apply css changes to switch between classic textarea and rich text frame
//
function WikEdSetEditArea(useFrame, notFrame) {
// turn rich text frame on
if (useFrame == true) {
wikEdTextareaWrapper.style.position = 'absolute';
wikEdTextareaWrapper.style.visibility = 'hidden';
wikEdTextarea.style.display = 'none';
if (notFrame != true) {
wikEdFrameWrapper.style.position = 'static';
wikEdFrameWrapper.style.visibility = 'visible';
wikEdFrameBody.style.display = 'block';
}
if (document.getElementById('toolbar') != null) {
if (wikEdCloseToolbar == true) {
wikEdToolbarWrapper.style.display = 'none';
}
else {
wikEdToolbarWrapper.style.display = 'block';
}
}
wikEdButtonBarFormat.style.display = 'block';
if (wikEdButtonBarCustom1 != null) {
wikEdButtonBarCustom1.style.display = 'block';
}
wikEdButtonBarFind.style.display = 'block';
wikEdButtonBarFix.style.display = 'block';
if (wikEdButtonBarCustom2 != null) {
wikEdButtonBarCustom2.style.display = 'block';
}
wikEdButtonBarControl.style.display = 'block';
}
// turn classic textarea on
else {
if (notFrame != true) {
wikEdFrameWrapper.style.position = 'absolute';
wikEdFrameWrapper.style.visibility = 'hidden';
// Mozilla or wikEd bug: <br> insertion before text a while after setting display to 'none', test with setTimeout('alert(wikEdFrameBody.innerHTML)', 1000);
// wikEdFrameBody.style.display = 'none';
}
wikEdTextareaWrapper.style.position = 'static';
wikEdTextareaWrapper.style.visibility = 'visible';
wikEdTextarea.style.display = 'block';
if (document.getElementById('toolbar') != null) {
wikEdToolbarWrapper.style.display = 'block';
}
wikEdButtonBarFormat.style.display = 'none';
if (wikEdButtonBarCustom1 != null) {
wikEdButtonBarCustom1.style.display = 'none';
}
wikEdButtonBarFind.style.display = 'none';
wikEdButtonBarFix.style.display = 'none';
if (wikEdButtonBarCustom2 != null) {
wikEdButtonBarCustom2.style.display = 'none';
}
wikEdButtonBarControl.style.display = 'block';
}
return;
}
//
// WikEdButton: toggle or set button checked state
// used for buttons that do not require nor change the text. Faster than WikEdEditButton()
//
function WikEdButton(buttonObj, whichButton, toggleButton, setButton, classButton, doButton) {
if (buttonObj != null) {
// 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();
switch (whichButton) {
// switch between syntax highlighting and plain text
case 'wikEdHighlightSyntax':
var obj = {};
obj.html = wikEdFrameBody.innerHTML;
obj.html = obj.html.replace(/(<br\b*>)\n* */g, '$1');
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 />');
WikEdSetCookie('wikEdSyntaxOff', '', -1, '/');
}
else {
wikEdHighlightSyntax = false;
WikEdRemoveHighlighting(obj);
obj.html = obj.html.replace(/(\t)/g, '<span class="wikEdTabPlain">$1</span><!--wikEdTabPlain-->');
WikEdSetCookie('wikEdSyntaxOff', '1', 0, '/');
}
wikEdFrameBody.innerHTML = obj.html;
break;
// align textbox with display top
case 'wikEdScrollToPreview':
case 'wikEdScrollToPreview2':
case 'wikEdScrollToPreview3':
window.scroll(0, WikEdGetOffsetTop(wikEdSubmitWrapper));
break;
// align edit buttons with display top
case 'wikEdScrollToEdit':
case 'wikEdScrollToEdit2':
case 'wikEdScrollToEdit3':
case 'wikEdScrollToEdit4':
window.scroll(0, WikEdGetOffsetTop(wikEdInputWrapper));
break;
// cycle through different font sizes
case 'wikEdTextZoomDown':
wikEdTextZoom = wikEdTextZoom / 1.2;
if (wikEdTextZoom < 100 / 1.2 / 1.2) {
wikEdTextZoom = 100 * 1.2 * 1.2;
}
wikEdFrameBody.style.fontSize = parseInt(wikEdTextZoom) + '%;';
break;
// cycle through different font sizes
case 'wikEdTextZoomUp':
wikEdTextZoom = wikEdTextZoom * 1.2;
if (wikEdTextZoom > 100 * 1.2 * 1.2) {
wikEdTextZoom = 100 / 1.2 / 1.2;
}
wikEdFrameBody.style.fontSize = parseInt(wikEdTextZoom) + '%;';
break;
// display local preview box
case 'wikEdLocalPreview':
if (wikEdFullScreenMode == true) {
WikEdFullScreen(false);
}
if (wikEdUseWikEd == true) {
WikEdUpdateTextarea();
}
// scroll to edit or preview field
if (whichButton == 'wikEdLocalPreview') {
window.scroll(0, WikEdGetOffsetTop(wikEdInputWrapper));
}
else {
window.scroll(0, WikEdGetOffsetTop(wikEdSubmitWrapper));
}
// prepare a local preview (Pilaf's InstaView)
if ( (wikEdUseLocalPreview == true) && (typeof(InstaView) == 'object') ) {
InstaView.conf.user.name = wgUserName;
wikEdPreviewBox.innerHTML = InstaView.convert(wikEdTextarea.value);
wikEdLocalPrevWrapper.style.display = 'block';
}
// prepare ajax preview
if ( (wikEdUseAjaxPreview == true) && (typeof(sajax_init_object) == 'function') ) {
wikEdLocalPrevWrapper.style.display = 'block';
// prepare the data
var boundary = '--(fR*3briuStOum6#v)--';
var postData = document.getElementById('wpTextbox1').value;
postData = '--' + boundary + '\nContent-Disposition: form-data; name="wpTextbox1"\n\n' + postData + '\n--' + boundary;
// allow ajax request from local copy for testing
if (wikEdAllowLocalAjax == true) {
if (typeof(netscape) == 'object') {
if (typeof(netscape) == 'object') {
netscape.security.PrivilegeManager.enablePrivilege('UniversalBrowserRead');
}
}
}
// make the ajax request
var ajax = WikEdAjaxInitObject();
if (ajax == null) {
break;
}
ajax.open('POST', document.editform.action + '&live', true);
ajax.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
if (ajax.overrideMimeType != null) {
ajax.overrideMimeType('text/html');
}
ajax.send(postData);
// ajax response handler function
ajax.onreadystatechange = function() {
if (ajax.readyState != 4) {
return;
}
// get response
var html = ajax.responseText;
// html-ize
html = html.replace(/</g, '<');
html = html.replace(/>/g, '>');
html = html.replace(/&/g, '&');
html = html.replace(/"/g, '"')
html = html.replace(/'/g, '\'');
html = html.replace(/(<preview>)<h2>.*?<\/h2>(.|\n)*?<div class=\'previewnote\'>(.|\n)*?<\/div>/, '$1');
// update the preview
wikEdPreviewBox.innerHTML = html;
};
}
break;
// display local diff box
case 'wikEdDiffPreview':
case 'wikEdDiffPreview2':
case 'wikEdLocalDiff':
if (typeof(WDiffString) != 'function') {
break;
}
if (wikEdFullScreenMode == true) {
WikEdFullScreen(false);
}
if (wikEdUseWikEd == true) {
WikEdUpdateTextarea();
}
// scroll to edit or preview field
if (whichButton == 'wikEdLocalDiff') {
window.scroll(0, WikEdGetOffsetTop(wikEdInputWrapper));
}
else {
window.scroll(0, WikEdGetOffsetTop(wikEdSubmitWrapper));
}
// call external diff program
var diffText = WDiffString(wikEdOrigVersion, wikEdTextarea.value);
if (wikEdFullDiff != true) {
diffText = WDiffShortenOutput(diffText);
}
wikEdPreviewBox.innerHTML = diffText;
wikEdLocalPrevWrapper.style.display = 'block';
break;
// toggle wikEdDiff
case 'wikEdDiff':
// turn wikEdDiff off
if (buttonObj.checked != true) {
wikEdDiff = false;
WikEdSetCookie('wikEdDiff', '', -1, '/');
if (typeof(wikEdDiffDiv) == 'object') {
wikEdDiffDiv.style.display = 'none';
}
window.scroll(0, WikEdGetOffsetTop(wikEdInputWrapper));
}
// turn wikEdDiff on
else {
wikEdDiff = true;
WikEdSetCookie('wikEdDiff', '1', 0, '/');
if (typeof(wikEdDiffDiv) == 'object') {
wikEdDiffDiv.style.display = 'block';
window.scroll(0, WikEdGetOffsetTop(wikEdDiffDiv));
WikEdDiff();
}
}
break;
// close the preview / diff box
case 'wikEdClose':
case 'wikEdClose2':
window.scroll(0, WikEdGetOffsetTop(wikEdInputWrapper));
wikEdLocalPrevWrapper.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();
// turn rich text frame on
WikEdSetEditArea(true);
wikEdUseWikEd = true;
WikEdSetCookie('wikEdUseClassic', '', -1, '/');
}
// turn classic textarea on, disable wikEd
else {
WikEdUpdateTextarea();
WikEdSetEditArea(false);
wikEdUseWikEd = false;
WikEdSetCookie('wikEdUseClassic', '1', 0, '/');
}
break;
// add "using wikEd" to summaries
case 'wikEdUsing':
if (buttonObj.checked == true) {
wikEdUsing = true;
WikEdSetCookie('wikEdSummaryUsing', '1', 0, '/');
}
else {
wikEdUsing = false;
WikEdSetCookie('wikEdSummaryUsing', '', -1, '/');
}
break;
// hide ref tags
case 'wikEdRefHide':
if (buttonObj.checked == true) {
wikEdRefHide = true;
WikEdSetCookie('wikEdRefHide', '1', 0, '/');
}
else {
wikEdRefHide = false;
WikEdSetCookie('wikEdRefHide', '', -1, '/');
}
if (wikEdUseWikEd == true) {
WikEdEditButton(null, 'wikEdWikify', 'whole');
}
break;
// close the toolbar
case 'wikEdCloseToolbar':
if (buttonObj.checked == true) {
wikEdCloseToolbar = true;
if (document.getElementById('toolbar') != null) {
wikEdToolbarWrapper.style.display = 'none';
}
WikEdSetCookie('wikEdCloseToolbar', '1', 0, '/');
}
else {
wikEdCloseToolbar = false;
if (document.getElementById('toolbar') != null) {
wikEdToolbarWrapper.style.display = 'block';
}
WikEdSetCookie('wikEdCloseToolbar', '', -1, '/');
}
if (wikEdFullScreenMode == true) {
WikEdFullScreen(wikEdFullScreenMode);
}
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-you-type search button
case 'wikEdFindAhead':
break;
// switch to fullscreen edit area
case 'wikEdFullScreen':
if (buttonObj.checked == true) {
WikEdFullScreen(true);
WikEdSetCookie('wikEdFullscreen', '1', 0, '/');
}
else {
WikEdFullScreen(false);
WikEdSetCookie('wikEdFullscreen', '', -1, '/');
}
break;
// clear the cookies for find, replace, and summary history
case 'wikEdClearHistory':
WikEdClearHistory('find');
WikEdClearHistory('replace');
WikEdClearHistory('summary');
break;
// for testing
case 'wikEdPlaceholder':
break;
}
}
// reset the frame DOM cache because the frame content might have changed
wikEdFrameDOMCache = null;
// reset cursor to normal
if (buttonObj != null) {
buttonObj.style.cursor = 'pointer';
}
return;
}
//
// WikEdEditButton: editing functions
// used for buttons that require or change the text, more time consuming than WikEdButton()
//
function WikEdEditButton(buttonObj, whichButton, parameters, CustomHandler) {
// check if button is disabled
if (buttonObj != null) {
if (buttonObj.className == 'wikEdButtonInactive') {
return;
}
}
// remove active and non-text content
WikEdRemoveElements();
// select the appropriate text change targets (whole, selection, cursor, focusWord, focusLine, selectionWord, or selectionLine)
var obj = {};
obj.changed = {};
switch (whichButton) {
// undo, redo: whole
case 'wikEdUndo':
case 'wikEdRedo':
case 'wikEdUndoAll':
case 'wikEdRedoAll':
WikEdGetText(obj, 'whole');
obj.changed = obj.whole;
break;
// basic wiki character formatting: selection / focusWord / cursor
case 'wikEdBold':
case 'wikEdItalic':
case 'wikEdUnderline':
case 'wikEdStrikethrough':
case 'wikEdNowiki':
case 'wikEdSuperscript':
case 'wikEdSubscript':
case 'wikEdWikiLink':
case 'wikEdWebLink':
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
WikEdGetText(obj, 'focusWord');
if (obj.focusWord.plain != '') {
obj.changed = obj.focusWord;
}
else {
obj.changed = obj.cursor;
}
}
break;
// reference: selection / cursor
case 'wikEdRef':
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
obj.changed = obj.cursor;
}
break;
// references and small references: selection / cursor
case 'wikEdReferences':
case 'wikEdReferencesSection':
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
obj.changed = obj.cursor;
}
break;
// character formatting: selection / focusWord / cursor
case 'wikEdCase':
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
WikEdGetText(obj, 'focusWord');
if (obj.focusWord.plain != '') {
obj.changed = obj.focusWord;
}
else {
obj.changed = obj.cursor;
}
}
break;
// multiple line changes: selectionLine / focusLine / cursor
case 'wikEdDecreaseHeading':
case 'wikEdIncreaseHeading':
case 'wikEdIncreaseBulletList':
case 'wikEdDecreaseBulletList':
case 'wikEdIncreaseNumberList':
case 'wikEdDecreaseNumberList':
case 'wikEdIncreaseIndentList':
case 'wikEdDecreaseIndentList':
case 'wikEdDefinitionList':
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
WikEdGetText(obj, 'selectionLine');
obj.changed = obj.selectionLine;
}
else {
WikEdGetText(obj, 'focusLine');
if (obj.focusLine.plain != '') {
obj.changed = obj.focusLine;
}
else {
obj.changed = obj.cursor;
}
}
break;
// image: selectionWord (if text is selected) / cursor
case 'wikEdImage':
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
WikEdGetText(obj, 'selectionWord');
obj.changed = obj.selectionWord;
}
else {
obj.changed = obj.cursor;
}
break;
// table: selectionLine / cursor
case 'wikEdTable':
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
WikEdGetText(obj, 'selectionLine');
obj.changed = obj.selectionLine;
}
else {
WikEdGetText(obj, 'focusLine');
obj.changed = obj.cursor;
}
break;
// wikify: selection / whole
case 'wikEdWikify':
if (parameters == 'whole') {
WikEdGetText(obj, 'whole');
obj.changed = obj.whole;
}
else {
WikEdGetText(obj, 'selection');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
WikEdGetText(obj, 'whole');
obj.changed = obj.whole;
}
}
break;
// textify: selection / whole, without wikifying
case 'wikEdTextify':
WikEdGetText(obj, 'selection', true);
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
WikEdGetText(obj, 'whole', true);
obj.changed = obj.whole;
}
break;
// redirect: whole
case 'wikEdRedirect':
WikEdGetText(obj, 'whole, selection, cursor');
if (obj.selection.plain == '') {
WikEdGetText(obj, 'selectionWord');
}
obj.changed = obj.whole;
break;
// find and replace: selection / focusWord / cursor
case 'wikEdFindPrev':
case 'wikEdFindNext':
case 'wikEdJumpPrev':
case 'wikEdJumpNext':
case 'wikEdReplacePrev':
case 'wikEdReplaceNext':
case 'wikEdFindAll':
WikEdGetText(obj, 'selection');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
WikEdGetText(obj, 'focusWord');
if (obj.focusWord.plain != '') {
obj.changed = obj.focusWord;
}
else {
obj.changed = obj.cursor;
}
}
break;
// replace all: selection / whole
case 'wikEdReplaceAll':
WikEdGetText(obj, 'selection');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
WikEdGetText(obj, 'whole');
obj.changed = obj.whole;
}
break;
// fixing buttons: selection / whole
case 'wikEdFixBasic':
case 'wikEdfixUnicode':
case 'wikEdFixAll':
case 'wikEdFixHtml':
case 'wikEdFixRegExTypo':
WikEdGetText(obj, 'selection');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
WikEdGetText(obj, 'whole');
obj.changed = obj.whole
}
break;
// fixing buttons: selection / focusLine / cursor
case 'wikEdFixPunct':
case 'wikEdFixMath':
case 'wikEdFixUnits':
case 'wikEdFixDashes':
case 'wikEdFixCaps':
case 'wikEdFixChem':
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
WikEdGetText(obj, 'focusLine');
if (obj.focusLine.plain != '') {
obj.changed = obj.focusLine;
}
else {
obj.changed = obj.cursor;
}
}
break;
// fixing buttons: selection / focusWord / cursor
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
WikEdGetText(obj, 'focusWord');
if (obj.focusWord.plain != '') {
obj.changed = obj.focusWord;
}
else {
obj.changed = obj.cursor;
}
}
break;
// source: selection / whole
case 'wikEdSource':
WikEdGetText(obj, 'selection');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
WikEdGetText(obj, 'whole');
obj.changed = obj.whole;
}
break;
// insert tags: selection / focusWord / cursor
case 'wikEdInsertTags':
WikEdGetText(obj, 'selection, cursor');
if (obj.selection.plain != '') {
obj.changed = obj.selection;
}
else {
WikEdGetText(obj, 'focusWord');
if (obj.focusWord.plain != '') {
obj.changed = obj.focusWord;
}
else {
obj.changed = obj.selection;
}
}
break;
// custom edit functions have to call WikEdGetText() themselves
default:
WikEdGetText(obj, 'cursor');
obj.changed = obj.cursor;
break;
}
// 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;
obj.changed.keepSel = true;
break;
// redo
case 'wikEdRedo':
WikEdFrameExecCommand('redo');
obj.changed.range = obj.sel.getRangeAt(obj.sel.rangeCount - 1);
obj.changed.plain = null;
obj.changed.keepSel = true;
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');
}
obj.changed.plain = obj.changed.plain.replace(/\'{6,}/g, '\'\'\'\'\'');
obj.changed.keepSel = true;
break;
// italic
case 'wikEdItalic':
if ( /(\'{3,})\'\'(.*?)\'\'(\'{3,})/.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/(\'{3,})\'\'(.*?)\'\'(\'{3,})/g, '$1$2$3');
}
else if ( /(^|)\'\'(.*?)\'\'(|$)/.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/(^|)\'\'(.*?)\'\'(|$)/g, '$1$2$3');
}
else {
obj.changed.plain = '\'\'' + obj.changed.plain + '\'\'';
obj.changed.plain = obj.changed.plain.replace(/(\'\')( *)(.*?)( *)(\'\')/, '$2$1$3$5$4');
}
obj.changed.plain = obj.changed.plain.replace(/\'{6,}/g, '\'\'\'\'\'');
obj.changed.keepSel = true;
break;
// underline
case 'wikEdUnderline':
if ( /<u>(.*?)<\/u>/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/<u>(.*?)<\/u>/gi, '$1');
}
else {
obj.changed.plain = '<u>' + obj.changed.plain + '<\/u>';
obj.changed.plain = obj.changed.plain.replace(/(<u>)( *)(.*?)( *)(<\/u>)/, '$2$1$3$5$4');
}
obj.changed.keepSel = true;
break;
// strikethrough
case 'wikEdStrikethrough':
if ( /<s>(.*?)<\/s>/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/<s>(.*?)<\/s>/gi, '$1');
}
else {
obj.changed.plain = '<s>' + obj.changed.plain + '<\/s>';
obj.changed.plain = obj.changed.plain.replace(/(<s>)( *)(.*?)( *)(<\/s>)/, '$2$1$3$5$4');
}
obj.changed.keepSel = true;
break;
// nowiki
case 'wikEdNowiki':
if ( /<nowiki>(.*?)<\/nowiki>/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/<nowiki>(.*?)<\/nowiki>/gi, '$1');
}
else {
obj.changed.plain = '<nowiki>' + obj.changed.plain + '<\/nowiki>';
obj.changed.plain = obj.changed.plain.replace(/(<nowiki>)( *)(.*?)( *)(<\/nowiki>)/, '$2$1$3$5$4');
}
obj.changed.keepSel = true;
break;
// superscript
case 'wikEdSuperscript':
if ( /<sup>(.*?)<\/sup>/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/<sup>(.*?)<\/sup>/gi, '$1');
}
else {
obj.changed.plain = '<sup>' + obj.changed.plain + '</sup>';
obj.changed.plain = obj.changed.plain.replace(/(<sup>)( *)(.*?)( *)(<\/sup>)/, '$2$1$3$5$4');
}
obj.changed.keepSel = true;
break;
// subscript
case 'wikEdSubscript':
if ( /<sub>(.*?)<\/sub>/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/<sub>(.*?)<\/sub>/gi, '$1');
}
else {
obj.changed.plain = '<sub>' + obj.changed.plain + '</sub>';
obj.changed.plain = obj.changed.plain.replace(/(<sub>)( *)(.*?)( *)(<\/sub>)/, '$2$1$3$5$4');
}
obj.changed.keepSel = true;
break;
// in-text reference
case 'wikEdRef':
if (obj.changed.plain == '') {
obj.changed.plain = '<ref name=\"\"/>';
}
else if ( /<ref name=\"\" ?\/>/i.test(obj.changed.plain) ) {
obj.changed.plain = '';
}
else if ( /<ref( name=\"\")?>(.*?)<\/ref>/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/<ref( name=\"\")?>(.*?)<\/ref>/gi, '$2');
}
else {
obj.changed.plain = '<ref name=\"\">' + obj.changed.plain + '</ref>';
obj.changed.plain = obj.changed.plain.replace(/(<ref name=\"\">)( *)(.*?)( *)(<\/ref>)/, '$2$1$3$5$4');
}
obj.changed.keepSel = true;
break;
// references location
case 'wikEdReferences':
case 'wikEdReferencesSection':
var ref = wikEdText;
ref = ref.replace(/</g, '<');
ref = ref.replace(/>/g, '>');
var refEscaped = ref;
refEscaped = refEscaped.replace(/()/g, '\\$1');
refEscaped = refEscaped.replace(/^\n|\n$/g, '\\n*');
refEscaped = refEscaped.replace(/(\n)/g, '\\n');
var regExp = new RegExp(refEscaped, 'gi');
// plain references tag
if (whichButton == 'wikEdReferences') {
if (obj.changed.plain == '') {
obj.changed.plain = '<references/>';
}
else if (regExp.test(obj.changed.plain)) {
obj.changed.plain = obj.changed.plain.replace(regExp, '');
}
else if ( /<references ?\/>/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/<references ?\/>/gi, '');
}
else {
obj.changed = obj.cursor;
obj.changed.plain = '<references/>';
}
}
// complete references code
else {
if (obj.changed.plain == '') {
obj.changed.plain = ref;
}
else if (regExp.test(obj.changed.plain)) {
obj.changed.plain = obj.changed.plain.replace(regExp, '');
}
else if ( /<references ?\/>/i.test(obj.changed.plain) ) {
obj.changed.plain = obj.changed.plain.replace(/<references ?\/>/gi, '');
}
else {
obj.changed = obj.cursor;
obj.changed.plain = ref;
}
}
obj.changed.keepSel = true;
break;
// toggle lowercase / uppercase
case 'wikEdCase':
// lowercase all uppercased text
if (obj.changed.plain == '') {
obj.changed.plain = null;
}
else {
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()(*)/g,
function (p, p1, p2) {
return(p1.toUpperCase() + p2.toLowerCase());
}
);
}
// uppercase mixed upper and lowercased text
else {
obj.changed.plain = obj.changed.plain.toUpperCase();
}
}
obj.changed.keepSel = true;
break;
// undo all
case 'wikEdUndoAll':
if (wikEdLastVersion == null) {
wikEdLastVersion = obj.changed.plain;
}
obj.changed.plain = wikEdOrigVersion;
obj.changed.plain = obj.changed.plain.replace(/&/g, '&');
obj.changed.plain = obj.changed.plain.replace(/>/g, '>');
obj.changed.plain = obj.changed.plain.replace(/</g, '<');
break;
// redo all
case 'wikEdRedoAll':
if (wikEdLastVersion != null) {
obj.changed.plain = wikEdLastVersion;
}
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.replace(/(\\])/, '$2$1$3$5$4');
}
obj.changed.keepSel = true;
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.replace(/(\)/, '$2$1$3$5$4');
}
obj.changed.keepSel = true;
break;
// decrease heading level
case 'wikEdDecreaseHeading':
// decrease heading
obj.changed.plain = obj.changed.plain.replace(/(^|\n)=(=+) *(*?) *=+(?=\n|$)/g, '$1$2 $3 $2');
// remove heading
obj.changed.plain = obj.changed.plain.replace(/(^|\n)=(?!=) *(*?) *=+(?=\n|$)/g, '$1$2');
// adjust closing tags
obj.changed.plain = obj.changed.plain.replace(/(^|\n)(=+) *(*?) *=+(?=\n|$)/g, '$1$2 $3 $2');
obj.changed.keepSel = true;
break;
// increase heading level
case 'wikEdIncreaseHeading':
// increase heading
obj.changed.plain = obj.changed.plain.replace(/(^|\n)(=+) *(*?) *=+(?=\n|$)/g, '$1=$2 $3 $2=');
// create new heading
if (/\n/.test(obj.changed.plain) == false) {
obj.changed.plain = obj.changed.plain.replace(/(^|\n)(*?)(?=\n|$)/g, '$1== $2 ==');
}
// adjust closing tags
obj.changed.plain = obj.changed.plain.replace(/(^|\n)(=+) *(*?) *=+(?=\n|$)/g, '$1$2 $3 $2');
obj.changed.keepSel = true;
break;
// increase bullet list
case 'wikEdIncreaseBulletList':
obj.changed.plain = obj.changed.plain.replace(/(+)/g,
function (p, p1) {
p1 = p1.replace(/^ *(*) */g, '*$1 ');
return(p1);
}
);
obj.changed.keepSel = true;
break;
// decrease bullet list
case 'wikEdDecreaseBulletList':
obj.changed.plain = obj.changed.plain.replace(/(+)/g,
function (p, p1) {
p1 = p1.replace(/^\* */g, '');
return(p1);
}
);
obj.changed.keepSel = true;
break;
// increase numbered list
case 'wikEdIncreaseNumberList':
obj.changed.plain = obj.changed.plain.replace(/(+)/g,
function (p, p1) {
p1 = p1.replace(/^ *(*) */g, '#$1 ');
return(p1);
}
);
obj.changed.keepSel = true;
break;
// decrease numbered list
case 'wikEdDecreaseNumberList':
obj.changed.plain = obj.changed.plain.replace(/(+)/g,
function (p, p1) {
p1 = p1.replace(/^\# */g, '');
return(p1);
}
);
obj.changed.keepSel = true;
break;
// increase indented list
case 'wikEdIncreaseIndentList':
obj.changed.plain = obj.changed.plain.replace(/(+)/g,
function (p, p1) {
p1 = p1.replace(/^ *(*) */g, ':$1 ');
return(p1);
}
);
obj.changed.keepSel = true;
break;
// decrease indented list
case 'wikEdDecreaseIndentList':
obj.changed.plain = obj.changed.plain.replace(/(+)/g,
function (p, p1) {
p1 = p1.replace(/^\# */g, '');
return(p1);
}
);
obj.changed.keepSel = true;
break;
// create definition list
case 'wikEdDefinitionList':
obj.changed.plain = obj.changed.plain.replace(/(+)/g,
function (p, p1) {
p1 = p1.replace(/^ *(+) */g, '; $1 : ');
return(p1);
}
);
break;
// create image
case 'wikEdImage':
if (obj.changed.plain != '') {
obj.changed.plain = ' + '</span>|thumb|<span class="wikEdInsertHere">' + wikEdText + '</span>px|' + obj.changed.plain + ']]';
}
else {
obj.changed.plain = ' + '</span>|thumb|<span class="wikEdInsertHere">' + wikEdText + '</span>px|<span class="wikEdInsertHere"> </span>]]';
if (obj.focusWord != null) {
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{| class="wikitable"\n');
obj.changed.plain = obj.changed.plain.replace(/$/g, '\n|}\n');
}
else {
obj.changed.plain = '\n{| class="wikitable"\n|+ <span class="wikEdInsertHere">' + wikEdText + '</span>\n! <span class="wikEdinserthere">' + wikEdText + '</span> !! <span class="wikEdInsertHere">' + wikEdText + '</span>\n|-\n| <span class="wikEdInsertHere">' + wikEdText + '</span> || <span class="wikEdInsertHere">' + wikEdText + '</span>\n|-\n| <span class="wikEdInsertHere">' + wikEdText + '</span> || <span class="wikEdInsertHere">' + wikEdText + '</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':
WikEdTextify(obj.changed);
break;
// redirect
case 'wikEdRedirect':
var linkTarget;
if (obj.selection.plain != '') {
linkTarget = obj.selection.plain;
}
else if (obj.selectionWord.plain != '') {
linkTarget = obj.selectionWord.plain;
}
else {
linkTarget = '<span class="wikEdInsertHere">' + wikEdText + '</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 ]';
// append to summary
if ( (obj.selection.plain != '') || (obj.selectionWord.plain != '') ) {
wikEdInputElement.value = wikEdInputElement.value.replace(/#redirect( \]*\]\])?(, *)?/g, '');
wikEdInputElement.value = WikEdAppendToSummary(wikEdInputElement.value, '#redirect ]');
}
else {
wikEdInputElement.value = WikEdAppendToSummary(wikEdInputElement.value, '#redirect');
}
selectChange = false;
break;
// find and replace
case 'wikEdFindPrev':
case 'wikEdFindNext':
case 'wikEdJumpPrev':
case 'wikEdJumpNext':
case 'wikEdReplacePrev':
case 'wikEdReplaceNext':
case 'wikEdFindAll':
case 'wikEdReplaceAll':
// get the find text
var findText;
// unescape <, >, and &
obj.changed.plain = obj.changed.plain.replace(/</g, '<');
obj.changed.plain = obj.changed.plain.replace(/>/g, '>');
obj.changed.plain = obj.changed.plain.replace(/&/g, '&');
// copy selection/word under cursor to find field
if ( (parameters == 'shift') && ( (whichButton == 'wikEdFindNext') || (whichButton == 'wikEdReplaceNext') ) ) {
if (/\n/.test(obj.changed.plain) == false) {
if (whichButton == 'wikEdFindNext') {
wikEdInputElement.value = obj.changed.plain;
}
else {
wikEdInputElement.value = obj.changed.plain;
}
obj.changed.keepSel = true;
obj.changed.plain = null;
break;
}
}
// get the find text from the find field
if ( (whichButton == 'wikEdJumpPrev') || (whichButton == 'wikEdJumpNext') ) {
findText = obj.changed.plain;
if (obj.selection.plain == '') {
obj.changed.keepSel = true;
obj.changed.plain = null;
break;
}
}
// get the find text from the find field
else {
if (wikEdInputElement.value != '') {
findText = wikEdInputElement.value;
}
else {
obj.changed.plain = null;
break;
}
}
// handle newlines and special blanks for built-in search
if (wikEdRegExp.checked == false) {
findText = findText.replace(/\n/g, '');
findText = findText.replace(/\s/g, ' ');
}
// get the replace text
var replaceText = wikEdInputElement.value;
var regExpFind;
// set regexp flags
var regExpFlags = 'g';
if (wikEdCaseSensitive.checked == false) {
regExpFlags += 'i';
}
// format the find and replace texts for a plain text search
if ( (wikEdRegExp.checked == false) || (whichButton == 'wikEdJumpPrev') || (whichButton == 'wikEdJumpNext') ) {
regExpFind = new RegExp(findText.replace(/(\{\}\:\=\!\|\,\-])/g, '\\$1'), regExpFlags);
}
// format the find and replace texts for a regular expression search
else {
regExpFind = new RegExp(findText, regExpFlags);
replaceText = replaceText.replace(/((^|)(\\\\)*)\\n/g, '$1\n');
}
// 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;
}
}
// replace an existing selection
else if ( (whichButton == 'wikEdReplacePrev') || (whichButton == 'wikEdReplaceNext') ) {
if (regExpFind.test(obj.selection.plain)) {
var replaced = obj.selection.plain.replace(regExpFind, replaceText);
if (obj.changed.plain != replaced) {
obj.changed.plain = replaced;
replacedFlag = true;
}
else {
obj.changed.plain = null;
}
}
else {
obj.changed.plain = null;
}
}
else if (
(whichButton == 'wikEdFindNext') || (whichButton == 'wikEdFindPrev') ||
(whichButton == 'wikEdJumpNext') || (whichButton == 'wikEdJumpPrev')
) {
obj.changed.plain = null;
}
if (
(whichButton == 'wikEdFindNext') || (whichButton == 'wikEdFindPrev') ||
(whichButton == 'wikEdJumpNext') || (whichButton == 'wikEdJumpPrev') ||
(whichButton == 'wikEdReplaceNext') || (whichButton == 'wikEdReplacePrev') ||
(whichButton == 'wikEdFindAll')
) {
if (replacedFlag == false) {
// get direction
var backwards = false;
if ( (whichButton == 'wikEdFindPrev') || (whichButton == 'wikEdJumpPrev') || (whichButton == 'wikEdReplacePrev') ) {
backwards = true;
}
// get case sensitive
var caseSensitive = false;
if (wikEdCaseSensitive.checked == true) {
caseSensitive = true;
}
// find all
if (whichButton == 'wikEdFindAll') {
var found;
var foundRanges = ;
// start at top of text
obj.sel.removeAllRanges();
var range = document.createRange();
range.setStartBefore(wikEdFrameBody.firstChild);
range.collapse(true);
range = obj.sel.addRange(range);
// cycle through matches
var scrollTop = wikEdFrameBody.scrollTop;
do {
// use regexp seach
if (wikEdRegExp.checked == true) {
found = WikEdFind(obj, findText, caseSensitive, false, false, regExpFind);
}
// use built-in sarch
else {
found = WikEdFind(obj, findText, caseSensitive, false, false, null);
}
if (found == true) {
foundRanges.push(obj.changed.range.cloneRange());
}
} while (found == true);
// scroll back
if (wikEdRegExp.checked == false) {
wikEdFrameBody.scrollTop = scrollTop;
}
// add the found ranges
obj.sel.removeAllRanges();
for (range in foundRanges) {
obj.sel.addRange(foundRanges);
}
obj.changed.plain = null;
}
// normal find
else {
if (wikEdRegExp.checked) {
WikEdFind(obj, findText, caseSensitive, backwards, true, regExpFind);
}
else {
WikEdFind(obj, findText, caseSensitive, backwards, true, null);
selectChange = false;
}
}
}
}
// escape <, >, and &
if (obj.changed.plain != null) {
obj.changed.plain = obj.changed.plain.replace(/&/g, '&');
obj.changed.plain = obj.changed.plain.replace(/</g, '<');
obj.changed.plain = obj.changed.plain.replace(/>/g, '>');
}
// save search history to cookie
if ( (whichButton == 'wikEdFindPrev') || (whichButton == 'wikEdFindNext') || (whichButton == 'wikEdFindAll') ) {
WikEdAddToHistory('find');
}
if ( (whichButton == 'wikEdReplacePrev') || (whichButton == 'wikEdReplaceNext') || (whichButton == 'wikEdReplaceAll') ) {
WikEdAddToHistory('find');
WikEdAddToHistory('replace');
}
obj.changed.keepSel = true;
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);
obj.changed.keepSel = true;
break;
case 'wikEdFixPunct':
WikEdFixPunct(obj.changed);
obj.changed.keepSel = true;
break;
case 'wikEdFixMath':
WikEdFixMath(obj.changed);
obj.changed.keepSel = true;
break;
case 'wikEdFixChem':
WikEdFixChem(obj.changed);
obj.changed.keepSel = true;
break;
case 'wikEdfixUnicode':
WikEdFixUnicode(obj.changed);
obj.changed.keepSel = true;
break;
case 'wikEdFixUnits':
WikEdFixUnits(obj.changed);
obj.changed.keepSel = true;
break;
case 'wikEdFixDashes':
WikEdFixDashes(obj.changed);
obj.changed.keepSel = true;
break;
case 'wikEdFixHtml':
WikEdFixHTML(obj.changed);
obj.changed.keepSel = true;
break;
case 'wikEdFixRegExTypo':
if (typeof(AWRegExTypoFix) == 'function') {
var objFix = {}
objFix.str = obj.changed.plain;
AWRegExTypoFix(objFix);
obj.changed.plain = objFix.str;
}
else {
obj.changed.plain = null;
}
obj.changed.keepSel = true;
break;
case 'wikEdFixCaps':
WikEdFixCaps(obj.changed);
obj.changed.keepSel = true;
break;
case 'wikEdFixAll':
WikEdFixAll(obj.changed);
obj.changed.keepSel = true;
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, '&');
obj.changed.plain = obj.changed.plain.replace(/</g, '<');
obj.changed.plain = obj.changed.plain.replace(/>/g, '>');
highlightSyntax = false;
break;
// insert tags
case 'wikEdInsertTags':
var tagOpen = parameters || '';
var tagClose = parameters || '';
var sampleText = parameters || '';
tagOpen = tagOpen.replace(/&/g, '&');
tagOpen = tagOpen.replace(/</g, '<');
tagOpen = tagOpen.replace(/>/g, '>');
tagClose = tagClose.replace(/&/g, '&');
tagClose = tagClose.replace(/</g, '<');
tagClose = tagClose.replace(/>/g, '>');
tagsampleText = sampleText.replace(/&/g, '&');
tagsampleText = sampleText.replace(/</g, '<');
tagsampleText = sampleText.replace(/>/g, '>');
// single string to insert
if ( (tagOpen.length > 0) && (tagClose.length == 0) && (sampleText.length == 0) ) {
obj.changed = obj.cursor;
obj.changed.plain = tagOpen;
}
// opening and closing strings
else if ( (obj.changed.plain == '') && (sampleText.length > 0) ) {
obj.changed.plain = tagOpen + sampleText + tagClose;
}
else {
obj.changed.plain = tagOpen + obj.changed.plain + tagClose;
}
break;
// custom edit functions
default:
if (CustomHandler != null) {
CustomHandler(obj);
}
else {
alert('Unknown edit function \'' + whichButton + '\'');
}
break;
}
// update the selection only, do not change the text
if (obj.changed.plain == null) {
if (whichButton != 'wikEdFindAll') {
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) {
plainText = plainText.replace(/\n/g, '');
obj.changed.range.collapse(false);
// parameters: 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, '<span class="wikEdTabPlain">$1</span><!--wikEdTabPlain-->');
}
// display multiple blanks as blank-
obj.html = obj.html.replace(/ /g, ' ');
obj.html = obj.html.replace(/ /g, ' ');
// 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 scrollTop;
if (obj.changed.from == 'whole') {
scrollTop = 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') {
obj.sel.removeAllRanges();
wikEdFrameBody.scrollTop = scrollTop;
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) {
plainText = plainText.replace(/\n/g, '');
// parameters: window.find(string, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog)
wikEdFrameWindow.find(plainText, true, true, false, false, false, false);
}
}
}
// remove selection, keep whole text auto-selection as warning
if (
( (obj.changed.keepSel != true) && (obj.changed.from != 'whole') ) ||
(whichButton == 'wikEdRedirect') ||
( (whichButton == 'wikEdWikify') && (parameters == 'whole') )
) {
// workaround for Firefox 1.5 bug using: obj.sel.getRangeAt(obj.sel.rangeCount - 1).collapse(false);
var range = document.createRange();
range.setStart(obj.sel.focusNode, obj.sel.focusOffset);
range.collapse(true);
obj.sel.removeAllRanges();
obj.sel.addRange(range);
}
// 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();
// reset the frame DOM cache because the frame content has been changed
wikEdFrameDOMCache = null;
// focus the frame
if (wikEdUseWikEd == true) {
wikEdFrameWindow.focus();
}
// add event handler to make highlighted frame links ctrl-clickable
if ( (highlightSyntax == true) && (obj.changed.plain != null) ) {
WikEdFollowLinks();
}
return;
}
//
// WikEdFollowLinks: add event handler to make highlighted frame links ctrl-clickable
//
function WikEdFollowLinks() {
if (wikEdFollowLinks == true) {
var spanArray = wikEdFrameBody.getElementsByTagName('span');
for (var i = 0; i < spanArray.length; i ++) {
if (spanArray.onclick != null) {
var onClickCode = spanArray.onclick.toString();
var linkMatch = onClickCode.match(/\svar linkName *= *(.*)/);
if (linkMatch != null) {
spanArray.title = linkMatch + ' ' + wikEdText;
}
spanArray.addEventListener('click', WikEdFollowLinkHandler, true);
}
}
}
return;
}
//
// WikEdGetText: get the text fragments to manipulate
//
function WikEdGetText(obj, whichFragment, noWikify) {
// get selection object
if (obj.sel == null) {
obj.sel = wikEdFrameWindow.getSelection();
}
// cursor for the cursor position (always done)
if (obj.cursor == null) {
obj.cursor = {};
obj.cursor.from = 'cursor';
obj.cursor.keepSel = false;
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 = '';
}
// whole for the whole text
if (obj.whole == null) {
if (/whole|selectionWord|selectionLine|focusWord|focusLine/.test(whichFragment) == true) {
obj.whole = {};
obj.whole.plainArray = ;
obj.whole.plainNode = ;
obj.whole.plainStart = ;
obj.whole.from = 'whole';
obj.whole.keepSel = false;
// set 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, noWikify);
obj.whole.plain = obj.whole.html;
obj.whole.plain = obj.whole.plain.replace(/<br\b*>*/g, '\n');
obj.whole.plain = obj.whole.plain.replace(/\u00a0/g, ' ');
}
}
// selection for the selected text
if (obj.selection == null) {
if (/selection\b|selectionWord|selectionLine/.test(whichFragment) == true) {
obj.selection = {};
obj.selection.from = 'selection';
obj.selection.keepSel = false;
// copy range to document fragment
obj.selection.range = obj.sel.getRangeAt(obj.sel.rangeCount - 1);
var documentFragment = obj.selection.range.cloneContents();
// get selected text
WikEdGetInnerHTML(obj.selection, documentFragment);
obj.selection.code = obj.selection.html;
WikEdRemoveHighlightingWikify(obj.selection, noWikify);
obj.selection.plain = obj.selection.html;
obj.selection.plain = obj.selection.plain.replace(/<br\b*>*/g, '\n');
obj.selection.plain = obj.selection.plain.replace(/\u00a0/g, ' ');
}
}
// focusWord and focusLine for the complete words and lines under the cursor
if (obj.focusWord == null) {
if (/focusWord|focusLine/.test(whichFragment) == true) {
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.keepSel = false;
obj.focusLine.range = document.createRange();
// find the word and line boundaries
WikEdFindBoundaries(obj.focusWord, obj.focusLine, obj.whole, obj.cursor);
// 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, noWikify);
obj.focusWord.plain = obj.focusWord.html;
obj.focusWord.plain = obj.focusWord.plain.replace(/<br\b*>*/g, '\n');
obj.focusWord.plain = obj.focusWord.plain.replace(/\u00a0/g, ' ');
// 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, noWikify);
obj.focusLine.plain = obj.focusLine.html;
obj.focusLine.plain = obj.focusLine.plain.replace(/<br\b*>*/g, '\n');
obj.focusLine.plain = obj.focusLine.plain.replace(/\u00a0/g, ' ');
}
}
// selectionWord and selectionLine for the complete words and lines under the selection
if (obj.selectionWord == null) {
if (/selectionWord|selectionLine/.test(whichFragment) == true) {
// setup selectionWord object for the words under the selection
obj.selectionWord = {};
obj.selectionWord.from = 'selectionWord';
obj.selectionWord.keepSel = false;
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 word and line boundaries
WikEdFindBoundaries(obj.selectionWord, obj.selectionLine, obj.whole, obj.selection);
// 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, noWikify);
obj.selectionWord.plain = obj.selectionWord.html;
obj.selectionWord.plain = obj.selectionWord.plain.replace(/<br\b*>*/g, '\n');
obj.selectionWord.plain = obj.selectionWord.plain.replace(/\u00a0/g, ' ');
// 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, noWikify);
obj.selectionLine.plain = obj.selectionLine.html;
obj.selectionLine.plain = obj.selectionLine.plain.replace(/<br\b*>*/g, '\n');
obj.selectionLine.plain = obj.selectionLine.plain.replace(/\u00a0/g, ' ');
}
}
return;
}
//
// WikEdFind: custom find function with regexp properties, sets obj.changed.range, uses obj ranges
//
function WikEdFind(obj, findText, caseSensitive, backwards, wrap, regExp) {
var range = obj.sel.getRangeAt(obj.sel.rangeCount - 1);
var found = false;
// 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) {
// parameters: window.find(string, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog)
found = wikEdFrameWindow.find(findText, caseSensitive, backwards, wrap, false, true, false);
if (found == true) {
range = obj.sel.getRangeAt(obj.sel.rangeCount - 1);
}
obj.changed.range = range.cloneRange();
}
// slow javascript regexp find and replace
else {
// perform find
if (obj.plainArray === undefined) {
WikEdParseDOM(obj, wikEdFrameBody);
}
var regExpMatch = ;
// find next, search to the right
if (backwards == false) {
// set start position for search to right
regExpMatch = regExp.exec(obj.plain);
regExp.lastIndex = obj.plainFocus;
// execute the regexp search to the right
regExpMatch = regExp.exec(obj.plain);
// remember position for repeated searches
obj.plainFocus = regExp.lastIndex;
// wrap around, start at beginning
if ( (wrap == true) && (regExpMatch == null) ) {
regExp.lastIndex = 0;
regExpMatch = regExp.exec(obj.plain);
}
}
// 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);
// wrap around, find last occurrence
if ( (wrap == true) && (regExpMatch == null) ) {
do {
regExpMatch = regExpMatchNext;
regExpMatchNext = regExp.exec(obj.plain);
} while (regExpMatchNext != null);
}
}
// select the find
if (regExpMatch != null) {
found = true;
var i = 0;
while ( (obj.plainStart <= regExpMatch.index) && (obj.plainStart != null) ) {
i ++;
}
var j = i;
while ( (obj.plainStart <= regExpMatch.index + regExpMatch.length) && (obj.plainStart != null) ) {
j ++;
}
obj.changed.range.setEnd (obj.plainNode, regExpMatch.index + regExpMatch.length - obj.plainStart);
obj.changed.range.setStart(obj.plainNode, regExpMatch.index - obj.plainStart);
}
}
return(found);
}
//
// WikEdTextify: strip html off of text
//
function WikEdTextify(obj) {
// convert html to plain
obj.plain = obj.html;
obj.plain = obj.plain.replace(/\n/g, ' ');
// delete tags
obj.plain = obj.plain.replace(/<(style|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|hr|isindex|p|pre)\b*>/g, '\u0000\u0000');
// keep headings only if starting with a newline
obj.html = obj.html.replace(/*(^|\n|\u0000)*<h\b*>(.*?)<\/h>*/g, '\u0000\u0000$2\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 spaces
obj.plain = obj.plain.replace(/+(\u0000)/g, '$1');
obj.plain = obj.plain.replace(/(\u0000)+/g, '$1');
// trim down \u0000 and \n
obj.plain = obj.plain.replace(/\u0000{3,}/g, '\n\n');
obj.plain = obj.plain.replace(/\u0000/g, '\n');
// remove empty lines and spaces from article start and end
if (obj.from == 'whole') {
obj.html = obj.html.replace(/^\s+|\s+$/g, '');
}
return;
}
//
// WikEdInactiveButtons: grey out inactive buttons, called after every change and click
//
function WikEdInactiveButtons() {
// undo
if (wikEdFrameDocument.queryCommandEnabled('undo') == true ) {
document.getElementById('wikEdUndo').className = 'wikEdButton';
document.getElementById('wikEdUndoAll').className = 'wikEdButton';
}
else {
document.getElementById('wikEdUndo').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';
}
return;
}
//
// WikEdFixBasic: fix characters, spaces, empty lines, certain headings, needed for all fixing functions
//
/// change: double spaces ok after dot
function WikEdFixBasic(obj) {
// non-breaking space character to normal space
obj.plain = obj.plain.replace(/(\u00a0)/g, ' ');
// remove trailing spaces
obj.plain = obj.plain.replace(/( | )+\n/g, '\n');
// remove spaces in empty lines
obj.plain = obj.plain.replace(/\n( | |\t)+\n/g, '\n\n');
// empty line before and after headings, spaces around word (lookahead)
obj.plain = obj.plain.replace(/\n+(=+) *(*?) *(=+)(?=\n)\n*/g, '\n\n$1 $2 $3\n\n');
// uppercase well known headings
var regExp = new RegExp('\\n=+ ' + wikEdText + '? =+\\n', 'gi');
obj.plain = obj.plain.replace(regExp, '\n== ' + wikEdText + ' ==\n');
regExp = new RegExp('\\n=+ ' + wikEdText + ' =+\\n', 'gi');
obj.plain = obj.plain.replace(regExp, '\n== ' + wikEdText + ' ==\n');
regExp = new RegExp('\\n=+ ' + wikEdText + '? =+\\n', 'gi');
obj.plain = obj.plain.replace(regExp, '\n== ' + wikEdText + ' ==\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\|\}(|$)) *(*)+/g, '$1\n\n$3\n\n');
// empty line before and after lists
obj.plain = obj.plain.replace(/(^|\n)(*)(?=\n)/g, '$1$2\n\n');
obj.plain = obj.plain.replace(/(^|\n)(*?)(?=\n)/g, '$1$2\n\n');
// 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;
// do not change lines starting with a blank
if (/^ /.test(line) == false) {
// 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
var regExp = new RegExp('^(\\ + ':.*?\\]\\])', 'ig');
line = line.replace(regExp, '\n$1');
regExp = new RegExp('(\\ + ':.*?(\\\\].*?)*\\]\\])$', 'ig');
line = line.replace(regExp, '$1\n');
// empty line before and after includes
line = line.replace(/^(\{\{.*?\}\})/g, '\n$1');
line = line.replace(/(\{\{.*?\}\})$/g, '$1\n');
}
}
// concatenate the lines
obj.plain += line;
if (i < lines.length - 1) {
obj.plain += '\n';
}
}
// remove underscores in wikilinks
obj.plain = obj.plain.replace(/\\]/g,
function (p, p1, p2) {
p1 = p1.replace(/_/g, ' ');
return(']');
}
);
// remove spaces in wikilinks
obj.plain = obj.plain.replace(/\*?) *\]\]/g, ']');
// remove spaces in external links
obj.plain = obj.plain.replace(/\*?) *\]/g, '');
// 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+(\{\{.*?\}\})/g, '\n$1$2');
// spaces in comments
obj.plain = obj.plain.replace(/(<!--) *(*?) *(-->)/g, '$1 $2 $3');
// empty line before and after categories
var regExp = new RegExp('( |\\n)*(\\ + ':*?\\]\\])( |\\n)*', 'gi');
obj.plain = obj.plain.replace(regExp, '\n\n$2\n\n');
// categories not separated by empty lines (lookahead)
regExp = new RegExp('(\\*?\\]\\])\\n*(?=\\ + ':*?\\]\\])', 'gi');
obj.plain = obj.plain.replace(regExp, '$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;
}
//
// WikEdFixPunct: remove space before .,:;
//
function WikEdFixPunct(obj) {
WikEdFixBasic(obj);
obj.plain = obj.plain.replace(/(\}\)]) +()(\s+|$)/g, '$1$2 ');
obj.plain = obj.plain.replace(/\s+$/g, '');
return;
}
//
// WikEdFixUnicode: fix unicode character representations
//
function WikEdFixUnicode(obj) {
// replace supported chars: change decimal, hex, and character entities into actual char
for (var i = 0; i < wikEdSupportedChars.length; i ++) {
var replaceChar = String.fromCharCode(parseInt(wikEdSupportedChars, 16));
// decimal representation
var regExpStr = '�*' + parseInt(wikEdSupportedChars, 16) + ';|';
// hex representation
regExpStr += '�*' + wikEdSupportedChars + ';';
// case insensitive replace
var regExp = new RegExp(regExpStr, 'gi');
obj.plain = obj.plain.replace(regExp, replaceChar);
// character entity representation
regExpStr = '&' + wikEdSupportedChars + ';';
// case sensitive replace
regExp = new RegExp(regExpStr, 'g');
obj.plain = obj.plain.replace(regExp, replaceChar);
}
// replace unsupported chars in IE6: change decimal, hex, and chars into character entities
for (var i = 0; i < wikEdProblemChars.length; i ++) {
replaceChar = '&' + wikEdProblemChars + ';';
// decimal representation
regExpStr = '�*' + parseInt(wikEdProblemChars, 16) + ';|';
// hex representation
regExpStr += '�*' + wikEdProblemChars + ';';
// case insensitive replace
regExp = new RegExp(regExpStr, 'gi');
obj.plain = obj.plain.replace(regExp, replaceChar);
// actual character representation
regExpStr = '\\u' + wikEdProblemChars;
// 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 (var i = 0; i < wikEdSpecialChars.length; i ++) {
var replaceChar = '&' + wikEdSpecialChars + ';';
// decimal representation
var regExpStr = '�*' + parseInt(wikEdSpecialChars, 16) + ';|';
// hex representation
regExpStr += '�*' + wikEdSpecialChars + ';';
// case insensitive replace
var regExp = new RegExp(regExpStr, 'gi');
obj.plain = obj.plain.replace(regExp, replaceChar);
// actual character representation
regExpStr = '\\u' + wikEdSpecialChars;
// 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;
}
//
// WikEdFixMath: math character fixer, originally from User:Omegatron
//
function WikEdFixMath(obj) {
WikEdFixBasic(obj);
// change only outside <math> </math> wikicode
obj.plain = obj.plain.replace(/(.*?)((<math(\b.*?)>.*?<\/math>)|$)/gi,
function (p, p1, p2) {
// convert html entities into actual dash characters
p1 = p1.replace(/+/g, '+');
p1 = p1.replace(/−/g, '\u2212');
p1 = p1.replace(/·/g, '·');
// convert dash next to a number into a minus sign character
p1 = p1.replace(/()-(\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<sup>$2</sup>');
// change x^3 to x<sup>3</sup>
p1 = p1.replace(/()\^(\u2212?\d+\.?\d*) /g, '$1<sup>$2</sup>');
// change +/- to ±
p1 = p1.replace(/( |\d)\+\/(-|\u2212)( |\d)/g, '$1\u00b1$3');
// htmlize single char superscripts
p1 = p1.replace(/(\u00b9|¹)/g, '<sup>1</sup>');
p1 = p1.replace(/(\u00b2|²)/g, '<sup>2</sup>');
p1 = p1.replace(/(\u00b3|³)/g, '<sup>3</sup>');
return(p1 + p2);
}
);
return;
}
//
// WikEdFixChem: fix chemical formulas
//
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(/(^|)h2o(|$)/g, '$1H2O$2');
obj.plain = obj.plain.replace(/(^|)h3o+/g, '$1H3O+');
obj.plain = obj.plain.replace(/(^|)oh-/g, '$1OH+');
// uppercase lowercased elements
var regExp = new RegExp('(^|)(' + realElements.toLowerCase() + pseudoElements.toLowerCase() + ')(|$)', '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(/+/g, '+');
obj.plain = obj.plain.replace(/−/g, '\u2212');
obj.plain = obj.plain.replace(/·/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 + '<sup>' + p2 + '</sup>');
}
);
// fix indices
regExp = new RegExp('(' + realElements + pseudoElements + '|\\))(\\d+)', 'g');
obj.plain = obj.plain.replace(regExp, '$1<sub>$2</sub>');
// fix prefixes
regExp = new RegExp('(\\d+) *(\\(|' + realElements + pseudoElements + ')', 'g');
obj.plain = obj.plain.replace(regExp, '$1$2');
// fix arrows
obj.plain = obj.plain.replace(/ *-+> */g, ' \u2192 ');
obj.plain = obj.plain.replace(/ *<-+ */g, ' \u2190 ');
// &hdarr; and "leftwards harpoon over rightwards harpoon" not supported in IE6
// obj.plain = obj.plain.replace(/ *(<=+>|&hdarr;|↔|\u2190 *\u2192) */g, ' \u21cc ');
obj.plain = obj.plain.replace(/ *(<==+>|&hdarr;|↔|\u21cc|\u2190 *\u2192) */g, ' <=> ');
// fix -
obj.plain = obj.plain.replace(/(|\)|>) +(-|\u2212) +(|\()/g, '$1 \u2212 $3');
return;
}
//
// WikEdFixUnits: unit formatter
//
function WikEdFixUnits(obj) {
WikEdFixBasic(obj);
// convert into actual characters
obj.plain = obj.plain.replace(/&deg;|&#00b0;/g, '°');
obj.plain = obj.plain.replace(/&#00b5;|&mu;|&micro;/g, 'µ');
obj.plain = obj.plain.replace(/&Omega;|&#8486;/g, '\u03a9');
// add space before units, remove space around /, and use abreviations
obj.plain = obj.plain.replace(/( *\/ *|\d *)(Y|yotta|Z|zetta|E|exa|P|peta|T|tera|G|giga|M|mega|k|kilo|K|h|hecto|da|deca|d|deci|c|centi|m|mill?i|micro|u|µ|n|nano|p|pico|f|femto|a|atto|z|zepto|y|yocto|mibi|mebi|)(gramm?s?|g|metres?|meters?|m|amperes?|Amperes?|amps?|Amps?|A|Angstroms?|Angströms?|Å|Kelvins?|kelvins?|K|moles?|Moles?|mol|candelas?|cd|rad|Ci|sr|Hert?z|hert?z|Hz|newtons?|Newtons?|N|Joules?|joules?|J|watts?|Watts?|W|pascals?|Pascals?|Pa|lm|lx|C|volts?|Volts?|V|O|Farads?|F|Wb|T|H|S|bequerels?|Bequerels?|Bq|Gy|Sv|kat|centigrades?|°C|decibels?|db|dB|M|ohms?|Ohms?|\u03a9|sec|seconds?|s|minutes?|min|hour?|h|bits?|Bits?|bit|bytes?|Bytes?|B|bps|Bps)(?=|$)/g,
function (p, p1, p2, p3) {
p1 = p1.replace(/ *\/ */g, '/');
p1 = p1.replace(/(\d) */g, '$1 ');
p2 = p2.replace(/yotta/g, 'Y');
p2 = p2.replace(/zetta/g, 'Z');
p2 = p2.replace(/exa/g, 'E');
p2 = p2.replace(/peta/g, 'P');
p2 = p2.replace(/tera/g, 'T');
p2 = p2.replace(/giga/g, 'G');
p2 = p2.replace(/mega/g, 'M');
p2 = p2.replace(/kilo/g, 'k');
p2 = p2.replace(/K/g, 'k');
p2 = p2.replace(/hecto/g, 'h');
p2 = p2.replace(/deca/g, 'da');
p2 = p2.replace(/deci/g, 'd');
p2 = p2.replace(/centi/g, 'c');
p2 = p2.replace(/mill?i/g, 'm');
p2 = p2.replace(/micro|u/g, 'µ');
p2 = p2.replace(/nano/g, 'n');
p2 = p2.replace(/pico/g, 'p');
p2 = p2.replace(/femto/g, 'f');
p2 = p2.replace(/atto/g, 'a');
p2 = p2.replace(/zepto/g, 'z');
p2 = p2.replace(/yocto/g, 'y');
p2 = p2.replace(/mibi/g, 'mebi');
p3 = p3.replace(/gramm?s?/g, 'g');
p3 = p3.replace(/metres?|meters?/g, 'm');
p3 = p3.replace(/amperes?|Amperes?|amps?|Amps?/g, 'A');
p3 = p3.replace(/Angstroms?|Angströms?/g, 'Å');
p3 = p3.replace(/Kelvins?|kelvins?/g, 'K');
p3 = p3.replace(/moles?|Moles?/g, 'mol');
p3 = p3.replace(/candelas?/g, 'cd');
p3 = p3.replace(/Hert?z|hert?z/g, 'Hz');
p3 = p3.replace(/newtons?|Newtons?/g, 'N');
p3 = p3.replace(/Joules?|joules?/g, 'J');
p3 = p3.replace(/watts?|Watts?/g, 'W');
p3 = p3.replace(/pascals?|Pascals?/g, 'Pa');
p3 = p3.replace(/volts?|Volts?/g, 'V');
p3 = p3.replace(/ohms?|Ohms?/g, '\u03a9');
p3 = p3.replace(/bequerels?|Bequerels?/g, 'Bq');
p3 = p3.replace(/Farads?/g, 'F');
p3 = p3.replace(/bits?|Bits?/g, 'bit');
p3 = p3.replace(/bytes?|Bytes?/g, 'B');
p3 = p3.replace(/sec|seconds?/g, 's');
p3 = p3.replace(/minutes?/g, 'min');
p3 = p3.replace(/hours?/g, 'h');
p3 = p3.replace(/sec|seconds?/g, 's');
p3 = p3.replace(/bps/g, 'bit/s');
p3 = p3.replace(/Bps/g, 'B/s');
return(p1 + p2 + p3);
}
);
// fix prefix casing
obj.plain = obj.plain.replace(/ K(bit\/s|B\/s)(|$)/g, ' k$1$2');
obj.plain = obj.plain.replace(/ m(bit\/s|B\/s)(|$)/g, ' M$1$2');
obj.plain = obj.plain.replace(/ g(bit\/s|B\/s)(|$)/g, ' G$1$2');
obj.plain = obj.plain.replace(/ t(bit\/s|B\/s)(|$)/g, ' T$1$2');
obj.plain = obj.plain.replace(/ e(bit\/s|B\/s)(|$)/g, ' E$1$2');
return;
}
//
// WikEdFixDashes: dash fixer - fixes several obvious en/em dash, minus sign, and such special characters.
// originally from User:Omegatron
//
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(/(\}\)]) *(--|—|&mdash;) *()/g, '$1 — $3');
// convert - or en dashes with spaces to em dash character surrounded by spaces
obj.plain = obj.plain.replace(/(\}])( |&nbsp;)+(\u2212|–|&ndash;) +()/g, '$1$2— $4');
// convert hyphen next to lone number into a minus sign character
obj.plain = obj.plain.replace(/(\>] )-(\d)/g, '$1\u2212$2');
// convert dashes to en dashes in dates
obj.plain = obj.plain.replace(/(\d\d\d) ?(--?|—|&mdash;) ?(\d\d\d|\d\d)()/g, '$1–$3$4');
return;
}
//
// WikEdFixHTML: fix html to wikicode
//
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(/<(\/?\w.*?)>/g, '<$1>');
// wikify, keep user added attribute
WikEdWikifyHTML(obj, true);
// turn real html into visible html code
obj.html = obj.html.replace(/<br\b*>*/g, '\n');
obj.html = obj.html.replace(/</g, '<');
obj.html = obj.html.replace(/>/g, '>');
obj.plain = obj.html;
return;
}
//
// WikEdFixCaps: fix capitalizing of lists, linklists, images, headings
//
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+\;|<*?>|\{\{.*?\}\}*|\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(/^(+ \*?)(\]\])/gm,
function (p, p1, p2, p3) {
// uppercase link
p2 = p2.replace(/^((\&\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+\;|<*?>||\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+\;|<*?>|\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
regExp = new RegExp('(\\ + ':()(*\\]\\])', 'igm');
obj.plain = obj.plain.replace(regExp,
function (p, p1, p2, p3) {
return(p1 + wikEdText + ':' + p2.toUpperCase() + p3);
}
);
return;
}
//
// WikEdFixAll:
//
function WikEdFixAll(obj) {
WikEdFixBasic(obj);
WikEdFixUnicode(obj);
WikEdFixHTML(obj);
WikEdFixCaps(obj);
return;
}
//
// WikEdRemoveElements: remove elements by tag name
//
function WikEdRemoveElements(tagNameArray) {
// cycle through the element names
for (var property in tagNameArray) {
if ((tagNameArray) != 'string') {
continue;
}
var elementArray = wikEdFrameDocument.getElementsByTagName(tagNameArray);
for (var i = 0; i < elementArray.length; i ++) {
elementArray.parentNode.removeChild(elementArray);
}
}
return;
}
//
// WikEdFindBoundaries: find word boundaries and line boundaries starting from selection.range
//
function WikEdFindBoundaries(word, line, whole, selection) {
// 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 = 0;
}
if (endNode.nodeType == 1) {
endNode = endNode.childNodes;
endNodeOffset = 0;
}
// find the start and end nodes in the whole plain text arrays
var startNodeIndex;
var endNodeIndex;
for (var i = 0; i < whole.plainNode.length; i ++) {
if (startNode == whole.plainNode) {
startNodeIndex = i;
}
if (endNode == whole.plainNode) {
endNodeIndex = i;
break;
}
}
// find last previous word and line boundary
var foundWord = false;
var foundLine = false;
var regExp = new RegExp('.*', 'g');
var plain = '';
// check text nodes left-wise for a boundary
for (var i = startNodeIndex; i >= 0; i --) {
plain = whole.plainArray;
plain = plain.replace(/&/g, '&');
plain = plain.replace(/</g, '<');
plain = plain.replace(/>/g, '>');
// boundary is a newline
if (plain == '\n') {
// current newline is the start node
if (i == startNodeIndex) {
if (! foundWord) {
word.range.setStartBefore(whole.plainNode);
foundWord = true;
}
line.range.setStartBefore(whole.plainNode);
}
else {
if (! foundWord) {
word.range.setStartAfter(whole.plainNode);
foundWord = true;
}
line.range.setStartAfter(whole.plainNode);
}
foundLine = true;
break;
}
// check text node for a word boundary
else if (! foundWord) {
if (i == startNodeIndex) {
plain = plain.substr(0, startNodeOffset);
plain = plain.replace(/&/g, '&');
plain = plain.replace(/</g, '<');
plain = plain.replace(/>/g, '>');
}
regExp.lastIndex = 0;
if (regExp.exec(plain) != null) {
word.range.setStart(whole.plainNode, regExp.lastIndex);
foundWord = true;
}
}
}
// boundary is start of text
if (! foundLine) {
line.range.setStartBefore(whole.plainNode);
if (! foundWord) {
word.range.setStartBefore(whole.plainNode);
}
}
// find next word and line boundary
regExp = new RegExp('', 'g');
foundWord = false;
foundLine = false;
// check text nodes right-wise for a boundary
for (var i = endNodeIndex; i < whole.plainArray.length; i ++) {
plain = whole.plainArray;
plain = plain.replace(/&/g, '&');
plain = plain.replace(/</g, '<');
plain = plain.replace(/>/g, '>');
// boundary is a newline
if (plain == '\n') {
if (! foundWord) {
word.range.setEndBefore(whole.plainNode);
foundWord = true;
}
line.range.setEndBefore(whole.plainNode);
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, regExpArray.index);
foundWord = true;
}
}
}
// boundary is end of text
if (! foundLine) {
line.range.setEndAfter(whole.plainNode);
if (! foundWord) {
word.range.setEndAfter(whole.plainNode);
}
}
return;
}
//
// remove syntax highlighting and wikify
//
function WikEdRemoveHighlightingWikify(obj, noWikify) {
if (obj.html != '') {
// remove syntax highlighting
WikEdRemoveHighlighting(obj);
// wikify, don't allow many attributes
if ( (obj.htmlCode == true) && (noWikify != true) ) {
WikEdWikifyHTML(obj, false);
}
}
return;
}
//
// WikEdWikifyHTML:
// obj.html contains the text to be wikified
// expects < > < > & spaces instead of <br> (not \n)
// returns <br> (not \n)
/*
allowed and converted tags:
br|p
h1|h2|h3|h4|h5|h6
hr
i|dfn|cite|em|var
b|strong
table|caption|col|thead|tfoot|tbody|tr|td|th
dl|dt|dd|li|ol|ul
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, relaxed) {
var regExpStr;
var regExp;
var regExpMatch;
// delete tags: <style>
obj.html = obj.html.replace(/<(style)\b*>.*?<\/\1>/g, '');
// remove MediaWiki section edit spans
obj.html = obj.html.replace(/<span*class=\"editsection\"*>.*?<\/span>\s*/g, '');
// remove MediaWiki heading spans
obj.html = obj.html.replace(/<span\b*\bclass=\"mw-headline\"*>(.*?)<\/span>\s*/g, '$1');
// remove MediaWiki divs from article top
obj.html = obj.html.replace(/<h3\b*\bid=\"siteSub\"*>.*?<\/h3>\s*/g, '');
obj.html = obj.html.replace(/<div\b*\bid=\"contentSub\"*>.*?<\/div>\s*/g, '');
obj.html = obj.html.replace(/<div\b*\bid=\"jump-to-nav\"*>.*?<\/div>\s*/g, '');
// remove MediaWiki table of contents
obj.html = obj.html.replace(/<table\b*?\bid=\"toc\"*>.*?<\/table>\s*/g, '');
// remove MediaWiki print footer
obj.html = obj.html.replace(/<div\b*?\bclass=\"printfooter\"*>+\"<a\b*>+<\/a>\"<\/div>\s*/g, '');
// remove MediaWiki category list tags
regExp = /<div\b*\bid=\"catlinks\"*>(.*?)<\/div>\s*/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');
}
// convert MS-Word non-standard lists: *
obj.html = obj.html.replace(/\s*<p *>\s*<!--\-->.*?<!--\-->\s*(.*?)\s*<\/p>\s*/g, '* $1\n');
// sanitize <span> <div> <p>
obj.html = obj.html.replace(/<(span|div|p)\b *(.*?) *\/?>/g,
function (p, p1, p2) {
return('<' + p1 + WikEdSanitizeAttributes(p1, p2, relaxed) + '>');
}
);
// 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('\u0000\u0000');
}
isRemove.push(false);
return(p1);
}
if (isRemove.pop() == true) {
return('\u0000\u0000');
}
return(p1);
}
);
// escape character entities
obj.html = obj.html.replace(/&(?!(amp;|lt;|gt;))/g, '&');
// remove comments
obj.html = obj.html.replace(/<!--.*?-->/g, '');
// <hr> horizontal rule
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*<hr\b*>(\s|<br\b*>|\u0000)*/i, '\u0000\u0000----\u0000\u0000');
// <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(/(\s|<br\b*>|\u0000)*(^|\n|<br\b*>|\u0000)(\s|<br\b*>|\u0000)*<h1\b*>(.*?)<\/h1>(\s|<br\b*>|\u0000)*/g, '\u0000\u0000= $4 =\u0000\u0000');
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*(^|\n|<br\b*>|\u0000)(\s|<br\b*>|\u0000)*<h2\b*>(.*?)<\/h2>(\s|<br\b*>|\u0000)*/g, '\u0000\u0000== $4 ==\u0000\u0000');
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*(^|\n|<br\b*>|\u0000)(\s|<br\b*>|\u0000)*<h3\b*>(.*?)<\/h3>(\s|<br\b*>|\u0000)*/g, '\u0000\u0000=== $4 ===\u0000\u0000');
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*(^|\n|<br\b*>|\u0000)(\s|<br\b*>|\u0000)*<h4\b*>(.*?)<\/h4>(\s|<br\b*>|\u0000)*/g, '\u0000\u0000==== $4 ====\u0000\u0000');
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*(^|\n|<br\b*>|\u0000)(\s|<br\b*>|\u0000)*<h5\b*>(.*?)<\/h5>(\s|<br\b*>|\u0000)*/g, '\u0000\u0000===== $4 =====\u0000\u0000');
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*(^|\n|<br\b*>|\u0000)(\s|<br\b*>|\u0000)*<h6\b*>(.*?)<\/h6>(\s|<br\b*>|\u0000)*/g, '\u0000\u0000====== $4 ======\u0000\u0000');
obj.html = obj.html.replace(/<(h)\b*>(.*?)<\/\1>/g, '$2');
// remove <thead> <tbody> <tfoot>
obj.html = obj.html.replace(/(\s|\u0000|<br\b*>)<\/?(thead|tbody|tfoot)\b*>(\s|\u0000|<br\b*>)*/g, '$1');
// remove <col></col> and <colgroup></colgroup>\s
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*<(col)\b*>.*?<\/\2>(|<br\b*>|\u0000)*/g, '');
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*<(colgroup)\b*>.*?<\/\2>(|<br\b*>|\u0000)*/g, '');
// line breaks in table cells
obj.html = obj.html.replace(/(<(td|th|caption)\b*>)(.*?)(<\/\2>)/g,
function(p, p1, p2, p3, p4) {
p3 = p3.replace(/^(\s|<br\b*|\u0000>)+/g, '');
p3 = p3.replace(/(\s|<br\b*|\u0000>)+$/g, '');
p3 = p3.replace(/<br\b*> */g, '<br />');
return(p1 + p3 + p4);
}
);
// remove table closing tags
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*<\/(tr|thead|tbody|tfoot)>(\s|<br\b*>|\u0000)*/g, '');
// <td> table cells
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*<td>(\s|<br\b*>|\u0000)*/g, '\u0000| ');
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*<(td) +(*)>(\s|<br\b*>|\u0000)*/g,
function (p, p1, p2, p3, p4) {
p3 = WikEdSanitizeAttributes(p2, p3, relaxed);
if (p3 == '') {
return('\u0000| ');
}
else {
return('\u0000|' + p3 + ' | ');
}
}
);
// <th> table cells
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*<th>(\s|<br\b*>|\u0000)*/g, '\u0000| ');
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*<(th) +(*)>(\s|<br\b*>|\u0000)*/g,
function (p, p1, p2, p3, p4) {
p3 = WikEdSanitizeAttributes(p2, p3, relaxed);
if (p3 == '') {
return('\u0000| ');
}
else {
return('\u0000|' + p3 + ' | ');
}
}
);
// <tr> table rows
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*<tr>(\s|<br\b*>|\u0000)*/g, '\u0000|-\u0000');
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*<(tr) +(*)>(\s|<br\b*>|\u0000)*/g,
function (p, p1, p2, p3, p4) {
return('\u0000|-' + WikEdSanitizeAttributes(p2, p3, relaxed) + '\u0000');
}
);
// <caption> table caption
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*<caption>(\s|<br\b*>|\u0000)*/g, '\u0000|+ ');
obj.html = obj.html.replace(/(\s|<br\b*>|\u0000)*<(caption) +(*)>(\s|<br\b*>|\u0000)*/g,
function (p, p1, p2, p3, p4) {
p3 = WikEdSanitizeAttributes(p2, p3, relaxed);
if (p3 == '') {
return('\u0000|+ ');
}
else {
return('\u0000|+' + p3 + ' | ');
}
}
);
// remove closing tags
obj.html = obj.html.replace(/\s*<\/(td|th|caption)>\s*/g, '');
// line breaks, also in table cells (continued)
obj.html = obj.html.replace(/<br\b*>*/g, '\u0000');
// <table>
obj.html = obj.html.replace(/*<table>*(\|-(?=))?/g, '\u0000\u0000{|\u0000');
obj.html = obj.html.replace(/*<(table) +(*)>*(\|-(?=))?/g,
function (p, p1, p2) {
return('\u0000{|' + WikEdSanitizeAttributes(p1, p2));
}
);
obj.html = obj.html.replace(/*<\/table>*/g, '\u0000|}\u0000\u0000');
// 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 pathArticle = '';
var linkTitle = '';
var urlPar = '';
var imgWidth = '';
var paramLink = false;
// check if it is a wiki article link, get path article name and url parameters
regExpStr = ' href=\\"(' + wikEdServer + '|\\.|(\\.\\.\/)*\\.\\.)(' + wikEdArticlePath + '(+)|' + wikEdScriptPath + 'index\\.php)(\\?(*))?(\\"|#)';
regExp = new RegExp(regExpStr);
regExpMatch = regExp.exec(linkPar);
if (regExpMatch != null) {
urlPar = regExpMatch;
if (regExpMatch != null) {
pathArticle = regExpMatch;
}
// check for links with special parameters, not title, action=edit, isbn
regExp = new RegExp('(\\?|&)(\\w+)=(+)', 'g');
while ( (regExpMatch = regExp.exec(linkPar)) != null) {
if ( (regExpMatch != 'title') && (regExpMatch != 'isbn') && ( (regExpMatch != 'action') || (regExpMatch != 'edit') ) ) {
paramLink = true;
break;
}
}
}
// get article name from path: /article
if (paramLink != true) {
if (pathArticle != '') {
linkArticle = pathArticle;
linkArticle = linkArticle.replace(/_/g, ' ');
linkArticle = decodeURIComponent(linkArticle);
}
// get article name from title="" html parameter
else {
regExpMatch = / title=\"(+)\"/.exec(linkPar);
if (regExpMatch != null) {
linkArticle = regExpMatch;
}
// get article name from title= url parameter
else if (urlPar != '') {
regExpMatch = /(^|&)title=(+)/.exec(urlPar);
if (regExpMatch != null) {
linkArticle = regExpMatch;
linkArticle = linkArticle.replace(/_/g, ' ');
linkArticle = decodeURIComponent(linkArticle);
// ISBN links
regExpMatch = /(^|&)isbn=(\\d+)/.exec(urlPar);
if (regExpMatch != null) {
var isbn = regExpMatch;
regExpMatch = /((\d\-?){13}|(\d\-?){10})/.exec(linkText);
if (regExpMatch != null) {
isbn = regExpMatch;
}
return('ISBN ' + isbn);
}
}
}
}
}
// 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;
imgWidth = '|' + imgWidth + 'px';
if ( (linkTitle != '') && (linkTitle != 'Enlarge') ) {
linkTitle = '|' + linkTitle;
return(']');
}
else {
return(']');
}
}
// category link
var regExp = new RegExp('^' + wikEdText + ':(.*)','i');
regExpMatch = regExp.exec(linkArticle);
if (regExpMatch != null) {
return(' + ':' + regExpMatch.substr(0, 1).toUpperCase() + linkText.substr(1) + ']]');
}
// wiki link
if (linkArticle == linkText.substr(0, 1).toUpperCase() + linkText.substr(1)) {
return(']');
}
// 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;
var day = regExpMatch;
if (linkText == (day + ' ' + month) ) {
return(']');
}
}
// 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)/g, '\\$1') + '(+)$';
regExp = new RegExp(regExpStr);
regExpMatch = regExp.exec(linkText);
if (regExpMatch != null) {
return(']' + regExpMatch);
}
return(']');
}
// external link
regExpMatch = linkPar.match(/ href=\"(*)\"/);
if (regExpMatch != null) {
var linkAddr = regExpMatch;
if (linkAddr != '') {
// PubMed link
regExpMatch = /^http:\/\/www\.ncbi\.nlm\.nih\.gov\/entrez\/query\.fcgi\?cmd=Retrieve&db=pubmed&.*?&list_uids=(\d+)/.exec(linkAddr);
if (regExpMatch != null) {
return('PMID ' + regExpMatch);
}
// DOI link
regExpMatch = /^http:\/\/dx\.doi\.org\/(.*)/.exec(linkAddr);
if (regExpMatch != null) {
return('{{doi|' + regExpMatch + '}}');
}
// other external link
return('');
}
}
// return unchanged text
return(p1);
}
);
// clean up MediaWiki category list
var regExp = new RegExp('<span\\b*>(\\ + ':]+\\]\\])<\\/span>*', 'gi');
obj.html = obj.html.replace(regExp, '$1\u0000');
// clean up DOI
obj.html = obj.html.replace(/\\]:(\{\{doi\|+\}\})/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.replace(/^ +| +$/g, '');
}
var imgAlt = '';
regExpMatch = /\balt\s*=\s*(\'|\")(*)(\'|\")/i.exec(p1);
if (regExpMatch != null) {
imgAlt = regExpMatch.replace(/^ +| +$/g, '');
imgAlt = imgAlt.replace(/&nbsp;|/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.replace(/^ +| +$/g, '') + 'px';
}
var imgLink = '';
regExpMatch = /(+)$/.exec(address);
if (regExpMatch != null) {
imgLink = regExpMatch;
if (imgLink != '') {
return(' + ':' + 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\u0000');
case 'li':
case 'dd':
return('\u0000' + listObj.prefix + ' ');
case 'dt':
return('\u0000' + listObj.prefix.replace(/:$/, ';') + ' ');
case '/li':
case '/dt':
case '/dd':
return('');
}
return('');
}
);
obj.html = obj.html.replace(/++ (?=)/g, '');
// <> 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('');
}
}
);
// 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, relaxed) + p3 + '>');
}
);
// unformat italic or bold blanks
obj.html = obj.html.replace(/\'\'\'(+)\'\'\'/g, '$1');
obj.html = obj.html.replace(/\'\'(+)\'\'/g, '$1');
// remove space-only lines
obj.html = obj.html.replace(/(*\u0000*)/g,
function (p, p1) {
return(p1.replace(/\n/g, '\u0000'));
}
);
obj.html = obj.html.replace(/\u0000\s+/g, '\u0000');
obj.html = obj.html.replace(/\s+(?=\u0000)/g, '\u0000');
// remove trailing linebreaks from table cells
obj.html = obj.html.replace(/\u0000{2,}(\|)/g, '\u0000$1');
// remove leading and trailing spaces
obj.html = obj.html.replace(/>\s+\u0000/g, '>\u0000');
obj.html = obj.html.replace(/\u0000\s+</g, '\u0000<');
// 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, '$1');
obj.html = obj.html.replace(/*<(blockquote|center|div|math|gallery|noinclude|includeonly|ref|references)\b*><\/\1>*/g, '\u0000\u0000');
// remove empty lines from div tags
obj.html = obj.html.replace(/(<div\b*>)+/g, '$1');
obj.html = obj.html.replace(/+(<\/div>)/g, '$1');
// escape < >
obj.html = obj.html.replace(/</g, '<');
obj.html = obj.html.replace(/>/g, '>');
// newlines to <br />
obj.html = obj.html.replace(/\n{2,}\u0000+\n/g, '\n\n');
obj.html = obj.html.replace(/\n\u0000+\n{2,}/g, '\n\n');
obj.html = obj.html.replace(/\u0000+\n{2,}/g, '\n\n');
obj.html = obj.html.replace(/\n{2,}\u0000+/g, '\n\n');
obj.html = obj.html.replace(/\u0000+\n/g, '\n');
obj.html = obj.html.replace(/\n\u0000+/g, '\n');
obj.html = obj.html.replace(/\u0000{2,}/g, '\n\n');
obj.html = obj.html.replace(/\u0000/g, '\n');
obj.html = obj.html.replace(/\n/g, '<br />');
// remove empty lines from article start and end
if (obj.from == 'whole') {
obj.html = obj.html.replace(/^(<br\b*>)+/g, '');
obj.html = obj.html.replace(/(<br\b*>)+$/g, '');
}
return;
}
//
// WikEdSanitizeAttributes: see Sanitizer.php
//
function WikEdSanitizeAttributes(tag, attributes, relaxed) {
var common;
var tablealign;
var tablecell;
var table;
if (relaxed == true) {
common = 'dir|style|class'; // not needed: lang|id|title
tablealign = '|align|char|charoff|valign';
table = '|summary|width|border|frame|rules|cellspacing|cellpadding|align|bgcolor';
tablecell = '|abbr|axis|headers|scope|rowspan|colspan|nowrap|width|height|bgcolor';
}
else {
common = 'dir';
table = '|border|cellspacing|cellpadding|align|bgcolor';
tablealign = '|align|valign';
tablecell = '|rowspan|colspan|nowrap|bgcolor';
}
tag = tag.toLowerCase();
var sanitized = '';
var regExp = /(\w+)\s*=\s*((\'|\")(.*?)\3|(\w+))/g;
var regExpMatch;
while ( (regExpMatch = regExp.exec(attributes)) != null) {
var attrib = regExpMatch;
var attribValue = regExpMatch || regExpMatch;
if (attribValue == '') {
continue;
}
var valid = false;
// relaxed, for existing text tags
if (relaxed == true) {
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 + table).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) {
}
else if ('gallery'.indexOf(tag) >= 0) {
if ((common + '|perrow|widths|heights').indexOf(attrib) >= 0) { valid = true; }
}
}
// strict, for html code to be wikified from external sources (websites, Word)
else {
if ('center|em|strong|cite|code|var|sub|supdl|dd|dt|tt|b|i|big|small|strike|s|u|rb|rp|ruby|blockquote|pre|ins|del'.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 ('br'.indexOf(tag) >= 0) {
if ('clear'.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 + table).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' + 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 + '|color').indexOf(attrib) >= 0) { valid = true; }
}
else if ('hr'.indexOf(tag) >= 0) {
if ((common + '|noshade|size').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) {
}
else if ('gallery'.indexOf(tag) >= 0) {
}
}
// clean up
if (valid == true) {
// clean up defaults for align
if (attrib == 'align') {
if ('tr|td|th'.indexOf(tag) >= 0) {
if (attribValue == 'left') {
attribValue = '';
}
}
}
// clean up defaults for valign
else if (attrib == 'valign') {
if ('tr|td|th'.indexOf(tag) >= 0) {
if (attribValue == 'top') {
attribValue = '';
}
}
}
// clean up style
else if (attrib == 'style') {
// remove non-standard Mozilla styles
attribValue = attribValue.replace(/(^| )(-moz-+): +; */g, '$1');
attribValue = attribValue.replace(/(^| )(+): *(-moz-+|windowtext)*; */g, '$1');
// remove dimensions from null values
attribValue = attribValue.replace(/\b0(%|in|cm|mm|em|ex|pt|pc|px)\b/g, '0');
// remove empty definitions and spaces
attribValue = attribValue.replace(/+ *\: *\; */g, '');
attribValue = attribValue.replace(/ *(;|:) */g, '$1 ');
attribValue = attribValue.replace(/( |;)+$/g, ';');
}
// clean up class
else if (attrib == 'class') {
// remove MS Word classes
attribValue = attribValue.replace(/^Ms.*$/g, '');
}
if (attribValue != '') {
sanitized += ' ' + attrib + '="' + attribValue + '"';
}
}
}
return(sanitized);
}
//
//
// WikEdRemoveHighlighting: remove syntax highlighting in obj.html; sets obj.htmlCode if text contains html code
// expects <br /> instead of \n
function WikEdRemoveHighlighting(obj) {
// 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 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, '');
// newlines
obj.html = obj.html.replace(/+/g, ' ');
// non-breaking spaces
obj.html = obj.html.replace(/ /g, '\u00a0');
// check for pasted html content
if (obj.html.match(/<(?!br\b)/)) {
obj.htmlCode = true;
}
else {
obj.htmlCode = false;
}
return;
}
//
// WikEdHighlightSyntax: highlight syntax in obj.html; if singleLine is set, no block syntax will be highlighted; call WikEdRemoveHighlighting first
// expects < > < > & \u00a0 instead of \n instead of <br />
function WikEdHighlightSyntax(obj, singleLine) {
// < and > to \u0000 and \u0001
obj.html = obj.html.replace(/</g, '\u0000');
obj.html = obj.html.replace(/>/g, '\u0001');
// #redirect
obj.html = obj.html.replace(/(^|\n)(#)(redirect\b)/g, '$1<span class="wikEdWikiRedir">$3</span><!--wikEdWikiRedir-->');
// nowiki (no html highlighting)
obj.html = obj.html.replace(/(\u0000nowiki\b.*?\u0001)(.*?)(\u0000\/nowiki\b.*?\u0001)/gi,
function (p, p1, p2, p3) {
p2 = p2.replace(/\u0000/g, '<');
p2 = p2.replace(/\u0001/g, '>');
return(p1 + p2 + p3);
}
);
// blocks
// lists * # : ;
obj.html = obj.html.replace(/^((\u0000!--.*?--\u0001)*)(+)(.*?)$/gm, '<span class="wikEdListLine">$1<span class="wikEdListTag">$3</span><!--wikEdListTag-->$4</span><!--wikEdListLine-->');
if (singleLine != true) {
obj.html = obj.html.replace(/((<span class=\"wikEdListLine\">*\n)+)/g, '<span class="wikEdListBlock">$1');
obj.html = obj.html.replace(/(<span class=\"wikEdListLine\">*)(\n)(?!<span class=\"wikEdListLine\">)/g, '$1</span><!--wikEdListBlock-->$2');
}
// #redirect (finish)
obj.html = obj.html.replace(/(<span class=\"wikEdWikiRedir\">)(.*?<\/span><!--wikEdWikiRedir-->)/g, '$1#$2');
// various blocks
if (singleLine != true) {
obj.html = obj.html.replace(/(\u0000(blockquote|center|div|pre|timeline|imagemap)\b*\u0001.*?\u0000\/\2\u0001)/gi, '<span class="wikEdBlock">$1</span><!--wikEdBlock-->');
}
// space-pre
if (singleLine != true) {
obj.html = obj.html.replace(/^((\u0000!--.*?--\u0001)*)(*)(.*?)$/gm, '<span class="wikEdSpaceLine">$1<span class="wikEdSpaceTag"> $3</span><!--wikEdSpaceTag-->$4</span><!--wikEdSpaceLine-->');
obj.html = obj.html.replace(/((<span class=\"wikEdSpaceLine\">*\n)+)/g, '<span class="wikEdSpaceBlock">$1');
obj.html = obj.html.replace(/(<span class=\"wikEdSpaceLine\">*)(\n)(?!<span class="wikEdSpaceLine">)/g, '$1</span><!--wikEdSpaceBlock-->$2');
}
// ---- <hr> horizontal rule
obj.html = obj.html.replace(/(^|\n)((\u0000!--.*?--\u0001|<*>)*)(----)((\u0000!--.*?--\u0001|<*>)*)(\n|$)/g, '$1<span class="wikEdHR">$2$4</span><!--wikEdHR-->$5$7');
obj.html = obj.html.replace(/(\u0000hr\u0001)/g, '<span class="wikEdHRInline">$1</span><!--wikEdHRInline-->');
// == headings
obj.html = obj.html.replace(/(^|\n)((\u0000!--.*?--\u0001|<*>)*)(=+*)(*?)(*=+)(?=(|<*>|\u0000!--.*?--\u0001)*(\n|$))/g,
function (p, p1, p2, p3, p4, p5, p6) {
p4 = p4.replace(/(=+)/g, '<span class="wikEdWiki">$1</span><!--wikEdWiki-->');
p6 = p6.replace(/(=+)/g, '<span class="wikEdWiki">$1</span><!--wikEdWiki-->');
var regExp = new RegExp('^' + wikEdText + '?|' + wikEdText + '|' + wikEdText + '|' + wikEdText + '$', 'i');
if (regExp.test(p5) ) {
p1 = p1 + '<span class="wikEdHeadingWp">';
p6 = p6 + '</span><!--wikEdHeadingWp-->';
}
else {
p1 = p1 + '<span class="wikEdHeading">';
p6 = p6 + '</span><!--wikEdHeading-->';
}
return(p1 + p2 + p4 + p5 + p6);
}
);
// tables {| |+ |- ! |} |
obj.html = obj.html.replace(/^((\u0000!--.*?--\u0001)*)(\{\||\|\+|\|\-|\!|\|\}(|$)|\|)(.*?)$/gm, '<span class="wikEdTableLine">$1<span class="wikEdTableTag">$3</span><!--wikEdTableTag-->$5</span><!--wikEdTableLine-->');
if (singleLine != true) {
obj.html = obj.html.replace(/(^|\n)((<*>|\u0000!--.*?--\u0001)*\{\|)/g, '$1<span class="wikEdTableBlock">$2');
obj.html = obj.html.replace(/(^|\n)((<*>|\u0000!--.*?--\u0001)*\|\}(<*>)*)/g, '$1$2</span><!--wikEdTableBlock-->');
obj.html = obj.html.replace(/(\u0000table\b*\u0001)/gi, '<span class="wikEdTableBlock">$1');
obj.html = obj.html.replace(/(\u0000\/table\u0001)/gi, '$1</span><!--wikEdTableBlock-->');
}
// <gallery> wiki markup
if (singleLine != true) {
obj.html = obj.html.replace(/(\u0000(gallery)\b*\u0001)/gi, '<span class="wikEdWiki">$1');
obj.html = obj.html.replace(/(\u0000\/(gallery)\u0001)/gi, '$1</span><!--wikEdWiki-->');
}
// various block tags
obj.html = obj.html.replace(/(\u0000\/?(blockquote|center|div|pre|timeline|imagemap)\b*\u0001)/gi, '<span class="wikEdBlockTag">$1</span><!--wikEdBlockTag-->');
// <p> ... </p> pairs with (wikEdBlockTag) and withhout attributes (wikEdUnknown)
var isRemove = ;
obj.html = obj.html.replace(/(\u0000(\/?)p\b(*?)\u0001)/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
// magic words
obj.html = obj.html.replace(/(__(NOTOC|FORCETOC|TOC|NOEDITSECTION|NEWSECTIONLINK|NOCONTENTCONVERT|NOCC|NOGALLERY|NOTITLECONVERT|NOTC|END|START)__)/gi, '<span class="wikEdMagic">$1</span><!--wikEdMagic-->');
// <sup> </sub> <ins> <del>
obj.html = obj.html.replace(/(\u0000sup\b*\u0001((.|\n)*?)\u0000\/sup\u0001)/gi, '<span class="wikEdSuperscript">$1</span><!--wikEdSuperscript-->');
obj.html = obj.html.replace(/(\u0000sub\b*\u0001((.|\n)*?)\u0000\/sub\u0001)/gi, '<span class="wikEdSubscript">$1</span><!--wikEdSubscript-->');
obj.html = obj.html.replace(/(\u0000(ins|u)\b*\u0001((.|\n)*?)\u0000\/(ins|u)\u0001)/gi, '<span class="wikEdIns">$1</span><!--wikEdIns-->');
obj.html = obj.html.replace(/(\u0000(del|s|strike)\b*\u0001((.|\n)*?)\u0000\/(del|s|strike)\u0001)/gi, '<span class="wikEdDel">$1</span><!--wikEdDel-->');
// <ref /> and <ref> wiki markup
if (wikEdRefHide != true) {
obj.html = obj.html.replace(/\u0000(ref\b*?\/)\u0001/gi, '<span class="wikEdRef"><$1></span><!--wikEdRef-->');
obj.html = obj.html.replace(/(\u0000ref\b*\u0001((.|\n)*?)\u0000\/ref\u0001)/gi, '<span class="wikEdRef">$1</span><!--wikEdRef-->');
}
// various inline tags
obj.html = obj.html.replace(/(\u0000\/?(sub|sup|ins|u|del|s|strike|big|br|colgroup|code|font|small|span|tt|rb|rp|rt|ruby|ref)\b*\u0001)/gi, '<span class="wikEdInlineTag">$1</span><!--wikEdInlineTag-->');
// <references/> wiki markup
obj.html = obj.html.replace(/\u0000((references)\b*?\/)\u0001/gi, '<span class="wikEdWiki"><$1></span><!--wikEdWiki-->');
// <math> <noinclude> <includeonly> <references> wiki markup
obj.html = obj.html.replace(/(\u0000(math|gallery|noinclude|includeonly|references)\b*\u0001((.|\n)*?)(\u0000)\/\2\u0001)/gi, '<span class="wikEdWiki">$1</span><!--wikEdWiki-->');
// unsupported or not needed <> tags
obj.html = obj.html.replace(/(\u0000\/?)(\w+)(.*?\/?\u0001)/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|timeline|imagemap)$/i.test(p2) ) {
p1 = '<span class="wikEdUnknown">' + p1;
p3 = p3 + '</span><!--wikEdUnknown-->';
}
return(p1 + p2 + p3);
}
);
// comments
obj.html = obj.html.replace(/(\u0000!--(.|\n)*?--\u0001)/g, '<span class="wikEdComment">$1</span><!--wikEdComment-->');
// URLs, allowed chars: \w / . & ? = - @ # % ~ + : (; allowed because of & and common misuse, : allowed for wikipedia links)
obj.html = obj.html.replace(/((http:\/\/|https:\/\/|ftp:\/\/|irc:\/\/|gopher:\/\/|news:|mailto:)\^\`\{-\|\}\u007f-\uffff]*)/gi,
function (p, p1, p2) {
return('<span class="wikEdURLLink"' + WikEdFollowLinkUrl(null, null, p1) + '">' + p1 + '</span><!--wikEdURLLink-->');
}
);
// URLs with text
obj.html = obj.html.replace(/(\*>.*?<\!--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);
}
);
// ] images
var regExpImg = new RegExp('(\\ + ' *: *)(\\*? *)(\\|(\\]*\\]|\\]*\\]\\]|\\|]+|\\|)*)?(\\]\\])', 'gi');
obj.html = obj.html.replace(regExpImg,
function (p, p1, p2, p3, p4, p5, p6) {
var linkTitle = p3;
linkTitle = linkTitle.replace(/\|.*/g, '');
linkTitle = linkTitle.replace(/\n.*/g, '');
p1 = '<span class="wikEdImage"' + WikEdFollowLinkUrl(p2, linkTitle) + '>' + p1;
p6 = p6 + '</span><!--wikEdImage-->';
p2 = '<span class="wikEdImageName">' + p2;
p3 = p3 + '</span><!--wikEdImageName-->';
// parameters and capture
p4 = p4.replace(/((\]\]|\]\]\]|\|])+)/g,
function (p, p1) {
if (/^(thumb|thumbnail|frame|right|left|center|none|\d+px|\d+x\d+px)$/.test(p1) == true) {
p1 = '<span class="wikEdImageParam">' + p1 + '</span><!--wikEdImageParam-->';
}
else {
p1 = '<span class="wikEdImageCaption">' + p1 + '</span><!--wikEdImageCaption-->';
}
return(p1);
}
);
// link tags
p1 = p1.replace(/(\[+)/, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
p6 = p6.replace(/(\]+)/, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
p4 = p4.replace(/(\|)/g, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
return(p1 + p2 + p3 + p4 + p6);
}
);
// ] links, categories
obj.html = obj.html.replace(/(\]*)(\]\])/g,
function (p, p1, p2, p3) {
// omit image tags
var regExpImg = new RegExp('^(<*>)*' + wikEdText + '\\s*:', 'i');
if (regExpImg.test(p2) == true) {
return(p1 + p2 + p3);
}
// get url
var linkParam = '';
var linkInter;
var linkMatch = p2.match(/^\s*((*\s*:)*)\s*(+)/);
if (linkMatch != null) {
linkInter = linkMatch;
linkParam = WikEdFollowLinkUrl(linkInter, linkMatch)
}
// category
var regExpCat = new RegExp('^\\s*' + wikEdText + '\\s*:', 'i');
if (regExpCat.test(p2)) {
var regExp = new RegExp('\\s*+\\s*:\\s*' + wikEdText + '\\s*:', 'i');
if (p2.match(regExp)) {
p1 = '<span class="wikEdCatInter"' + linkParam + '>' + p1;
p3 = p3 + '</span><!--wikEdCatInter-->';
}
else {
p1 = '<span class="wikEdCat"' + linkParam + '>' + p1;
p3 = p3 + '</span><!--wikEdCat-->';
}
p2 = p2.replace(/^(\s*)((\w*:)+)/, '$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 (linkInter != '') {
p1 = '<span class="wikEdLinkInter"' + linkParam + '>' + p1;
p3 = p3 + '</span><!--wikEdLinkInter-->';
}
else {
p1 = '<span class="wikEdLink"' + linkParam + '">' + p1;
p3 = p3 + '</span><!--wikEdLink-->';
}
p2 = p2.replace(/^(\s*)((\w*:)+)/, '$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(/(\|)/g, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
p3 = p3.replace(/(\]+)/, '<span class="wikEdLinkTag">$1</span><!--wikEdLinkTag-->');
return(p1 + p2 + p3);
}
);
// {{ }} simple non-nested templates
obj.html = obj.html.replace(/(\{{2,3})(+)(\}{2,3})/g,
function (p, p1, p2, p3) {
// get url
var linkParam = '';
var linkInter;
var linkMatch = p2.match(/^\s*((*\s*:)*)\s*(+)/);
if (linkMatch != null) {
linkInter = linkMatch;
linkParam = WikEdFollowLinkUrl(linkInter + wikEdText + ':', linkMatch)
}
if (linkInter != '') {
p1 = '<span class="wikEdTemplInter"' + linkParam + '>' + p1;
p3 = p3 + '</span><!--wikEdTemplInter-->';
}
else {
p1 = '<span class="wikEdTempl"' + linkParam + '>' + p1;
p3 = p3 + '</span><!--wikEdTempl-->';
}
p2 = p2.replace(/^(\s*)((\w*:)+)/, '$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
p2 = p2.replace(/(\|)/g, '<span class="wikEdTemplTag">$1</span><!--wikEdTemplTag-->');
return(p1 + p2 + p3);
}
);
// highlighting curly template brackets at template start
obj.html = obj.html.replace(/(\{{2,})(\s*+)/g,
function (p, p1, p2) {
var linkMatch = p2.match(/^\s*((*\s*:)*)\s*(+)/);
var linkParam = '';
var linkInter;
if (linkMatch != null) {
linkInter = linkMatch;
linkParam = WikEdFollowLinkUrl(linkInter + wikEdText + ':', linkMatch)
}
return('<span class="wikEdTempl"' + linkParam + '><span class="wikEdTemplTag">' + p1 + '</span><span class="wikEdTemplName">' + p2 + '</span><!--wikEdTemplName--><!--wikEdTemplTag-->');
}
);
// highlighting curly template brackets at template end
obj.html = obj.html.replace(/(\}{2,})(?!<\/span><!--wikEdTemplTag-->)/g, '<span class="wikEdTemplTag">$1</span><!--wikEdTemplTag--></span><!--wikEdTempl-->');
// <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 html colors
obj.html = obj.html.replace(/(\'|\")(aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|blanchedalmond|burlywood|chartreuse|coral|cornsilk|cyan|darkgray|darkgrey|darkkhaki|darkorange|darksalmon|darkseagreen|floralwhite|fuchsia|gainsboro|ghostwhite|gold|goldenrod|greenyellow|honeydew|hotpink|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightskyblue|lightsteelblue|lightyellow|lime|linen|magenta|mediumaquamarine|mediumspringgreen|mediumturquoise|mintcream|mistyrose|moccasin|navajowhite|oldlace|orange|palegoldenrod|palegreen|paleturquoise|papayawhip|peachpuff|peru|pink|plum|powderblue|salmon|sandybrown|seashell|silver|skyblue|snow|springgreen|tan|thistle|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen)(\1)/g, '$1<span style="background-color: $2;" class="wikEdColorsLight">$2</span><!--wikEdColorsLight-->$3');
obj.html = obj.html.replace(/(\'|\")(black|blue|blueviolet|brown|cadetblue|chocolate|cornflowerblue|crimson|darkblue|darkcyan|darkgoldenrod|darkgreen|darkmagenta|darkolivegreen|darkorchid|darkred|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|forestgreen|gray|green|grey|indianred|indigo|lightseagreen|lightslategray|lightslategrey|limegreen|maroon|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumvioletred|midnightblue|navy|olive|olivedrab|orangered|orchid|palevioletred|purple|red|rosybrown|royalblue|saddlebrown|seagreen|sienna|slateblue|slategray|slategrey|steelblue|teal|tomato)(\1)/g, '$1<span style="background-color: $2;" class="wikEdColorsDark">$2</span><!--wikEdColorsDark-->$3');
// RGB hex colors #d4d0cc
obj.html = obj.html.replace(/(^|)(#({2})({2})({2}))(?=(\W|$))/g,
function (p, p1, p2, p3, p4, p5) {
var luminance = parseInt(p3, 16) * 0.299 + parseInt(p4, 16) * 0.587 + parseInt(p5, 16) * 0.114;
if (luminance > 128) {
return(p1 + '<span style="background-color: ' + p2 + '" class="wikEdColorsLight">' + p2 + '</span><!--wikEdColorsLight-->');
}
else {
return(p1 + '<span style="background-color: ' + p2 + '" class="wikEdColorsDark">' + p2 + '</span><!--wikEdColorsDark-->');
}
}
);
// RGB hex colors #ddc
obj.html = obj.html.replace(/(^|)(#()()())(?=(\W|$))/g,
function (p, p1, p2, p3, p4, p5) {
var luminance = parseInt(p3, 16) * 16 * 0.299 + parseInt(p4, 16) * 16 * 0.587 + parseInt(p5, 16) * 16 * 0.114;
if (luminance > 128) {
return(p1 + '<span style="background-color: ' + p2 + '" class="wikEdColorsLight">' + p2 + '</span><!--wikEdColorsLight-->');
}
else {
return(p1 + '<span style="background-color: ' + p2 + '" class="wikEdColorsDark">' + p2 + '</span><!--wikEdColorsDark-->');
}
}
);
// RGB decimal colors rgb(128,64,265)
obj.html = obj.html.replace(/(rgb\(\s*(\d+),\s*(\d+),\s*(\d+)\s*\))/gi,
function (p, p1, p2, p3, p4) {
var luminance = p2 * 0.299 + p3 * 0.587 + p4 * 0.114;
if (luminance > 128) {
return('<span style="background-color: ' + p1 + '" class="wikEdColorsLight">' + p1 + '</span><!--wikEdColorsLight-->');
}
else {
return('<span style="background-color: ' + p1 + '" class="wikEdColorsDark">' + p1 + '</span><!--wikEdColorsDark-->');
}
}
);
// nowiki (remove highlighting)
obj.html = obj.html.replace(/(\u0000nowiki\b*\u0001)((.|\n)*?)(\u0000\/nowiki\u0001)/gi,
function (p, p1, p2, p3, p4) {
p1 = '<span class="wikEdNowiki"><span class="wikEdInlineTag">' + p1 + '</span><!--wikEdInlineTag-->';
p2 = p2.replace(/<*>/g, '');
p4 = '<span class="wikEdInlineTag">' + p4 + '</span><!--wikEdInlineTag--></span><!--wikEdNowiki-->';
return(p1 + p2 + p4);
}
);
// hide (fade) <ref>
if (wikEdRefHide == true) {
// escape <ref />
obj.html = obj.html.replace(/\u0000(ref\b*?\/)\u0001/g, '<span class="wikEdRefHide"><$1></span><!--wikEdRefHide-->');
// remove <ref> inner highlighting
obj.html = obj.html.replace(/(\u0000ref\b*\u0001)((.|\n)*?)(\u0000\/ref\u0001)/gi,
function (p, p1, p2, p3, p4) {
p2 = p2.replace(/<*>/g, '');
var str = '<span class="wikEdRefHide">' + p1 + p2 + p4 + '</span><!--wikEdRefHide-->';
return(str);
}
);
}
// \u0000 and \u0001 back to < and >
obj.html = obj.html.replace(/\u0000/g, '<');
obj.html = obj.html.replace(/\u0001/g, '>');
// display control chars with popup title
var regExp = new RegExp('()', 'g');
obj.html = obj.html.replace(regExp,
function (p, p1) {
if (p1 == '\u0009') {
p1 = '<span class="wikEdTab" title="' + wikEdControlChars + '">' + p1 + '</span><!--wikEdTab-->';
}
else if (p1 != '\u000a') {
p1 = '<span class="wikEdCtrl" title="' + wikEdControlChars + '">' + p1 + '</span><!--wikEdCtrl-->';
}
return(p1);
}
);
// display strange spaces with popup title
var regExpStr = '';
for (var decimalValue in wikEdStrangeSpaces) {
if (typeof(wikEdStrangeSpaces) != 'string') {
continue;
}
regExpStr += String.fromCharCode(decimalValue);
}
var regExp = new RegExp('()', 'g');
obj.html = obj.html.replace(regExp,
function (p, p1) {
if (p1 != '\u000a') {
p1 = '<span class="wikEdBlank" title="' + wikEdStrangeSpaces + '">' + p1 + '</span><!--wikEdBlank-->';
}
return(p1);
}
);
// remove comments
if (wikEdRemoveHighlightComments == true) {
obj.html = obj.html.replace(/<!--wikEd\w+-->/g, '');
}
return;
}
//
// WikEdFollowLinkUrl: prepare the span tag parameters for ctrl-click opening of highlighted links
// add support for ]
function WikEdFollowLinkUrl(linkPrefix, linkTitle, linkUrl) {
var linkName = '';
// generate url from interlanguage or namespace prefix and title
if (linkUrl == null) {
// test for templates
if ( (/\{|\}/.test(linkPrefix) == true) || (/\{|\}/.test(linkTitle) ) == true) {
return('');
}
// remove highlighting code
linkPrefix = linkPrefix.replace(/<*>/g, '');
linkTitle = linkTitle.replace(/<*>/g, '');
// remove control chars
var regExp = new RegExp('', 'g');
linkPrefix = linkPrefix.replace(regExp, '');
linkTitle = linkTitle.replace(regExp, '');
// remove strange white spaces
linkPrefix = linkPrefix.replace(/\s/, ' ');
linkTitle = linkTitle.replace(/\s/, ' ');
linkPrefix = linkPrefix.replace(/\s/g, '');
linkPrefix = linkPrefix.replace(/^:+/g, '');
linkTitle = linkTitle.replace(/ /g, '_');
linkTitle = linkTitle.substr(0, 1).toUpperCase() + linkTitle.substr(1);
linkUrl = linkPrefix + linkTitle;
linkUrl = encodeURI(linkUrl);
linkUrl = linkUrl.replace(/%25(\d\d)/g, '%$1');
linkUrl = linkUrl.replace(/\'/g, '%27');
linkUrl = linkUrl.replace(/#/g, '%23');
if (typeof(wgArticlePath) != 'string') {
linkUrl = '';
}
else {
linkUrl = wgArticlePath.replace(/\$1/, linkUrl);
linkName = linkPrefix + linkTitle;
}
}
// url provided
else {
// test for templates
if (/\{|\}/.test(linkUrl) == true) {
return('');
}
linkName = linkUrl;
linkUrl = encodeURI(linkUrl);
linkUrl = linkUrl.replace(/%25(\d\d)/g, '%$1');
linkUrl = linkUrl.replace(/\'/g, '%27');
}
linkName = linkName.replace(/</g, '<');
linkName = linkName.replace(/>/g, '>');
linkName = linkName.replace(/\"/g, '"');
linkName = linkName.replace(/\'/g, '\\u0027');
var linkParam = '';
if (linkUrl != '') {
linkParam = ' onclick="var linkUrl=\'' + linkUrl + '\'; var linkName = \'' + linkName + '\';"';
}
return(linkParam)
}
//
// WikEdUpdateTextarea: copy frame content to textarea
//
function WikEdUpdateTextarea() {
// get frame content
var obj = {};
obj.html = wikEdFrameBody.innerHTML;
obj.html = obj.html.replace(/(<br\b*>)\n* */g, '$1');
// textify so that no html formatting is submitted
WikEdTextify(obj);
obj.plain = obj.plain.replace(/ /g, ' ');
obj.plain = obj.plain.replace(/</g, '<');
obj.plain = obj.plain.replace(/>/g, '>');
obj.plain = obj.plain.replace(/&/g, '&');
// copy to textarea
wikEdTextarea.value = obj.plain;
// remember frame scroll position
wikEdFrameScrollTop = wikEdFrameBody.scrollTop;
return;
}
//
// WikEdUpdateFrame: copy textarea content to frame
//
function WikEdUpdateFrame() {
// get textarea content
var obj = {};
obj.html = wikEdTextarea.value;
obj.html = obj.html.replace(/&/g, '&');
obj.html = obj.html.replace(/>/g, '>');
obj.html = obj.html.replace(/</g, '<');
// highlight the syntax
if (wikEdHighlightSyntax == true) {
WikEdHighlightSyntax(obj);
}
// display tabs
else {
obj.html = obj.html.replace(/(\t)/g, '<span class="wikEdTabPlain">$1</span><!--wikEdTabPlain-->');
}
// multiple blanks to blank-
obj.html = obj.html.replace(/ /g, ' ');
obj.html = obj.html.replace(/ /g, ' ');
obj.html = obj.html.replace(/ \n/g, ' \n');
// newlines to <br />
obj.html = obj.html.replace(/\n/g, '<br />');
// select the whole text after replacing the whole text and scroll to same height
obj.sel = wikEdFrameWindow.getSelection();
obj.sel.removeAllRanges();
// insert content into empty frame
if ( (wikEdFrameBody.firstChild == null) || (wikEdFrameBody.innerHTML == '<br>') ) {
wikEdFrameBody.innerHTML = obj.html;
}
// insert content into frame, preserve history
else {
var range = document.createRange();
range.setStartBefore(wikEdFrameBody.firstChild);
range.setEndAfter(wikEdFrameBody.lastChild);
obj.sel.addRange(range);
// replace the frame content with the new text
if (obj.html != '') {
WikEdFrameExecCommand('inserthtml', obj.html);
}
else {
WikEdFrameExecCommand('delete');
}
obj.sel.removeAllRanges();
// scroll to previous position
if (wikEdFrameScrollTop != null) {
wikEdFrameBody.scrollTop = wikEdFrameScrollTop;
}
}
wikEdFrameScrollTop = null;
// add event handler to make highlighted frame links ctrl-clickable
if (wikEdHighlightSyntax == true) {
WikEdFollowLinks();
}
return;
}
//
// WikEdKeyFrame: event handler for key and mouse events in the frame
//
function WikEdKeyFrame(event) {
if (wikEdUseWikEd == true) {
switch (event.type) {
// trap the tab key
case 'keydown':
switch (event.keyCode) {
case 9:
if (event.shiftKey == false) {
event.preventDefault();
// scroll to text input top
if (wikEdFullScreenMode == false) {
var inputWrapperTop = WikEdGetOffsetTop(wikEdInputWrapper);
window.scroll(0, inputWrapperTop);
}
// focus the summary
wikEdSummaryText.focus();
}
break;
}
break;
// trap any other frame event
case 'keyup':
case 'keypress':
case 'mouseup':
// grey out inactive buttons
WikEdInactiveButtons();
// reset the frame DOM cache
wikEdFrameDOMCache = null;
break;
}
}
return;
}
//
// WikEdFrameExecCommand: wrapper for execCommand method
//
function WikEdFrameExecCommand(command, option) {
wikEdFrameDocument.execCommand(command, false, option);
return;
}
//
// WikEdFindAhead: non-regexp and case-insensitive find-as-you-type, event handler for find field
//
function WikEdFindAhead() {
if (wikEdFindAhead.checked == true) {
// get the find text
var findText = wikEdFindText.value;
if (findText == '') {
return;
}
// remember position
var sel = wikEdFrameWindow.getSelection();
var range = sel.getRangeAt(sel.rangeCount - 1).cloneRange();
var rangeClone = range.cloneRange();
var scrollTop = wikEdFrameBody.scrollTop;
sel.removeAllRanges();
sel.addRange(range);
range.collapse(true);
// parameters: window.find(string, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog)
// Mozilla bug: searchInFrames must be true, otherwise wrapAround does not work
var found = wikEdFrameWindow.find(findText, false, false, true, false, true, false);
// add original selection
if (found == false) {
wikEdFrameBody.scrollTop = scrollTop;
sel.removeAllRanges();
sel.addRange(rangeClone);
}
}
return;
}
//
// WikEdMainSwitch: onclick handler for program logo
//
function WikEdMainSwitch() {
// disable function if browser is incompatible
if (wikEdBrowserNotSupported == true) {
return;
}
// enable wikEd
if (wikEdDisabled == true) {
wikEdDisabled = false;
WikEdSetCookie('wikEdDisabled', '', -1, '/');
// turn rich text frame on
if (wikEdLoaded == true) {
WikEdSetLogo();
WikEdUpdateFrame();
WikEdSetEditArea(true);
wikEdButtonBarControl.style.display = 'block';
wikEdButtonBarPreview.style.display = 'block';
wikEdButtonBarJump.style.display = 'block';
}
// setup wikEd
else {
WikEdSetup(false);
return;
}
}
// disable wikEd
else {
wikEdDisabled = true;
WikEdSetLogo();
WikEdSetCookie('wikEdDisabled', '1', 0, '/');
if (wikEdLoaded == true) {
if (wikEdFullScreenMode == true) {
WikEdFullScreen(false);
}
// turn classic textarea on
WikEdUpdateTextarea();
WikEdSetEditArea(false);
wikEdButtonBarControl.style.display = 'none';
wikEdButtonBarPreview.style.display = 'none';
wikEdLocalPrevWrapper.style.display = 'none';
wikEdButtonBarJump.style.display = 'none';
}
}
return;
}
//
// WikEdFullScreen: change to fullscreen edit area or back to normal view
//
function WikEdFullScreen(fullscreen, notFrame) {
// hide or show elements
var displayStyle;
if (fullscreen == true) {
displayStyle = 'none';
}
else {
displayStyle = 'block';
}
// elements above input wrapper
var node = document.getElementById('editform').previousSibling;
while (node != null) {
if ( (node.nodeName == 'DIV') || (node.nodeName == 'H3') ) {
node.style.display = displayStyle;
}
node = node.previousSibling;
}
document.getElementsByTagName('H1').style.display = displayStyle;
// divs below input wrapper
var node = wikEdInputWrapper.nextSibling;
while (node != null) {
if (node.nodeName == 'DIV') {
node.style.display = displayStyle;
}
node = node.nextSibling;
}
// divs below input wrapper, some levels up
var node = document.getElementById('column-one');
while (node != null) {
if (node.nodeName == 'DIV') {
node.style.display = displayStyle;
}
node = node.nextSibling;
}
// insert wrapper
document.getElementById('wikEdInsertWrapper').style.display = displayStyle;
// change styles
if (fullscreen) {
if (notFrame != true) {
wikEdInputWrapper.className = 'wikEdInputWrapperFull';
}
wikEdButtonBarPreview.className = 'wikEdButtonBarPreviewFull';
}
else {
if (notFrame != true) {
wikEdInputWrapper.className = 'wikEdInputWrapper';
}
wikEdButtonBarPreview.className = 'wikEdButtonBarPreview';
}
// resize the frame
if (fullscreen) {
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(wikEdInputWrapper) - 2);
}
// set the fullscreen button state
WikEdButton(document.getElementById('wikEdFullScreen'), 'wikEdFullScreen', null, fullscreen);
// grey out or re-activate scroll-to buttons
var buttonClass;
if (fullscreen) {
buttonClass = 'wikEdButtonInactive';
}
else {
buttonClass = 'wikEdButton';
}
document.getElementById('wikEdScrollToPreview').className = buttonClass;
document.getElementById('wikEdScrollToPreview2').className = buttonClass;
document.getElementById('wikEdScrollToEdit').className = buttonClass;
document.getElementById('wikEdScrollToEdit2').className = buttonClass;
// resize the summary field
WikEdResizeSummary();
wikEdFullScreenMode = fullscreen;
return;
}
//
// WikEdResizeSummary: recalculate the summary width after resizing the window
//
function WikEdResizeSummary() {
wikEdSummaryText.style.width = '';
wikEdSummarySelect.style.width = '';
var wikEdSummaryTextWidth = wikEdSummaryWrapper.clientWidth - ( WikEdGetOffsetLeft(wikEdSummaryText) - WikEdGetOffsetLeft(wikEdSummaryWrapper) );
if (wikEdSummaryTextWidth < 150) {
wikEdSummaryTextWidth = 150;
}
wikEdSummaryText.style.width = wikEdSummaryTextWidth + 'px';
WikEdResizeComboInput('summary');
return;
}
//
// WikEdResizeComboInput: set the size of the background select boxes so that the button is visible
//
function WikEdResizeComboInput(field) {
// add a dummy option if no options have been added yet
var dummy;
var testOption = 1;
if (wikEdSelectElement.options.length == 0) {
testOption = 0;
wikEdSelectElement.options = new Option('');
dummy = true;
}
// set option widths to 0
for (var i = 0; i < wikEdSelectElement.options.length; i ++) {
wikEdSelectElement.options.style.width = '0';
}
// calculate select width
var inputWidth = wikEdInputElement.clientWidth;
var selectWidth = wikEdSelectElement.clientWidth;
var optionWidth = wikEdSelectElement.options.offsetWidth;
var border = wikEdInputElement.offsetWidth - wikEdInputElement.clientWidth;
selectWidth = selectWidth - optionWidth + inputWidth - border + 1;
var buttonWidth = selectWidth - inputWidth;
if (inputWidth - buttonWidth > 150) {
wikEdInputElement.style.width = (inputWidth - buttonWidth) + 'px';
wikEdSelectElement.style.width = (selectWidth - buttonWidth) + 'px';
}
else {
wikEdSelectElement.style.width = selectWidth + 'px';
}
// delete dummy option
if (dummy == true) {
wikEdSelectElement.options = null;
}
// set option widths to auto
for (var i = 0; i < wikEdSelectElement.options.length; i ++) {
wikEdSelectElement.options.style.width = 'auto';
}
return;
}
//
// WikEdChangeComboInput: set the input value to selected option; onchange event handler for select boxes
//
function WikEdChangeComboInput(field) {
wikEdInputElement.focus;
// get selection index (-1 for unselected)
var selected = wikEdSelectElement.selectedIndex;
if (selected >= 0) {
wikEdSelectElement.selectedIndex = -1;
// get selected option
var option = wikEdSelectElement.options;
if (option.text != '') {
// jump to heading
if (/^=/.test(option.value) == true) {
// parameters: window.find(string, caseSensitive, backwards, wrapAround, wholeWord, searchInFrames, showDialog)
// Mozilla bug: searchInFrames must be true, otherwise wrapAround does not work
wikEdFrameWindow.find(option.value, true, false, true, false, true, false);
}
// update input field
else {
// add a tag to the summary box
if (field == 'summary') {
wikEdInputElement.value = WikEdAppendToSummary(wikEdInputElement.value, option.text);
}
// add case and regexp checkboxes to find / replace fields
else if (option.value == 'setcheck') {
WikEdButton(document.getElementById('wikEdCaseSensitive'), 'wikEdCaseSensitive', null, (option.text.charAt(0) == wikEdCheckMarker) );
WikEdButton(document.getElementById('wikEdRegExp'), 'wikEdRegExp', null, (option.text.charAt(1) == wikEdCheckMarker) );
wikEdInputElement.value = option.text.substr(3);
}
// add option text
else {
wikEdInputElement.value = option.text;
}
// find the new text
if ( (field == 'find') && (wikEdFindAhead.checked == true) ) {
WikEdFindAhead();
}
}
}
}
return;
}
//
// WikEdAppendToSummary: append a phrase to the summary text
//
function WikEdAppendToSummary(summary, append) {
summary = summary.replace(/^+/, '');
summary = summary.replace(/+$/, '');
if (summary != '') {
if (summary.match(/ \*\/$/) != null) {
summary += ' ';
}
else if (summary.match(/$/) != null) {
summary += ' ';
}
else if (summary.match(/^/) == null) {
summary += ' ';
}
else {
summary += ', ';
}
}
summary += append;
return(summary);
}
//
// WikEdAddToHistory: add an input value to the cookie history
//
function WikEdAddToHistory(field) {
if (wikEdInputElement.value != '') {
// load history from cookie
WikEdLoadHistoryFromCookie(field);
// add current value to history
wikEdFieldHist.unshift(wikEdInputElement.value);
// add case and regexp checkboxes to find / replace value
if ( (field == 'find') || (field == 'replace') ) {
wikEdFieldHist =
wikEdCheckMarker +
wikEdCheckMarker +
' ' + wikEdFieldHist;
}
// remove paragraph names from summary
if (field == 'summary') {
wikEdFieldHist = wikEdFieldHist.replace(/^\/\* .*? \*\/ */, '');
}
// remove multiple old copies from history
var i = 1;
while (i < wikEdFieldHist.length) {
if (wikEdFieldHist == wikEdFieldHist) {
wikEdFieldHist.splice(i, 1);
}
else {
i ++;
}
}
// remove new value if it is a preset value
if (wikEdComboPresetOptions != null) {
var i = 0;
while (i < wikEdComboPresetOptions.length) {
if (wikEdComboPresetOptions == wikEdFieldHist) {
wikEdFieldHist.shift();
break;
}
else {
i ++;
}
}
}
// cut history number to maximal history length
wikEdFieldHist = wikEdFieldHist.slice(0, wikEdHistoryLength);
// saved history to cookie
if (wikEdFieldHist != '') {
WikEdSaveHistoryToCookie(field);
}
}
return;
}
//
// WikEdSetComboOptions: generate the select options from cookie history; onfocus handler for select box
//
function WikEdSetComboOptions(field) {
// load history from cookie
WikEdLoadHistoryFromCookie(field);
var option = {};
var selectedOption = null;
// delete options
var options = wikEdSelectElement.options;
for (var i = 0; i < options.length; i ++) {
wikEdSelectElement.remove(i);
}
// delete optgroup
option = document.getElementById(field + 'Optgroup');
if (option != null) {
wikEdSelectElement.removeChild(option);
}
// workaround for onchange not firing when selecting first option from unselected dropdown
option = document.createElement('option');
option.style.display = 'none';
j = 0;
wikEdSelectElement.options = option;
// add history entries
for (var i = 0; i < wikEdFieldHist.length; i ++) {
if (wikEdFieldHist != null) {
if (wikEdFieldHist == wikEdInputElement.value) {
selectedOption = j;
}
option = document.createElement('option');
option.text = wikEdFieldHist;
if ( (field == 'find') || (field == 'replace') ) {
option.value = 'setcheck';
}
wikEdSelectElement.options = option;
}
}
// add preset entries
var startPreset = 0;
if (wikEdComboPresetOptions != null) {
startPreset = j;
for (var i = 0; i < wikEdComboPresetOptions.length; i ++) {
if (wikEdComboPresetOptions != null) {
// replace spaces with nbsp to allow for multiple and trailing spaces
wikEdComboPresetOptions = wikEdComboPresetOptions.replace(/ /g, '\u00a0');
// select a dropdown value
if (wikEdComboPresetOptions == wikEdInputElement.value) {
selectedOption = j;
}
option = document.createElement('option');
option.text = wikEdComboPresetOptions;
if (field == 'summary') {
option.text = option.text.replace(/\{wikEdUsing\}/g, wikEdSummaryUsing);
}
wikEdSelectElement.options = option;
}
}
}
// set the selection
wikEdSelectElement.selectedIndex = selectedOption;
// add a blank preset separator
if ( (startPreset > 1) && (startPreset < j) ) {
option = document.createElement('optgroup');
option.label = '\u00a0';
option.id = field + 'Optgroup';
wikEdSelectElement.insertBefore(option, wikEdSelectElement.options);
}
// add the TOC jumper to the find field
var startTOC = 0;
if (field == 'find') {
startTOC = j;
// get the whole plain text
var plain = wikEdFrameBody.innerHTML;
plain = plain.replace(/<br\b*>/g, '\n');
plain = plain.replace(/<.*?>/g, '');
// cycle through the headings
var heading = plain.match(/(^|\n)=++?=+**(?=(\n|$))/g);
for (var i = 0; i < heading.length; i ++) {
var headingMatch = heading.match(/\n?((=+) *(+?)( *\2))/);
var headingIndent = headingMatch
headingIndent = headingIndent.replace(/^=/g, '');
headingIndent = headingIndent.replace(/=/g, '\u00a0');
// add headings to the select element
option = document.createElement('option');
option.text = '\u21d2' + headingIndent + headingMatch;
option.value = headingMatch;
wikEdSelectElement.options = option;
}
}
// add a blank TOC separator
if ( (startTOC > 1) && (startTOC < j) ) {
option = document.createElement('optgroup');
option.label = '\u00a0';
option.id = field + 'Optgroup';
wikEdSelectElement.insertBefore(option, wikEdSelectElement.options);
}
return;
}
//
// WikEdClearHistory: clear the history of combo input fields
//
function WikEdClearHistory(field) {
WikEdSetCookie(wikEdCookieName, '', 0, '/');
WikEdSetComboOptions(field);
return;
}
//
// WikEdLoadHistoryFromCookie: get the input box history from the respective cookie
//
function WikEdLoadHistoryFromCookie(field) {
var cookie = WikEdGetCookie(wikEdCookieName);
if (cookie != '') {
cookie = decodeURIComponent(cookie);
wikEdFieldHist = cookie.split('\n');
}
else {
wikEdFieldHist = ;
}
return;
}
//
// WikEdSaveHistoryToCookie: save the input box history to the respective cookie
//
function WikEdSaveHistoryToCookie(field) {
var cookie = '';
cookie = wikEdFieldHist.join('\n')
cookie = cookie.replace(/\n$/, '');
cookie = encodeURIComponent(cookie);
WikEdSetCookie(wikEdCookieName, cookie, 0, '/');
return;
}
// 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);
}
//
// WikEdGetCookie: get a cookie
//
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);
}
//
// WikEdSetCookie: set a cookie, deletes a cookie for expire = -1
//
function WikEdSetCookie(name, value, expires, path, domain, secure) {
var cookie = name + '=' + encodeURIComponent(value);
if (expires != null) {
// generate a date 1 hour ago to delete the cookie
if (expires == -1) {
var cookieExpire = new Date();
expires = cookieExpire.setTime(cookieExpire.getTime() - 60 * 60 * 1000);
expires = cookieExpire.toUTCString();
}
// get date from expiration preset
else if (expires == 0) {
var cookieExpire = new Date();
expires = cookieExpire.setTime(cookieExpire.getTime() + wikEdCookieExpireSec * 1000);
expires = cookieExpire.toUTCString();
}
cookie += '; expires=' + expires;
}
if (path != null) {
cookie += '; path=' + path;
}
if (domain != null) {
cookie += '; domain=' + domain;
}
if (secure != null) {
cookie += '; secure';
}
document.cookie = cookie;
}
//
// WikEdGetCookieSetting: get a wikEd setting depending on the presence of a cookie
//
function WikEdGetCookieSetting(cookieName, preset) {
if (WikEdGetCookie(cookieName) != '') {
return(!preset);
}
else {
return(preset);
}
}
//
// WikEdGetOffsetTop: get element offset relative to window top
//
function WikEdGetOffsetTop(element) {
var offset = 0;
do {
offset += element.offsetTop;
} while ( (element = element.offsetParent) != null );
return(offset);
}
//
// WikEdGetOffsetLeft: get element offset relative to left window border
//
function WikEdGetOffsetLeft(element) {
var offset = 0;
do {
offset += element.offsetLeft;
} while ( (element = element.offsetParent) != null );
return(offset);
}
// define leaf elements for WikEdGetInnerHTML
var wikEdLeafElements = ;
wikEdLeafElements = true;
wikEdLeafElements = true;
wikEdLeafElements = true;
wikEdLeafElements = true;
//
// WikEdParseDOM: parses a DOM subtree and and adds plain text into a complex data structure
// wikEdFrameDOMCache contains the last parse if the frame has not changed
//
function WikEdParseDOM(obj, topNode) {
/* 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;
}
//
// WikEdParseDOMRecursive: parses a DOM tree and and adds plain text into the data structure
//
function WikEdParseDOMRecursive(obj, currentNode) {
// cycle through the child nodes of currentNode
for (var property in currentNode.childNodes) {
var childNode = currentNode.childNodes;
if (typeof(childNode) != 'string') {
continue;
}
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 == 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 = obj.plainLength;
// current text length
obj.plainLength += value.length;
}
}
return;
}
//
// WikEdGetInnerHTML: get the innerHTML from a document fragment
//
function WikEdGetInnerHTML(obj, currentNode) {
// 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, '<').replace(/>/g, '>') + '"';
}
}
if ( (childNode.childNodes.length == 0) && wikEdLeafElements ) {
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 & < >
obj.plainNode.push(childNode);
obj.plainStart.push(obj.plain.length);
value = value.replace(/&/g, '&');
value = value.replace(/</g, '<');
value = value.replace(/>/g, '>');
obj.html += value;
obj.plain += value;
break;
case 4: obj.html += '<!]>';
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, '&');
obj.html += value;
obj.plain += value;
break;
case 8: obj.html += '<!--' + childNode.nodeValue + '-->';
break;
}
}
return;
}
//
// WikEdStyleSheet: create a new style sheet object, also defined in wikEdDiff.js
//
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');
if (insert != null) {
insert.appendChild(this.styleElement);
}
}
// addRule: add one rule at the time using DOM method, very slow
// 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);
}
}
}
};
// addRules: add all rules at once, much faster
this.addRules = function(rules) {
this.styleElement.innerHTML = rules;
return;
}
}
//
// WikEdAjaxInitObject: cross browser wrapper for creating new XMLHttpRequest object
//
function WikEdAjaxInitObject() {
var ajax;
// current browsers
try {
ajax = new XMLHttpRequest();
}
catch (e) {
// IE 6
try {
ajax = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (e) {
// IE 5.5
try {
ajax = new ActiveXObject('Msxml2.XMLHTTP');
}
catch (e) { }
}
}
return(ajax);
}
//
// WED: shortcut for WikEdDebug
//
function WED(objectName, object) {
WikEdDebug(objectName, object);
return;
}
//
// WikEdDebug: print the value of variables
//
function WikEdDebug(objectName, object) {
if (wikEdLoaded == true) {
document.getElementById('wikEdTextareaWrapper').style.position = 'static';
document.getElementById('wikEdTextareaWrapper').style.visibility = 'visible';
wikEdTextarea.style.display = 'block';
if (objectName == null) {
wikEdTextarea.value = '';
wikEdTextarea.style.height = '25em';
}
else {
wikEdTextarea.value += objectName + ': ' + object + '\n';
}
}
else if (objectName != null) {
alert(objectName + ':\n\n' + object + '\n');
}
return;
}
//
// WikEdDebugTimer: show all measured timepoints
// add a new time measurement: wikEdDebugTimer.push();
function WikEdDebugTimer() {
var times = '';
var start = wikEdDebugTimer.getTime();
var prev = 0;
for (var i = 0; i < wikEdDebugTimer.length; i ++) {
var curr = wikEdDebugTimer.getTime() - start;
var diff = curr - prev;
var prev = curr;
times += wikEdDebugTimer + ': ' + curr + ' ms (+' + diff + 'ms)\n';
}
alert(times);
}
//
// WikEdInsertTags: overrides the insertTags function in wikibits.js used by the standard button toolbar and the editpage special chars
//
function WikEdInsertTags(tagOpen, tagClose, sampleText) {
if (wikEdUseWikEd == true) {
WikEdEditButton(document.getElementById('wikEdInsertTags'), 'wikEdInsertTags', );
}
else if (wikeEdInsertTagsOriginal != null) {
wikeEdInsertTagsOriginal(tagOpen, tagClose, sampleText);
}
return;
}
//
// WikEdInitUnicode: define character tables used in WikedFixUnicode()
// see http://kmi.open.ac.uk/projects/ceryle/doc/docs/NOTE-charents.html
// removed because of internal use: < ; > ; & ,
function WikEdInitUnicode() {
// define only once
if (wikEdSupportedChars != null) {
return;
}
// supported chars in Mozilla and IE
wikEdSupportedChars = [
, // ¡
, // ¢
, // £
, // ¤
, // ¥
, // ¦
, // §
, // ¨
, // ©
, // ª
, // «
, // ¬
, // ®
, // ¯
, // °
, // ±
, // ²
, // ³
, // ´
, // µ
, // ¶
, // ·
, // ¸
, // ¹
, // º
, // »
, // ¼
, // ½
, // ¾
, // ¿
, // À
, // Á
, // Â
, // Ã
, // Ä
, // Å
, // Æ
, // Ç
, // È
, // É
, // Ê
, // Ë
, // Ì
, // Í
, // Î
, // Ï
, // Ð
, // Ñ
, // Ò
, // Ó
, // Ô
, // Õ
, // Ö
, // ×
, // Ø
, // Ù
, // Ú
, // Û
, // Ü
, // Ý
, // Þ
, // ß
, // à
, // á
, // â
, // ã
, // ä
, // å
, // æ
, // ç
, // è
, // é
, // ê
, // ë
, // ì
, // í
, // î
, // ï
, // ð
, // ñ
, // ò
, // ó
, // ô
, // õ
, // ö
, // ÷
, // ø
, // ù
, // ú
, // û
, // ü
, // ý
, // þ
, // ÿ
, // '
, // "
, // Œ
, // œ
, // Š
, // š
, // Ÿ
, // ˆ
, // ˜
, // –
, // —
, // ‘
, // ’
, // ‚
, // “
, // ”
, // „
, // †
, // ‡
, // ‰
, // ‹
, // ›
, // €
, // ƒ
, // Α
, // Β
, // Γ
, // Δ
,// Ε
, // Ζ
, // Η
, // Θ
, // Ι
, // Κ
, // Λ
, // Μ
, // Ν
, // Ξ
,// Ο
, // Π
, // Ρ
, // Σ
, // Τ
,// Υ
, // Φ
, // Χ
, // Ψ
, // Ω
, // α
, // β
, // γ
, // δ
,// ε
, // ζ
, // η
, // θ
, // ι
, // κ
, // λ
, // μ
, // ν
, // ξ
,// ο
, // π
, // ρ
, // ς
, // σ
, // τ
,// υ
, // φ
, // χ
, // ψ
, // ω
, // •
, // …
, // ′
, // ″
, // ‾
, // ⁄
, // ™
, // ←
, // ↑
, // →
, // ↓
, // ↔
, // ⇒
, // ⇔
, // ∀
, // ∂
, // ∃
, // ∇
, // ∈
, // ∋
, // ∏
, // ∑
, // −
, // √
, // ∝
, // ∞
, // ∠
, // ∧
, // ∨
, // ∩
, // ∪
, // ∫
, // ∴
, // ∼
, // ≈
, // ≠
, // ≡
, // ≤
, // ≥
, // ⊂
, // ⊃
, // ⊆
, // ⊇
, // ⊕
, // ⊥
, // ◊
, // ♠
, // ♣
, // ♥
// ♦
];
// special chars (spaces and invisible characters)
wikEdSpecialChars = [
, // en space
, // soft hyphen
, // em space
, // thin space
, // zero width non-joiner
, // zero width joiner
, // left-to-right mark
// right-to-left mark
];
// unsupported chars in IE6
wikEdProblemChars = [
, // ϑ
, // ϒ
, // ϖ
, // ℘
, // ℑ
, // ℜ
, // ℵ
, // ↵
, // ⇐
, // ⇑
, // ⇓
, // ∅
, // ∉
, // ∗
, // ≅
, // ⊄
, // ⊥
, // ⊗
, // ⋅
, // ⌈
, // ⌉
, // ⌊
, // ⌋
, // 〈
// 〉
];
// ASCII control characters and invisibles, used for syntax highlighting
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
};
for (var decimalValue in wikEdControlChars) {
if (typeof(wikEdControlChars) != 'string') {
continue;
}
wikEdControlCharsStr += String.fromCharCode(decimalValue);
}
// strange spaces, used for syntax highlighting
wikEdStrangeSpaces = {
'31': 'non-breaking space', // \u00a0
'8194': 'en space', // \u2002
'8195': 'em space', // \u2003
'8201': 'thin space' // \u2009
};
return;
}
/* </nowiki></pre> */