From c1f9b1f7b1b77776192048005dcc66dcf3df2bfb Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sat, 27 Dec 2014 15:41:37 +0100 Subject: Update to MediaWiki 1.24.1 --- extensions/WikiEditor/modules/contentCollector.js | 439 --- extensions/WikiEditor/modules/ext.wikiEditor.css | 22 - .../WikiEditor/modules/ext.wikiEditor.dialogs.js | 7 +- .../WikiEditor/modules/ext.wikiEditor.highlight.js | 8 - extensions/WikiEditor/modules/ext.wikiEditor.js | 3 +- .../WikiEditor/modules/ext.wikiEditor.preview.js | 3 +- .../modules/ext.wikiEditor.previewDialog.js | 3 +- .../WikiEditor/modules/ext.wikiEditor.publish.js | 3 +- .../modules/ext.wikiEditor.templateEditor.js | 12 - .../WikiEditor/modules/ext.wikiEditor.templates.js | 12 - .../modules/ext.wikiEditor.tests.toolbar.js | 24 +- .../WikiEditor/modules/ext.wikiEditor.toc.js | 8 - .../modules/ext.wikiEditor.toolbar.hideSig.js | 4 +- .../WikiEditor/modules/ext.wikiEditor.toolbar.js | 3 +- .../modules/ext.wikiEditor.toolbar.styles.css | 25 + .../modules/images/templateEditor/collapse.png | Bin 347 -> 0 bytes .../images/templateEditor/dialog-collapsed.png | Bin 266 -> 0 bytes .../images/templateEditor/dialog-expanded.png | Bin 263 -> 0 bytes .../modules/images/templateEditor/expand.png | Bin 223 -> 0 bytes .../modules/images/templateEditor/name-base.png | Bin 138 -> 0 bytes .../modules/images/templateEditor/text-base.png | Bin 88 -> 0 bytes .../modules/images/templateEditor/wiki-text.png | Bin 206 -> 0 bytes extensions/WikiEditor/modules/images/toc/close.png | Bin 216 -> 0 bytes extensions/WikiEditor/modules/images/toc/grab.png | Bin 92 -> 0 bytes extensions/WikiEditor/modules/images/toc/grip.png | Bin 108 -> 0 bytes extensions/WikiEditor/modules/images/toc/open.png | Bin 217 -> 0 bytes .../modules/images/toolbar/button-sprite.svg | 3038 ++++++++++++++++++++ .../modules/images/toolbar/format-big.svg | 113 + .../modules/images/toolbar/format-bold-A.svg | 131 + .../modules/images/toolbar/format-bold-B.svg | 147 + .../modules/images/toolbar/format-bold-F.svg | 147 + .../modules/images/toolbar/format-bold-G.svg | 163 ++ .../modules/images/toolbar/format-bold-N.svg | 147 + .../modules/images/toolbar/format-bold-P.svg | 147 + .../modules/images/toolbar/format-bold-V.svg | 147 + .../modules/images/toolbar/format-bold-hy.png | Bin 0 -> 1675 bytes .../modules/images/toolbar/format-bold.svg | 131 + .../modules/images/toolbar/format-indent-rtl.png | Bin 317 -> 0 bytes .../modules/images/toolbar/format-indent.png | Bin 316 -> 0 bytes .../modules/images/toolbar/format-indent.svg | 220 ++ .../modules/images/toolbar/format-italic-A.svg | 147 + .../modules/images/toolbar/format-italic-C.svg | 147 + .../modules/images/toolbar/format-italic-K.svg | 147 + .../modules/images/toolbar/format-italic-hy.png | Bin 0 -> 1475 bytes .../modules/images/toolbar/format-italic-i.svg | 104 + .../modules/images/toolbar/format-italic.svg | 147 + .../modules/images/toolbar/format-olist.svg | 202 ++ .../modules/images/toolbar/format-small.svg | 114 + .../modules/images/toolbar/format-subscript.svg | 114 + .../modules/images/toolbar/format-superscript.svg | 114 + .../modules/images/toolbar/format-ulist.svg | 204 ++ .../modules/images/toolbar/insert-file.svg | 206 ++ .../modules/images/toolbar/insert-gallery.svg | 191 ++ .../modules/images/toolbar/insert-ilink.svg | 148 + .../modules/images/toolbar/insert-link.svg | 94 + .../modules/images/toolbar/insert-newline.svg | 105 + .../modules/images/toolbar/insert-nowiki.svg | 112 + .../modules/images/toolbar/insert-redirect.svg | 118 + .../modules/images/toolbar/insert-reference.svg | 88 + .../modules/images/toolbar/insert-signature.svg | 274 ++ .../modules/images/toolbar/insert-table.svg | 131 + .../modules/images/toolbar/insert-xlink.svg | 125 + .../modules/images/toolbar/search-replace.svg | 228 ++ .../WikiEditor/modules/jquery.wikiEditor.css | 32 +- .../modules/jquery.wikiEditor.dialogs.config.css | 2 +- .../modules/jquery.wikiEditor.dialogs.config.js | 340 +-- .../modules/jquery.wikiEditor.dialogs.js | 72 +- .../modules/jquery.wikiEditor.highlight.js | 373 --- .../WikiEditor/modules/jquery.wikiEditor.html | 85 - .../WikiEditor/modules/jquery.wikiEditor.iframe.js | 1387 --------- extensions/WikiEditor/modules/jquery.wikiEditor.js | 127 +- .../modules/jquery.wikiEditor.preview.js | 115 +- .../modules/jquery.wikiEditor.previewDialog.js | 33 +- .../modules/jquery.wikiEditor.publish.js | 29 +- .../modules/jquery.wikiEditor.templateEditor.js | 865 ------ .../modules/jquery.wikiEditor.templates.js | 69 - .../WikiEditor/modules/jquery.wikiEditor.toc.css | 204 -- .../WikiEditor/modules/jquery.wikiEditor.toc.js | 676 ----- .../modules/jquery.wikiEditor.toolbar.config.js | 31 +- .../modules/jquery.wikiEditor.toolbar.css | 39 +- .../modules/jquery.wikiEditor.toolbar.js | 292 +- 81 files changed, 8409 insertions(+), 4729 deletions(-) delete mode 100644 extensions/WikiEditor/modules/contentCollector.js delete mode 100644 extensions/WikiEditor/modules/ext.wikiEditor.highlight.js delete mode 100644 extensions/WikiEditor/modules/ext.wikiEditor.templateEditor.js delete mode 100644 extensions/WikiEditor/modules/ext.wikiEditor.templates.js delete mode 100644 extensions/WikiEditor/modules/ext.wikiEditor.toc.js create mode 100644 extensions/WikiEditor/modules/ext.wikiEditor.toolbar.styles.css delete mode 100644 extensions/WikiEditor/modules/images/templateEditor/collapse.png delete mode 100644 extensions/WikiEditor/modules/images/templateEditor/dialog-collapsed.png delete mode 100644 extensions/WikiEditor/modules/images/templateEditor/dialog-expanded.png delete mode 100644 extensions/WikiEditor/modules/images/templateEditor/expand.png delete mode 100644 extensions/WikiEditor/modules/images/templateEditor/name-base.png delete mode 100644 extensions/WikiEditor/modules/images/templateEditor/text-base.png delete mode 100644 extensions/WikiEditor/modules/images/templateEditor/wiki-text.png delete mode 100644 extensions/WikiEditor/modules/images/toc/close.png delete mode 100644 extensions/WikiEditor/modules/images/toc/grab.png delete mode 100644 extensions/WikiEditor/modules/images/toc/grip.png delete mode 100644 extensions/WikiEditor/modules/images/toc/open.png create mode 100644 extensions/WikiEditor/modules/images/toolbar/button-sprite.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-big.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-bold-A.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-bold-B.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-bold-F.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-bold-G.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-bold-N.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-bold-P.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-bold-V.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-bold-hy.png create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-bold.svg delete mode 100644 extensions/WikiEditor/modules/images/toolbar/format-indent-rtl.png delete mode 100644 extensions/WikiEditor/modules/images/toolbar/format-indent.png create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-indent.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-italic-A.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-italic-C.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-italic-K.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-italic-hy.png create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-italic-i.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-italic.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-olist.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-small.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-subscript.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-superscript.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/format-ulist.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/insert-file.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/insert-gallery.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/insert-ilink.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/insert-link.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/insert-newline.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/insert-nowiki.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/insert-redirect.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/insert-reference.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/insert-signature.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/insert-table.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/insert-xlink.svg create mode 100644 extensions/WikiEditor/modules/images/toolbar/search-replace.svg delete mode 100644 extensions/WikiEditor/modules/jquery.wikiEditor.highlight.js delete mode 100644 extensions/WikiEditor/modules/jquery.wikiEditor.iframe.js delete mode 100644 extensions/WikiEditor/modules/jquery.wikiEditor.templateEditor.js delete mode 100644 extensions/WikiEditor/modules/jquery.wikiEditor.templates.js delete mode 100644 extensions/WikiEditor/modules/jquery.wikiEditor.toc.css delete mode 100644 extensions/WikiEditor/modules/jquery.wikiEditor.toc.js (limited to 'extensions/WikiEditor/modules') diff --git a/extensions/WikiEditor/modules/contentCollector.js b/extensions/WikiEditor/modules/contentCollector.js deleted file mode 100644 index 2c289212..00000000 --- a/extensions/WikiEditor/modules/contentCollector.js +++ /dev/null @@ -1,439 +0,0 @@ -// THIS FILE HAS BEEN MODIFIED for use with the mediawiki wikiEditor -// It no longer requires etherpad.collab.ace.easysync2.Changeset -// THIS FILE WAS ORIGINALLY AN APPJET MODULE: etherpad.collab.ace.contentcollector - -/** - * Copyright 2009 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS-IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -var _MAX_LIST_LEVEL = 8; - -function sanitizeUnicode(s) { - return s.replace(/[\uffff\ufffe\ufeff\ufdd0-\ufdef\ud800-\udfff]/g, '?'); -} - -function makeContentCollector( browser, domInterface ) { - browser = browser || {}; - - var dom = domInterface || { - isNodeText : function(n) { - return (n.nodeType == 3); - }, - nodeTagName : function(n) { - return n.tagName; - }, - nodeValue : function(n) { - try { - return n.nodeValue; - } catch ( err ) { - return ''; - } - }, - nodeName : function(n) { - return n.nodeName; - }, - nodeNumChildren : function(n) { - return n.childNodes.length; - }, - nodeChild : function(n, i) { - return n.childNodes.item(i); - }, - nodeProp : function(n, p) { - return n[p]; - }, - nodeAttr : function(n, a) { - return n.getAttribute(a); - }, - optNodeInnerHTML : function(n) { - return n.innerHTML; - } - }; - - var _blockElems = { - "div" : 1, - "p" : 1, - "pre" : 1, - "li" : 1 - }; - function isBlockElement(n) { - return !!_blockElems[(dom.nodeTagName(n) || "").toLowerCase()]; - } - function textify(str) { - return sanitizeUnicode(str.replace(/[\n\r ]/g, ' ').replace(/\xa0/g, - ' ').replace(/\t/g, ' ')); - } - function getAssoc(node, name) { - return dom.nodeProp(node, "_magicdom_" + name); - } - - var lines = (function() { - var textArray = []; - var self = { - length : function() { - return textArray.length; - }, - atColumnZero : function() { - return textArray[textArray.length - 1] === ""; - }, - startNew : function() { - textArray.push(""); - self.flush(true); - }, - textOfLine : function(i) { - return textArray[i]; - }, - appendText : function(txt, attrString) { - textArray[textArray.length - 1] += txt; - // dmesg(txt+" / "+attrString); - }, - textLines : function() { - return textArray.slice(); - }, - // call flush only when you're done - flush : function(withNewline) { - - } - }; - self.startNew(); - return self; - }()); - var cc = {}; - function _ensureColumnZero(state) { - if (!lines.atColumnZero()) { - _startNewLine(state); - } - } - var selection, startPoint, endPoint; - var selStart = [ -1, -1 ], selEnd = [ -1, -1 ]; - var blockElems = { - "div" : 1, - "p" : 1, - "pre" : 1 - }; - function _isEmpty(node, state) { - // consider clean blank lines pasted in IE to be empty - if (dom.nodeNumChildren(node) == 0) - return true; - if (dom.nodeNumChildren(node) == 1 && getAssoc(node, "shouldBeEmpty") - && dom.optNodeInnerHTML(node) == " " - && !getAssoc(node, "unpasted")) { - if (state) { - var child = dom.nodeChild(node, 0); - _reachPoint(child, 0, state); - _reachPoint(child, 1, state); - } - return true; - } - return false; - } - function _pointHere(charsAfter, state) { - var ln = lines.length() - 1; - var chr = lines.textOfLine(ln).length; - if (chr == 0 && state.listType && state.listType != 'none') { - chr += 1; // listMarker - } - chr += charsAfter; - return [ ln, chr ]; - } - function _reachBlockPoint(nd, idx, state) { - if (!dom.isNodeText(nd)) - _reachPoint(nd, idx, state); - } - function _reachPoint(nd, idx, state) { - if (startPoint && nd == startPoint.node && startPoint.index == idx) { - selStart = _pointHere(0, state); - } - if (endPoint && nd == endPoint.node && endPoint.index == idx) { - selEnd = _pointHere(0, state); - } - } - function _incrementFlag(state, flagName) { - state.flags[flagName] = (state.flags[flagName] || 0) + 1; - } - function _decrementFlag(state, flagName) { - state.flags[flagName]--; - } - function _enterList(state, listType) { - var oldListType = state.listType; - state.listLevel = (state.listLevel || 0) + 1; - if (listType != 'none') { - state.listNesting = (state.listNesting || 0) + 1; - } - state.listType = listType; - return oldListType; - } - function _exitList(state, oldListType) { - state.listLevel--; - if (state.listType != 'none') { - state.listNesting--; - } - state.listType = oldListType; - } - function _produceListMarker(state) { - - } - function _startNewLine(state) { - if (state) { - var atBeginningOfLine = lines.textOfLine(lines.length() - 1).length == 0; - if (atBeginningOfLine && state.listType && state.listType != 'none') { - _produceListMarker(state); - } - } - lines.startNew(); - } - cc.notifySelection = function(sel) { - if (sel) { - selection = sel; - startPoint = selection.startPoint; - endPoint = selection.endPoint; - } - }; - cc.collectContent = function(node, state) { - if (!state) { - state = { - flags : {/* name -> nesting counter */} - }; - } - var isBlock = isBlockElement(node); - var isEmpty = _isEmpty(node, state); - if (isBlock) - _ensureColumnZero(state); - var startLine = lines.length() - 1; - _reachBlockPoint(node, 0, state); - if (dom.isNodeText(node)) { - var txt = dom.nodeValue(node); - var rest = ''; - var x = 0; // offset into original text - if (txt.length == 0) { - if (startPoint && node == startPoint.node) { - selStart = _pointHere(0, state); - } - if (endPoint && node == endPoint.node) { - selEnd = _pointHere(0, state); - } - } - while (txt.length > 0) { - var consumed = 0; - if (!browser.firefox || state.flags.preMode) { - var firstLine = txt.split('\n', 1)[0]; - consumed = firstLine.length + 1; - rest = txt.substring(consumed); - txt = firstLine; - } else { /* will only run this loop body once */ - } - if (startPoint && node == startPoint.node - && startPoint.index - x <= txt.length) { - selStart = _pointHere(startPoint.index - x, state); - } - if (endPoint && node == endPoint.node - && endPoint.index - x <= txt.length) { - selEnd = _pointHere(endPoint.index - x, state); - } - var txt2 = txt; - if ((!state.flags.preMode) && /^[\r\n]*$/.exec(txt)) { - // prevents textnodes containing just "\n" from being - // significant - // in safari when pasting text, now that we convert them to - // spaces instead of removing them, because in other cases - // removing "\n" from pasted HTML will collapse words - // together. - txt2 = ""; - } - var atBeginningOfLine = lines.textOfLine(lines.length() - 1).length == 0; - if (atBeginningOfLine) { - // newlines in the source mustn't become spaces at beginning - // of line box - txt2 = txt2.replace(/^\n*/, ''); - } - if (atBeginningOfLine && state.listType - && state.listType != 'none') { - _produceListMarker(state); - } - lines.appendText(textify(txt2)); - - x += consumed; - txt = rest; - if (txt.length > 0) { - _startNewLine(state); - } - } - - } else { - var cls = dom.nodeProp(node, "className"); - var tname = (dom.nodeTagName(node) || "").toLowerCase(); - if (tname == "br") { - _startNewLine(state); - } else if (tname == "script" || tname == "style") { - // ignore - } else if (!isEmpty) { - var styl = dom.nodeAttr(node, "style"); - - var isPre = (tname == "pre"); - if ((!isPre) && browser.safari) { - isPre = (styl && /\bwhite-space:\s*pre\b/i.exec(styl)); - } - if (isPre) - _incrementFlag(state, 'preMode'); - var oldListTypeOrNull = null; - - var nc = dom.nodeNumChildren(node); - for ( var i = 0; i < nc; i++) { - var c = dom.nodeChild(node, i); - //very specific IE case where it inserts which we want to ginore. - //to reproduce copy content from wordpad andpaste into the middle of a line in IE - if ( browser.msie && cls.indexOf('wikiEditor') >= 0 && dom.nodeName(c) == 'SPAN' && dom.nodeAttr(c, 'lang') == "" ) { - continue; - } - cc.collectContent(c, state); - } - - if (isPre) - _decrementFlag(state, 'preMode'); - - if (oldListTypeOrNull) { - _exitList(state, oldListTypeOrNull); - } - } - } - if (!browser.msie) { - _reachBlockPoint(node, 1, state); - } - if (isBlock) { - if (lines.length() - 1 == startLine) { - _startNewLine(state); - } else { - _ensureColumnZero(state); - } - } - - if (browser.msie) { - // in IE, a point immediately after a DIV appears on the next line - //_reachBlockPoint(node, 1, state); - } - }; - // can pass a falsy value for end of doc - cc.notifyNextNode = function(node) { - // an "empty block" won't end a line; this addresses an issue in IE with - // typing into a blank line at the end of the document. typed text - // goes into the body, and the empty line div still looks clean. - // it is incorporated as dirty by the rule that a dirty region has - // to end a line. - if ((!node) || (isBlockElement(node) && !_isEmpty(node))) { - _ensureColumnZero(null); - } - }; - // each returns [line, char] or [-1,-1] - var getSelectionStart = function() { - return selStart; - }; - var getSelectionEnd = function() { - return selEnd; - }; - - // returns array of strings for lines found, last entry will be "" if - // last line is complete (i.e. if a following span should be on a new line). - // can be called at any point - cc.getLines = function() { - return lines.textLines(); - }; - - // cc.applyHints = function(hints) { - // if (hints.pastedLines) { - // - // } - // } - - cc.finish = function() { - lines.flush(); - var lineStrings = cc.getLines(); - - if ( lineStrings.length > 0 && !lineStrings[lineStrings.length - 1] ) { - lineStrings.length--; - } - - var ss = getSelectionStart(); - var se = getSelectionEnd(); - - function fixLongLines() { - // design mode does not deal with with really long lines! - var lineLimit = 2000; // chars - var buffer = 10; // chars allowed over before wrapping - var linesWrapped = 0; - var numLinesAfter = 0; - for ( var i = lineStrings.length - 1; i >= 0; i--) { - var oldString = lineStrings[i]; - if (oldString.length > lineLimit + buffer) { - var newStrings = []; - while (oldString.length > lineLimit) { - // var semiloc = oldString.lastIndexOf(';', - // lineLimit-1); - // var lengthToTake = (semiloc >= 0 ? (semiloc+1) : - // lineLimit); - lengthToTake = lineLimit; - newStrings.push(oldString.substring(0, lengthToTake)); - oldString = oldString.substring(lengthToTake); - - } - if (oldString.length > 0) { - newStrings.push(oldString); - } - function fixLineNumber(lineChar) { - if (lineChar[0] < 0) - return; - var n = lineChar[0]; - var c = lineChar[1]; - if (n > i) { - n += (newStrings.length - 1); - } else if (n == i) { - var a = 0; - while (c > newStrings[a].length) { - c -= newStrings[a].length; - a++; - } - n += a; - } - lineChar[0] = n; - lineChar[1] = c; - } - fixLineNumber(ss); - fixLineNumber(se); - linesWrapped++; - numLinesAfter += newStrings.length; - - newStrings.unshift(i, 1); - lineStrings.splice.apply(lineStrings, newStrings); - - } - } - return { - linesWrapped : linesWrapped, - numLinesAfter : numLinesAfter - }; - } - var wrapData = fixLongLines(); - - return { - selStart : ss, - selEnd : se, - linesWrapped : wrapData.linesWrapped, - numLinesAfter : wrapData.numLinesAfter, - lines : lineStrings - }; - }; - - return cc; -} - - diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.css b/extensions/WikiEditor/modules/ext.wikiEditor.css index 30a27326..6ea7e631 100644 --- a/extensions/WikiEditor/modules/ext.wikiEditor.css +++ b/extensions/WikiEditor/modules/ext.wikiEditor.css @@ -2,28 +2,6 @@ * CSS for WikiEditor */ -form#editform { - margin: 0; - padding: 0; -} - -#wpSummary, -#wpSummaryLabel { - margin-bottom: 1em; -} - -.wikiEditor-ui textarea#wpTextbox1 { - border: none; - padding: 0; - margin: -1px; - line-height: 1.5em; - resize: vertical; -} - -.wikiEditor-ui .wikiEditor-ui-text > textarea#wpTextbox1 { - margin: 0; -} - /* Hide vanilla MediaWiki's "Editing help" link, as we provide it in the toolbar */ .editButtons .editHelp, .editButtons .mw-editButtons-pipe-separator { diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.dialogs.js b/extensions/WikiEditor/modules/ext.wikiEditor.dialogs.js index 0e0dd090..c6d327f8 100644 --- a/extensions/WikiEditor/modules/ext.wikiEditor.dialogs.js +++ b/extensions/WikiEditor/modules/ext.wikiEditor.dialogs.js @@ -1,15 +1,14 @@ /* * JavaScript for WikiEditor Dialogs */ - -$( document ).ready( function() { +jQuery( document ).ready( function ( $ ) { if ( !$.wikiEditor.isSupported( $.wikiEditor.modules.dialogs ) ) { return; } - + // Replace icons $.wikiEditor.modules.dialogs.config.replaceIcons( $( '#wpTextbox1' ) ); - + // Add dialogs module $( '#wpTextbox1' ).wikiEditor( 'addModule', $.wikiEditor.modules.dialogs.config.getDefaultConfig() ); } ); diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.highlight.js b/extensions/WikiEditor/modules/ext.wikiEditor.highlight.js deleted file mode 100644 index a6b43851..00000000 --- a/extensions/WikiEditor/modules/ext.wikiEditor.highlight.js +++ /dev/null @@ -1,8 +0,0 @@ -/* - * JavaScript for WikiEditor Highlighting - */ - -$( document ).ready( function() { - // Add highlight module - $( '#wpTextbox1' ).wikiEditor( 'addModule', 'highlight' ); -} ); diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.js b/extensions/WikiEditor/modules/ext.wikiEditor.js index 6056e63b..46087989 100644 --- a/extensions/WikiEditor/modules/ext.wikiEditor.js +++ b/extensions/WikiEditor/modules/ext.wikiEditor.js @@ -1,8 +1,7 @@ /* * JavaScript for WikiEditor */ - -$( document ).ready( function() { +jQuery( document ).ready( function ( $ ) { // Initialize wikiEditor $( '#wpTextbox1' ).wikiEditor(); } ); diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.preview.js b/extensions/WikiEditor/modules/ext.wikiEditor.preview.js index 3fbca82d..cdc00f7b 100644 --- a/extensions/WikiEditor/modules/ext.wikiEditor.preview.js +++ b/extensions/WikiEditor/modules/ext.wikiEditor.preview.js @@ -1,8 +1,7 @@ /* * JavaScript for WikiEditor Preview module */ - -$( document ).ready( function() { +jQuery( document ).ready( function ( $ ) { // Add preview module $( 'textarea#wpTextbox1' ).wikiEditor( 'addModule', 'preview' ); } ); diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.previewDialog.js b/extensions/WikiEditor/modules/ext.wikiEditor.previewDialog.js index 67f97e00..3b1acd7c 100644 --- a/extensions/WikiEditor/modules/ext.wikiEditor.previewDialog.js +++ b/extensions/WikiEditor/modules/ext.wikiEditor.previewDialog.js @@ -1,8 +1,7 @@ /* * JavaScript for WikiEditor Preview Dialog */ - -$( document ).ready( function() { +jQuery( document ).ready( function ( $ ) { // Add preview module $( 'textarea#wpTextbox1' ).wikiEditor( 'addModule', 'previewDialog' ); } ); diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.publish.js b/extensions/WikiEditor/modules/ext.wikiEditor.publish.js index d874478c..423766d2 100644 --- a/extensions/WikiEditor/modules/ext.wikiEditor.publish.js +++ b/extensions/WikiEditor/modules/ext.wikiEditor.publish.js @@ -1,8 +1,7 @@ /* * JavaScript for WikiEditor Publish module */ - -$( document ).ready( function() { +jQuery( document ).ready( function ( $ ) { // Add publish module $( '#wpTextbox1' ).wikiEditor( 'addModule', 'publish' ); } ); diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.templateEditor.js b/extensions/WikiEditor/modules/ext.wikiEditor.templateEditor.js deleted file mode 100644 index 8879d10d..00000000 --- a/extensions/WikiEditor/modules/ext.wikiEditor.templateEditor.js +++ /dev/null @@ -1,12 +0,0 @@ -/* - * JavaScript for WikiEditor Template Editor - */ - -$( document ).ready( function () { - // Disable in template namespace - if ( mw.config.get( 'wgNamespaceNumber' ) === 10 ) { - return true; - } - // Add template editor module - $( 'textarea#wpTextbox1' ).wikiEditor( 'addModule', 'templateEditor' ); -}); diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.templates.js b/extensions/WikiEditor/modules/ext.wikiEditor.templates.js deleted file mode 100644 index 6eae6de5..00000000 --- a/extensions/WikiEditor/modules/ext.wikiEditor.templates.js +++ /dev/null @@ -1,12 +0,0 @@ -/* - * JavaScript for WikiEditor Templates - */ - -$( document ).ready( function () { - // Disable for template namespace - if ( mw.config.get( 'wgNamespaceNumber' ) === 10 ) { - return true; - } - // Add templates module - $( '#wpTextbox1' ).wikiEditor( 'addModule', 'templates' ); -} ); diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.tests.toolbar.js b/extensions/WikiEditor/modules/ext.wikiEditor.tests.toolbar.js index d4ffe5ae..3475284b 100644 --- a/extensions/WikiEditor/modules/ext.wikiEditor.tests.toolbar.js +++ b/extensions/WikiEditor/modules/ext.wikiEditor.tests.toolbar.js @@ -4,7 +4,7 @@ var textareaId = '#wpTextbox1'; var wikiEditorTests = { // Add emoticons section - add_sections_toolbar: { + 'add_sections_toolbar': { call: 'addToToolbar', data: { 'sections': { @@ -159,8 +159,8 @@ var wikiEditorTests = { data: { section: 'info', page: 'removeme' - }, - test: '*[rel=info].section *[rel=removeme].page', + }, + test: '*[rel=info].section *[rel=removeme].page', pre: 1, post: 0 }, @@ -171,8 +171,8 @@ var wikiEditorTests = { section: 'info', page: 'emoticons', 'character': ':))' - }, - test: '*[rel=info].section *[rel=emoticons].page *[rel=":))"]', + }, + test: '*[rel=info].section *[rel=emoticons].page *[rel=":))"]', pre: 1, post: 0 }, @@ -190,7 +190,7 @@ var wikiEditorTests = { } }; -jQuery(document).ready( function ( $ ) { +jQuery( document ).ready( function ( $ ) { var $button = $( '' ) .css( { position: 'fixed', @@ -206,12 +206,12 @@ jQuery(document).ready( function ( $ ) { cursor: 'pointer' } ) .click( function () { - if ( $(this).data( 'testDone' ) ) { - $(this).slideUp( 'fast' ); + if ( $( this ).data( 'testDone' ) ) { + $( this ).slideUp( 'fast' ); return false; } - var test, pre, post, + var test, pre, post, i, messages = [ 'Running tests for wikiEditor API' ], $target = $( textareaId ), $ui = $target.data( 'wikiEditor-context' ).$ui, @@ -234,13 +234,13 @@ jQuery(document).ready( function ( $ ) { } if ( window.console ) { - for ( var i = 0; i < messages.length; i++ ) { + for ( i = 0; i < messages.length; i++ ) { window.console.log( messages[i] ); } } - $(this) - .attr( 'title', messages.join( " | " ) ) + $( this ) + .attr( 'title', messages.join( ' | ' ) ) .text( passes + ' / ' + tests + ' were successful' ) .css( 'backgroundColor', passes < tests ? 'red' : 'green' ) .data( 'testDone', 'true' ) diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.toc.js b/extensions/WikiEditor/modules/ext.wikiEditor.toc.js deleted file mode 100644 index 264e9f86..00000000 --- a/extensions/WikiEditor/modules/ext.wikiEditor.toc.js +++ /dev/null @@ -1,8 +0,0 @@ -/* - * JavaScript for WikiEditor Table of Contents - */ - -$( document ).ready( function() { - // Add table of contents module - $( '#wpTextbox1' ).wikiEditor( 'addModule', 'toc' ); -} ); diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.hideSig.js b/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.hideSig.js index 3bc0f0b4..48d30274 100644 --- a/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.hideSig.js +++ b/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.hideSig.js @@ -1,7 +1,7 @@ /* * Remove the signature button if the main namespace is edited. */ -$( document ).ready( function() { +jQuery( document ).ready( function ( $ ) { // This module is designed not to depend on ext.wikiEditor or jquery.wikiEditor. // Removing this dependency fixed various bugs, but it does mean that we have to // account for the situation where $.wikiEditor is not present @@ -11,4 +11,4 @@ $( document ).ready( function() { if ( $( 'body' ).hasClass( 'ns-0' ) ) { $( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', { 'section': 'main', 'group': 'insert', 'tool': 'signature' } ); } -}); +} ); diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.js b/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.js index 5cdeae57..3f30c0c4 100644 --- a/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.js +++ b/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.js @@ -1,8 +1,7 @@ /* * JavaScript for WikiEditor Toolbar */ - -$( document ).ready( function() { +jQuery( document ).ready( function ( $ ) { if ( !$.wikiEditor.isSupported( $.wikiEditor.modules.toolbar ) ) { $( '.wikiEditor-oldToolbar' ).show(); return; diff --git a/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.styles.css b/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.styles.css new file mode 100644 index 00000000..cc80c169 --- /dev/null +++ b/extensions/WikiEditor/modules/ext.wikiEditor.toolbar.styles.css @@ -0,0 +1,25 @@ +/** + * CSS for WikiEditor + */ + +form#editform { + margin: 0; + padding: 0; +} + +#wpSummary, +#wpSummaryLabel { + margin-bottom: 1em; +} + +#wpTextbox1 { + line-height: 1.5em; + resize: vertical; +} + +/* Hide the old toolbar until the wikiEditor toolbar is deemed not supported, + * hide the WikiEditor toolbar until it's css has loaded */ +.wikiEditor-oldToolbar, +.wikiEditor-ui-toolbar { + display: none; +} diff --git a/extensions/WikiEditor/modules/images/templateEditor/collapse.png b/extensions/WikiEditor/modules/images/templateEditor/collapse.png deleted file mode 100644 index b155a180..00000000 Binary files a/extensions/WikiEditor/modules/images/templateEditor/collapse.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/templateEditor/dialog-collapsed.png b/extensions/WikiEditor/modules/images/templateEditor/dialog-collapsed.png deleted file mode 100644 index 0cb83821..00000000 Binary files a/extensions/WikiEditor/modules/images/templateEditor/dialog-collapsed.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/templateEditor/dialog-expanded.png b/extensions/WikiEditor/modules/images/templateEditor/dialog-expanded.png deleted file mode 100644 index 8cd3a8b3..00000000 Binary files a/extensions/WikiEditor/modules/images/templateEditor/dialog-expanded.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/templateEditor/expand.png b/extensions/WikiEditor/modules/images/templateEditor/expand.png deleted file mode 100644 index 1db80410..00000000 Binary files a/extensions/WikiEditor/modules/images/templateEditor/expand.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/templateEditor/name-base.png b/extensions/WikiEditor/modules/images/templateEditor/name-base.png deleted file mode 100644 index 0d1cce71..00000000 Binary files a/extensions/WikiEditor/modules/images/templateEditor/name-base.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/templateEditor/text-base.png b/extensions/WikiEditor/modules/images/templateEditor/text-base.png deleted file mode 100644 index 8fda004a..00000000 Binary files a/extensions/WikiEditor/modules/images/templateEditor/text-base.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/templateEditor/wiki-text.png b/extensions/WikiEditor/modules/images/templateEditor/wiki-text.png deleted file mode 100644 index 44afb4df..00000000 Binary files a/extensions/WikiEditor/modules/images/templateEditor/wiki-text.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/toc/close.png b/extensions/WikiEditor/modules/images/toc/close.png deleted file mode 100644 index a540856f..00000000 Binary files a/extensions/WikiEditor/modules/images/toc/close.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/toc/grab.png b/extensions/WikiEditor/modules/images/toc/grab.png deleted file mode 100644 index 6291ec86..00000000 Binary files a/extensions/WikiEditor/modules/images/toc/grab.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/toc/grip.png b/extensions/WikiEditor/modules/images/toc/grip.png deleted file mode 100644 index 07898519..00000000 Binary files a/extensions/WikiEditor/modules/images/toc/grip.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/toc/open.png b/extensions/WikiEditor/modules/images/toc/open.png deleted file mode 100644 index c782beb7..00000000 Binary files a/extensions/WikiEditor/modules/images/toc/open.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/toolbar/button-sprite.svg b/extensions/WikiEditor/modules/images/toolbar/button-sprite.svg new file mode 100644 index 00000000..061ffa38 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/button-sprite.svg @@ -0,0 +1,3038 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + A + + + + + A + + + + + B + + + + + F + + + + + G + + + + + N + + + + + P + + + + + V + + + + + A + + + + + + + + + + + A + + + + + C + + + + + + I + + + + + + K + + + + + A + + + + + 1 + 2 + 3 + + + + + + - + A + + + + + â–¼ + A + + + + + â–² + A + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + W + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1 + 2 + 3 + + + + + + + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-big.svg b/extensions/WikiEditor/modules/images/toolbar/format-big.svg new file mode 100644 index 00000000..68d0193a --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-big.svg @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + A + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-bold-A.svg b/extensions/WikiEditor/modules/images/toolbar/format-bold-A.svg new file mode 100644 index 00000000..83a0cb81 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-bold-A.svg @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + A + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-bold-B.svg b/extensions/WikiEditor/modules/images/toolbar/format-bold-B.svg new file mode 100644 index 00000000..ef04e499 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-bold-B.svg @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + B + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-bold-F.svg b/extensions/WikiEditor/modules/images/toolbar/format-bold-F.svg new file mode 100644 index 00000000..8c8de992 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-bold-F.svg @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + F + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-bold-G.svg b/extensions/WikiEditor/modules/images/toolbar/format-bold-G.svg new file mode 100644 index 00000000..4c924a63 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-bold-G.svg @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + G + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-bold-N.svg b/extensions/WikiEditor/modules/images/toolbar/format-bold-N.svg new file mode 100644 index 00000000..69c9c5a1 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-bold-N.svg @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + N + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-bold-P.svg b/extensions/WikiEditor/modules/images/toolbar/format-bold-P.svg new file mode 100644 index 00000000..96d36e6d --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-bold-P.svg @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + P + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-bold-V.svg b/extensions/WikiEditor/modules/images/toolbar/format-bold-V.svg new file mode 100644 index 00000000..2ef715af --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-bold-V.svg @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + V + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-bold-hy.png b/extensions/WikiEditor/modules/images/toolbar/format-bold-hy.png new file mode 100644 index 00000000..453a9580 Binary files /dev/null and b/extensions/WikiEditor/modules/images/toolbar/format-bold-hy.png differ diff --git a/extensions/WikiEditor/modules/images/toolbar/format-bold.svg b/extensions/WikiEditor/modules/images/toolbar/format-bold.svg new file mode 100644 index 00000000..83a0cb81 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-bold.svg @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + A + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-indent-rtl.png b/extensions/WikiEditor/modules/images/toolbar/format-indent-rtl.png deleted file mode 100644 index 6dbad6d4..00000000 Binary files a/extensions/WikiEditor/modules/images/toolbar/format-indent-rtl.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/toolbar/format-indent.png b/extensions/WikiEditor/modules/images/toolbar/format-indent.png deleted file mode 100644 index ec1ba450..00000000 Binary files a/extensions/WikiEditor/modules/images/toolbar/format-indent.png and /dev/null differ diff --git a/extensions/WikiEditor/modules/images/toolbar/format-indent.svg b/extensions/WikiEditor/modules/images/toolbar/format-indent.svg new file mode 100644 index 00000000..870274f9 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-indent.svg @@ -0,0 +1,220 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-italic-A.svg b/extensions/WikiEditor/modules/images/toolbar/format-italic-A.svg new file mode 100644 index 00000000..0e484a13 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-italic-A.svg @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + A + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-italic-C.svg b/extensions/WikiEditor/modules/images/toolbar/format-italic-C.svg new file mode 100644 index 00000000..d58e1deb --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-italic-C.svg @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + C + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-italic-K.svg b/extensions/WikiEditor/modules/images/toolbar/format-italic-K.svg new file mode 100644 index 00000000..25f31558 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-italic-K.svg @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + K + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-italic-hy.png b/extensions/WikiEditor/modules/images/toolbar/format-italic-hy.png new file mode 100644 index 00000000..108bae64 Binary files /dev/null and b/extensions/WikiEditor/modules/images/toolbar/format-italic-hy.png differ diff --git a/extensions/WikiEditor/modules/images/toolbar/format-italic-i.svg b/extensions/WikiEditor/modules/images/toolbar/format-italic-i.svg new file mode 100644 index 00000000..c5183082 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-italic-i.svg @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + I + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-italic.svg b/extensions/WikiEditor/modules/images/toolbar/format-italic.svg new file mode 100644 index 00000000..23b01c9c --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-italic.svg @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + A + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-olist.svg b/extensions/WikiEditor/modules/images/toolbar/format-olist.svg new file mode 100644 index 00000000..909cb94b --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-olist.svg @@ -0,0 +1,202 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + 1 + 2 + 3 + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-small.svg b/extensions/WikiEditor/modules/images/toolbar/format-small.svg new file mode 100644 index 00000000..af49cc73 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-small.svg @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + - + A + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-subscript.svg b/extensions/WikiEditor/modules/images/toolbar/format-subscript.svg new file mode 100644 index 00000000..f6d094da --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-subscript.svg @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + â–¼ + A + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-superscript.svg b/extensions/WikiEditor/modules/images/toolbar/format-superscript.svg new file mode 100644 index 00000000..0c94275c --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-superscript.svg @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + â–² + A + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/format-ulist.svg b/extensions/WikiEditor/modules/images/toolbar/format-ulist.svg new file mode 100644 index 00000000..21091807 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/format-ulist.svg @@ -0,0 +1,204 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/insert-file.svg b/extensions/WikiEditor/modules/images/toolbar/insert-file.svg new file mode 100644 index 00000000..012ffeff --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/insert-file.svg @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/insert-gallery.svg b/extensions/WikiEditor/modules/images/toolbar/insert-gallery.svg new file mode 100644 index 00000000..99d73797 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/insert-gallery.svg @@ -0,0 +1,191 @@ + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/insert-ilink.svg b/extensions/WikiEditor/modules/images/toolbar/insert-ilink.svg new file mode 100644 index 00000000..58a64a6c --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/insert-ilink.svg @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/insert-link.svg b/extensions/WikiEditor/modules/images/toolbar/insert-link.svg new file mode 100644 index 00000000..0a0f8c4a --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/insert-link.svg @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/insert-newline.svg b/extensions/WikiEditor/modules/images/toolbar/insert-newline.svg new file mode 100644 index 00000000..c7db3a8f --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/insert-newline.svg @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/insert-nowiki.svg b/extensions/WikiEditor/modules/images/toolbar/insert-nowiki.svg new file mode 100644 index 00000000..35a788d7 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/insert-nowiki.svg @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + W + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/insert-redirect.svg b/extensions/WikiEditor/modules/images/toolbar/insert-redirect.svg new file mode 100644 index 00000000..ca036928 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/insert-redirect.svg @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/insert-reference.svg b/extensions/WikiEditor/modules/images/toolbar/insert-reference.svg new file mode 100644 index 00000000..c404e860 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/insert-reference.svg @@ -0,0 +1,88 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/insert-signature.svg b/extensions/WikiEditor/modules/images/toolbar/insert-signature.svg new file mode 100644 index 00000000..d0fd5d89 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/insert-signature.svg @@ -0,0 +1,274 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/insert-table.svg b/extensions/WikiEditor/modules/images/toolbar/insert-table.svg new file mode 100644 index 00000000..3585edfc --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/insert-table.svg @@ -0,0 +1,131 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/insert-xlink.svg b/extensions/WikiEditor/modules/images/toolbar/insert-xlink.svg new file mode 100644 index 00000000..c7c664b5 --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/insert-xlink.svg @@ -0,0 +1,125 @@ + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/images/toolbar/search-replace.svg b/extensions/WikiEditor/modules/images/toolbar/search-replace.svg new file mode 100644 index 00000000..91cb6ace --- /dev/null +++ b/extensions/WikiEditor/modules/images/toolbar/search-replace.svg @@ -0,0 +1,228 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.css b/extensions/WikiEditor/modules/jquery.wikiEditor.css index d8e331cc..cabe6a94 100644 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.css +++ b/extensions/WikiEditor/modules/jquery.wikiEditor.css @@ -3,31 +3,27 @@ */ .wikiEditor-ui { - float: left; position: relative; clear: both; width: 100%; background-color: #E0EEf7; - border: solid silver 1px; - -moz-box-sizing: border-box; - -webkit-box-sizing: border-box; - box-sizing: border-box; } .wikiEditor-ui textarea { width: 100%; + border: 0; } .wikiEditor-ui textarea:focus { outline: none; } -.wikiEditor-ui .wikiEditor-ui-bottom { - +.wikiEditor-ui .wikiEditor-ui-clear { + clear: both; } -.wikiEditor-ui .wikiEditor-ui-text { - line-height: 0; +.wikiEditor-ui .wikiEditor-ui-view { + border: 1px solid silver; } .wikiEditor-ui .wikiEditor-ui-top { position: relative; - border-bottom: solid silver 1px; + border-bottom: 1px solid silver; } .wikiEditor-ui .wikiEditor-ui-left { float: left; @@ -46,16 +42,14 @@ float: left; width: 100%; background-color: white; - margin-top: -1px; - border-bottom: solid 1px silver; } .wikiEditor-ui-tabs { float: left; height: 2.5em; - margin-left: -1px; + margin-right: -1px; background-color: white; - border-left: solid 1px silver; - border-top: solid 1px silver; + border-left: 1px solid silver; + border-top: 1px solid silver; } .wikiEditor-ui-buttons { float: right; @@ -63,7 +57,7 @@ margin-right: -1px; background-color: white; padding-left: 1em; - border-top: solid 1px white; + border-top: 1px solid white; } .wikiEditor-ui-buttons button { margin-left: 0.5em; @@ -72,11 +66,11 @@ float: left; height: 2.5em; background-color: #f3f3f3; - border-right: solid 1px silver; - border-bottom: solid 1px silver; + border-right: 1px solid silver; + border-bottom: 1px solid silver; } .wikiEditor-ui-tabs div.current { - border-bottom: solid 1px white; + border-bottom: 1px solid white; background-color: white; } .wikiEditor-ui-tabs div a { diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.css b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.css index 39d9d50e..1cc9f5a1 100644 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.css +++ b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.css @@ -129,7 +129,7 @@ body.rtl .wikiEditor-toolbar-dialog .ui-dialog-buttonpane button { } .wikiEditor-template-dialog-fields .wikiEditor-template-dialog-field-wrapper { padding: 0.75em 0.33em; - border-bottom: dashed 1px silver; + border-bottom: 1px dashed silver; clear: both; } .wikiEditor-template-dialog-fields .wikiEditor-template-dialog-field-wrapper:first-child { diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js index 0d769164..8cd50a06 100644 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js +++ b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.config.js @@ -1,8 +1,12 @@ /** * Configuration of Dialog module for wikiEditor */ +/*jshint curly:false, noarg:false, quotmark:false, onevar:false */ +/*global alert */ ( function ( $, mw ) { +var hasOwn = Object.prototype.hasOwnProperty; + $.wikiEditor.modules.dialogs.config = { replaceIcons: function ( $textarea ) { @@ -124,7 +128,7 @@ $.wikiEditor.modules.dialogs.config = { if ( typeof arguments.callee.regex === 'undefined' ) { // Cache the regex arguments.callee.regex = - new RegExp( "^(" + mw.config.get( 'wgUrlProtocols' ) + "|www\\.)", 'i'); + new RegExp( "^(" + mw.config.get( 'wgUrlProtocols' ) + "|www\\.)", 'i' ); } return s.match( arguments.callee.regex ); } @@ -146,8 +150,8 @@ $.wikiEditor.modules.dialogs.config = { .addClass( 'disabled' ); } else { $( '.ui-dialog:visible .ui-dialog-buttonpane button:first' ) - .removeAttr('disabled') - .removeClass('disabled'); + .removeAttr( 'disabled' ) + .removeClass( 'disabled' ); } } @@ -165,7 +169,7 @@ $.wikiEditor.modules.dialogs.config = { } var target = $( '#wikieditor-toolbar-link-int-target' ).val(); var cache = $( '#wikieditor-toolbar-link-int-target-status' ).data( 'existencecache' ); - if ( cache[target] ) { + if ( hasOwn.call( cache, target ) ) { updateWidget( cache[target] ); return; } @@ -202,8 +206,8 @@ $.wikiEditor.modules.dialogs.config = { indexpageids: true } ).done( function ( data ) { var status; - if ( !data.query ) { - // This happens in some weird cases + if ( !data.query || !data.query.pages ) { + // This happens in some weird cases like interwiki links status = false; } else { var page = data.query.pages[data.query.pageids[0]]; @@ -226,7 +230,7 @@ $.wikiEditor.modules.dialogs.config = { ); } $( '#wikieditor-toolbar-link-type-int, #wikieditor-toolbar-link-type-ext' ).click( function () { - if ( $( '#wikieditor-toolbar-link-type-ext' ).is( ':checked' ) ) { + if ( $( '#wikieditor-toolbar-link-type-ext' ).prop( 'checked' ) ) { // Abort previous request var request = $( '#wikieditor-toolbar-link-int-target-status' ).data( 'request' ); if ( request ) { @@ -234,15 +238,16 @@ $.wikiEditor.modules.dialogs.config = { } updateWidget( 'external' ); } - if ( $( '#wikieditor-toolbar-link-type-int' ).is( ':checked' ) ) + if ( $( '#wikieditor-toolbar-link-type-int' ).prop( 'checked' ) ) { updateExistence( true ); - }); + } + } ); // Set labels of tabs based on rel values - $(this).find( '[rel]' ).each( function () { - $(this).text( mw.msg( $(this).attr( 'rel' ) ) ); - }); + $( this ).find( '[rel]' ).each( function () { + $( this ).text( mw.msg( $( this ).attr( 'rel' ) ) ); + } ); // Set tabindexes on form fields - $.wikiEditor.modules.dialogs.fn.setTabindexes( $(this).find( 'input' ).not( '[tabindex]' ) ); + $.wikiEditor.modules.dialogs.fn.setTabindexes( $( this ).find( 'input' ).not( '[tabindex]' ) ); // Setup the tooltips in the textboxes $( '#wikieditor-toolbar-link-int-target' ) .data( 'tooltip', mw.msg( 'wikieditor-toolbar-tool-link-int-target-tooltip' ) ); @@ -250,12 +255,12 @@ $.wikiEditor.modules.dialogs.config = { .data( 'tooltip', mw.msg( 'wikieditor-toolbar-tool-link-int-text-tooltip' ) ); $( '#wikieditor-toolbar-link-int-target, #wikieditor-toolbar-link-int-text' ) .each( function () { - var tooltip = mw.msg( $( this ).attr( 'id' ) + '-tooltip' ); - if ( $( this ).val() === '' ) + if ( $( this ).val() === '' ) { $( this ) .addClass( 'wikieditor-toolbar-dialog-hint' ) .val( $( this ).data( 'tooltip' ) ) .data( 'tooltip-mode', true ); + } } ) .focus( function () { if ( $( this ).val() === $( this ).data( 'tooltip' ) ) { @@ -264,14 +269,14 @@ $.wikiEditor.modules.dialogs.config = { .removeClass( 'wikieditor-toolbar-dialog-hint' ) .data( 'tooltip-mode', false ); } - }) + } ) .bind( 'change', function () { if ( $( this ).val() !== $( this ).data( 'tooltip' ) ) { $( this ) .removeClass( 'wikieditor-toolbar-dialog-hint' ) .data( 'tooltip-mode', false ); } - }) + } ) .bind( 'blur', function () { if ( $( this ).val() === '' ) { $( this ) @@ -279,13 +284,13 @@ $.wikiEditor.modules.dialogs.config = { .val( $( this ).data( 'tooltip' ) ) .data( 'tooltip-mode', true ); } - }); + } ); // Automatically copy the value of the internal link page title field to the link text field unless the // user has changed the link text field - this is a convenience thing since most link texts are going to // be the the same as the page title - Also change the internal/external radio button accordingly $( '#wikieditor-toolbar-link-int-target' ).bind( 'change keydown paste cut', function () { - // $(this).val() is the old value, before the keypress - Defer this until $(this).val() has + // $( this ).val() is the old value, before the keypress - Defer this until $( this ).val() has // been updated setTimeout( function () { if ( isExternalLink( $( '#wikieditor-toolbar-link-int-target' ).val() ) ) { @@ -295,28 +300,32 @@ $.wikiEditor.modules.dialogs.config = { $( '#wikieditor-toolbar-link-type-int' ).prop( 'checked', true ); updateExistence(); } - if ( $( '#wikieditor-toolbar-link-int-text' ).data( 'untouched' ) ) + /*jshint eqeqeq:false */ + if ( $( '#wikieditor-toolbar-link-int-text' ).data( 'untouched' ) ) { if ( $( '#wikieditor-toolbar-link-int-target' ).val() == - $( '#wikieditor-toolbar-link-int-target' ).data( 'tooltip' ) ) { - $( '#wikieditor-toolbar-link-int-text' ) - .addClass( 'wikieditor-toolbar-dialog-hint' ) - .val( $( '#wikieditor-toolbar-link-int-text' ).data( 'tooltip' ) ) - .change(); - } else { - $( '#wikieditor-toolbar-link-int-text' ) - .val( $( '#wikieditor-toolbar-link-int-target' ).val() ) - .change(); - } + $( '#wikieditor-toolbar-link-int-target' ).data( 'tooltip' ) + ) { + $( '#wikieditor-toolbar-link-int-text' ) + .addClass( 'wikieditor-toolbar-dialog-hint' ) + .val( $( '#wikieditor-toolbar-link-int-text' ).data( 'tooltip' ) ) + .change(); + } else { + $( '#wikieditor-toolbar-link-int-text' ) + .val( $( '#wikieditor-toolbar-link-int-target' ).val() ) + .change(); + } + } }, 0 ); - }); + } ); $( '#wikieditor-toolbar-link-int-text' ).bind( 'change keydown paste cut', function () { - var oldVal = $(this).val(); + var oldVal = $( this ).val(); var that = this; setTimeout( function () { - if ( $(that).val() !== oldVal ) - $(that).data( 'untouched', false ); + if ( $( that ).val() !== oldVal ) { + $( that ).data( 'untouched', false ); + } }, 0 ); - }); + } ); // Add images to the page existence widget, which will be shown mutually exclusively to communicate if // the page exists, does not exist or the title is invalid (like if it contains a | character) var existsMsg = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-exists' ); @@ -360,18 +369,18 @@ $.wikiEditor.modules.dialogs.config = { $( '#wikieditor-toolbar-link-int-target' ) .bind( 'keyup paste cut', function () { // Cancel the running timer if applicable - if ( typeof $(this).data( 'timerID' ) !== 'undefined' ) { - clearTimeout( $(this).data( 'timerID' ) ); + if ( typeof $( this ).data( 'timerID' ) !== 'undefined' ) { + clearTimeout( $( this ).data( 'timerID' ) ); } // Delay fetch for a while // FIXME: Make 120 configurable elsewhere var timerID = setTimeout( updateExistence, 120 ); - $(this).data( 'timerID', timerID ); + $( this ).data( 'timerID', timerID ); } ) .change( function () { // Cancel the running timer if applicable - if ( typeof $(this).data( 'timerID' ) !== 'undefined' ) { - clearTimeout( $(this).data( 'timerID' ) ); + if ( typeof $( this ).data( 'timerID' ) !== 'undefined' ) { + clearTimeout( $( this ).data( 'timerID' ) ); } // Fetch right now updateExistence(); @@ -379,18 +388,18 @@ $.wikiEditor.modules.dialogs.config = { // Title suggestions $( '#wikieditor-toolbar-link-int-target' ).data( 'suggcache', {} ).suggestions( { - fetch: function ( query ) { + fetch: function () { var that = this; - var title = $(this).val(); + var title = $( this ).val(); - if ( isExternalLink( title ) || title.indexOf( '|' ) !== -1 || title === '') { - $(this).suggestions( 'suggestions', [] ); + if ( isExternalLink( title ) || title.indexOf( '|' ) !== -1 || title === '' ) { + $( this ).suggestions( 'suggestions', [] ); return; } - var cache = $(this).data( 'suggcache' ); - if ( typeof cache[title] !== 'undefined' ) { - $(this).suggestions( 'suggestions', cache[title] ); + var cache = $( this ).data( 'suggcache' ); + if ( hasOwn.call( cache, title ) ) { + $( this ).suggestions( 'suggestions', cache[title] ); return; } @@ -406,17 +415,17 @@ $.wikiEditor.modules.dialogs.config = { dataType: 'json', success: function ( data ) { cache[title] = data[1]; - $(that).suggestions( 'suggestions', data[1] ); + $( that ).suggestions( 'suggestions', data[1] ); } - }); - $(this).data( 'request', request ); + } ); + $( this ).data( 'request', request ); }, cancel: function () { - var request = $(this).data( 'request' ); + var request = $( this ).data( 'request' ); if ( request ) request.abort(); } - }); + } ); }, dialog: { width: 500, @@ -470,21 +479,21 @@ $.wikiEditor.modules.dialogs.config = { target = 'http://' + target; // Detect if this is really an internal link in disguise - var match = target.match( $(this).data( 'articlePathRegex' ) ); - if ( match && !$(this).data( 'ignoreLooksInternal' ) ) { + var match = target.match( $( this ).data( 'articlePathRegex' ) ); + if ( match && !$( this ).data( 'ignoreLooksInternal' ) ) { var buttons = { }; var that = this; buttons[ mw.msg( 'wikieditor-toolbar-tool-link-lookslikeinternal-int' ) ] = function () { $( '#wikieditor-toolbar-link-int-target' ).val( match[1] ).change(); - $(this).dialog( 'close' ); + $( this ).dialog( 'close' ); }; buttons[ mw.msg( 'wikieditor-toolbar-tool-link-lookslikeinternal-ext' ) ] = function () { - $(that).data( 'ignoreLooksInternal', true ); - $(that).closest( '.ui-dialog' ).find( 'button:first' ).click(); - $(that).data( 'ignoreLooksInternal', false ); - $(this).dialog( 'close' ); + $( that ).data( 'ignoreLooksInternal', true ); + $( that ).closest( '.ui-dialog' ).find( 'button:first' ).click(); + $( that ).data( 'ignoreLooksInternal', false ); + $( this ).dialog( 'close' ); }; $.wikiEditor.modules.dialogs.quickDialog( mw.msg( 'wikieditor-toolbar-tool-link-lookslikeinternal', match[1] ), @@ -507,13 +516,13 @@ $.wikiEditor.modules.dialogs.config = { if ( whitespace ) { insertText = whitespace[0] + insertText + whitespace[1]; } - $(this).dialog( 'close' ); - $.wikiEditor.modules.toolbar.fn.doAction( $(this).data( 'context' ), { + $( this ).dialog( 'close' ); + $.wikiEditor.modules.toolbar.fn.doAction( $( this ).data( 'context' ), { type: 'replace', options: { pre: insertText } - }, $(this) ); + }, $( this ) ); // Blank form $( '#wikieditor-toolbar-link-int-target, #wikieditor-toolbar-link-int-text' ).val( '' ); @@ -522,9 +531,9 @@ $.wikiEditor.modules.dialogs.config = { }, 'wikieditor-toolbar-tool-link-cancel': function () { // Clear any saved selection state - var context = $(this).data( 'context' ); + var context = $( this ).data( 'context' ); context.fn.restoreCursorAndScrollTop(); - $(this).dialog( 'close' ); + $( this ).dialog( 'close' ); } }, open: function () { @@ -533,12 +542,12 @@ $.wikiEditor.modules.dialogs.config = { // Obtain the server name without the protocol. wgServer may be protocol-relative var serverName = mw.config.get( 'wgServer' ).replace( /^(https?:)?\/\//, '' ); // Cache the articlepath regex - $(this).data( 'articlePathRegex', new RegExp( + $( this ).data( 'articlePathRegex', new RegExp( '^https?://' + $.escapeRE( serverName + mw.config.get( 'wgArticlePath' ) ) .replace( /\\\$1/g, '(.*)' ) + '$' ) ); // Pre-fill the text fields based on the current selection - var context = $(this).data( 'context' ); + var context = $( this ).data( 'context' ); // Restore and immediately save selection state, needed for inserting stuff later context.fn.restoreCursorAndScrollTop(); context.fn.saveCursorAndScrollTop(); @@ -599,27 +608,27 @@ $.wikiEditor.modules.dialogs.config = { $( '#wikieditor-toolbar-link-int-text, #wikiedit-toolbar-link-int-target' ) .each( function () { - if ( $(this).val() === '' ) - $(this).parent().find( 'label' ).show(); - }); + if ( $( this ).val() === '' ) + $( this ).parent().find( 'label' ).show(); + } ); - if ( !$(this).data( 'dialogkeypressset' ) ) { - $(this).data( 'dialogkeypressset', true ); + if ( !$( this ).data( 'dialogkeypressset' ) ) { + $( this ).data( 'dialogkeypressset', true ); // Execute the action associated with the first button // when the user presses Enter - $(this).closest( '.ui-dialog' ).keypress( function ( e ) { - if ( ( e.keyCode || e.which ) == 13 ) { - var button = $(this).data( 'dialogaction' ) || $(this).find( 'button:first' ); + $( this ).closest( '.ui-dialog' ).keypress( function ( e ) { + if ( ( e.keyCode || e.which ) === 13 ) { + var button = $( this ).data( 'dialogaction' ) || $( this ).find( 'button:first' ); button.click(); e.preventDefault(); } - }); + } ); // Make tabbing to a button and pressing // Enter do what people expect - $(this).closest( '.ui-dialog' ).find( 'button' ).focus( function () { - $(this).closest( '.ui-dialog' ).data( 'dialogaction', this ); - }); + $( this ).closest( '.ui-dialog' ).find( 'button' ).focus( function () { + $( this ).closest( '.ui-dialog' ).data( 'dialogaction', this ); + } ); } } } @@ -678,7 +687,7 @@ $.wikiEditor.modules.dialogs.config = { }, open: function () { // Pre-fill the text fields based on the current selection - var context = $(this).data( 'context' ); + var context = $( this ).data( 'context' ); // Restore and immediately save selection state, needed for inserting stuff later context.fn.restoreCursorAndScrollTop(); context.fn.saveCursorAndScrollTop(); @@ -706,7 +715,7 @@ $.wikiEditor.modules.dialogs.config = { // Execute the action associated with the first button // when the user presses Enter $( this ).closest( '.ui-dialog' ).keypress( function ( e ) { - if ( ( e.keyCode || e.which ) == 13 ) { + if ( ( e.keyCode || e.which ) === 13 ) { var button = $( this ).data( 'dialogaction' ) || $( this ).find( 'button:first' ); button.click(); e.preventDefault(); @@ -767,7 +776,7 @@ $.wikiEditor.modules.dialogs.config = { .find( '[data-i18n-magic]' ) .text( function () { return magicWordsI18N[ $( this ).attr( 'data-i18n-magic' ) ]; - }) + } ) .removeAttr( 'data-i18n-magic' ) .end() .find( '#wikieditor-toolbar-file-size' ) @@ -778,7 +787,7 @@ $.wikiEditor.modules.dialogs.config = { .find( '[rel]' ) .text( function () { return mw.msg( $( this ).attr( 'rel' ) ); - }) + } ) .removeAttr( 'rel' ) .end(); }, @@ -790,7 +799,8 @@ $.wikiEditor.modules.dialogs.config = { 'wikieditor-toolbar-tool-file-insert': function () { var fileName, caption, fileFloat, fileFormat, fileSize, fileTitle, options, fileUse, - hasPxRgx = /.+px$/; + hasPxRgx = /.+px$/, + magicWordsI18N = mw.config.get( 'wgWikiEditorMagicWords' ); fileName = $( '#wikieditor-toolbar-file-target' ).val(); caption = $( '#wikieditor-toolbar-file-caption' ).val(); fileFloat = $( '#wikieditor-toolbar-file-float' ).val(); @@ -835,10 +845,11 @@ $.wikiEditor.modules.dialogs.config = { // Restore form state $( ['#wikieditor-toolbar-file-target', '#wikieditor-toolbar-file-caption', - '#wikieditor-toolbar-file-size', - '#wikieditor-toolbar-file-float', - '#wikieditor-toolbar-file-format'].join( ',' ) + '#wikieditor-toolbar-file-size'].join( ',' ) ).val( '' ); + $( '#wikieditor-toolbar-file-float' ).val( 'default' ); + /*jshint camelcase: false */ + $( '#wikieditor-toolbar-file-format' ).val( magicWordsI18N.img_thumbnail ); }, 'wikieditor-toolbar-tool-file-cancel': function () { $( this ).dialog( 'close' ); @@ -850,20 +861,20 @@ $.wikiEditor.modules.dialogs.config = { $( this ).data( 'dialogkeypressset', true ); // Execute the action associated with the first button // when the user presses Enter - $( this ).closest( '.ui-dialog' ).keypress( function( e ) { + $( this ).closest( '.ui-dialog' ).keypress( function ( e ) { if ( e.which === 13 ) { var button = $( this ).data( 'dialogaction' ) || $( this ).find( 'button:first' ); button.click(); e.preventDefault(); } - }); + } ); // Make tabbing to a button and pressing // Enter do what people expect - $( this ).closest( '.ui-dialog' ).find( 'button' ).focus( function() { + $( this ).closest( '.ui-dialog' ).find( 'button' ).focus( function () { $( this ).closest( '.ui-dialog' ).data( 'dialogaction', this ); - }); + } ); } } } @@ -934,17 +945,17 @@ $.wikiEditor.modules.dialogs.config = { \ ', init: function () { - $(this).find( '[rel]' ).each( function () { - $(this).text( mw.msg( $(this).attr( 'rel' ) ) ); - }); + $( this ).find( '[rel]' ).each( function () { + $( this ).text( mw.msg( $( this ).attr( 'rel' ) ) ); + } ); // Set tabindexes on form fields - $.wikiEditor.modules.dialogs.fn.setTabindexes( $(this).find( 'input' ).not( '[tabindex]' ) ); + $.wikiEditor.modules.dialogs.fn.setTabindexes( $( this ).find( 'input' ).not( '[tabindex]' ) ); $( '#wikieditor-toolbar-table-dimensions-rows' ).val( 3 ); $( '#wikieditor-toolbar-table-dimensions-columns' ).val( 3 ); $( '#wikieditor-toolbar-table-wikitable' ).click( function () { $( '.wikieditor-toolbar-table-preview' ).toggleClass( 'wikitable' ); - }); + } ); // Hack for sortable preview: dynamically adding // sortable class doesn't work, so we use a clone @@ -957,7 +968,7 @@ $.wikiEditor.modules.dialogs.config = { mw.loader.using( 'jquery.tablesorter', function () { $( '#wikieditor-toolbar-table-preview2' ).tablesorter(); - }); + } ); $( '#wikieditor-toolbar-table-sortable' ).click( function () { // Swap the currently shown one clone with the other one @@ -968,7 +979,7 @@ $.wikiEditor.modules.dialogs.config = { .attr( 'id', 'wikieditor-toolbar-table-preview' ) .show(); $( '#wikieditor-toolbar-table-preview3' ).attr( 'id', 'wikieditor-toolbar-table-preview2' ); - }); + } ); $( '#wikieditor-toolbar-table-dimensions-header' ).click( function () { // Instead of show/hiding, switch the HTML around @@ -978,12 +989,12 @@ $.wikiEditor.modules.dialogs.config = { var hiddenHTML = $( '.wikieditor-toolbar-table-preview-hidden' ).html(); $( '.wikieditor-toolbar-table-preview-header' ).html( hiddenHTML ); $( '.wikieditor-toolbar-table-preview-hidden' ).html( headerHTML ); - if ( typeof jQuery.fn.tablesorter == 'function' ) { - $( '#wikieditor-toolbar-table-preview, #wikieditor-toolbar-table-preview2' ) - .filter( '.sortable' ) - .tablesorter(); + if ( typeof jQuery.fn.tablesorter === 'function' ) { + $( '#wikieditor-toolbar-table-preview, #wikieditor-toolbar-table-preview2' ) + .filter( '.sortable' ) + .tablesorter(); } - }); + } ); }, dialog: { resizable: false, @@ -996,7 +1007,7 @@ $.wikiEditor.modules.dialogs.config = { var rows = parseInt( rowsVal, 10 ); var cols = parseInt( colsVal, 10 ); var header = $( '#wikieditor-toolbar-table-dimensions-header' ).prop( 'checked' ) ? 1 : 0; - if ( isNaN( rows ) || isNaN( cols ) || String( rows ) !== rowsVal || String( cols ) !== colsVal || rowsVal < 0 || colsVal < 0 ) { + if ( isNaN( rows ) || isNaN( cols ) || String( rows ) !== rowsVal || String( cols ) !== colsVal || rowsVal < 0 || colsVal < 0 ) { alert( mw.msg( 'wikieditor-toolbar-tool-table-invalidnumber' ) ); return; } @@ -1032,9 +1043,9 @@ $.wikiEditor.modules.dialogs.config = { if ( $( '#wikieditor-toolbar-table-sortable' ).is( ':checked' ) ) classes.push( 'sortable' ); var classStr = classes.length > 0 ? ' class="' + classes.join( ' ' ) + '"' : ''; - $(this).dialog( 'close' ); + $( this ).dialog( 'close' ); $.wikiEditor.modules.toolbar.fn.doAction( - $(this).data( 'context' ), + $( this ).data( 'context' ), { type: 'replace', options: { @@ -1044,7 +1055,7 @@ $.wikiEditor.modules.dialogs.config = { ownline: true } }, - $(this) + $( this ) ); // Restore form state @@ -1060,28 +1071,28 @@ $.wikiEditor.modules.dialogs.config = { $( '#wikieditor-toolbar-table-sortable' ).click(); }, 'wikieditor-toolbar-tool-table-cancel': function () { - $(this).dialog( 'close' ); + $( this ).dialog( 'close' ); } }, open: function () { $( '#wikieditor-toolbar-table-dimensions-rows' ).focus(); - if ( !( $(this).data( 'dialogkeypressset' ) ) ) { - $(this).data( 'dialogkeypressset', true ); + if ( !( $( this ).data( 'dialogkeypressset' ) ) ) { + $( this ).data( 'dialogkeypressset', true ); // Execute the action associated with the first button // when the user presses Enter - $(this).closest( '.ui-dialog' ).keypress( function ( e ) { - if ( ( e.keyCode || e.which ) == 13 ) { - var button = $(this).data( 'dialogaction' ) || $(this).find( 'button:first' ); + $( this ).closest( '.ui-dialog' ).keypress( function ( e ) { + if ( ( e.keyCode || e.which ) === 13 ) { + var button = $( this ).data( 'dialogaction' ) || $( this ).find( 'button:first' ); button.click(); e.preventDefault(); } - }); + } ); // Make tabbing to a button and pressing // Enter do what people expect - $(this).closest( '.ui-dialog' ).find( 'button' ).focus( function () { - $(this).closest( '.ui-dialog' ).data( 'dialogaction', this ); - }); + $( this ).closest( '.ui-dialog' ).find( 'button' ).focus( function () { + $( this ).closest( '.ui-dialog' ).data( 'dialogaction', this ); + } ); } } } @@ -1133,14 +1144,14 @@ $.wikiEditor.modules.dialogs.config = { \ ', init: function () { - $(this).find( '[rel]' ).each( function () { - $(this).text( mw.msg( $(this).attr( 'rel' ) ) ); - }); + $( this ).find( '[rel]' ).each( function () { + $( this ).text( mw.msg( $( this ).attr( 'rel' ) ) ); + } ); // Set tabindexes on form fields - $.wikiEditor.modules.dialogs.fn.setTabindexes( $(this).find( 'input' ).not( '[tabindex]' ) ); + $.wikiEditor.modules.dialogs.fn.setTabindexes( $( this ).find( 'input' ).not( '[tabindex]' ) ); // TODO: Find a cleaner way to share this function - $(this).data( 'replaceCallback', function ( mode ) { + $( this ).data( 'replaceCallback', function ( mode ) { var offset, textRemainder, regex, index, i, start, end; @@ -1180,14 +1191,14 @@ $.wikiEditor.modules.dialogs.config = { return; } - var $textarea = $(this).data( 'context' ).$textarea; + var $textarea = $( this ).data( 'context' ).$textarea; var text = $textarea.textSelection( 'getContents' ); var match = false; if ( mode !== 'replaceAll' ) { if ( mode === 'replace' ) { - offset = $(this).data( 'matchIndex' ); + offset = $( this ).data( 'matchIndex' ); } else { - offset = $(this).data( 'offset' ); + offset = $( this ).data( 'offset' ); } textRemainder = text.substr( offset ); match = textRemainder.match( regex ); @@ -1202,7 +1213,7 @@ $.wikiEditor.modules.dialogs.config = { if ( !match ) { $( '#wikieditor-toolbar-replace-nomatch' ).show(); - } else if ( mode == 'replaceAll' ) { + } else if ( mode === 'replaceAll' ) { // Instead of using repetitive .match() calls, we use one .match() call with /g // and indexOf() followed by substr() to find the offsets. This is actually // faster because our indexOf+substr loop is faster than a match loop, and the @@ -1234,20 +1245,20 @@ $.wikiEditor.modules.dialogs.config = { $( '#wikieditor-toolbar-replace-success' ) .text( mw.msg( 'wikieditor-toolbar-tool-replace-success', match.length ) ) .show(); - $(this).data( 'offset', 0 ); + $( this ).data( 'offset', 0 ); } else { - if ( mode == 'replace' ) { + if ( mode === 'replace' ) { var actualReplacement; - if (isRegex) { + if ( isRegex ) { // If backreferences (like $1) are used, the actual actual replacement string will be different actualReplacement = match[0].replace( regex, replaceStr ); } else { actualReplacement = replaceStr; } - if (match) { + if ( match ) { // Do the replacement $textarea.textSelection( 'encapsulateSelection', { 'peri': actualReplacement, @@ -1261,7 +1272,7 @@ $.wikiEditor.modules.dialogs.config = { textRemainder = text.substr( offset ); match = textRemainder.match( regex ); - if (match) { + if ( match ) { start = offset + match.index; end = start + match[0].length; } else { @@ -1269,7 +1280,7 @@ $.wikiEditor.modules.dialogs.config = { // TODO: Add a "Wrap around" option. textRemainder = text; match = textRemainder.match( regex ); - if (match) { + if ( match ) { start = match.index; end = start + match[0].length; } else { @@ -1283,7 +1294,7 @@ $.wikiEditor.modules.dialogs.config = { end = start + match[0].length; } - $( this ).data( 'matchIndex', start); + $( this ).data( 'matchIndex', start ); $textarea.textSelection( 'setSelection', { 'start': start, @@ -1291,12 +1302,9 @@ $.wikiEditor.modules.dialogs.config = { } ); $textarea.textSelection( 'scrollToCaretPosition' ); $( this ).data( 'offset', end ); - var context = $( this ).data( 'context' ); - var textbox = typeof context.$iframe !== 'undefined' ? - context.$iframe[0].contentWindow : $textarea[0]; - textbox.focus(); + $textarea[0].focus(); } - }); + } ); }, dialog: { width: 500, @@ -1304,69 +1312,67 @@ $.wikiEditor.modules.dialogs.config = { modal: false, buttons: { 'wikieditor-toolbar-tool-replace-button-findnext': function ( e ) { - $(this).closest( '.ui-dialog' ).data( 'dialogaction', e.target ); - $(this).data( 'replaceCallback' ).call( this, 'find' ); + $( this ).closest( '.ui-dialog' ).data( 'dialogaction', e.target ); + $( this ).data( 'replaceCallback' ).call( this, 'find' ); }, 'wikieditor-toolbar-tool-replace-button-replace': function ( e ) { - $(this).closest( '.ui-dialog' ).data( 'dialogaction', e.target ); - $(this).data( 'replaceCallback' ).call( this, 'replace' ); + $( this ).closest( '.ui-dialog' ).data( 'dialogaction', e.target ); + $( this ).data( 'replaceCallback' ).call( this, 'replace' ); }, 'wikieditor-toolbar-tool-replace-button-replaceall': function ( e ) { - $(this).closest( '.ui-dialog' ).data( 'dialogaction', e.target ); - $(this).data( 'replaceCallback' ).call( this, 'replaceAll' ); + $( this ).closest( '.ui-dialog' ).data( 'dialogaction', e.target ); + $( this ).data( 'replaceCallback' ).call( this, 'replaceAll' ); }, 'wikieditor-toolbar-tool-replace-close': function () { - $(this).dialog( 'close' ); + $( this ).dialog( 'close' ); } }, open: function () { - $(this).data( 'offset', 0 ); - $(this).data( 'matchIndex', 0 ); + $( this ).data( 'offset', 0 ); + $( this ).data( 'matchIndex', 0 ); $( '#wikieditor-toolbar-replace-search' ).focus(); $( '#wikieditor-toolbar-replace-nomatch, #wikieditor-toolbar-replace-success, #wikieditor-toolbar-replace-emptysearch, #wikieditor-toolbar-replace-invalidregex' ).hide(); - if ( !( $(this).data( 'onetimeonlystuff' ) ) ) { - $(this).data( 'onetimeonlystuff', true ); + if ( !( $( this ).data( 'onetimeonlystuff' ) ) ) { + $( this ).data( 'onetimeonlystuff', true ); // Execute the action associated with the first button // when the user presses Enter - $(this).closest( '.ui-dialog' ).keypress( function ( e ) { - if ( ( e.keyCode || e.which ) == 13 ) { - var button = $(this).data( 'dialogaction' ) || $(this).find( 'button:first' ); + $( this ).closest( '.ui-dialog' ).keypress( function ( e ) { + if ( ( e.keyCode || e.which ) === 13 ) { + var button = $( this ).data( 'dialogaction' ) || $( this ).find( 'button:first' ); button.click(); e.preventDefault(); } - }); + } ); // Make tabbing to a button and pressing // Enter do what people expect - $(this).closest( '.ui-dialog' ).find( 'button' ).focus( function () { - $(this).closest( '.ui-dialog' ).data( 'dialogaction', this ); - }); + $( this ).closest( '.ui-dialog' ).find( 'button' ).focus( function () { + $( this ).closest( '.ui-dialog' ).data( 'dialogaction', this ); + } ); } - var dialog = $(this).closest( '.ui-dialog' ); + var dialog = $( this ).closest( '.ui-dialog' ); var that = this; - var context = $(this).data( 'context' ); - var textbox = typeof context.$iframe !== 'undefined' ? - context.$iframe[0].contentWindow.document : context.$textarea; + var context = $( this ).data( 'context' ); + var textbox = context.$textarea; $( textbox ) .bind( 'keypress.srdialog', function ( e ) { - if ( e.which == 13 ) { + if ( e.which === 13 ) { // Enter var button = dialog.data( 'dialogaction' ) || dialog.find( 'button:first' ); button.click(); e.preventDefault(); - } else if ( e.which == 27 ) { + } else if ( e.which === 27 ) { // Escape - $(that).dialog( 'close' ); + $( that ).dialog( 'close' ); } - }); + } ); }, close: function () { - var context = $(this).data( 'context' ); - var textbox = typeof context.$iframe !== 'undefined' ? - context.$iframe[0].contentWindow.document : context.$textarea; + var context = $( this ).data( 'context' ); + var textbox = context.$textarea; $( textbox ).unbind( 'keypress.srdialog' ); - $(this).closest( '.ui-dialog' ).data( 'dialogaction', false ); + $( this ).closest( '.ui-dialog' ).data( 'dialogaction', false ); } } } diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.js b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.js index f6d86d78..907b0485 100644 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.js +++ b/extensions/WikiEditor/modules/jquery.wikiEditor.dialogs.js @@ -42,8 +42,8 @@ $.wikiEditor.modules.dialogs = { }, openDialog: function ( context, module ) { if ( module in $.wikiEditor.modules.dialogs.modules ) { - var mod = $.wikiEditor.modules.dialogs.modules[module]; - var $dialog = $( '#' + mod.id ); + var mod = $.wikiEditor.modules.dialogs.modules[module], + $dialog = $( '#' + mod.id ); if ( $dialog.length === 0 ) { $.wikiEditor.modules.dialogs.fn.reallyCreate( context, mod, module ); $dialog = $( '#' + mod.id ); @@ -77,12 +77,12 @@ $.wikiEditor.modules.dialogs = { create: function ( context, config ) { var mod, module, filtered, i, $existingDialog; - // Defer building of modules, but do check whether they need the iframe rightaway + // Defer building of modules, unless they require immediate creation for ( mod in config ) { module = config[mod]; // Only create the dialog if it's supported, isn't filtered and doesn't exist yet filtered = false; - if ( typeof module.filters != 'undefined' ) { + if ( typeof module.filters !== 'undefined' ) { for ( i = 0; i < module.filters.length; i++ ) { if ( $( module.filters[i] ).length === 0 ) { filtered = true; @@ -92,17 +92,13 @@ $.wikiEditor.modules.dialogs = { } // If the dialog already exists, but for another textarea, simply remove it $existingDialog = $( '#' + module.id ); - if ( $existingDialog.length > 0 && $existingDialog.data( 'context' ).$textarea != context.$textarea ) { + if ( $existingDialog.length > 0 && $existingDialog.data( 'context' ).$textarea !== context.$textarea ) { $existingDialog.remove(); } // Re-select from the DOM, we might have removed the dialog just now $existingDialog = $( '#' + module.id ); if ( !filtered && $.wikiEditor.isSupported( module ) && $existingDialog.length === 0 ) { $.wikiEditor.modules.dialogs.modules[mod] = module; - // If this dialog requires the iframe, set it up - if ( typeof context.$iframe === 'undefined' && $.wikiEditor.isRequired( module, 'iframe' ) ) { - context.fn.setupIframe(); - } context.$textarea.trigger( 'wikiEditor-dialogs-setup-' + mod ); // If this dialog requires immediate creation, create it now if ( typeof module.immediateCreate !== 'undefined' && module.immediateCreate ) { @@ -119,13 +115,13 @@ $.wikiEditor.modules.dialogs = { * @param {String} name Dialog name (key in $.wikiEditor.modules.dialogs.modules) */ reallyCreate: function ( context, module, name ) { - var msg, + var msg, dialogDiv, configuration = module.dialog; // Add some stuff to configuration configuration.bgiframe = true; configuration.autoOpen = false; // By default our dialogs are modal, unless explicitely defined in their specific configuration. - if( typeof configuration.modal == "undefined" ) { + if ( typeof configuration.modal === 'undefined' ) { configuration.modal = true; } configuration.title = $.wikiEditor.autoMsg( module, 'title' ); @@ -138,7 +134,7 @@ $.wikiEditor.modules.dialogs = { } configuration.buttons = configuration.newButtons; // Create the dialog
- var dialogDiv = $( '
' ) + dialogDiv = $( '
' ) .attr( 'id', module.id ) .html( module.html ) .data( 'context', context ) @@ -152,9 +148,9 @@ $.wikiEditor.modules.dialogs = { dialogDiv .bind( 'dialogopen', $.wikiEditor.modules.dialogs.fn.resize ) .find( '.ui-tabs' ).bind( 'tabsshow', function () { - $(this).closest( '.ui-dialog-content' ).each( + $( this ).closest( '.ui-dialog-content' ).each( $.wikiEditor.modules.dialogs.fn.resize ); - }); + } ); } dialogDiv.bind( 'dialogclose', function () { context.fn.restoreSelection(); @@ -171,36 +167,38 @@ $.wikiEditor.modules.dialogs = { * NOTE: This function assumes $.ui.dialog has already been loaded */ resize: function () { - var wrapper = $(this).closest( '.ui-dialog' ); - var oldWidth = wrapper.width(); - // Make sure elements don't wrapped so we get an accurate idea of whether they really fit. Also temporarily show - // hidden elements. Work around jQuery bug where
inside a dialog is both - // :visible and :hidden - var oldHidden = $(this).find( '*' ).not( ':visible' ); + var oldWS, thisWidth, wrapperWidth, + wrapper = $( this ).closest( '.ui-dialog' ), + oldWidth = wrapper.width(), + // Make sure elements don't wrapped so we get an accurate idea of whether they really fit. Also temporarily show + // hidden elements. Work around jQuery bug where
inside a dialog is both + // :visible and :hidden + oldHidden = $( this ).find( '*' ).not( ':visible' ); + // Save the style attributes of the hidden elements to restore them later. Calling hide() after show() messes up // for elements hidden with a class oldHidden.each( function () { - $(this).data( 'oldstyle', $(this).attr( 'style' ) ); - }); + $( this ).data( 'oldstyle', $( this ).attr( 'style' ) ); + } ); oldHidden.show(); - var oldWS = $(this).css( 'white-space' ); - $(this).css( 'white-space', 'nowrap' ); - if ( wrapper.width() <= $(this).get(0).scrollWidth ) { - var thisWidth = $(this).data( 'thisWidth' ) ? $(this).data( 'thisWidth' ) : 0; - thisWidth = Math.max( $(this).get(0).width, thisWidth ); - $(this).width( thisWidth ); - $(this).data( 'thisWidth', thisWidth ); - var wrapperWidth = $(this).data( 'wrapperWidth' ) ? $(this).data( 'wrapperWidth' ) : 0; - wrapperWidth = Math.max( wrapper.get(0).scrollWidth, wrapperWidth ); + oldWS = $( this ).css( 'white-space' ); + $( this ).css( 'white-space', 'nowrap' ); + if ( wrapper.width() <= $( this ).get( 0 ).scrollWidth ) { + thisWidth = $( this ).data( 'thisWidth' ) ? $( this ).data( 'thisWidth' ) : 0; + thisWidth = Math.max( $( this ).get( 0 ).width, thisWidth ); + $( this ).width( thisWidth ); + $( this ).data( 'thisWidth', thisWidth ); + wrapperWidth = $( this ).data( 'wrapperWidth' ) ? $( this ).data( 'wrapperWidth' ) : 0; + wrapperWidth = Math.max( wrapper.get( 0 ).scrollWidth, wrapperWidth ); wrapper.width( wrapperWidth ); - $(this).data( 'wrapperWidth', wrapperWidth ); - $(this).dialog( { 'width': wrapper.width() } ); + $( this ).data( 'wrapperWidth', wrapperWidth ); + $( this ).dialog( { 'width': wrapper.width() } ); wrapper.css( 'left', parseInt( wrapper.css( 'left' ), 10 ) - ( wrapper.width() - oldWidth ) / 2 ); } - $(this).css( 'white-space', oldWS ); + $( this ).css( 'white-space', oldWS ); oldHidden.each( function () { - $(this).attr( 'style', $(this).data( 'oldstyle' ) ); - }); + $( this ).attr( 'style', $( this ).data( 'oldstyle' ) ); + } ); }, /** * Set the right tabindexes on elements in a dialog @@ -210,7 +208,7 @@ $.wikiEditor.modules.dialogs = { // Get the highest tab index var tabIndex = $( document ).lastTabIndex() + 1; $elements.each( function () { - $(this).attr( 'tabindex', tabIndex++ ); + $( this ).attr( 'tabindex', tabIndex++ ); } ); } }, diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.highlight.js b/extensions/WikiEditor/modules/jquery.wikiEditor.highlight.js deleted file mode 100644 index 9d964fa7..00000000 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.highlight.js +++ /dev/null @@ -1,373 +0,0 @@ -/* Highlight module for wikiEditor */ - -( function ( $ ) { - -$.wikiEditor.modules.highlight = { - - /** - * Core Requirements - */ - req: [ 'iframe' ], - - /** - * Configuration - */ - cfg: { - styleVersion: 3 - }, - - /** - * Internally used event handlers - */ - evt: { - delayedChange: function ( context, event ) { - if ( event.data.scope == 'realchange' ) { - $.wikiEditor.modules.highlight.fn.scan( context ); - $.wikiEditor.modules.highlight.fn.mark( context, event.data.scope ); - } - }, - ready: function ( context, event ) { - $.wikiEditor.modules.highlight.fn.scan( context ); - $.wikiEditor.modules.highlight.fn.mark( context, 'ready' ); - } - }, - - /** - * Internally used functions - */ - fn: { - /** - * Creates a highlight module within a wikiEditor - * - * @param config Configuration object to create module from - */ - create: function ( context, config ) { - context.modules.highlight.markersStr = ''; - }, - /** - * Scans text division for tokens - * - * @param division - */ - scan: function ( context, division ) { - var tokenArray, text, module, exp, - left, right, match; - /*jshint eqnull: true */ - - // Remove all existing tokens - tokenArray = context.modules.highlight.tokenArray = []; - // Scan text for new tokens - text = context.fn.getContents(); - // Perform a scan for each module which provides any expressions to scan for - // FIXME: This traverses the entire string once for every regex. Investigate - // whether |-concatenating regexes then traversing once is faster. - for ( module in context.modules ) { - if ( module in $.wikiEditor.modules && 'exp' in $.wikiEditor.modules[module] ) { - for ( exp in $.wikiEditor.modules[module].exp ) { - // Prepare configuration - var regex = $.wikiEditor.modules[module].exp[exp].regex; - var label = $.wikiEditor.modules[module].exp[exp].label; - var markAfter = $.wikiEditor.modules[module].exp[exp].markAfter || false; - // Search for tokens - var offset = 0; - while ( ( match = text.substr( offset ).match( regex ) ) != null ) { - right = ( left = offset + match.index ) + match[0].length; - tokenArray[tokenArray.length] = { - offset: markAfter ? right : left, - label: label, - tokenStart: left, - match: match - }; - // Move to the right of this match - offset = right; - } - } - } - } - // Sort by start - tokenArray.sort( function ( a, b ) { - return a.tokenStart - b.tokenStart; - } ); - // Let the world know, a scan just happened! - context.fn.trigger( 'scan' ); - }, - - /** - * Marks up text with HTML - * - * @param division - * @param tokens - */ - // FIXME: What do division and tokens do? - // TODO: Document the scan() and mark() APIs somewhere - mark: function ( context, division, tokens ) { - var i, subtracted, oldLength, j, o; - - // Reset markers - var markers = []; - - // Recycle markers that will be skipped in this run - if ( context.modules.highlight.markers && division !== '' ) { - for ( i = 0; i < context.modules.highlight.markers.length; i++ ) { - if ( context.modules.highlight.markers[i].skipDivision == division ) { - markers.push( context.modules.highlight.markers[i] ); - } - } - } - context.modules.highlight.markers = markers; - - // Get all markers - context.fn.trigger( 'mark' ); - markers.sort( function ( a, b ) { - return a.start - b.start || a.end - b.end; - } ); - - // Serialize the markers array to a string and compare it with the one stored in the previous run - if they're - // equal, there's no markers to change - var markersStr = ''; - for ( i = 0; i < markers.length; i++ ) { - markersStr += markers[i].start + ',' + markers[i].end + ',' + markers[i].type + ','; - } - if ( context.modules.highlight.markersStr == markersStr ) { - // No change, bail out - return; - } - context.modules.highlight.markersStr = markersStr; - - // Traverse the iframe DOM, inserting markers where they're needed - store visited markers here so we know which - // markers should be removed - var visited = [], v = 0; - for ( i = 0; i < markers.length; i++ ) { - if ( typeof markers[i].skipDivision !== 'undefined' && ( division == markers[i].skipDivision ) ) { - continue; - } - - // We want to isolate each marker, so we may need to split textNodes if a marker starts or ends halfway one. - var start = markers[i].start; - var s = context.fn.getOffset( start ); - if ( !s ) { - // This shouldn't happen - continue; - } - var startNode = s.node; - - // Don't wrap leading BRs, produces undesirable results - // FIXME: It's also possible that the offset is a bit high because getOffset() has incremented .length to - // fake the newline caused by startNode being in a P. In this case, prevent the textnode splitting below - // from making startNode an empty textnode, IE barfs on that - while ( startNode.nodeName === 'BR' || s.offset === startNode.nodeValue.length ) { - start++; - s = context.fn.getOffset( start ); - startNode = s.node; - } - - // The next marker starts somewhere in this textNode or at this BR - if ( s.offset > 0 && s.node.nodeName == '#text' ) { - // Split off the prefix - this leaves the prefix in the current node and puts the rest in a new node - // which is our start node - var newStartNode = startNode.splitText( s.offset < s.node.nodeValue.length ? - s.offset : s.node.nodeValue.length - 1 - ); - var oldStartNode = startNode; - startNode = newStartNode; - // Update offset objects. We don't need purgeOffsets(), simply manipulating the existing offset objects - // will suffice - // FIXME: This manipulates context.offsets directly, which is ugly, but the performance improvement vs. - // purgeOffsets() is worth it - this code doesn't set lastTextNode to newStartNode for offset objects - // with lastTextNode == oldStartNode, but that doesn't really matter - subtracted = s.offset; - oldLength = s.length; - - // Update offset objects referring to oldStartNode - for ( j = start - subtracted; j < start; j++ ) { - if ( j in context.offsets ) { - o = context.offsets[j]; - o.node = oldStartNode; - o.length = subtracted; - } - } - // Update offset objects referring to newStartNode - for ( j = start; j < start - subtracted + oldLength; j++ ) { - if ( j in context.offsets ) { - o = context.offsets[j]; - o.node = newStartNode; - o.offset -= subtracted; - o.length -= subtracted; - o.lastTextNode = oldStartNode; - } - } - } - var end = markers[i].end; - // To avoid ending up at the first char of the next node, we grab the offset for end - 1 and add one to the - // offset - var e = context.fn.getOffset( end - 1 ); - if ( !e ) { - // This shouldn't happen - continue; - } - var endNode = e.node; - if ( e.offset + 1 < e.length - 1 && endNode.nodeName == '#text' ) { - // Split off the suffix. This puts the suffix in a new node and leaves the rest in endNode - var oldEndNode = endNode; - var newEndNode = endNode.splitText( e.offset + 1 ); - // Update offset objects - subtracted = e.offset + 1; - oldLength = e.length; - - // Update offset objects referring to oldEndNode - for ( j = end - subtracted; j < end; j++ ) { - if ( j in context.offsets ) { - o = context.offsets[j]; - o.node = oldEndNode; - o.length = subtracted; - } - } - // We have to insert this one, as it might not exist: we didn't call getOffset( end ) - context.offsets[end] = { - 'node': newEndNode, - 'offset': 0, - 'length': oldLength - subtracted, - 'lastTextNode': oldEndNode - }; - // Update offset objects referring to newEndNode - for ( j = end + 1; j < end - subtracted + oldLength; j++ ) { - if ( j in context.offsets ) { - o = context.offsets[j]; - o.node = newEndNode; - o.offset -= subtracted; - o.length -= subtracted; - o.lastTextNode = oldEndNode; - } - } - } - // Don't wrap trailing BRs, doing that causes weird issues - if ( endNode.nodeName == 'BR' ) { - endNode = e.lastTextNode; - } - // If startNode and endNode have different parents, we need to pull endNode and all textnodes in between - // into startNode's parent and replace

with
- if ( startNode.parentNode !== endNode.parentNode ) { - var startP = $( startNode ).closest( 'p' ).get( 0 ); - var t = new context.fn.rawTraverser( startNode, startP, context.$content.get( 0 ), false ); - var afterStart = startNode.nextSibling; - var lastP = startP; - var nextT = t.next(); - while ( nextT && t.node !== endNode ) { - t = nextT; - nextT = t.next(); - // If t.node has a different parent, merge t.node.parentNode with startNode.parentNode - if ( t.node.parentNode !== startNode.parentNode ) { - var oldParent = t.node.parentNode; - if ( afterStart ) { - if ( lastP !== t.inP ) { - // We're entering a new

, insert a
- startNode.parentNode.insertBefore( - startNode.ownerDocument.createElement( 'br' ), - afterStart - ); - } - // A

with just a
in it is an empty line, so let's not bother with unwrapping it - if ( !( oldParent.childNodes.length == 1 && oldParent.firstChild.nodeName == 'BR' ) ) { - // Move all children of oldParent into startNode's parent - while ( oldParent.firstChild ) { - startNode.parentNode.insertBefore( oldParent.firstChild, afterStart ); - } - } - } else { - if ( lastP !== t.inP ) { - // We're entering a new

, insert a
- startNode.parentNode.appendChild( - startNode.ownerDocument.createElement( 'br' ) - ); - } - // A

with just a
in it is an empty line, so let's not bother with unwrapping it - if ( !( oldParent.childNodes.length == 1 && oldParent.firstChild.nodeName == 'BR' ) ) { - // Move all children of oldParent into startNode's parent - while ( oldParent.firstChild ) { - startNode.parentNode.appendChild( oldParent.firstChild ); - } - } - } - // Remove oldParent, which is now empty - oldParent.parentNode.removeChild( oldParent ); - } - lastP = t.inP; - } - // Moving nodes around like this invalidates offset objects - // TODO: Update offset objects ourselves for performance. Requires rewriting this code block to be - // offset-based rather than traverser-based - } - // Now wrap everything between startNode and endNode (may be equal). - var ca1 = startNode, ca2 = endNode; - if ( ca1 && ca2 && ca1.parentNode ) { - var anchor = markers[i].getAnchor( ca1, ca2 ); - if ( !anchor ) { - var commonAncestor = ca1.parentNode; - if ( markers[i].anchor == 'wrap') { - // We have to store things like .parentNode and .nextSibling because appendChild() changes these - var newNode = ca1.ownerDocument.createElement( 'span' ); - var nextNode = ca2.nextSibling; - // Append all nodes between ca1 and ca2 (inclusive) to newNode - var n = ca1; - while ( n !== nextNode ) { - var ns = n.nextSibling; - newNode.appendChild( n ); - n = ns; - } - // Insert newNode in the right place - if ( nextNode ) { - commonAncestor.insertBefore( newNode, nextNode ); - } else { - commonAncestor.appendChild( newNode ); - } - anchor = newNode; - } else if ( markers[i].anchor == 'tag' ) { - anchor = commonAncestor; - } - $( anchor ).data( 'marker', markers[i] ).addClass( 'wikiEditor-highlight' ); - // Allow the module adding this marker to manipulate it - markers[i].afterWrap( anchor, markers[i] ); - - } else { - // Update the marker object - $( anchor ).data( 'marker', markers[i] ); - if ( typeof markers[i].onSkip == 'function' ) { - markers[i].onSkip( anchor ); - } - } - visited[v++] = anchor; - } - } - // Remove markers that were previously inserted but weren't passed to this function - visited[] contains the - // visited elements in order and find() and each() preserve order - j = 0; - context.$content.find( '.wikiEditor-highlight' ).each( function () { - if ( visited[j] == this ) { - // This marker is legit, leave it in - j++; - return true; - } - // Remove this marker - var marker = $(this).data( 'marker' ); - if ( marker && typeof marker.skipDivision !== 'undefined' && ( division === marker.skipDivision ) ) { - // Don't remove these either - return true; - } - if ( marker && typeof marker.beforeUnwrap === 'function' ) - marker.beforeUnwrap( this ); - if ( ( marker && marker.anchor === 'tag' ) || $(this).is( 'p' ) ) { - // Remove all classes - $(this).removeAttr( 'class' ); - } else { - // Assume anchor == 'wrap' - $(this).replaceWith( this.childNodes ); - } - context.fn.purgeOffsets(); - }); - - } - } -}; - -}( jQuery ) ); - diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.html b/extensions/WikiEditor/modules/jquery.wikiEditor.html index f11521a3..7a890af0 100644 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.html +++ b/extensions/WikiEditor/modules/jquery.wikiEditor.html @@ -44,91 +44,6 @@ .wikiEditor-tab { padding-left: 4em; } - /* WikiEditor Templates */ - .wikiEditor-templates .wikiEditor-template { - color: silver; - } - /* WikiEditor TemplateEditor */ - .wikiEditor-templateEditor .wikiEditor-template-text-shrunken{ - height: 1px !important; - width: 1px !important; - overflow: hidden; - float: right; - } - .wikiEditor-templateEditor .wikiEditor-template-text-visible{ - padding: 0.5em 4px; - padding-top: 1.25em; - margin-top: -0.95em; - background: #F3F3F3 url(images/templateEditor/text-base.png) repeat-x scroll center top; - display: block; - width: 100%; - border-bottom: solid 1px #cccccc; - } - .wikiEditor-templateEditor .wikiEditor-template { - display: inline-block; - font-size: 12px; - } - .wikiEditor-templateEditor .wikiEditor-template-name { - cursor: pointer; - vertical-align: -2px; - display: inline-block; - height: 16px; - margin-bottom: -1px; - margin-right: 2px; - overflow: hidden; - background: url(images/templateEditor/name-base.png) 0 0 repeat-x #e8e8e8; - color: #000000; - font-family: monospace; - text-decoration: none; - padding-left: 0.33em; - line-height: 16px; - } - .wikiEditor-templateEditor .wikiEditor-template-expand { - cursor: pointer; - vertical-align: -2px; - display: inline-block; - margin-left: 2px; - height: 16px; - margin-bottom: -1px; - line-height: 16px; - overflow: hidden; - width: 13px; - background-position: 50%; - } - .wikiEditor-templateEditor .wikiEditor-template-dialog { - cursor: pointer; - vertical-align: -18%; - display: inline-block; - height: 16px; - overflow: hidden; - width: 22px; - background-position: 50%; - } - .wikiEditor-templateEditor .wikiEditor-template-name:hover { - text-decoration: underline; - } - .wikiEditor-templateEditor .wikiEditor-template-expanded .wikiEditor-template-expand { - background-image: url(images/templateEditor/collapse.png); - } - .wikiEditor-templateEditor .wikiEditor-template-expanded .wikiEditor-template-dialog { - background-image: url(images/templateEditor/dialog-expanded.png); - } - .wikiEditor-templateEditor .wikiEditor-template-collapsed .wikiEditor-template-expand { - background-image: url(images/templateEditor/expand.png); - } - .wikiEditor-templateEditor .wikiEditor-template-collapsed .wikiEditor-template-dialog { - background-image: url(images/templateEditor/dialog-collapsed.png); - } - .wikiEditor-templateEditor .wikiEditor-template-expanded { - display: block; - } - .wikiEditor-templateEditor .wikiEditor-template .wikiEditor-template-text { - - } - .wikiEditor-templateEditor .wikiEditor-template-end, .wikiEditor-template-start { - color: blue; - cursor: pointer; - } diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.iframe.js b/extensions/WikiEditor/modules/jquery.wikiEditor.iframe.js deleted file mode 100644 index 4d425012..00000000 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.iframe.js +++ /dev/null @@ -1,1387 +0,0 @@ -/* IFrame extension for wikiEditor */ - -( function( $ ) { $.wikiEditor.extensions.iframe = function( context ) { - -/* - * Event Handlers - * - * These act as filters returning false if the event should be ignored or returning true if it should be passed - * on to all modules. This is also where we can attach some extra information to the events. - */ -context.evt = $.extend( context.evt, { - /** - * Filters change events, which occur when the user interacts with the contents of the iframe. The goal of this - * function is to both classify the scope of changes as 'division' or 'character' and to prevent further - * processing of events which did not actually change the content of the iframe. - */ - 'keydown': function( event ) { - switch ( event.which ) { - case 90: // z - case 89: // y - if ( event.which == 89 && !$.browser.msie ) { - // only handle y events for IE - return true; - } else if ( ( event.ctrlKey || event.metaKey ) && context.history.length ) { - // HistoryPosition is a negative number between -1 and -context.history.length, in other words - // it's the number of steps backwards from the latest state. - var newPosition; - if ( event.shiftKey || event.which == 89 ) { - // Redo - newPosition = context.historyPosition + 1; - } else { - // Undo - newPosition = context.historyPosition - 1; - } - // Only act if we are switching to a valid state - if ( newPosition >= ( context.history.length * -1 ) && newPosition < 0 ) { - // Make sure we run the history storing code before we make this change - context.fn.updateHistory( context.oldDelayedHTML != context.$content.html() ); - context.oldDelayedHistoryPosition = context.historyPosition; - context.historyPosition = newPosition; - // Change state - // FIXME: Destroys event handlers, will be a problem with template folding - context.$content.html( - context.history[context.history.length + context.historyPosition].html - ); - context.fn.purgeOffsets(); - if( context.history[context.history.length + context.historyPosition].sel ) { - context.fn.setSelection( { - start: context.history[context.history.length + context.historyPosition].sel[0], - end: context.history[context.history.length + context.historyPosition].sel[1] - } ); - } - } - // Prevent the browser from jumping in and doing its stuff - return false; - } - break; - // Intercept all tab events to provide consisten behavior across browsers - // Webkit browsers insert tab characters by default into the iframe rather than changing input focus - case 9: //tab - // if any modifier keys are pressed, allow the browser to do it's thing - if ( event.ctrlKey || event.altKey || event.shiftKey ) { - return true; - } else { - var $tabindexList = $( '[tabindex]:visible' ).sort( function( a, b ) { - return a.tabIndex - b.tabIndex; - } ); - for( var i=0; i < $tabindexList.length; i++ ) { - if( $tabindexList.eq( i ).attr( 'id' ) == context.$iframe.attr( 'id' ) ) { - $tabindexList.get( i + 1 ).focus(); - break; - } - } - return false; - } - break; - case 86: //v - if ( event.ctrlKey && $.browser.msie && 'paste' in context.evt ) { - //paste, intercepted for IE - context.evt.paste( event ); - } - break; - } - return true; - }, - 'change': function( event ) { - event.data.scope = 'division'; - var newHTML = context.$content.html(); - if ( context.oldHTML != newHTML ) { - context.fn.purgeOffsets(); - context.oldHTML = newHTML; - event.data.scope = 'realchange'; - } - // Never let the body be totally empty - if ( context.$content.children().length == 0 ) { - context.$content.append( '

