diff --git a/src/test/unit/lists.js b/src/test/unit/lists.js index 4cdf0c27..85670a19 100644 --- a/src/test/unit/lists.js +++ b/src/test/unit/lists.js @@ -2177,3 +2177,181 @@ test("Shouldn't eat newline text spacing in li", function () { wymeditor.update(); htmlEquals(wymeditor, expectedHtml); }); + +module("list-indent_outdent_with_table", {setup: setupWym}); + +/** + changeIndent + ============ + + Puts the html in the body of the wymeditor and applies either the indent or + outdent command to the selection ranging from the element with id selStart + to the element with id selEnd. selStart and selEnd should be strings in the + form '#' where is the id attribute of the element + to be selected. inOrOur should be the string 'indent' if the indent command + should be applied to the selection, or it should be the string 'outdent' if + the outdent command should be applied to the selection. +*/ +function changeIndent(wymeditor, html, selStart, selEnd, inOrOut) { + var $body; + + wymeditor.html(html); + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + makeTextSelection(wymeditor, $body.find(selStart)[0], + $body.find(selEnd)[0], 0, 1); + if (inOrOut === "indent") { + wymeditor.indent(); + } else if (inOrOut === "outdent") { + wymeditor.outdent(); + } +} + +var TEST_LINEBREAK_SPACER = '
'; + +var expectedMiddleIn = String() + + '
    ' + + '
  1. 1' + + '
      ' + + '
    1. 2' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
      test_1
      1_1
      ' + + TEST_LINEBREAK_SPACER + + '
    2. ' + + '
    3. 3
    4. ' + + '
    ' + + '
  2. ' + + '
'; + +var expectedMiddleOutPartial = String() + + '
    ' + + '
  1. 1
  2. ' + + '
  3. 2' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
    test_1
    1_1
    ' + + TEST_LINEBREAK_SPACER + + '
      ' + + '
    1. 3
    2. ' + + '
    ' + + '
  4. ' + + '
'; + +var expectedMiddleOutFull = String() + + '
    ' + + '
  1. 1
  2. ' + + '
  3. 2' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
    test_1
    1_1
    ' + + TEST_LINEBREAK_SPACER + + '
  4. ' + + '
  5. 3
  6. ' + + '
'; + +var expectedEndIn = String() + + '
    ' + + '
  1. 1
  2. ' + + '
  3. 2' + + '
      ' + + '
    1. 3' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
      test_1
      1_1
      ' + + TEST_LINEBREAK_SPACER + + '
    2. ' + + '
    ' + + '
  4. ' + + '
'; + +var expectedEndOut = String() + + '
    ' + + '
  1. 1
  2. ' + + '
  3. 2
  4. ' + + '
  5. 3' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
    test_1
    1_1
    ' + + TEST_LINEBREAK_SPACER + + '
  6. ' + + '
'; + +var startEndInNoBR = expectedEndIn.replace(TEST_LINEBREAK_SPACER, ''); + +var startEndOutNoBR = expectedEndOut.replace(TEST_LINEBREAK_SPACER, ''); + +test("Indent with table in the middle of a list", function () { + expect(1); + var wymeditor = jQuery.wymeditors(0), + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + + changeIndent(wymeditor, expectedMiddleOutFull, '#li_2', '#li_3', 'indent'); + equals(normalizeHtml($body.get(0).firstChild), expectedMiddleIn, + "Table indented in the middle of a list"); +}); + +test("Indent with table at the end of a list", function () { + expect(2); + var wymeditor = jQuery.wymeditors(0), + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + + changeIndent(wymeditor, expectedEndOut, '#li_3', '#li_3', 'indent'); + equals(normalizeHtml($body.get(0).firstChild), expectedEndIn, + "Table indented at the end of a list"); + + changeIndent(wymeditor, startEndOutNoBR, '#li_3', '#li_3', 'indent'); + equals(normalizeHtml($body.get(0).firstChild), expectedEndIn, + "Table indented at the end of a list with no line break"); +}); + +test("Outdent with table in the middle of a list", function () { + expect(1); + var wymeditor = jQuery.wymeditors(0), + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + + changeIndent(wymeditor, expectedMiddleIn, '#li_2', '#li_2', 'outdent'); + equals(normalizeHtml($body.get(0).firstChild), expectedMiddleOutPartial, + "Table outdented in the middle of a list"); +}); + +test("Outdent with table at the end of a list", function () { + expect(2); + var wymeditor = jQuery.wymeditors(0), + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + + changeIndent(wymeditor, expectedEndIn, '#li_3', '#li_3', 'outdent'); + equals(normalizeHtml($body.get(0).firstChild), expectedEndOut, + "Table outdented at the end of a list"); + + changeIndent(wymeditor, expectedEndOut, '#li_3', '#li_3', 'outdent'); + equals(normalizeHtml($body.get(0).firstChild), expectedEndOut, + "Table outdented at the end of a list with no line break"); +}); + diff --git a/src/test/unit/test.js b/src/test/unit/test.js index 88f34b94..432fdb91 100644 --- a/src/test/unit/test.js +++ b/src/test/unit/test.js @@ -939,6 +939,362 @@ if (jQuery.browser.mozilla) { }); } +// Functions and html strings for table in list modules + +/** + setupTable + ========== + + Puts the html in the body of the wymeditor and creates a rowsXcols-sized + table at the selection (using the specified selectionType which can be + 'text' or 'collapsed'). The table's cells each have an id attribute of the + form "t__" where is the last + character of the caption, is the x-coordinate of the cell in the table, + and is the y-coordinate of the cell in the table. Each cell then has + text of the form "_" where and are the same as described for + the id attribute. Here is a small example: + + setupTable(wymeditor, html, selection, selectionType, 2, 1, 'test_1') + inserts the following html at the selection: + + + + + + + + + + + +
test_1
1_1
2_1
+*/ +function setupTable(wymeditor, html, selection, selectionType, + rows, cols, caption) { + var $body, + $element, + $table, + i, + j, + selectionNum = (selectionType === 'text') ? 1 : 0, + cellStr, + idStr = 't' + caption.slice(-1); + + wymeditor.html(html); + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + $element = $body.find(selection); + makeTextSelection(wymeditor, $element, $element, 0, selectionNum); + + wymeditor.insertTable(rows, cols, caption, ''); + $tableCells = $body.find('caption:contains(' + caption + ')') + .parent() + .find('td'); + + for (i = 0; i < rows; i++) { + for (j = 0; j < cols; j++) { + cellStr = (i+1) + '_' + (j+1); + $tableCells.eq(i + j) + .attr('id', idStr + '_' + cellStr) + .text(cellStr); + } + } +} + +var TEST_LINEBREAK_SPACER = '
'; + +var listForTableInsertion = String() + + '
    ' + + '
  1. 1
  2. ' + + '
  3. 2
  4. ' + + '
  5. 3
  6. ' + + '
'; + +var sublistForTableInsertion = String() + + '
    ' + + '
  1. 1' + + '
      ' + + '
    1. 2' + + '
        ' + + '
      1. 3
      2. ' + + '
      ' + + '
    2. ' + + '
    ' + + '
  2. ' + + '
'; + +var expectedSublistOneTable = String() + + '
    ' + + '
  1. 1' + + '
      ' + + '
    1. 2' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
      test_1
      1_1
      ' + + TEST_LINEBREAK_SPACER + + '
        ' + + '
      1. 3
      2. ' + + '
      ' + + '
    2. ' + + '
    ' + + '
  2. ' + + '
'; + +var expectedSublistTwoTables = String() + + '
    ' + + '
  1. 1' + + '
      ' + + '
    1. 2' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
      test_2
      1_1
      2_1
      ' + + TEST_LINEBREAK_SPACER + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
      test_1
      1_1
      ' + + TEST_LINEBREAK_SPACER + + '
        ' + + '
      1. 3
      2. ' + + '
      ' + + '
    2. ' + + '
    ' + + '
  2. ' + + '
'; + +var expectedSublistThreeTables = String() + + '
    ' + + '
  1. 1' + + '
      ' + + '
    1. 2' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
      test_3
      1_1
      2_1
      3_1
      ' + + TEST_LINEBREAK_SPACER + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
      test_2
      1_1
      2_1
      ' + + TEST_LINEBREAK_SPACER + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
      test_1
      1_1
      ' + + TEST_LINEBREAK_SPACER + + '
        ' + + '
      1. 3
      2. ' + + '
      ' + + '
    2. ' + + '
    ' + + '
  2. ' + + '
'; + +var sublistThreeTablesNoBR = + expectedSublistThreeTables.replace( + RegExp(TEST_LINEBREAK_SPACER, 'g'), ''); + +var expectedMiddleOutFull = String() + + '
    ' + + '
  1. 1
  2. ' + + '
  3. 2' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
    test_1
    1_1
    ' + + TEST_LINEBREAK_SPACER + + '
  4. ' + + '
  5. 3
  6. ' + + '