' ); - } - return true; - }, - 'delayedChange': function( event ) { - event.data.scope = 'division'; - var newHTML = context.$content.html(); - if ( context.oldDelayedHTML != newHTML ) { - context.oldDelayedHTML = newHTML; - event.data.scope = 'realchange'; - // Surround by

if it does not already have it - var cursorPos = context.fn.getCaretPosition(); - var t = context.fn.getOffset( cursorPos[0] ); - if ( ! $.browser.msie && t && t.node.nodeName == '#text' && t.node.parentNode.nodeName.toLowerCase() == 'body' ) { - $( t.node ).wrap( "

" ); - context.fn.purgeOffsets(); - context.fn.setSelection( { start: cursorPos[0], end: cursorPos[1] } ); - } - } - context.fn.updateHistory( event.data.scope == 'realchange' ); - return true; - }, - 'cut': function( event ) { - setTimeout( function() { - context.$content.find( 'br' ).each( function() { - if ( $(this).parent().is( 'body' ) ) { - $(this).wrap( $( '

' ) ); - } - } ); - }, 100 ); - return true; - }, - 'paste': function( event ) { - // Save the cursor position to restore it after all this voodoo - var cursorPos = context.fn.getCaretPosition(); - var oldLength = context.fn.getContents().length; - var positionFromEnd = oldLength - cursorPos[1]; - - //give everything the wikiEditor class so that we can easily pick out things without that class as pasted - context.$content.find( '*' ).addClass( 'wikiEditor' ); - if ( $.layout.name !== 'webkit' ) { - context.$content.addClass( 'pasting' ); - } - - setTimeout( function() { - // Kill stuff we know we don't want - context.$content.find( 'script,style,img,input,select,textarea,hr,button,link,meta' ).remove(); - var nodeToDelete = []; - var pastedContent = []; - var firstDirtyNode; - var $lastDirtyNode; - var elementAtCursor; - if ( $.browser.msie && !context.offsets ) { - elementAtCursor = null; - } else { - elementAtCursor = context.fn.getOffset( cursorPos[0] ); - } - if ( elementAtCursor == null || elementAtCursor.node == null ) { - context.$content.prepend( '

' ); - firstDirtyNode = context.$content.children()[0]; - } else { - firstDirtyNode = elementAtCursor.node; - } - - //this is ugly but seems like the best way to handle the case where we select and replace all editor contents - try { - firstDirtyNode.parentNode; - } catch ( err ) { - context.$content.prepend( '

' ); - firstDirtyNode = context.$content.children()[0]; - } - - while ( firstDirtyNode != null ) { - //we're going to replace the contents of the entire parent node. - while ( firstDirtyNode.parentNode && firstDirtyNode.parentNode.nodeName != 'BODY' - && ! $( firstDirtyNode ).hasClass( 'wikiEditor' ) - ) { - firstDirtyNode = firstDirtyNode.parentNode; - } - //go back till we find the first pasted node - while ( firstDirtyNode.previousSibling != null - && ! $( firstDirtyNode.previousSibling ).hasClass( 'wikiEditor' ) - ) { - - if ( $( firstDirtyNode.previousSibling ).hasClass( '#comment' ) ) { - $( firstDirtyNode ).remove(); - } else { - firstDirtyNode = firstDirtyNode.previousSibling; - } - } - - if ( firstDirtyNode.previousSibling != null ) { - $lastDirtyNode = $( firstDirtyNode.previousSibling ); - } else { - $lastDirtyNode = $( firstDirtyNode ); - } - - var cc = makeContentCollector( $.browser, null ); - while ( firstDirtyNode != null ) { - cc.collectContent(firstDirtyNode); - cc.notifyNextNode(firstDirtyNode.nextSibling); - - nodeToDelete.push( firstDirtyNode ); - - firstDirtyNode = firstDirtyNode.nextSibling; - if ( $( firstDirtyNode ).hasClass( 'wikiEditor' ) ) { - break; - } - } - - var ccData = cc.finish(); - pastedContent = ccData.lines; - var pastedPretty = ''; - for ( var i = 0; i < pastedContent.length; i++ ) { - //escape html - pastedPretty = pastedContent[i].replace(/&/g, '&').replace(//g, '>').replace(/\r?\n/g, '\\n'); - //replace leading white spaces with   - match = pastedContent[i].match(/^[\s]+[^\s]/); - if ( match != null && match.length > 0 ) { - index = match[0].length; - leadingSpace = match[0].replace(/[\s]/g, ' '); - pastedPretty = leadingSpace + pastedPretty.substring(index, pastedPretty.length); - } - - - if( !pastedPretty && $.browser.msie && i == 0 ) { - continue; - } - $newElement = $( '

' ); - if ( pastedPretty ) { - $newElement.html( pastedPretty ); - } else { - $newElement.html( '
' ); - } - $newElement.insertAfter( $lastDirtyNode ); - - $lastDirtyNode = $newElement; - - } - - //now delete all the original nodes that we prettified already - while ( nodeToDelete.length > 0 ) { - $deleteNode = $( nodeToDelete.pop() ); - $deleteNode.remove(); - } - - //anything without wikiEditor class was pasted. - $selection = context.$content.find( ':not(.wikiEditor)' ); - if ( $selection.length == 0 ) { - break; - } else { - firstDirtyNode = $selection.eq( 0 )[0]; - } - } - context.$content.find( '.wikiEditor' ).removeClass( 'wikiEditor' ); - - //now place the cursor at the end of pasted content - var newLength = context.fn.getContents().length; - var newPos = newLength - positionFromEnd; - - context.fn.purgeOffsets(); - context.fn.setSelection( { start: newPos, end: newPos } ); - - context.fn.scrollToCaretPosition(); - }, 0 ); - return true; - }, - 'ready': function( event ) { - // Initialize our history queue - if ( context.$content ) { - context.history.push( { 'html': context.$content.html(), 'sel': context.fn.getCaretPosition() } ); - } else { - context.history.push( { 'html': '', 'sel': context.fn.getCaretPosition() } ); - } - return true; - } -} ); - -/** - * Internally used functions - */ -context.fn = $.extend( context.fn, { - 'highlightLine': function( $element, mode ) { - if ( !$element.is( 'p' ) ) { - $element = $element.closest( 'p' ); - } - $element.css( 'backgroundColor', '#AACCFF' ); - setTimeout( function() { $element.animate( { 'backgroundColor': 'white' }, 'slow' ); }, 100 ); - setTimeout( function() { $element.css( 'backgroundColor', 'white' ); }, 1000 ); - }, - 'htmlToText': function( html ) { - // This function is slow for large inputs, so aggressively cache input/output pairs - if ( html in context.htmlToTextMap ) { - return context.htmlToTextMap[html]; - } - var origHTML = html; - - // We use this elaborate trickery for cross-browser compatibility - // IE does overzealous whitespace collapsing for $( '
' ).html( html );
-		// We also do 
and easy cases for

conversion here, complicated cases are handled later - html = html - .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements - .replace( / /g, " " ) // We inserted these to prevent IE from collapsing spaces - .replace( /\]*\>\<\/p\>/gi, '

' ) // Remove trailing
from

- .replace( /\<\/p\>\s*\]*\>/gi, "\n" ) // Easy case for

conversion - .replace( /\]*\>/gi, "\n" ) //
conversion - .replace( /\<\/p\>(\n*)\]*\>/gi, "$1\n" ) - // Un-nest

tags - .replace( /\]*\>]*\>/gi, '