'; + +var expectedEndIn = String() + + '
    ' + + '
  1. 1
  2. ' + + '
  3. 2' + + '
      ' + + '
    1. 3' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
      test_1
      1_1
      ' + + TEST_LINEBREAK_SPACER + + '
    2. ' + + '
    ' + + '
  4. ' + + '
'; + +var expectedEndOut = String() + + '
    ' + + '
  1. 1
  2. ' + + '
  3. 2
  4. ' + + '
  5. 3' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
    test_1
    1_1
    ' + + TEST_LINEBREAK_SPACER + + '
  6. ' + + '
'; + +module("table-insert_in_list", {setup: setupWym}); + +test("Table insertion in the middle of a list with text selection", function () { + expect(1); + var wymeditor = jQuery.wymeditors(0), + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + + setupTable(wymeditor, listForTableInsertion, '#li_2', 'text', + 1, 1, 'test_1'); + equals(normalizeHtml($body.get(0).firstChild), expectedMiddleOutFull, + "Table insertion in the middle of a list with text selection"); +}); + +test("Table insertion at the end of a list with text selection", function () { + expect(1); + var wymeditor = jQuery.wymeditors(0), + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + + setupTable(wymeditor, listForTableInsertion, '#li_3', 'text', + 1, 1, 'test_1'); + equals(normalizeHtml($body.get(0).firstChild), expectedEndOut, + "Table insertion at the end of a list with text selection"); +}); + +test("Table insertion in the middle of a list with collapsed selection", function () { + expect(1); + var wymeditor = jQuery.wymeditors(0), + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + + setupTable(wymeditor, listForTableInsertion, '#li_2', 'collapsed', + 1, 1, 'test_1'); + equals(normalizeHtml($body.get(0).firstChild), expectedMiddleOutFull, + "Table insertion in the middle of a list with collapsed selection"); +}); + +test("Table insertion at the end of a list with collapsed selection", function () { + expect(1); + var wymeditor = jQuery.wymeditors(0), + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + + setupTable(wymeditor, listForTableInsertion, '#li_3', 'collapsed', + 1, 1, 'test_1'); + equals(normalizeHtml($body.get(0).firstChild), expectedEndOut, + "Table insertion at the end of a list with collapsed selection"); +}); + +module("table-insert_in_sublist", {setup: setupWym}); + +test("Single table insertion into a sublist", function () { + expect(1); + var wymeditor = jQuery.wymeditors(0), + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + + setupTable(wymeditor, sublistForTableInsertion, '#li_2', 'text', + 1, 1, 'test_1'); + equals(normalizeHtml($body.get(0).firstChild), expectedSublistOneTable, + "Single table insertion within a sublist"); +}); + +test("Double table insertion into a sublist", function () { + expect(1); + var wymeditor = jQuery.wymeditors(0), + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + + setupTable(wymeditor, expectedSublistOneTable, '#li_2', 'text', + 2, 1, 'test_2'); + equals(normalizeHtml($body.get(0).firstChild), expectedSublistTwoTables, + "Double table insertion within a sublist"); +}); + +test("Triple table insertion into a sublist", function () { + expect(1); + var wymeditor = jQuery.wymeditors(0), + $body = jQuery(wymeditor._doc).find('body.wym_iframe'); + + setupTable(wymeditor, expectedSublistTwoTables, '#li_2', 'text', + 3, 1, 'test_3'); + equals(normalizeHtml($body.get(0).firstChild), + expectedSublistThreeTables, + "Triple table insertion within a sublist"); +}); + +module("table-parse_spacers_in_list", {setup: setupWym}); +// The tests in this module use the htmlEquals function from utils.js to parse +// the resulting html from tables being inserted into a list or sublist using +// the parser to ensure that the line break spacers are properly removed. + +test("Parse list with a table at the end", function () { + var wymeditor = jQuery.wymeditors(0); + + wymeditor.html(expectedEndOut); + htmlEquals(wymeditor, startEndOutNoBR); +}); + +test("Parse list with a table at the end in a sublist", function () { + var wymeditor = jQuery.wymeditors(0); + + wymeditor.html(expectedEndIn); + htmlEquals(wymeditor, startEndInNoBR); +}); + +test("Parse list with multiple tables in a sublist", function () { + var wymeditor = jQuery.wymeditors(0); + + wymeditor.html(expectedSublistThreeTables); + htmlEquals(wymeditor, sublistThreeTablesNoBR); +}); + module("preformatted text", {setup: setupWym}); test("Preformatted text retains spacing", function () { diff --git a/src/test/unit/utils.js b/src/test/unit/utils.js index 62a95cd5..db89d6d4 100644 --- a/src/test/unit/utils.js +++ b/src/test/unit/utils.js @@ -5,6 +5,11 @@ var pr_lt = //g; var pr_quot = /\"/g; +// Attributes with browser specific use that should be ignored when normalizing +// HTML for comparison across browsers. +var ignoreAttributes = ['_moz_editor_bogus_node', '_moz_dirty', + '_wym_visited', 'sizset']; + /** * Escape html special characters. */ @@ -36,7 +41,21 @@ function normalizeHtml(node) { n, child, sortedAttrs, - i; + i, + $captions; + + if (jQuery.browser.msie) { + $captions = jQuery(node).find('table > caption'); + if ($captions.length) { + // Some versions of IE can unexpectedly add the caption of a table + // after the table body. This ensures the table caption is always + // at the start. + $captions.each(function () { + jQuery(this).prependTo(jQuery(this).parent()); + }); + } + } + switch (node.nodeType) { case 1: // an element name = node.tagName.toLowerCase(); @@ -50,8 +69,18 @@ function normalizeHtml(node) { for (i = n; --i >= 0;) { attr = attrs[i]; if (attr.specified) { - // We only care about specified attributes - sortedAttrs.push(attr); + // We only care about specified attributes and ignore + // attributes that are only used in specific browsers. + if (jQuery.inArray(attr.nodeName, ignoreAttributes) === -1 && + + // With some versions of jQuery on IE, sometimes an + // attribute named `sizcache` followed by a differing + // string of numbers is added to elements, so regex + // must be used to check for it. + !/sizcache\d*/.test(attr.nodeName)) { + + sortedAttrs.push(attr); + } } } sortedAttrs.sort(function (a, b) { @@ -65,7 +94,13 @@ function normalizeHtml(node) { '="' + attribToHtml(attr.value) + '"'; } } - html += '>'; + if (name === "br" || name === "img" || name === "link") { + // close self-closing element + html += '/>'; + } else { + html += '>'; + } + for (child = node.firstChild; child; child = child.nextSibling) { html += normalizeHtml(child); } diff --git a/src/wymeditor/core.js b/src/wymeditor/core.js index 82a8f990..89ea79f8 100644 --- a/src/wymeditor/core.js +++ b/src/wymeditor/core.js @@ -249,14 +249,28 @@ jQuery.extend(WYMeditor, { // The remaining `MAIN_CONTAINERS` that are not considered `BLOCKING_ELEMENTS` NON_BLOCKING_ELEMENTS : ["p", "h1", "h2", "h3", "h4", "h5", "h6"], - // The subset of the `MAIN_CONTAINERS` containing the header elements. - HEADER_ELEMENTS : ["h1", "h2", "h3", "h4", "h5", "h6"], + // The elements that define a type of list. + LIST_TYPE_ELEMENTS : ["ul", "ol"], // The elements that are allowed to be turned in to lists. If an item in // this array isn't in the MAIN_CONTAINERS array, then its contents will be // turned in to a list instead. POTENTIAL_LIST_ELEMENTS : ["p", "h1", "h2", "h3", "h4", "h5", "h6", "pre", "blockquote", "td"], + // The elements that are allowed to have a table inserted after them or + // within them. + POTENTIAL_TABLE_INSERT_ELEMENTS : ["p", "h1", "h2", "h3", "h4", "h5", "h6", + "pre", "blockquote", "li"], + + // The elements that are allowed to have a table inserted inline within + // them. + INLINE_TABLE_INSERTION_ELEMENTS : ["li"], + + // Class used to identify
elements that are used to space out + // blocking elements in the editor so that they can be removed before + // parsing the html. + BLOCKING_ELEMENT_SPACER_CLASS : "wym-blocking-element-spacer", + // Keyboard mappings so that we don't have to remember that 38 means up // when reading keyboard handlers KEY : { diff --git a/src/wymeditor/editor/base.js b/src/wymeditor/editor/base.js index c82d8c54..c85a754e 100644 --- a/src/wymeditor/editor/base.js +++ b/src/wymeditor/editor/base.js @@ -279,15 +279,25 @@ WYMeditor.editor.prototype.html = function (html) { enforce a valid, well-formed, semantic xhtml result. */ WYMeditor.editor.prototype.xhtml = function () { - var html; - - // Remove any of the placeholder nodes we've created for start/end content - // insertion - jQuery(this._doc.body).children(WYMeditor.BR).remove(); + this.removeBlockingElementSpacers(); return this.parser.parse(this.html()); }; +/** + WYMeditor.editor.removeBlockingElementSpacers + ============================================= + + Remove any placeholder nodes that were created to space apart blocking + elements for managable editing within the editor. +*/ +WYMeditor.editor.prototype.removeBlockingElementSpacers = function () { + var $body = jQuery(this._doc.body); + + $body.children(WYMeditor.BR).remove(); + $body.find('.' + WYMeditor.BLOCKING_ELEMENT_SPACER_CLASS).remove(); +}; + /** WYMeditor.editor.exec ===================== @@ -724,9 +734,6 @@ WYMeditor.editor.prototype.status = function (sMessage) { WYMeditor.editor.prototype.update = function () { var html; - // Dirty fix to remove stray line breaks (#189) - jQuery(this._doc.body).children(WYMeditor.BR).remove(); - html = this.xhtml(); jQuery(this._element).val(html); jQuery(this._box).find(this._options.htmlValSelector).not('.hasfocus').val(html); //#147 @@ -742,8 +749,8 @@ WYMeditor.editor.prototype.update = function () { certain block elements. */ WYMeditor.editor.prototype.fixBodyHtml = function () { - this.fixDoubleBr(); this.spaceBlockingElements(); + this.fixDoubleBr(); }; /** @@ -759,10 +766,26 @@ WYMeditor.editor.prototype.spaceBlockingElements = function () { $body = jQuery(this._doc).find('body.wym_iframe'), children = $body.children(), - placeholderNode = '
', + + placeholderNode, $firstChild, $lastChild, - blockSepSelector; + blockSepSelector, + blockInListSepSelector, + $blockInList; + + if (jQuery.browser.mozilla) { + placeholderNode = '
'; + } else { + placeholderNode = '
'; + } // Make sure that we still have a bogus node at both the begining and end if (children.length > 0) { @@ -773,7 +796,9 @@ WYMeditor.editor.prototype.spaceBlockingElements = function () { $firstChild.before(placeholderNode); } - if ($lastChild.is(blockingSelector)) { + if ($lastChild.is(blockingSelector) && + !(jQuery.browser.msie && jQuery.browser.version < "7.0")) { + $lastChild.after(placeholderNode); } } @@ -783,10 +808,31 @@ WYMeditor.editor.prototype.spaceBlockingElements = function () { // Put placeholder nodes between consecutive blocking elements and between // blocking elements and normal block-level elements $body.find(blockSepSelector).before(placeholderNode); + + blockInListSepSelector = this._getBlockInListSepSelector(); + $blockInList = $body.find(blockInListSepSelector); + + // The $blockInList selection must be iterated over to only add placeholder + // nodes after blocking elements at the end of a list item rather than all + // blocking elements in a list. No jQuery selection that is supported on + // all browsers can do this check, so that is why it must be done by using + // `each` to iterate over the selection. Note that the handling of the + // spacing of other blocking elements in a list besides after the last + // blocking element in a list item is already handled by the + // blockSepSelector used before this. + $blockInList.each(function () { + var $block = jQuery(this); + + if(!$block.next(blockingSelector).length && + !$block.next(WYMeditor.BR).length) { + + $block.after(placeholderNode); + } + }); }; /** - editor._buildBlockSepSelector + editor._getBlockSepSelector ============================= Build a string representing a jquery selector that will find all @@ -815,10 +861,36 @@ WYMeditor.editor.prototype._getBlockSepSelector = function () { blockCombo.push(elementI + ' + ' + elementO); }); }); + this._blockSpacersSel = blockCombo.join(', '); return this._blockSpacersSel; }; +/* + editor._getBlockInListSepSelector + ================================== + + Returns a selector for getting all of the block elements in lists + or sublists. The block elements at the end of lists or sublists should have + a spacer line break after them in the editor at all times. +*/ +WYMeditor.editor.prototype._getBlockInListSepSelector = function () { + if (typeof (this._blockInListSpacersSel) !== 'undefined') { + return this._blockInListSpacersSel; + } + + var blockCombo = []; + + jQuery.each(WYMeditor.LIST_TYPE_ELEMENTS, function (indexO, elementO) { + jQuery.each(WYMeditor.BLOCKING_ELEMENTS, function (indexI, elementI) { + blockCombo.push(elementO + ' ' + elementI); + }); + }); + + this._blockInListSpacersSel = blockCombo.join(', '); + return this._blockInListSpacersSel; +}; + /** editor.fixDoubleBr ================== @@ -828,8 +900,11 @@ WYMeditor.editor.prototype._getBlockSepSelector = function () { */ WYMeditor.editor.prototype.fixDoubleBr = function () { var $body = jQuery(this._doc).find('body.wym_iframe'), - $last_br; - // Strip consecutive brs unless they're in a a pre tag + $last_br, + + blockingSelector = WYMeditor.BLOCKING_ELEMENTS.join(', '); + + // Strip consecutive brs unless they're in a pre tag $body.children('br + br').filter(':not(pre br)').remove(); // Also remove any brs between two p's @@ -1981,10 +2056,12 @@ WYMeditor.editor.prototype.indent = function () { manipulationFunc = function () { var domChanged = false; + for (i = 0; i < listItems.length; i++) { wym._indentSingleItem(listItems[i]); domChanged = true; } + return domChanged; }; return wym.restoreSelectionAfterManipulation(manipulationFunc); @@ -2041,10 +2118,12 @@ WYMeditor.editor.prototype.outdent = function () { manipulationFunc = function () { var domChanged = false; + for (i = 0; i < listItems.length; i++) { wym._outdentSingleItem(listItems[i]); domChanged = true; } + return domChanged; }; return wym.restoreSelectionAfterManipulation(manipulationFunc); @@ -2274,7 +2353,6 @@ WYMeditor.editor.prototype.insertTable = function (rows, columns, caption, summa x, y, - container; // Create the table caption @@ -2296,14 +2374,22 @@ WYMeditor.editor.prototype.insertTable = function (rows, columns, caption, summa // Find the currently-selected container container = jQuery( - this.findUp(this.container(), WYMeditor.MAIN_CONTAINERS) + this.findUp(this.container(), WYMeditor.POTENTIAL_TABLE_INSERT_ELEMENTS) ).get(0); if (!container || !container.parentNode) { // No valid selected container. Put the table at the end. jQuery(this._doc.body).append(table); + + } else if (jQuery.inArray(container.nodeName.toLowerCase(), + WYMeditor.INLINE_TABLE_INSERTION_ELEMENTS) > -1) { + // Insert table after selection if container is allowed to have tables + // inserted inline. + jQuery(this.selection().focusNode).after(table); + } else { - // Append the table after the currently-selected container + // If the table is not allowed to be inserted inline with the + // container, insert it after the container. jQuery(container).after(table); } diff --git a/src/wymeditor/editor/ie.js b/src/wymeditor/editor/ie.js index 547acb5b..e0dc0904 100644 --- a/src/wymeditor/editor/ie.js +++ b/src/wymeditor/editor/ie.js @@ -25,8 +25,6 @@ WYMeditor.WymClassExplorer = function (wym) { this._class = "className"; }; -WYMeditor.WymClassExplorer.PLACEHOLDER_NODE = '
'; - WYMeditor.WymClassExplorer.prototype.initIframe = function (iframe) { //This function is executed twice, though it is called once! //But MSIE needs that, otherwise designMode won't work. @@ -281,36 +279,3 @@ WYMeditor.WymClassExplorer.prototype.setFocusToNode = function (node, toStart) { node.focus(); }; -/** @name spaceBlockingElements - * @description Insert
elements between adjacent blocking elements and - * p elements, between block elements or blocking elements and after blocking - * elements. - */ -WYMeditor.WymClassExplorer.prototype.spaceBlockingElements = function () { - var blockingSelector = WYMeditor.BLOCKING_ELEMENTS.join(', '); - - var $body = jQuery(this._doc).find('body.wym_iframe'); - var children = $body.children(); - var placeholderNode = WYMeditor.WymClassExplorer.PLACEHOLDER_NODE; - - // Make sure we have the appropriate placeholder nodes - if (children.length > 0) { - var $firstChild = jQuery(children[0]); - var $lastChild = jQuery(children[children.length - 1]); - - // Ensure begining placeholder - if ($firstChild.is(blockingSelector)) { - $firstChild.before(placeholderNode); - } - if (jQuery.browser.version >= "7.0" && $lastChild.is(blockingSelector)) { - $lastChild.after(placeholderNode); - } - } - - var blockSepSelector = this._getBlockSepSelector(); - - // Put placeholder nodes between consecutive blocking elements and between - // blocking elements and normal block-level elements - $body.find(blockSepSelector).before(placeholderNode); -}; -