' ) - .replace( /\<\/p\><\/p\>/gi, '

' ); - // Save leading and trailing whitespace now and restore it later. IE eats it all, and even Firefox - // won't leave everything alone - var leading = html.match( /^\s*/ )[0]; - var trailing = html.match( /\s*$/ )[0]; - html = html.substr( leading.length, html.length - leading.length - trailing.length ); - var $pre = $( '
' + html + '
' ); - $pre.find( '.wikiEditor-noinclude' ).each( function() { $( this ).remove(); } ); - // Convert tabs,

s and
s back - $pre.find( '.wikiEditor-tab' ).each( function() { $( this ).text( "\t" ); } ); - $pre.find( 'br' ).each( function() { $( this ).replaceWith( "\n" ); } ); - // Converting

s is wrong if there's nothing before them, so check that. - // .find( '* + p' ) isn't good enough because textnodes aren't considered - $pre.find( 'p' ).each( function() { - var text = $( this ).text(); - // If this

is preceded by some text, add a \n at the beginning, and if - // it's followed by a textnode, add a \n at the end - // We need the traverser because there can be other weird stuff in between - - // Check for preceding text - var t = new context.fn.rawTraverser( this.firstChild, this, $pre.get( 0 ), true ).prev(); - while ( t && t.node.nodeName != '#text' && t.node.nodeName != 'BR' && t.node.nodeName != 'P' ) { - t = t.prev(); - } - if ( t ) { - text = "\n" + text; - } - - // Check for following text - t = new context.fn.rawTraverser( this.lastChild, this, $pre.get( 0 ), true ).next(); - while ( t && t.node.nodeName != '#text' && t.node.nodeName != 'BR' && t.node.nodeName != 'P' ) { - t = t.next(); - } - if ( t && !t.inP && t.node.nodeName == '#text' && t.node.nodeValue.charAt( 0 ) != '\n' - && t.node.nodeValue.charAt( 0 ) != '\r' ) { - text += "\n"; - } - $( this ).text( text ); - } ); - var retval; - if ( $.browser.msie ) { - // IE aggressively collapses whitespace in .text() after having done DOM manipulation, - // but for some crazy reason this does work. Also convert \r back to \n - retval = $( '

' + $pre.html() + '
' ).text().replace( /\r/g, '\n' ); - } else { - retval = $pre.text(); - } - return context.htmlToTextMap[origHTML] = leading + retval + trailing; - }, - /** - * Get the first element before the selection that's in a certain class - * @param classname Class to match. Defaults to '', meaning any class - * @param strict If true, the element the selection starts in cannot match (default: false) - * @return jQuery object or null if unknown - */ - 'beforeSelection': function( classname, strict ) { - if ( typeof classname == 'undefined' ) { - classname = ''; - } - var e = null, offset = null; - if ( $.browser.msie && !context.$iframe[0].contentWindow.document.body ) { - return null; - } - if ( context.$iframe[0].contentWindow.getSelection ) { - // Firefox and Opera - var selection = context.$iframe[0].contentWindow.getSelection(); - // On load, webkit seems to not have a valid selection - if ( selection.baseNode !== null ) { - // Start at the selection's start and traverse the DOM backwards - // This is done by traversing an element's children first, then the element itself, then its parent - e = selection.getRangeAt( 0 ).startContainer; - offset = selection.getRangeAt( 0 ).startOffset; - } else { - return null; - } - - // When the cursor is on an empty line, Opera gives us a bogus range object with - // startContainer=endContainer=body and startOffset=endOffset=1 - var body = context.$iframe[0].contentWindow.document.body; - if ( $.browser.opera && e == body && offset == 1 ) { - return null; - } - } - if ( !e && context.$iframe[0].contentWindow.document.selection ) { - // IE - // Because there's nothing like range.startContainer in IE, we need to do a DOM traversal - // to find the element the start of the selection is in - var range = context.$iframe[0].contentWindow.document.selection.createRange(); - // Set range2 to the text before the selection - var range2 = context.$iframe[0].contentWindow.document.body.createTextRange(); - // For some reason this call throws errors in certain cases, e.g. when the selection is - // not in the iframe - try { - range2.setEndPoint( 'EndToStart', range ); - } catch ( ex ) { - return null; - } - var seekPos = context.fn.htmlToText( range2.htmlText ).length; - var offset = context.fn.getOffset( seekPos ); - e = offset ? offset.node : null; - offset = offset ? offset.offset : null; - if ( !e ) { - return null; - } - } - if ( e.nodeName != '#text' ) { - // The selection is not in a textnode, but between two non-text nodes - // (usually inside the between two
s). Go to the rightmost - // child of the node just before the selection - var newE = e.firstChild; - for ( var i = 0; i < offset - 1 && newE; i++ ) { - newE = newE.nextSibling; - } - while ( newE && newE.lastChild ) { - newE = newE.lastChild; - } - e = newE || e; - } - - // We'd normally use if( $( e ).hasClass( class ) in the while loop, but running the jQuery - // constructor thousands of times is very inefficient - var classStr = ' ' + classname + ' '; - while ( e ) { - if ( !strict && ( !classname || ( ' ' + e.className + ' ' ).indexOf( classStr ) != -1 ) ) { - return $( e ); - } - var next = e.previousSibling; - while ( next && next.lastChild ) { - next = next.lastChild; - } - e = next || e.parentNode; - strict = false; - } - return $( [] ); - }, - /** - * Object used by traverser(). Don't use this unless you know what you're doing - */ - 'rawTraverser': function( node, inP, ancestor, skipNoinclude ) { - this.node = node; - this.inP = inP; - this.ancestor = ancestor; - this.skipNoinclude = skipNoinclude; - this.next = function() { - var p = this.node; - var nextInP = this.inP; - while ( p && !p.nextSibling ) { - p = p.parentNode; - if ( p == this.ancestor ) { - // We're back at the ancestor, stop here - p = null; - } - if ( p && p.nodeName == "P" ) { - nextInP = null; - } - } - p = p ? p.nextSibling : null; - if ( p && p.nodeName == "P" ) { - nextInP = p; - } - do { - // Filter nodes with the wikiEditor-noinclude class - // Don't use $( p ).hasClass( 'wikiEditor-noinclude' ) because - // $() is slow in a tight loop - if ( this.skipNoinclude ) { - while ( p && ( ' ' + p.className + ' ' ).indexOf( ' wikiEditor-noinclude ' ) != -1 ) { - p = p.nextSibling; - } - } - if ( p && p.firstChild ) { - p = p.firstChild; - if ( p.nodeName == "P" ) { - nextInP = p; - } - } - } while ( p && p.firstChild ); - // Instead of calling the rawTraverser constructor, inline it. This avoids function call overhead - return p ? { 'node': p, 'inP': nextInP, 'ancestor': this.ancestor, - 'skipNoinclude': this.skipNoinclude, 'next': this.next, 'prev': this.prev } : null; - }; - this.prev = function() { - var p = this.node; - var prevInP = this.inP; - while ( p && !p.previousSibling ) { - p = p.parentNode; - if ( p == this.ancestor ) { - // We're back at the ancestor, stop here - p = null; - } - if ( p && p.nodeName == "P" ) { - prevInP = null; - } - } - p = p ? p.previousSibling : null; - if ( p && p.nodeName == "P" ) { - prevInP = p; - } - do { - // Filter nodes with the wikiEditor-noinclude class - // Don't use $( p ).hasClass( 'wikiEditor-noinclude' ) because - // $() is slow in a tight loop - if ( this.skipNoinclude ) { - while ( p && ( ' ' + p.className + ' ' ).indexOf( ' wikiEditor-noinclude ' ) != -1 ) { - p = p.previousSibling; - } - } - if ( p && p.lastChild ) { - p = p.lastChild; - if ( p.nodeName == "P" ) { - prevInP = p; - } - } - } while ( p && p.lastChild ); - // Instead of calling the rawTraverser constructor, inline it. This avoids function call overhead - return p ? { 'node': p, 'inP': prevInP, 'ancestor': this.ancestor, - 'skipNoinclude': this.skipNoinclude, 'next': this.next, 'prev': this.prev } : null; - }; - }, - /** - * Get an object used to traverse the leaf nodes in the iframe DOM. This traversal skips leaf nodes - * inside an element with the wikiEditor-noinclude class. This basically wraps rawTraverser - * - * @param start Node to start at - * @return Traverser object, use .next() or .prev() to get a traverser object referring to the - * previous/next node - */ - 'traverser': function( start ) { - // Find the leftmost leaf node in the tree - var startNode = start.jquery ? start.get( 0 ) : start; - var node = startNode; - var inP = node.nodeName == "P" ? node : null; - do { - // Filter nodes with the wikiEditor-noinclude class - // Don't use $( p ).hasClass( 'wikiEditor-noinclude' ) because - // $() is slow in a tight loop - while ( node && ( ' ' + node.className + ' ' ).indexOf( ' wikiEditor-noinclude ' ) != -1 ) { - node = node.nextSibling; - } - if ( node && node.firstChild ) { - node = node.firstChild; - if ( node.nodeName == "P" ) { - inP = node; - } - } - } while ( node && node.firstChild ); - return new context.fn.rawTraverser( node, inP, startNode, true ); - }, - 'getOffset': function( offset ) { - if ( !context.offsets ) { - context.fn.refreshOffsets(); - } - if ( offset in context.offsets ) { - return context.offsets[offset]; - } - // Our offset is not pre-cached. Find the highest offset below it and interpolate - // We need to traverse the entire object because for() doesn't traverse in order - // We don't do in-order traversal because the object is sparse - var lowerBound = -1; - for ( var o in context.offsets ) { - var realO = parseInt( o ); - if ( realO < offset && realO > lowerBound) { - lowerBound = realO; - } - } - if ( !( lowerBound in context.offsets ) ) { - // Weird edge case: either offset is too large or the document is empty - return null; - } - var base = context.offsets[lowerBound]; - return context.offsets[offset] = { - 'node': base.node, - 'offset': base.offset + offset - lowerBound, - 'length': base.length, - 'lastTextNode': base.lastTextNode - }; - }, - 'purgeOffsets': function() { - context.offsets = null; - }, - 'refreshOffsets': function() { - context.offsets = [ ]; - var t = context.fn.traverser( context.$content ); - var pos = 0, lastTextNode = null; - while ( t ) { - if ( t.node.nodeName != '#text' && t.node.nodeName != 'BR' ) { - t = t.next(); - continue; - } - var nextPos = t.node.nodeName == '#text' ? pos + t.node.nodeValue.length : pos + 1; - var nextT = t.next(); - var leavingP = t.node.nodeName == '#text' && t.inP && nextT && ( !nextT.inP || nextT.inP != t.inP ); - context.offsets[pos] = { - 'node': t.node, - 'offset': 0, - 'length': nextPos - pos + ( leavingP ? 1 : 0 ), - 'lastTextNode': lastTextNode - }; - if ( leavingP ) { - //

Foo

looks like "Foo\n", make it quack like it too - // Basically we're faking the \n character much like we're treating
s - context.offsets[nextPos] = { - 'node': t.node, - 'offset': nextPos - pos, - 'length': nextPos - pos + 1, - 'lastTextNode': lastTextNode - }; - } - pos = nextPos + ( leavingP ? 1 : 0 ); - if ( t.node.nodeName == '#text' ) { - lastTextNode = t.node; - } - t = nextT; - } - }, - 'saveCursorAndScrollTop': function() { - // Stub out textarea behavior - return; - }, - 'restoreCursorAndScrollTop': function() { - // Stub out textarea behavior - return; - }, - 'saveSelection': function() { - if ( $.client.profile().name === 'msie' ) { - context.$iframe[0].contentWindow.focus(); - context.savedSelection = context.$iframe[0].contentWindow.document.selection.createRange(); - } - }, - 'restoreSelection': function() { - if ( $.client.profile().name === 'msie' && context.savedSelection !== null ) { - context.$iframe[0].contentWindow.focus(); - context.savedSelection.select(); - context.savedSelection = null; - } - }, - /** - * Update the history queue - * - * @param htmlChange pass true or false to inidicate if there was a text change that should potentially - * be given a new history state. - */ - 'updateHistory': function( htmlChange ) { - var newHTML = context.$content.html(); - var newSel = context.fn.getCaretPosition(); - // Was text changed? Was it because of a REDO or UNDO action? - if ( - context.history.length == 0 || - ( htmlChange && context.oldDelayedHistoryPosition == context.historyPosition ) - ) { - context.oldDelayedSel = newSel; - // Do we need to trim extras from our history? - // FIXME: this should really be happing on change, not on the delay - if ( context.historyPosition < -1 ) { - //clear out the extras - context.history.splice( context.history.length + context.historyPosition + 1 ); - context.historyPosition = -1; - } - context.history.push( { 'html': newHTML, 'sel': newSel } ); - // If the history has grown longer than 10 items, remove the earliest one - while ( context.history.length > 10 ) { - context.history.shift(); - } - } else if ( context.oldDelayedSel != newSel ) { - // If only the selection was changed, update it - context.oldDelayedSel = newSel; - context.history[context.history.length + context.historyPosition].sel = newSel; - } - // synch our old delayed history position until the next undo/redo action - context.oldDelayedHistoryPosition = context.historyPosition; - }, - /** - * Sets up the iframe in place of the textarea to allow more advanced operations - */ - 'setupIframe': function() { - context.$iframe = $( '' ) - .attr( { - 'frameBorder': 0, - 'border': 0, - 'tabindex': 1, - 'src': mw.config.get( 'wgExtensionAssetsPath' ) + '/WikiEditor/modules/jquery.wikiEditor.html?' + - 'instance=' + context.instance + '&ts=' + ( new Date() ).getTime() + '&is=content', - 'id': 'wikiEditor-iframe-' + context.instance - } ) - .css( { - 'backgroundColor': 'white', - 'width': '100%', - 'height': context.$textarea.height(), - 'display': 'none', - 'overflow-y': 'scroll', - 'overflow-x': 'hidden' - } ) - .insertAfter( context.$textarea ) - .load( function() { - // Internet Explorer will reload the iframe once we turn on design mode, so we need to only turn it - // on during the first run, and then bail - if ( !this.isSecondRun ) { - // Turn the document's design mode on - context.$iframe[0].contentWindow.document.designMode = 'on'; - // Let the rest of this function happen next time around - if ( $.browser.msie ) { - this.isSecondRun = true; - return; - } - } - // Get a reference to the content area of the iframe - context.$content = $( context.$iframe[0].contentWindow.document.body ); - // Add classes to the body to influence the styles based on what's enabled - for ( module in context.modules ) { - context.$content.addClass( 'wikiEditor-' + module ); - } - // If we just do "context.$content.text( context.$textarea.val() )", Internet Explorer will strip - // out the whitespace charcters, specifically "\n" - so we must manually encode text and append it - // TODO: Refactor this into a textToHtml() function - var html = context.$textarea.val() - // We're gonna use &esc; as an escape sequence - .replace( /&esc;/g, '&esc;esc;' ) - // Escape existing uses of

,

,   and - .replace( /\/g, '&esc;<p>' ) - .replace( /\<\/p\>/g, '&esc;</p>' ) - .replace( - /\\<\/span\>/g, - '&esc;<span class="wikiEditor-tab"></span>' - ) - .replace( / /g, '&esc;&nbsp;' ); - // We must do some extra processing on IE to avoid dirty diffs, specifically IE will collapse - // leading spaces - browser sniffing is not ideal, but executing this code on a non-broken browser - // doesn't cause harm - if ( $.browser.msie ) { - html = html.replace( /\t/g, '' ); - if ( $.browser.versionNumber <= 7 ) { - // Replace all spaces matching   - IE <= 7 needs this because of its overzealous - // whitespace collapsing - html = html.replace( / /g, " " ); - } else { - // IE8 is happy if we just convert the first leading space to   - html = html.replace( /(^|\n) /g, "$1 " ); - } - } - // Use a dummy div to escape all entities - // This'll also escape
, and   , so we unescape those after - // We also need to unescape the doubly-escaped things mentioned above - html = $( '
' ).text( '

' + html.replace( /\r?\n/g, '

' ) + '

' ).html() - .replace( /&nbsp;/g, ' ' ) - // Allow

tags to survive encoding - .replace( /<p>/g, '

' ) - .replace( /<\/p>/g, '

' ) - // And too - .replace( - /<span( | )class=("|")wikiEditor-tab("|")><\/span>/g, - '' - ) - // Empty

tags need
tags in them - .replace( /

<\/p>/g, '


' ) - // Unescape &esc; stuff - .replace( /&esc;&amp;nbsp;/g, '&nbsp;' ) - .replace( /&esc;&lt;p&gt;/g, '<p>' ) - .replace( /&esc;&lt;\/p&gt;/g, '</p>' ) - .replace( - /&esc;&lt;span&nbsp;class=&quot;wikiEditor-tab&quot;&gt;&lt;\/span&gt;/g, - '<span class="wikiEditor-tab"><\/span>' - ) - .replace( /&esc;esc;/g, '&esc;' ); - context.$content.html( html ); - - // Reflect direction of parent frame into child - if ( $( 'body' ).is( '.rtl' ) ) { - context.$content.addClass( 'rtl' ).attr( 'dir', 'rtl' ); - } - // Activate the iframe, encoding the content of the textarea and copying it to the content of iframe - context.$textarea.attr( 'disabled', true ); - context.$textarea.hide(); - context.$iframe.show(); - // Let modules know we're ready to start working with the content - context.fn.trigger( 'ready' ); - // Only save HTML now: ready handlers may have modified it - context.oldHTML = context.oldDelayedHTML = context.$content.html(); - //remove our temporary loading - /* Disaling our loading div for now - $( '.wikiEditor-ui-loading' ).fadeOut( 'fast', function() { - $( this ).remove(); - } ); - */ - // Setup event handling on the iframe - $( context.$iframe[0].contentWindow.document ) - .bind( 'keydown', function( event ) { - event.jQueryNode = context.fn.getElementAtCursor(); - return context.fn.trigger( 'keydown', event ); - - } ) - .bind( 'keyup', function( event ) { - event.jQueryNode = context.fn.getElementAtCursor(); - return context.fn.trigger( 'keyup', event ); - } ) - .bind( 'keypress', function( event ) { - event.jQueryNode = context.fn.getElementAtCursor(); - return context.fn.trigger( 'keypress', event ); - } ) - .bind( 'paste', function( event ) { - return context.fn.trigger( 'paste', event ); - } ) - .bind( 'cut', function( event ) { - return context.fn.trigger( 'cut', event ); - } ) - .bind( 'keyup paste mouseup cut encapsulateSelection', function( event ) { - return context.fn.trigger( 'change', event ); - } ) - .delayedBind( 250, 'keyup paste mouseup cut encapsulateSelection', function( event ) { - context.fn.trigger( 'delayedChange', event ); - } ); - } ); - // Attach a submit handler to the form so that when the form is submitted the content of the iframe gets - // decoded and copied over to the textarea - context.$textarea.closest( 'form' ).submit( function() { - context.$textarea.attr( 'disabled', false ); - context.$textarea.val( context.$textarea.textSelection( 'getContents' ) ); - } ); - /* FIXME: This was taken from EditWarning.js - maybe we could do a jquery plugin for this? */ - // Attach our own handler for onbeforeunload which respects the current one - context.fallbackWindowOnBeforeUnload = window.onbeforeunload; - window.onbeforeunload = function() { - context.$textarea.val( context.$textarea.textSelection( 'getContents' ) ); - if ( context.fallbackWindowOnBeforeUnload ) { - return context.fallbackWindowOnBeforeUnload(); - } - }; - }, - - /** - * Compatibility with the $.textSelection jQuery plug-in. When the iframe is in use, these functions provide - * equivilant functionality to the otherwise textarea-based functionality. - */ - - 'getElementAtCursor': function() { - if ( context.$iframe[0].contentWindow.getSelection ) { - // Firefox and Opera - var selection = context.$iframe[0].contentWindow.getSelection(); - if ( selection.rangeCount == 0 ) { - // We don't know where the cursor is - return $( [] ); - } - var sc = selection.getRangeAt( 0 ).startContainer; - if ( sc.nodeName == "#text" ) sc = sc.parentNode; - return $( sc ); - } else if ( context.$iframe[0].contentWindow.document.selection ) { // should come last; Opera! - // IE - var selection = context.$iframe[0].contentWindow.document.selection.createRange(); - return $( selection.parentElement() ); - } - }, - - /** - * Gets the complete contents of the iframe (in plain text, not HTML) - */ - 'getContents': function() { - // For

, .html() returns

 

in IE - // This seems to convince IE while not affecting display - if ( !context.$content ) { - return ''; - } - var html; - if ( $.browser.msie ) { - // Don't manipulate the iframe DOM itself, causes cursor jumping issues - var $c = $( context.$content.get( 0 ).cloneNode( true ) ); - $c.find( 'p' ).each( function() { - if ( $(this).html() == '' ) { - $(this).replaceWith( '

' ); - } - } ); - html = $c.html(); - } else { - html = context.$content.html(); - } - return context.fn.htmlToText( html ); - }, - /** - * Gets the currently selected text in the content - * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead - */ - 'getSelection': function() { - var retval; - if ( context.$iframe[0].contentWindow.getSelection ) { - // Firefox and Opera - retval = context.$iframe[0].contentWindow.getSelection(); - if ( $.browser.opera ) { - // Opera strips newlines in getSelection(), so we need something more sophisticated - if ( retval.rangeCount > 0 ) { - retval = context.fn.htmlToText( $( '
' )
-							.append( retval.getRangeAt( 0 ).cloneContents() )
-							.html()
-					);
-				} else {
-					retval = '';
-				}
-			}
-		} else if ( context.$iframe[0].contentWindow.document.selection ) { // should come last; Opera!
-			// IE
-			retval = context.$iframe[0].contentWindow.document.selection.createRange();
-		}
-		if ( typeof retval.text != 'undefined' ) {
-			// In IE8, retval.text is stripped of newlines, so we need to process retval.htmlText
-			// to get a reliable answer. IE7 does get this right though
-			// Run this fix for all IE versions anyway, it doesn't hurt
-			retval = context.fn.htmlToText( retval.htmlText );
-		} else if ( typeof retval.toString != 'undefined' ) {
-			retval = retval.toString();
-		}
-		return retval;
-	},
-	/**
-	 * Inserts text at the begining and end of a text selection, optionally inserting text at the caret when
-	 * selection is empty.
-	 * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead
-	 */
-	'encapsulateSelection': function( options ) {
-		var selText = $(this).textSelection( 'getSelection' );
-		var selTextArr;
-		var collapseToEnd = false;
-		var selectAfter = false;
-		var setSelectionTo = null;
-		var pre = options.pre, post = options.post;
-		if ( !selText ) {
-			selText = options.peri;
-			selectAfter = true;
-		} else if ( options.peri == selText.replace( /\s+$/, '' ) ) {
-			// Probably a successive button press
-			// strip any extra white space from selText
-			selText = selText.replace( /\s+$/, '' );
-			// set the collapseToEnd flag to ensure our selection is collapsed to the end before any insertion is done
-			collapseToEnd = true;
-			// set selectAfter to true since we know we'll be populating with our default text
-			selectAfter = true;
-		} else if ( options.replace ) {
-			selText = options.peri;
-		} else if ( selText.charAt( selText.length - 1 ) == ' ' ) {
-			// Exclude ending space char
-			// FIXME: Why?
-			selText = selText.substring( 0, selText.length - 1 );
-			post += ' ';
-		}
-		if ( options.splitlines ) {
-			selTextArr = selText.split( /\n/ );
-		}
-
-		if ( context.$iframe[0].contentWindow.getSelection ) {
-			// Firefox and Opera
-			var range = context.$iframe[0].contentWindow.getSelection().getRangeAt( 0 );
-			// if our test above indicated that this was a sucessive button press, we need to collapse the
-			// selection to the end to avoid replacing text
-			if ( collapseToEnd ) {
-				// Make sure we're not collapsing ourselves into a BR tag
-				if ( range.endContainer.nodeName == 'BR' ) {
-					range.setEndBefore( range.endContainer );
-				}
-				range.collapse( false );
-			}
-			if ( options.ownline ) {
-				// We need to figure out if the cursor is at the start or end of a line
-				var atStart = false, atEnd = false;
-				var body = context.$content.get( 0 );
-				if ( range.startOffset == 0 ) {
-					// Start of a line
-					// FIXME: Not necessarily the case with syntax highlighting or
-					// template collapsing
-					atStart = true;
-				} else if ( range.startContainer == body ) {
-					// Look up the node just before the start of the selection
-					// If it's a 
, we're at the start of a line that starts with a - // block element; if not, we're at the end of a line - var n = body.firstChild; - for ( var i = 0; i < range.startOffset - 1 && n; i++ ) { - n = n.nextSibling; - } - if ( n && n.nodeName == 'BR' ) { - atStart = true; - } else { - atEnd = true; - } - } - if ( ( range.endOffset == 0 && range.endContainer.nodeValue == null ) || - ( range.endContainer.nodeName == '#text' && - range.endOffset == range.endContainer.nodeValue.length ) || - ( range.endContainer.nodeName == 'P' && range.endContainer.nodeValue == null ) ) { - atEnd = true; - } - if ( !atStart ) { - pre = "\n" + options.pre; - } - if ( !atEnd ) { - post += "\n"; - } - } - var insertText = ""; - if ( options.splitlines ) { - for( var j = 0; j < selTextArr.length; j++ ) { - insertText = insertText + pre + selTextArr[j] + post; - if( j != selTextArr.length - 1 ) { - insertText += "\n"; - } - } - } else { - insertText = pre + selText + post; - } - var insertLines = insertText.split( "\n" ); - range.extractContents(); - // Insert the contents one line at a time - insertNode() inserts at the beginning, so this has to happen - // in reverse order - // Track the first and last inserted node, and if we need to also track where the text we need to select - // afterwards starts and ends - var firstNode = null, lastNode = null; - var selSC = null, selEC = null, selSO = null, selEO = null, offset = 0; - for ( var i = insertLines.length - 1; i >= 0; i-- ) { - firstNode = context.$iframe[0].contentWindow.document.createTextNode( insertLines[i] ); - range.insertNode( firstNode ); - lastNode = lastNode || firstNode; - var newOffset = offset + insertLines[i].length; - if ( !selEC && post.length <= newOffset ) { - selEC = firstNode; - selEO = selEC.nodeValue.length - ( post.length - offset ); - } - if ( selEC && !selSC && pre.length >= insertText.length - newOffset ) { - selSC = firstNode; - selSO = pre.length - ( insertText.length - newOffset ); - } - offset = newOffset; - if ( i > 0 ) { - firstNode = context.$iframe[0].contentWindow.document.createElement( 'br' ); - range.insertNode( firstNode ); - newOffset = offset + 1; - if ( !selEC && post.length <= newOffset ) { - selEC = firstNode; - selEO = 1 - ( post.length - offset ); - } - if ( selEC && !selSC && pre.length >= insertText.length - newOffset ) { - selSC = firstNode; - selSO = pre.length - ( insertText.length - newOffset ); - } - offset = newOffset; - } - } - if ( firstNode ) { - context.fn.scrollToTop( $( firstNode.parentNode ) ); - } - if ( selectAfter ) { - setSelectionTo = { - startContainer: selSC, - endContainer: selEC, - start: selSO, - end: selEO - }; - } else if ( lastNode ) { - setSelectionTo = { - startContainer: lastNode, - endContainer: lastNode, - start: lastNode.nodeValue.length, - end: lastNode.nodeValue.length - }; - } - } else if ( context.$iframe[0].contentWindow.document.selection ) { - // IE - context.$iframe[0].contentWindow.focus(); - var range = context.$iframe[0].contentWindow.document.selection.createRange(); - if ( options.ownline && range.moveStart ) { - // Check if we're at the start of a line - // If not, prepend a newline - var range2 = context.$iframe[0].contentWindow.document.selection.createRange(); - range2.collapse(); - range2.moveStart( 'character', -1 ); - // FIXME: Which check is correct? - if ( range2.text != "\r" && range2.text != "\n" && range2.text != "" ) { - pre = "\n" + pre; - } - - // Check if we're at the end of a line - // If not, append a newline - var range3 = context.$iframe[0].contentWindow.document.selection.createRange(); - range3.collapse( false ); - range3.moveEnd( 'character', 1 ); - if ( range3.text != "\r" && range3.text != "\n" && range3.text != "" ) { - post += "\n"; - } - } - // if our test above indicated that this was a sucessive button press, we need to collapse the - // selection to the end to avoid replacing text - if ( collapseToEnd ) { - range.collapse( false ); - } - // TODO: Clean this up. Duplicate code due to the pre-existing browser specific structure of this - // function - var insertText = ""; - if ( options.splitlines ) { - for( var j = 0; j < selTextArr.length; j++ ) { - insertText = insertText + pre + selTextArr[j] + post; - if( j != selTextArr.length - 1 ) { - insertText += "\n"; - } - } - } else { - insertText = pre + selText + post; - } - // TODO: Maybe find a more elegant way of doing this like the Firefox code above? - range.pasteHTML( insertText - .replace( /\/g, '>' ) - .replace( /\r?\n/g, '
' ) - ); - if ( selectAfter ) { - range.moveStart( 'character', -post.length - selText.length ); - range.moveEnd( 'character', -post.length ); - range.select(); - } - } - - if ( setSelectionTo ) { - context.fn.setSelection( setSelectionTo ); - } - // Trigger the encapsulateSelection event (this might need to get named something else/done differently) - $( context.$iframe[0].contentWindow.document ).trigger( - 'encapsulateSelection', [ pre, options.peri, post, options.ownline, options.replace ] - ); - return context.$textarea; - }, - /** - * Gets the position (in resolution of bytes not nessecarily characters) in a textarea - * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead - */ - 'getCaretPosition': function( options ) { - var startPos = null, endPos = null; - if ( context.$iframe[0].contentWindow.getSelection ) { - var selection = context.$iframe[0].contentWindow.getSelection(); - if ( selection.rangeCount == 0 ) { - // We don't know where the cursor is - return [ 0, 0 ]; - } - var sc = selection.getRangeAt( 0 ).startContainer, ec = selection.getRangeAt( 0 ).endContainer; - var so = selection.getRangeAt( 0 ).startOffset, eo = selection.getRangeAt( 0 ).endOffset; - if ( sc.nodeName == 'BODY' ) { - // Grab the node just before the start of the selection - var n = sc.firstChild; - for ( var i = 0; i < so - 1 && n; i++ ) { - n = n.nextSibling; - } - sc = n; - so = 0; - } - if ( ec.nodeName == 'BODY' ) { - var n = ec.firstChild; - for ( var i = 0; i < eo - 1 && n; i++ ) { - n = n.nextSibling; - } - ec = n; - eo = 0; - } - - // Make sure sc and ec are leaf nodes - while ( sc.firstChild ) { - sc = sc.firstChild; - } - while ( ec.firstChild ) { - ec = ec.firstChild; - } - // Make sure the offsets are regenerated if necessary - context.fn.getOffset( 0 ); - var o; - for ( o in context.offsets ) { - if ( startPos === null && context.offsets[o].node == sc ) { - // For some wicked reason o is a string, even though - // we put it in as an integer. Use ~~ to coerce it too an int - startPos = ~~o + so - context.offsets[o].offset; - } - if ( startPos !== null && context.offsets[o].node == ec ) { - endPos = ~~o + eo - context.offsets[o].offset; - break; - } - } - } else if ( context.$iframe[0].contentWindow.document.selection ) { - // IE - // FIXME: This is mostly copypasted from the textSelection plugin - var d = context.$iframe[0].contentWindow.document; - var postFinished = false; - var periFinished = false; - var postFinished = false; - var preText, rawPreText, periText; - var rawPeriText, postText, rawPostText; - // Depending on the document state, and if the cursor has ever been manually placed within the document - // the following call such as setEndPoint can result in nasty errors. These cases are always cases - // in which the start and end points can safely be assumed to be 0, so we will just try our best to do - // the full process but fall back to 0. - try { - // Create range containing text in the selection - var periRange = d.selection.createRange().duplicate(); - // Create range containing text before the selection - var preRange = d.body.createTextRange(); - // Move the end where we need it - preRange.setEndPoint( "EndToStart", periRange ); - // Create range containing text after the selection - var postRange = d.body.createTextRange(); - // Move the start where we need it - postRange.setEndPoint( "StartToEnd", periRange ); - // Load the text values we need to compare - preText = rawPreText = preRange.text; - periText = rawPeriText = periRange.text; - postText = rawPostText = postRange.text; - /* - * Check each range for trimmed newlines by shrinking the range by 1 - * character and seeing if the text property has changed. If it has - * not changed then we know that IE has trimmed a \r\n from the end. - */ - do { - if ( !postFinished ) { - if ( preRange.compareEndPoints( "StartToEnd", preRange ) == 0 ) { - postFinished = true; - } else { - preRange.moveEnd( "character", -1 ); - if ( preRange.text == preText ) { - rawPreText += "\r\n"; - } else { - postFinished = true; - } - } - } - if ( !periFinished ) { - if ( periRange.compareEndPoints( "StartToEnd", periRange ) == 0 ) { - periFinished = true; - } else { - periRange.moveEnd( "character", -1 ); - if ( periRange.text == periText ) { - rawPeriText += "\r\n"; - } else { - periFinished = true; - } - } - } - if ( !postFinished ) { - if ( postRange.compareEndPoints("StartToEnd", postRange) == 0 ) { - postFinished = true; - } else { - postRange.moveEnd( "character", -1 ); - if ( postRange.text == postText ) { - rawPostText += "\r\n"; - } else { - postFinished = true; - } - } - } - } while ( ( !postFinished || !periFinished || !postFinished ) ); - startPos = rawPreText.replace( /\r\n/g, "\n" ).length; - endPos = startPos + rawPeriText.replace( /\r\n/g, "\n" ).length; - } catch( e ) { - startPos = endPos = 0; - } - } - return [ startPos, endPos ]; - }, - /** - * Sets the selection of the content - * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead - * - * @param start Character offset of selection start - * @param end Character offset of selection end - * @param startContainer Element in iframe to start selection in. If not set, start is a character offset - * @param endContainer Element in iframe to end selection in. If not set, end is a character offset - */ - 'setSelection': function( options ) { - var sc = options.startContainer, ec = options.endContainer; - sc = sc && sc.jquery ? sc[0] : sc; - ec = ec && ec.jquery ? ec[0] : ec; - if ( context.$iframe[0].contentWindow.getSelection ) { - // Firefox and Opera - var start = options.start, end = options.end; - if ( !sc || !ec ) { - var s = context.fn.getOffset( start ); - var e = context.fn.getOffset( end ); - sc = s ? s.node : null; - ec = e ? e.node : null; - start = s ? s.offset : null; - end = e ? e.offset : null; - // Don't try to set the selection past the end of a node, causes errors - // Just put the selection at the end of the node in this case - if ( sc != null && sc.nodeName == '#text' && start > sc.nodeValue.length ) { - start = sc.nodeValue.length - 1; - } - if ( ec != null && ec.nodeName == '#text' && end > ec.nodeValue.length ) { - end = ec.nodeValue.length - 1; - } - } - if ( !sc || !ec ) { - // The requested offset isn't in the offsets array - // Give up - return context.$textarea; - } - - var sel = context.$iframe[0].contentWindow.getSelection(); - while ( sc.firstChild && sc.nodeName != '#text' ) { - sc = sc.firstChild; - } - while ( ec.firstChild && ec.nodeName != '#text' ) { - ec = ec.firstChild; - } - var range = context.$iframe[0].contentWindow.document.createRange(); - range.setStart( sc, start ); - range.setEnd( ec, end ); - sel.removeAllRanges(); - sel.addRange( range ); - context.$iframe[0].contentWindow.focus(); - } else if ( context.$iframe[0].contentWindow.document.body.createTextRange ) { - // IE - var range = context.$iframe[0].contentWindow.document.body.createTextRange(); - if ( sc ) { - range.moveToElementText( sc ); - } - range.collapse(); - range.moveEnd( 'character', options.start ); - - var range2 = context.$iframe[0].contentWindow.document.body.createTextRange(); - if ( ec ) { - range2.moveToElementText( ec ); - } - range2.collapse(); - range2.moveEnd( 'character', options.end ); - - // IE does newline emulation for

s:

foo

bar

becomes foo\nbar just fine - // but

foo



bar

becomes foo\n\n\n\nbar , one \n too many - // Correct for this - var matches, counted = 0; - // while ( matches = range.htmlText.match( regex ) && matches.length <= counted ) doesn't work - // because the assignment side effect hasn't happened yet when the second term is evaluated - while ( matches = range.htmlText.match( /\<\/p\>(\]*\>)+\/gi ) ) { - if ( matches.length <= counted ) - break; - range.moveEnd( 'character', matches.length ); - counted += matches.length; - } - range2.moveEnd( 'character', counted ); - while ( matches = range2.htmlText.match( /\<\/p\>(\]*\>)+\/gi ) ) { - if ( matches.length <= counted ) - break; - range2.moveEnd( 'character', matches.length ); - counted += matches.length; - } - - range2.setEndPoint( 'StartToEnd', range ); - range2.select(); - } - return context.$textarea; - }, - /** - * Scroll a textarea to the current cursor position. You can set the cursor position with setSelection() - * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead - */ - 'scrollToCaretPosition': function( options ) { - context.fn.scrollToTop( context.fn.getElementAtCursor(), true ); - }, - /** - * Scroll an element to the top of the iframe - * DO NOT CALL THIS DIRECTLY, use $.textSelection( 'functionname', options ) instead - * - * @param $element jQuery object containing an element in the iframe - * @param force If true, scroll the element even if it's already visible - */ - 'scrollToTop': function( $element, force ) { - var html = context.$content.closest( 'html' ), - body = context.$content.closest( 'body' ), - parentHtml = $( 'html' ), - parentBody = $( 'body' ); - var y = $element.offset().top; - if ( !$.browser.msie && ! $element.is( 'body' ) ) { - y = parentHtml.scrollTop() > 0 ? y + html.scrollTop() - parentHtml.scrollTop() : y; - y = parentBody.scrollTop() > 0 ? y + body.scrollTop() - parentBody.scrollTop() : y; - } - var topBound = html.scrollTop() > body.scrollTop() ? html.scrollTop() : body.scrollTop(), - bottomBound = topBound + context.$iframe.height(); - if ( force || y < topBound || y > bottomBound ) { - html.scrollTop( y ); - body.scrollTop( y ); - } - $element.trigger( 'scrollToTop' ); - } -} ); - -/* Setup the IFrame */ -context.fn.setupIframe(); - -} } )( jQuery ); diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.js b/extensions/WikiEditor/modules/jquery.wikiEditor.js index def8b69e..e5d34aa9 100644 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.js +++ b/extensions/WikiEditor/modules/jquery.wikiEditor.js @@ -8,7 +8,8 @@ * $( 'textarea#wpTextbox1' ).wikiEditor( 'addModule', 'toolbar', { ... config ... } ); * */ -( function ( $ ) { +/*jshint onevar:false, boss:true */ +( function ( $, mw ) { /** * Global static object for wikiEditor that provides generally useful functionality to all modules and contexts. @@ -47,15 +48,15 @@ $.wikiEditor = { msie: [['>=', 7]], // Layout issues in FF < 2 firefox: [['>=', 2]], - // Text selection bugs galore - this may be a different situation with the new iframe-based solution + // Text selection bugs galore opera: [['>=', 9.6]], // jQuery minimums safari: [['>=', 3]], chrome: [['>=', 3]], netscape: [['>=', 9]], blackberry: false, - ipod: false, - iphone: false + ipod: [['>=', 6]], + iphone: [['>=', 6]] }, // Right-to-left languages rtl: { @@ -63,15 +64,15 @@ $.wikiEditor = { msie: [['>=', 8]], // Layout issues in FF < 2 firefox: [['>=', 2]], - // Text selection bugs galore - this may be a different situation with the new iframe-based solution + // Text selection bugs galore opera: [['>=', 9.6]], // jQuery minimums safari: [['>=', 3]], chrome: [['>=', 3]], netscape: [['>=', 9]], blackberry: false, - ipod: false, - iphone: false + ipod: [['>=', 6]], + iphone: [['>=', 6]] } }, @@ -113,7 +114,7 @@ $.wikiEditor = { isRequired: function ( module, requirement ) { if ( typeof module.req !== 'undefined' ) { for ( var req in module.req ) { - if ( module.req[req] == requirement ) { + if ( module.req[req] === requirement ) { return true; } } @@ -132,9 +133,10 @@ $.wikiEditor = { * with the key 'bar'. */ autoMsg: function ( object, property ) { + var i, p; // Accept array of possible properties, of which the first one found will be used - if ( typeof property == 'object' ) { - for ( var i in property ) { + if ( typeof property === 'object' ) { + for ( i in property ) { if ( property[i] in object || property[i] + 'Msg' in object ) { property = property[i]; break; @@ -144,11 +146,11 @@ $.wikiEditor = { if ( property in object ) { return object[property]; } else if ( property + 'Msg' in object ) { - var p = object[property + 'Msg']; + p = object[property + 'Msg']; if ( $.isArray( p ) && p.length >= 2 ) { - return mediaWiki.message.apply( mediaWiki.message, p ).plain(); + return mw.message.apply( mw.message, p ).plain(); } else { - return mediaWiki.message( p ).plain(); + return mw.message( p ).plain(); } } else { return ''; @@ -181,10 +183,10 @@ $.wikiEditor = { var src = $.wikiEditor.autoLang( icon, lang ); path = path || $.wikiEditor.imgPath; // Prepend path if src is not absolute - if ( src.substr( 0, 7 ) != 'http://' && src.substr( 0, 8 ) != 'https://' && src[0] != '/' ) { + if ( src.substr( 0, 7 ) !== 'http://' && src.substr( 0, 8 ) !== 'https://' && src[0] !== '/' ) { src = path + src; } - return src + '?' + mw.loader.version( 'jquery.wikiEditor' ); + return src + '?' + mw.loader.getVersion( 'jquery.wikiEditor' ); }, /** @@ -197,9 +199,9 @@ $.wikiEditor = { */ autoIconOrOffset: function ( icon, offset, path, lang ) { lang = lang || mw.config.get( 'wgUserLanguage' ); - if ( typeof offset == 'object' && lang in offset ) { + if ( typeof offset === 'object' && lang in offset ) { return offset[lang]; - } else if ( typeof icon == 'object' && lang in icon ) { + } else if ( typeof icon === 'object' && lang in icon ) { return $.wikiEditor.autoIcon( icon, undefined, lang ); } else { return $.wikiEditor.autoLang( offset, lang ); @@ -214,21 +216,21 @@ $.fn.wikiEditor = function () { // Skip any further work when running in browsers that are unsupported if ( !$.wikiEditor.isSupported() ) { - return $(this); + return $( this ); } /* Initialization */ // The wikiEditor context is stored in the element's data, so when this function gets called again we can pick up right // where we left off -var context = $(this).data( 'wikiEditor-context' ); +var context = $( this ).data( 'wikiEditor-context' ); // On first call, we need to set things up, but on all following calls we can skip right to the API handling -if ( !context || typeof context == 'undefined' ) { +if ( !context || typeof context === 'undefined' ) { // Star filling the context with useful data - any jQuery selections, as usual should be named with a preceding $ context = { // Reference to the textarea element which the wikiEditor is being built around - '$textarea': $(this), + '$textarea': $( this ), // Container for any number of mutually exclusive views that are accessible by tabs 'views': {}, // Container for any number of module-specific data - only including data for modules in use on this context @@ -236,25 +238,9 @@ if ( !context || typeof context == 'undefined' ) { // General place to shouve bits of data into 'data': {}, // Unique numeric ID of this instance used both for looking up and differentiating instances of wikiEditor - 'instance': $.wikiEditor.instances.push( $(this) ) - 1, - // Array mapping elements in the textarea to character offsets - 'offsets': null, - // Cache for context.fn.htmlToText() - 'htmlToTextMap': {}, - // The previous HTML of the iframe, stored to detect whether something really changed. - 'oldHTML': null, - // Same for delayedChange() - 'oldDelayedHTML': null, - // The previous selection of the iframe, stored to detect whether the selection has changed - 'oldDelayedSel': null, - // Saved selection state for IE + 'instance': $.wikiEditor.instances.push( $( this ) ) - 1, + // Saved selection state for old IE (<=10) 'savedSelection': null, - // Stack of states in { html: [string] } form - 'history': [], - // Current history state position - this is number of steps backwards, so it's always -1 or less - 'historyPosition': -1, - /// The previous historyPosition, stored to detect if change events were due to an undo or redo action - 'oldDelayedHistoryPosition': -1, // List of extensions active on this context 'extensions': [] }; @@ -262,7 +248,7 @@ if ( !context || typeof context == 'undefined' ) { /** * Externally Accessible API * - * These are available using calls to $(selection).wikiEditor( call, data ) where selection is a jQuery selection + * These are available using calls to $( selection ).wikiEditor( call, data ) where selection is a jQuery selection * of the textarea that the wikiEditor instance was built around. */ @@ -276,14 +262,14 @@ if ( !context || typeof context == 'undefined' ) { 'addModule': function ( context, data ) { var module, call, modules = {}; - if ( typeof data == 'string' ) { + if ( typeof data === 'string' ) { modules[data] = {}; - } else if ( typeof data == 'object' ) { + } else if ( typeof data === 'object' ) { modules = data; } for ( module in modules ) { // Check for the existance of an available / supported module with a matching name and a create function - if ( typeof module == 'string' && typeof $.wikiEditor.modules[module] !== 'undefined' && + if ( typeof module === 'string' && typeof $.wikiEditor.modules[module] !== 'undefined' && $.wikiEditor.isSupported( $.wikiEditor.modules[module] ) ) { // Extend the context's core API with this module's own API calls @@ -326,11 +312,11 @@ if ( !context || typeof context == 'undefined' ) { */ trigger: function ( name, event ) { // Event is an optional argument, but from here on out, at least the type field should be dependable - if ( typeof event == 'undefined' ) { + if ( typeof event === 'undefined' ) { event = { 'type': 'custom' }; } // Ensure there's a place for extra information to live - if ( typeof event.data == 'undefined' ) { + if ( typeof event.data === 'undefined' ) { event.data = {}; } @@ -350,9 +336,9 @@ if ( !context || typeof context == 'undefined' ) { name in $.wikiEditor.modules[module].evt ) { var ret = $.wikiEditor.modules[module].evt[name]( context, event ); - if (ret !== null) { + if ( ret !== null ) { //if 1 returns false, the end result is false - if( returnFromModules === null ) { + if ( returnFromModules === null ) { returnFromModules = ret; } else { returnFromModules = returnFromModules && ret; @@ -393,7 +379,7 @@ if ( !context || typeof context == 'undefined' ) { // Return the newly appended tab return $( '
' ) .attr( 'rel', 'wikiEditor-ui-view-' + options.name ) - .addClass( context.view == options.name ? 'current' : null ) + .addClass( context.view === options.name ? 'current' : null ) .append( $( '' ) .attr( 'href', '#' ) .mousedown( function () { @@ -402,11 +388,11 @@ if ( !context || typeof context == 'undefined' ) { } ) .click( function ( event ) { context.$ui.find( '.wikiEditor-ui-view' ).hide(); - context.$ui.find( '.' + $(this).parent().attr( 'rel' ) ).show(); + context.$ui.find( '.' + $( this ).parent().attr( 'rel' ) ).show(); context.$tabs.find( 'div' ).removeClass( 'current' ); - $(this).parent().addClass( 'current' ); - $(this).blur(); - if ( 'init' in options && typeof options.init == 'function' ) { + $( this ).parent().addClass( 'current' ); + $( this ).blur(); + if ( 'init' in options && typeof options.init === 'function' ) { options.init( context ); } event.preventDefault(); @@ -457,17 +443,17 @@ if ( !context || typeof context == 'undefined' ) { }, /** - * Save text selection for IE + * Save text selection for old IE (<=10) */ saveSelection: function () { - if ( $.client.profile().name === 'msie' ) { + if ( $.client.profile().name === 'msie' && document.selection && document.selection.createRange ) { context.$textarea.focus(); context.savedSelection = document.selection.createRange(); } }, /** - * Restore text selection for IE + * Restore text selection for old IE (<=10) */ restoreSelection: function () { if ( $.client.profile().name === 'msie' && context.savedSelection !== null ) { @@ -478,6 +464,13 @@ if ( !context || typeof context == 'undefined' ) { } }; + /** + * Workaround for a scrolling bug in IE8 (bug 61908) + */ + if ( $.client.profile().name === 'msie' ) { + context.$textarea.css( 'height', context.$textarea.height() ); + } + /** * Base UI Construction * @@ -493,6 +486,9 @@ if ( !context || typeof context == 'undefined' ) { .append( $( '' + mediaWiki.msg( 'wikieditor-loading' ) + '' ) .css( 'marginTop', context.$textarea.height() / 2 ) ); */ + /* Preserving cursor and focus state, which will get lost due to wrapAll */ + var hasFocus = context.$textarea.is( ':focus' ), + cursorPos = context.$textarea.textSelection( 'getCaretPosition', { startAndEnd: true } ); // Encapsulate the textarea with some containers for layout context.$textarea /* Disabling our loading div for now @@ -504,6 +500,14 @@ if ( !context || typeof context == 'undefined' ) { .wrapAll( $( '
' ).addClass( 'wikiEditor-ui-left' ) ) .wrapAll( $( '
' ).addClass( 'wikiEditor-ui-bottom' ) ) .wrapAll( $( '
' ).addClass( 'wikiEditor-ui-text' ) ); + // Restore scroll position after this wrapAll (tracked by mediawiki.action.edit) + context.$textarea.prop( 'scrollTop', $( '#wpScrolltop' ).val() ); + // Restore focus and cursor if needed + if ( hasFocus ) { + context.$textarea.focus(); + context.$textarea.textSelection( 'setSelection', { start: cursorPos[0], end: cursorPos[1] } ); + } + // Get references to some of the newly created containers context.$ui = context.$textarea.parent().parent().parent().parent().parent(); context.$wikitext = context.$textarea.parent().parent().parent().parent(); @@ -514,15 +518,16 @@ if ( !context || typeof context == 'undefined' ) { .append( $( '
' ).addClass( 'wikiEditor-ui-tabs' ).hide() ) .append( $( '
' ).addClass( 'wikiEditor-ui-buttons' ) ) ) - .before( $( '
' ) ); + .before( $( '
' ).addClass( 'wikiEditor-ui-clear' ) ); // Get references to some of the newly created containers context.$controls = context.$ui.find( '.wikiEditor-ui-buttons' ).hide(); context.$buttons = context.$ui.find( '.wikiEditor-ui-buttons' ); context.$tabs = context.$ui.find( '.wikiEditor-ui-tabs' ); // Clear all floating after the UI - context.$ui.after( $( '
' ) ); + context.$ui.after( $( '
' ).addClass( 'wikiEditor-ui-clear' ) ); // Attach a right container context.$wikitext.append( $( '
' ).addClass( 'wikiEditor-ui-right' ) ); + context.$wikitext.append( $( '
' ).addClass( 'wikiEditor-ui-clear' ) ); // Attach a top container to the left pane context.$wikitext.find( '.wikiEditor-ui-left' ).prepend( $( '
' ).addClass( 'wikiEditor-ui-top' ) ); // Setup the intial view @@ -539,9 +544,9 @@ if ( !context || typeof context == 'undefined' ) { var args = $.makeArray( arguments ); // Dynamically setup core extensions for modules that are required -if ( args[0] == 'addModule' && typeof args[1] !== 'undefined' ) { +if ( args[0] === 'addModule' && typeof args[1] !== 'undefined' ) { var modules = args[1]; - if ( typeof modules !== "object" ) { + if ( typeof modules !== 'object' ) { modules = {}; modules[args[1]] = ''; } @@ -573,8 +578,8 @@ if ( args.length > 0 ) { } // Store the context for next time, and support chaining -return $(this).data( 'wikiEditor-context', context ); +return $( this ).data( 'wikiEditor-context', context ); }; -}( jQuery ) ); +}( jQuery, mediaWiki ) ); diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.preview.js b/extensions/WikiEditor/modules/jquery.wikiEditor.preview.js index 39907364..f0665220 100644 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.preview.js +++ b/extensions/WikiEditor/modules/jquery.wikiEditor.preview.js @@ -1,6 +1,6 @@ /* Preview module for wikiEditor */ ( function ( $, mw ) { - +/*jshint onevar:false */ $.wikiEditor.modules.preview = { /** @@ -32,7 +32,7 @@ fn: { * @param context Context object of editor to create module in * @param config Configuration object to create module from */ - create: function ( context, config ) { + create: function ( context ) { if ( 'initialized' in context.modules.preview ) { return; } @@ -53,32 +53,37 @@ fn: { } context.modules.preview.$preview.find( '.wikiEditor-preview-contents' ).empty(); context.modules.preview.$preview.find( '.wikiEditor-preview-loading' ).show(); - $.post( - mw.util.wikiScript( 'api' ), - { + $.ajax( { + url: mw.util.wikiScript( 'api' ), + type: 'POST', + dataType: 'json', + data: { format: 'json', action: 'parse', title: mw.config.get( 'wgPageName' ), text: wikitext, - prop: 'text', + prop: 'text|modules', pst: '' - }, - function ( data ) { - if ( - typeof data.parse == 'undefined' || - typeof data.parse.text == 'undefined' || - typeof data.parse.text['*'] == 'undefined' - ) { - return; - } - context.modules.preview.previewText = wikitext; - context.modules.preview.$preview.find( '.wikiEditor-preview-loading' ).hide(); - context.modules.preview.$preview.find( '.wikiEditor-preview-contents' ) - .html( data.parse.text['*'] ) - .find( 'a:not([href^=#])' ).click( false ); - }, - 'json' - ); + } + } ).done( function ( data ) { + if ( !data.parse || !data.parse.text || data.parse.text['*'] === undefined ) { + return; + } + + context.modules.preview.previewText = wikitext; + context.modules.preview.$preview.find( '.wikiEditor-preview-loading' ).hide(); + context.modules.preview.$preview.find( '.wikiEditor-preview-contents' ) + .html( data.parse.text['*'] ) + .find( 'a:not([href^=#])' ) + .click( false ); + + var loadmodules = data.parse.modules.concat( + data.parse.modulescripts, + data.parse.modulestyles, + data.parse.modulemessages + ); + mw.loader.load( loadmodules ); + } ); } } ); @@ -89,21 +94,25 @@ fn: { // Gets the latest copy of the wikitext var wikitext = context.$textarea.textSelection( 'getContents' ); // Aborts when nothing has changed since the last time - if ( context.modules.preview.changesText == wikitext ) { + if ( context.modules.preview.changesText === wikitext ) { return; } context.$changesTab.find( 'table.diff tbody' ).empty(); context.$changesTab.find( '.wikiEditor-preview-loading' ).show(); // Call the API. First PST the input, then diff it - var postdata = { - format: 'json', - action: 'parse', - onlypst: '', - text: wikitext - }; - - $.post( mw.util.wikiScript( 'api' ), postdata, function ( data ) { + $.ajax( { + url: mw.util.wikiScript( 'api' ), + type: 'POST', + dataType: 'json', + data: { + format: 'json', + action: 'parse', + title: mw.config.get( 'wgPageName' ), + onlypst: '', + text: wikitext + } + } ).done( function ( data ) { try { var postdata2 = { format: 'json', @@ -115,25 +124,33 @@ fn: { rvprop: '' }; var section = $( '[name="wpSection"]' ).val(); - if ( section !== '' ) + if ( section !== '' ) { postdata2.rvsection = section; + } + + $.ajax( { + url: mw.util.wikiScript( 'api' ), + type: 'POST', + dataType: 'json', + data: postdata2 + } ).done( function ( data ) { + // Add diff CSS + mw.loader.load( 'mediawiki.action.history.diff' ); + try { + var diff = data.query.pages[data.query.pageids[0]] + .revisions[0].diff['*']; - $.post( mw.util.wikiScript( 'api' ), postdata2, function ( data ) { - // Add diff CSS - mw.loader.load( 'mediawiki.action.history.diff' ); - try { - var diff = data.query.pages[data.query.pageids[0]] - .revisions[0].diff['*']; - context.$changesTab.find( 'table.diff tbody' ) - .html( diff ); - context.$changesTab - .find( '.wikiEditor-preview-loading' ).hide(); - context.modules.preview.changesText = wikitext; - } catch ( e ) { } // "blah is undefined" error, ignore - }, 'json' - ); - } catch ( e ) { } // "blah is undefined" error, ignore - }, 'json' ); + context.$changesTab.find( 'table.diff tbody' ).html( diff ); + context.modules.preview.changesText = wikitext; + } catch ( e ) { + // "data.blah is undefined" error, ignore + } + context.$changesTab.find( '.wikiEditor-preview-loading' ).hide(); + } ); + } catch ( e ) { + // "data.blah is undefined" error, ignore + } + } ); } } ); diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.previewDialog.js b/extensions/WikiEditor/modules/jquery.wikiEditor.previewDialog.js index ca88c79a..34f38e30 100644 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.previewDialog.js +++ b/extensions/WikiEditor/modules/jquery.wikiEditor.previewDialog.js @@ -1,5 +1,6 @@ /* Publish module for wikiEditor */ -( function( $ ) { $.wikiEditor.modules.previewDialog = { +/*jshint onevar:false */ +( function ( $, mw ) { $.wikiEditor.modules.previewDialog = { /** * Compatability map @@ -29,7 +30,7 @@ fn: { * @param context Context object of editor to create module in * @param config Configuration object to create module from */ - create: function( context, config ) { + create: function ( context ) { // Build the dialog behind the Publish button var dialogID = 'wikiEditor-' + context.instance + '-preview-dialog'; $.wikiEditor.modules.dialogs.fn.create( @@ -42,11 +43,11 @@ fn: {
\
\ ', - init: function() { + init: function () { }, dialog: { buttons: { - 'wikieditor-publish-dialog-publish': function() { + 'wikieditor-publish-dialog-publish': function () { var minorChecked = $( '#wikiEditor-' + context.instance + '-dialog-minor' ).is( ':checked' ) ? 'checked' : ''; @@ -59,15 +60,15 @@ fn: { '-dialog-summary' ).val() ); $( '#editform' ).submit(); }, - 'wikieditor-publish-dialog-goback': function() { - $(this).dialog( 'close' ); + 'wikieditor-publish-dialog-goback': function () { + $( this ).dialog( 'close' ); } }, resizable: false, height: $( 'body' ).height() - 100, width: $( 'body' ).width() - 300, position: ['center', 'top'], - open: function() { + open: function () { // Gets the latest copy of the wikitext var wikitext = context.fn.getContents(); var $dialog = $( '#' + dialogID ); @@ -78,7 +79,7 @@ fn: { .css( 'top', '25px' ); // $dialog.dialog( 'option', 'width', $( 'body' ).width() - 300 ); // Aborts when nothing has changed since the last preview - if ( context.modules.preview.previewText == wikitext ) { + if ( context.modules.preview.previewText === wikitext ) { return; } @@ -94,11 +95,11 @@ fn: { 'pst': '', 'format': 'json' }, - function( data ) { + function ( data ) { if ( - typeof data.parse == 'undefined' || - typeof data.parse.text == 'undefined' || - typeof data.parse.text['*'] == 'undefined' + typeof data.parse === 'undefined' || + typeof data.parse.text === 'undefined' || + typeof data.parse.text['*'] === 'undefined' ) { return; } @@ -108,7 +109,7 @@ fn: { .html( '

' + mw.config.get( 'wgTitle' ) + '

' + data.parse.text['*'] ) - .find( 'a:not([href^=#])' ).click( function() { return false; } ); + .find( 'a:not([href^=#])' ).click( function () { return false; } ); }, 'json' ); @@ -120,12 +121,12 @@ fn: { ); context.fn.addButton( { 'captionMsg': 'wikieditor-preview-tab', - 'action': function() { - context.$textarea.wikiEditor( 'openDialog', 'preview'); + 'action': function () { + context.$textarea.wikiEditor( 'openDialog', 'preview' ); return false; } } ); } } -}; } )( jQuery ); +}; } )( jQuery, mediaWiki ); diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.publish.js b/extensions/WikiEditor/modules/jquery.wikiEditor.publish.js index b61140dc..c7360006 100644 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.publish.js +++ b/extensions/WikiEditor/modules/jquery.wikiEditor.publish.js @@ -1,4 +1,5 @@ /* Publish module for wikiEditor */ +/*jshint onevar:false */ ( function ( $ ) { $.wikiEditor.modules.publish = { @@ -31,7 +32,7 @@ fn: { * @param context Context object of editor to create module in * @param config Configuration object to create module from */ - create: function ( context, config ) { + create: function ( context ) { // Build the dialog behind the Publish button var dialogID = 'wikiEditor-' + context.instance + '-dialog'; $.wikiEditor.modules.dialogs.fn.create( @@ -66,9 +67,9 @@ fn: { init: function () { var i; - $(this).find( '[rel]' ).each( function () { - $(this).text( mediaWiki.msg( $(this).attr( 'rel' ) ) ); - }); + $( this ).find( '[rel]' ).each( function () { + $( this ).text( mediaWiki.msg( $( this ).attr( 'rel' ) ) ); + } ); /* REALLY DIRTY HACK! */ // Reformat the copyright warning stuff @@ -84,26 +85,28 @@ fn: { } newCopyWarnHTML += ''; // No list if there's only one element - $(this).find( '.wikiEditor-publish-dialog-copywarn' ).html( + $( this ).find( '.wikiEditor-publish-dialog-copywarn' ).html( copyWarnStatements.length > 1 ? newCopyWarnHTML : copyWarnHTML ); /* END OF REALLY DIRTY HACK */ - if ( $( '#wpMinoredit' ).length === 0 ) + if ( $( '#wpMinoredit' ).length === 0 ) { $( '#wikiEditor-' + context.instance + '-dialog-minor' ).hide(); - else if ( $( '#wpMinoredit' ).is( ':checked' ) ) + } else if ( $( '#wpMinoredit' ).prop( 'checked' ) ) { $( '#wikiEditor-' + context.instance + '-dialog-minor' ) .prop( 'checked', true ); - if ( $( '#wpWatchthis' ).length === 0 ) + } + if ( $( '#wpWatchthis' ).length === 0 ) { $( '#wikiEditor-' + context.instance + '-dialog-watch' ).hide(); - else if ( $( '#wpWatchthis' ).is( ':checked' ) ) + } else if ( $( '#wpWatchthis' ).prop( 'checked' ) ) { $( '#wikiEditor-' + context.instance + '-dialog-watch' ) .prop( 'checked', true ); + } - $(this).find( 'form' ).submit( function ( e ) { - $(this).closest( '.ui-dialog' ).find( 'button:first' ).click(); + $( this ).find( 'form' ).submit( function ( e ) { + $( this ).closest( '.ui-dialog' ).find( 'button:first' ).click(); e.preventDefault(); - }); + } ); }, immediateCreate: true, dialog: { @@ -122,7 +125,7 @@ fn: { $( '#editform' ).submit(); }, 'wikieditor-publish-dialog-goback': function () { - $(this).dialog( 'close' ); + $( this ).dialog( 'close' ); } }, open: function () { diff --git a/extensions/WikiEditor/modules/jquery.wikiEditor.templateEditor.js b/extensions/WikiEditor/modules/jquery.wikiEditor.templateEditor.js deleted file mode 100644 index bd00325f..00000000 --- a/extensions/WikiEditor/modules/jquery.wikiEditor.templateEditor.js +++ /dev/null @@ -1,865 +0,0 @@ -/* TemplateEditor module for wikiEditor */ -( function( $ ) { $.wikiEditor.modules.templateEditor = { -/** - * Name mappings, dirty hack which will be removed once "TemplateInfo" extension is more fully supported - */ -'nameMappings': { //keep these all lowercase to navigate web of redirects - "infobox skyscraper": "building_name", - "infobox settlement": "official_name" -}, - - -/** - * Compatability map - */ -'browsers': { - // Left-to-right languages - 'ltr': { - 'msie': [['>=', 8]], - 'firefox': [['>=', 3]], - 'opera': [['>=', 10]], - 'safari': [['>=', 4]] - }, - // Right-to-left languages - 'rtl': { - 'msie': false, - 'firefox': [['>=', 3]], - 'opera': [['>=', 10]], - 'safari': [['>=', 4]] - } -}, -/** - * Core Requirements - */ -'req': [ 'iframe' ], -/** - * Event handlers - */ -evt: { - - mark: function( context, event ) { - // The markers returned by this function are skipped on realchange, so don't regenerate them in that case - if ( context.modules.highlight.currentScope == 'realchange' ) { - return; - } - - // Get references to the markers and tokens from the current context - var markers = context.modules.highlight.markers; - var tokenArray = context.modules.highlight.tokenArray; - // Collect matching level 0 template call boundaries from the tokenArray - var level = 0; - var tokenIndex = 0; - while ( tokenIndex < tokenArray.length ){ - while ( tokenIndex < tokenArray.length && tokenArray[tokenIndex].label != 'TEMPLATE_BEGIN' ) { - tokenIndex++; - } - //open template - if ( tokenIndex < tokenArray.length ) { - var beginIndex = tokenIndex; - var endIndex = -1; //no match found - var openTemplates = 1; - var templatesMatched = false; - while ( tokenIndex < tokenArray.length - 1 && endIndex == -1 ) { - tokenIndex++; - if ( tokenArray[tokenIndex].label == 'TEMPLATE_BEGIN' ) { - openTemplates++; - } else if ( tokenArray[tokenIndex].label == 'TEMPLATE_END' ) { - openTemplates--; - if ( openTemplates == 0 ) { - endIndex = tokenIndex; - } //we can stop looping - } - }//while finding template ending - if ( endIndex != -1 ) { - markers.push( { - start: tokenArray[beginIndex].offset, - end: tokenArray[endIndex].offset, - type: 'template', - anchor: 'wrap', - afterWrap: function( node ) { - // Generate model - var model = $.wikiEditor.modules.templateEditor.fn.updateModel( $( node ) ); - if ( model.isCollapsible() ) { - $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) ); - $.wikiEditor.modules.templateEditor.fn.bindTemplateEvents( $( node ) ); - } else { - $( node ).addClass( 'wikiEditor-template-text' ); - } - }, - beforeUnwrap: function( node ) { - if ( $( node ).parent().hasClass( 'wikiEditor-template' ) ) { - $.wikiEditor.modules.templateEditor.fn.unwrapTemplate( $( node ) ); - } - }, - onSkip: function( node ) { - if ( $( node ).html() == $( node ).data( 'oldHTML' ) ) { - // No change - return; - } - - // Text changed, regenerate model - var model = $.wikiEditor.modules.templateEditor.fn.updateModel( $( node ) ); - - // Update template name if needed - if ( $( node ).parent().hasClass( 'wikiEditor-template' ) ) { - var $label = $( node ).parent().find( '.wikiEditor-template-label' ); - var displayName = $.wikiEditor.modules.templateEditor.fn.getTemplateDisplayName( model ); - if ( $label.text() != displayName ) { - $label.text( displayName ); - } - } - - // Wrap or unwrap the template if needed - if ( $( node ).parent().hasClass( 'wikiEditor-template' ) && - !model.isCollapsible() ) { - $.wikiEditor.modules.templateEditor.fn.unwrapTemplate( $( node ) ); - } else if ( !$( node ).parent().hasClass( 'wikiEditor-template' ) && - model.isCollapsible() ) { - $.wikiEditor.modules.templateEditor.fn.wrapTemplate( $( node ) ); - $.wikiEditor.modules.templateEditor.fn.bindTemplateEvents( $( node ) ); - } - }, - getAnchor: function( ca1, ca2 ) { - return $( ca1.parentNode ).is( 'span.wikiEditor-template-text' ) ? - ca1.parentNode : null; - }, - context: context, - skipDivision: 'realchange' - } ); - } else { //else this was an unmatched opening - tokenArray[beginIndex].label = 'TEMPLATE_FALSE_BEGIN'; - tokenIndex = beginIndex; - } - }//if opentemplates - } - }, //mark - - keydown: function( context, event ) { - // Reset our ignoreKeypress variable if it's set to true - if ( context.$iframe.data( 'ignoreKeypress' ) ) { - context.$iframe.data( 'ignoreKeypress', false ); - } - var $evtElem = event.jQueryNode; - if ( $evtElem.hasClass( 'wikiEditor-template-label' ) ) { - // Allow anything if the command or control key are depressed - if ( event.ctrlKey || event.metaKey ) return true; - switch ( event.which ) { - case 13: // Enter - $evtElem.click(); - event.preventDefault(); - return false; - case 32: // Space - $evtElem.parent().siblings( '.wikiEditor-template-expand' ).click(); - event.preventDefault(); - return false; - case 37:// Left - case 38:// Up - case 39:// Right - case 40: //Down - return true; - default: - // Set the ignroreKeypress variable so we don't allow typing if the key is held - context.$iframe.data( 'ignoreKeypress', true ); - // Can't type in a template name - event.preventDefault(); - return false; - } - } else if ( $evtElem.hasClass( 'wikiEditor-template-text' ) ) { - switch ( event.which ) { - case 13: // Enter - // Ensure that the user can't break this by holding in the enter key - context.$iframe.data( 'ignoreKeypress', true ); - // FIXME: May be a more elegant way to do this, but this works too - context.fn.encapsulateSelection( { 'pre': '\n', 'peri': '', 'post': '' } ); - event.preventDefault(); - return false; - default: return true; - } - } - }, - keyup: function( context, event ) { - // Rest our ignoreKeypress variable if it's set to true - if ( context.$iframe.data( 'ignoreKeypress' ) ) { - context.$iframe.data( 'ignoreKeypress', false ); - } - return true; - }, - keypress: function( context, event ) { - // If this event is from a keydown event which we want to block, ignore it - return ( context.$iframe.data( 'ignoreKeypress' ) ? false : true ); - } -}, -/** - * Regular expressions that produce tokens - */ -exp: [ - { 'regex': /{{/, 'label': "TEMPLATE_BEGIN" }, - { 'regex': /}}/, 'label': "TEMPLATE_END", 'markAfter': true } -], -/** - * Configuration - */ -cfg: { -}, -/** - * Internally used functions - */ -fn: { - /** - * Creates template form module within wikieditor - * @param context Context object of editor to create module in - * @param config Configuration object to create module from - */ - create: function( context, config ) { - // Initialize module within the context - context.modules.templateEditor = {}; - }, - /** - * Turns a simple template wrapper (really just a ) into a complex one - * @param $wrapper Wrapping - */ - wrapTemplate: function( $wrapper ) { - var model = $wrapper.data( 'model' ); - var context = $wrapper.data( 'marker' ).context; - var $template = $wrapper - .wrap( '' ) - .addClass( 'wikiEditor-template-text wikiEditor-template-text-shrunken' ) - .parent() - .addClass( 'wikiEditor-template-collapsed' ) - .prepend( - '' + - '' + - '' + - $.wikiEditor.modules.templateEditor.fn.getTemplateDisplayName( model ) + '' + - '' + - '' - ); - }, - /** - * Turn a complex template wrapper back into a simple one - * @param $wrapper Wrapping - */ - unwrapTemplate: function( $wrapper ) { - $wrapper.parent().replaceWith( $wrapper ); - }, - /** - * Bind events to a template - * @param $wrapper Original wrapper for the template to bind events to - */ - bindTemplateEvents: function( $wrapper ) { - var $template = $wrapper.parent( '.wikiEditor-template' ); - - if ( typeof ( opera ) == "undefined" ) { - $template.parent().attr('contentEditable', 'false'); - } - - $template.click( function(event) {event.preventDefault(); return false;} ); - - $template.find( '.wikiEditor-template-name' ) - .click( function( event ) { - $.wikiEditor.modules.templateEditor.fn.createDialog( $wrapper ); - event.stopPropagation(); - return false; - } ) - .mousedown( function( event ) { event.stopPropagation(); return false; } ); - $template.find( '.wikiEditor-template-expand' ) - .click( function( event ) { - $.wikiEditor.modules.templateEditor.fn.toggleWikiTextEditor( $wrapper ); - event.stopPropagation(); - return false; - } ) - .mousedown( function( event ) { event.stopPropagation(); return false; } ); - }, - /** - * Toggle the visisbilty of the wikitext for a given template - * @param $wrapper The origianl wrapper we want expand/collapse - */ - toggleWikiTextEditor: function( $wrapper ) { - var context = $wrapper.data( 'marker' ).context; - var $template = $wrapper.parent( '.wikiEditor-template' ); - context.fn.purgeOffsets(); - $template - .toggleClass( 'wikiEditor-template-expanded' ) - .toggleClass( 'wikiEditor-template-collapsed' ) ; - - var $templateText = $template.find( '.wikiEditor-template-text' ); - $templateText.toggleClass( 'wikiEditor-template-text-shrunken' ); - $templateText.toggleClass( 'wikiEditor-template-text-visible' ); - if( $templateText.hasClass('wikiEditor-template-text-shrunken') ){ - //we just closed the template - - // Update the model if we need to - if ( $templateText.html() != $templateText.data( 'oldHTML' ) ) { - var templateModel = $.wikiEditor.modules.templateEditor.fn.updateModel( $templateText ); - - //this is the only place the template name can be changed; keep the template name in sync - var $tLabel = $template.find( '.wikiEditor-template-label' ); - $tLabel.text( $.wikiEditor.modules.templateEditor.fn.getTemplateDisplayName( templateModel ) ); - } - - } - }, - /** - * Create a dialog for editing a given template and open it - * @param $wrapper The origianl wrapper for which to create the dialog - */ - createDialog: function( $wrapper ) { - var context = $wrapper.data( 'marker' ).context; - var $template = $wrapper.parent( '.wikiEditor-template' ); - var dialog = { - 'titleMsg': 'wikieditor-template-editor-dialog-title', - 'id': 'wikiEditor-template-dialog', - 'html': '\ -
\ -
\ -
\ -
', - init: function() { - $(this).find( '[rel]' ).each( function() { - $(this).text( mediaWiki.msg( $(this).attr( 'rel' ) ) ); - } ); - }, - immediateCreate: true, - dialog: { - width: 600, - height: 400, - dialogClass: 'wikiEditor-toolbar-dialog', - buttons: { - 'wikieditor-template-editor-dialog-submit': function() { - // More user feedback - var $templateDiv = $( this ).data( 'templateDiv' ); - context.fn.highlightLine( $templateDiv ); - - var $templateText = $templateDiv.children( '.wikiEditor-template-text' ); - var templateModel = $templateText.data( 'model' ); - $( this ).find( '.wikiEditor-template-dialog-field-wrapper textarea' ).each( function() { - // Update the value - templateModel.setValue( $( this ).data( 'name' ), $( this ).val() ); - }); - //keep text consistent - $.wikiEditor.modules.templateEditor.fn.updateModel( $templateText, templateModel ); - - $( this ).dialog( 'close' ); - }, - 'wikieditor-template-editor-dialog-cancel': function() { - $(this).dialog( 'close' ); - } - }, - open: function() { - var $templateDiv = $( this ).data( 'templateDiv' ); - var $templateText = $templateDiv.children( '.wikiEditor-template-text' ); - var templateModel = $templateText.data( 'model' ); - // Update the model if we need to - if ( $templateText.html() != $templateText.data( 'oldHTML' ) ) { - templateModel = $.wikiEditor.modules.templateEditor.fn.updateModel( $templateText ); - } - - // Build the table - // TODO: Be smart and recycle existing table - var params = templateModel.getAllInitialParams(); - var $fields = $( this ).find( '.wikiEditor-template-dialog-fields' ); - // Do some bookkeeping so we can recycle existing rows - var $rows = $fields.find( '.wikiEditor-template-dialog-field-wrapper' ); - for ( var paramIndex in params ) { - var param = params[paramIndex]; - if ( typeof param.name == 'undefined' ) { - // param is the template name, skip it - continue; - } - var paramText = typeof param == 'string' ? - param.name.replace( /[\_\-]/g, ' ' ) : - param.name; - var paramVal = templateModel.getValue( param.name ); - if ( $rows.length > 0 ) { - // We have another row to recycle - var $row = $rows.eq( 0 ); - $row.children( 'label' ).text( paramText ); - $row.children( 'textarea' ) - .data( 'name', param.name ) - .val( paramVal ) - .each( function() { - $(this).css( 'height', $(this).val().length > 24 ? '4.5em' : '1.5em' ); - } ); - $rows = $rows.not( $row ); - } else { - // Create a new row - var $paramRow = $( '
' ) - .addClass( 'wikiEditor-template-dialog-field-wrapper' ); - $( '