module("tinymce.dom.TridentSelection", { setupModule: function() { if (window.getSelection) { return; } QUnit.stop(); document.getElementById('view').innerHTML = ''; tinymce.init({ selector: "textarea", elements: "elm1", add_unload_trigger: false, disable_nodechange: true, skin: false, init_instance_callback: function(ed) { window.editor = ed; QUnit.start(); } }); } }); if (!window.getSelection) { test("Selection of element containing text", function(){ expect(5); editor.setContent('

123

', { format: 'raw' }); var rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); rng = editor.selection.getRng(1); equal(rng.startContainer.nodeName, '#text', 'Start container is text node'); equal(rng.endContainer.nodeName, '#text', 'End container is text node'); equal(rng.startOffset, 0, 'Start of text node'); equal(rng.endOffset, 3, 'End of text node'); equal(editor.dom.getOuterHTML(rng.cloneContents()), '123', 'Contents matches'); }); test("Single image selection", function(){ expect(6); editor.setContent('

', { format: 'raw' }); var rng = editor.dom.createRng(); rng.setStartBefore(editor.dom.select('img')[0]); rng.setEndAfter(editor.dom.select('img')[0]); editor.selection.setRng(rng); rng = editor.selection.getRng(1); equal(rng.startContainer.nodeName, 'P', 'Check startContainer'); equal(rng.endContainer.nodeName, 'P', 'Check endContainer'); equal(rng.startOffset, 0, 'Check startOffset'); equal(rng.endOffset, 1, 'Check endOffset'); equal(Utils.cleanHtml(editor.dom.getOuterHTML(rng.cloneContents()).toLowerCase()), '', 'Check contents'); ok(editor.selection.getRng().item, 'Check if it\'s a control selection'); }); test("Multiple image selection", function(){ expect(6); editor.setContent('

', { format: 'raw' }); var rng = editor.dom.createRng(); rng.setStartBefore(editor.dom.select('img')[0]); rng.setEndAfter(editor.dom.select('img')[1]); editor.selection.setRng(rng); rng = editor.selection.getRng(1); equal(rng.startContainer.nodeName, 'P'); equal(rng.endContainer.nodeName, 'P'); equal(rng.startOffset, 0); equal(rng.endOffset, 2); equal(editor.dom.getOuterHTML(rng.cloneContents()).toLowerCase(), ''); ok(editor.selection.getRng().parentElement, 'Is text selection'); }); test("Text node selection", function(){ expect(5); editor.setContent('

1234

', { format: 'raw' }); var rng = editor.dom.createRng(); rng.setStart(editor.getBody().firstChild.firstChild, 1); rng.setEnd(editor.getBody().firstChild.firstChild, 3); editor.selection.setRng(rng); rng = editor.selection.getRng(1); equal(rng.startContainer.nodeName, '#text'); equal(rng.endContainer.nodeName, '#text'); equal(rng.startOffset, 1); equal(rng.endOffset, 3); equal(editor.dom.getOuterHTML(rng.cloneContents()), '23'); }); test("Text node selection between two elements", function(){ expect(5); editor.setContent('

1234

abcd

', { format: 'raw' }); var rng = editor.dom.createRng(); rng.setStart(editor.getBody().firstChild.firstChild, 1); rng.setEnd(editor.getBody().childNodes[1].firstChild, 3); editor.selection.setRng(rng); rng = editor.selection.getRng(1); equal(rng.startContainer.nodeName, '#text'); equal(rng.endContainer.nodeName, '#text'); equal(rng.startOffset, 1); equal(rng.endOffset, 3); equal(editor.dom.getOuterHTML(rng.cloneContents()).replace(/[\r\n]/g, '').toLowerCase(), '

234

abc

'); editor.setContent('

1

1234

abcd

2

', { format: 'raw' }); }); test("Mixed selection start at element end at text", function(){ expect(5); editor.setContent('

text

', { format: 'raw' }); var rng = editor.dom.createRng(); rng.setStartBefore(editor.dom.select('img')[0]); rng.setEnd(editor.getBody().firstChild.lastChild, 3); editor.selection.setRng(rng); rng = editor.selection.getRng(1); equal(rng.startContainer.nodeName, 'P'); equal(rng.endContainer.nodeName, '#text'); equal(rng.startOffset, 0); equal(rng.endOffset, 3); equal(editor.dom.getOuterHTML(rng.cloneContents()).toLowerCase(), 'tex'); }); test("Mixed selection start at text end at element", function(){ expect(5); editor.setContent('

text

', { format: 'raw' }); var rng = editor.dom.createRng(); rng.setStart(editor.getBody().firstChild.firstChild, 1); rng.setEndAfter(editor.getBody().firstChild.lastChild); editor.selection.setRng(rng); rng = editor.selection.getRng(1); equal(rng.startContainer.nodeName, '#text'); equal(rng.startOffset, 1); equal(rng.endContainer.nodeName, 'P'); equal(rng.endOffset, 2); equal(editor.dom.getOuterHTML(rng.cloneContents()).toLowerCase(), 'ext'); }); test("Caret position before image", function(){ expect(4); editor.setContent('

', { format: 'raw' }); var rng = editor.dom.createRng(); rng.setStartBefore(editor.dom.select('img')[0]); rng.setEndBefore(editor.dom.select('img')[0]); editor.selection.setRng(rng); rng = editor.selection.getRng(1); equal(rng.startContainer.nodeName, 'P'); equal(rng.endContainer.nodeName, 'P'); equal(rng.startOffset, 0); equal(rng.endOffset, 0); }); test("Caret position between images", function(){ expect(4); editor.setContent('

', { format: 'raw' }); var rng = editor.dom.createRng(); rng.setStartAfter(editor.dom.select('img')[0]); rng.setEndAfter(editor.dom.select('img')[0]); editor.selection.setRng(rng); rng = editor.selection.getRng(1); equal(rng.startContainer.nodeName, 'P'); equal(rng.endContainer.nodeName, 'P'); equal(rng.startOffset, 1); equal(rng.endOffset, 1); }); test("Caret position after image", function(){ expect(4); editor.setContent('

', { format: 'raw' }); var rng = editor.dom.createRng(); rng.setStartAfter(editor.dom.select('img')[1]); rng.setEndAfter(editor.dom.select('img')[1]); editor.selection.setRng(rng); rng = editor.selection.getRng(1); equal(rng.startContainer.nodeName, 'P'); equal(rng.endContainer.nodeName, 'P'); equal(rng.startOffset, 2); equal(rng.endOffset, 2); }); test("Selection of empty text element", function(){ expect(6); editor.setContent('
', { format: 'raw' }); var rng = editor.dom.createRng(); rng.setStart(editor.getBody(), 0); rng.setEnd(editor.getBody(), 1); editor.selection.setRng(rng); rng = editor.selection.getRng(true); equal(rng.startContainer.nodeName, 'BODY'); equal(rng.endContainer.nodeName, 'BODY'); equal(rng.startOffset, 0); equal(rng.endOffset, 1); equal(rng.startContainer.childNodes[0].innerHTML, ''); equal(editor.dom.getOuterHTML(rng.cloneContents()).toLowerCase(), '
'); }); test("Selection of empty text element with caret inside", function(){ expect(6); editor.setContent('
', { format: 'raw' }); var rng = editor.dom.createRng(); rng.setStart(editor.getBody().firstChild, 0); rng.setEnd(editor.getBody().firstChild, 0); editor.selection.setRng(rng); rng = editor.selection.getRng(true); equal(rng.startContainer.nodeName, 'DIV'); equal(rng.endContainer.nodeName, 'DIV'); equal(rng.startOffset, 0); equal(rng.endOffset, 0); equal(rng.startContainer.innerHTML, ''); equal(editor.dom.getOuterHTML(rng.cloneContents()).toLowerCase(), ''); }); /*test("Caret position before table", function() { var table, rng; editor.focus(); editor.setContent('

Before

Cell 1Cell 2
Cell 3Cell 4

After

'); table = editor.dom.get('table'); rng = editor.selection.getRng(); rng.moveToElementText(table); rng.move('character', -1); rng.select(); rng = editor.selection.getRng(1); equal(rng.startContainer.nodeName, 'BODY'); equal(rng.startOffset, 1); equal(rng.endContainer.nodeName, 'BODY'); equal(rng.endOffset, 1); });*/ test("Selection end within empty element", function() { var rng; editor.focus(); editor.getBody().innerHTML = '

123

'; rng = editor.execCommand('SelectAll'); rng = editor.selection.getRng(true); equal(rng.startContainer.nodeName, '#text'); equal(rng.startOffset, 0); equal(rng.endContainer.nodeName, 'BODY'); equal(rng.endOffset, 2); }); test("Selection after paragraph", function() { var rng; editor.focus(); editor.getBody().innerHTML = '

123

abcd

'; rng = editor.dom.createRng(); rng.setStart(editor.getBody().firstChild, 1); rng.setEnd(editor.getBody().firstChild, 1); editor.selection.setRng(rng); rng = editor.selection.getRng(true); ok(rng.startContainer == rng.endContainer); equal(rng.startContainer.nodeName, '#text'); equal(rng.startOffset, 3); equal(rng.endContainer.nodeName, '#text'); equal(rng.endOffset, 3); }); test("Selection of text outside of a block element", function() { var r; editor.settings.forced_root_block = ''; editor.focus(); editor.getBody().innerHTML = 'Text'; r = editor.dom.createRng(); r.setStart(editor.getBody().lastChild, 2); r.setEnd(editor.getBody().lastChild, 2); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody().lastChild, "Start container is text node."); equal(r.endContainer, editor.getBody().lastChild, "End container is text node."); equal(r.startOffset, 2); equal(r.endOffset, 2); equal(editor.selection.getStart(), editor.getBody(), "Selection start is body."); deepEqual(editor.selection.getSelectedBlocks(), [], "No blocks selected."); }); test("Resizable element text selection", function() { var r; editor.getBody().innerHTML = '
.
abc
'; editor.focus(); r = editor.dom.createRng(); r.setStart(editor.getBody().firstChild.lastChild, 1); r.setEnd(editor.getBody().firstChild.lastChild, 2); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody().firstChild.lastChild, "Start container is text node."); equal(r.endContainer, editor.getBody().firstChild.lastChild, "End container is text node."); equal(r.startOffset, 1); equal(r.endOffset, 2); }); test("Resizable element before table selection", function() { var r; editor.getBody().innerHTML = '
.
'; editor.focus(); r = editor.dom.createRng(); r.setStart(editor.getBody().firstChild, 0); r.setEnd(editor.getBody().firstChild, 0); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody().firstChild, "Start container is div node."); equal(r.endContainer, editor.getBody().firstChild, "End container is div node."); equal(r.startOffset, 0); equal(r.endOffset, 0); }); test("Fragmented text nodes after element", function() { var r; editor.getBody().innerHTML = 'x'; editor.getBody().appendChild(editor.getDoc().createTextNode('1')); editor.getBody().appendChild(editor.getDoc().createTextNode('23')); editor.getBody().appendChild(editor.getDoc().createTextNode('456')); editor.getBody().appendChild(editor.getDoc().createTextNode('7890')); editor.focus(); r = editor.dom.createRng(); r.setStart(editor.getBody().lastChild, 1); r.setEnd(editor.getBody().lastChild, 1); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody().lastChild, "Start container is last text node."); equal(r.endContainer, editor.getBody().lastChild, "End container is last text node."); equal(r.startOffset, 1); equal(r.endOffset, 1); r = editor.dom.createRng(); r.setStart(editor.getBody().childNodes[2], 2); r.setEnd(editor.getBody().childNodes[2], 2); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody().childNodes[2], "Start container is second text node."); equal(r.endContainer, editor.getBody().childNodes[2], "End container is second text node."); equal(r.startOffset, 2); equal(r.endOffset, 2); r = editor.dom.createRng(); r.setStart(editor.getBody().childNodes[3], 0); r.setEnd(editor.getBody().childNodes[3], 1); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody().childNodes[2], "Start container is second text node (lean left)."); equal(r.endContainer, editor.getBody().childNodes[3], "End container is third text node."); equal(r.startOffset, 2); equal(r.endOffset, 1); }); test("Fragmented text nodes before element", function() { var r; editor.getBody().innerHTML = ''; editor.getBody().appendChild(editor.getDoc().createTextNode('1')); editor.getBody().appendChild(editor.getDoc().createTextNode('23')); editor.getBody().appendChild(editor.getDoc().createTextNode('456')); editor.getBody().appendChild(editor.getDoc().createTextNode('7890')); editor.getBody().appendChild(editor.dom.create('b', null, 'x')); editor.focus(); r = editor.dom.createRng(); r.setStart(editor.getBody().childNodes[3], 1); r.setEnd(editor.getBody().childNodes[3], 1); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody().childNodes[3], "Start container is last text node."); equal(r.endContainer, editor.getBody().childNodes[3], "End container is last text node."); equal(r.startContainer.nodeValue, '7890'); equal(r.startOffset, 1); equal(r.endOffset, 1); r = editor.dom.createRng(); r.setStart(editor.getBody().childNodes[1], 2); r.setEnd(editor.getBody().childNodes[1], 2); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody().childNodes[2], "Start container is second text node. (lean right)"); equal(r.endContainer, editor.getBody().childNodes[2], "End container is second text node."); equal(r.startContainer.nodeValue, '456'); equal(r.startOffset, 0); equal(r.endOffset, 0); r = editor.dom.createRng(); r.setStart(editor.getBody().childNodes[1], 0); r.setEnd(editor.getBody().childNodes[1], 1); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody().childNodes[1], "Start container is second text node."); equal(r.endContainer, editor.getBody().childNodes[1], "End container is third text node."); equal(r.startContainer.nodeValue, '23'); equal(r.endContainer.nodeValue, '23'); equal(r.startOffset, 0); equal(r.endOffset, 1); }); test("Non contentEditable elements", function() { var r; editor.getBody().innerHTML = 'aaa'; editor.focus(); r = editor.dom.createRng(); r.setStart(editor.getBody(), 0); r.setEnd(editor.getBody(), 0); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody(), "Start container is before first nonEditable."); equal(r.endContainer, editor.getBody(), "End container is before first nonEditable."); equal(r.startOffset, 0); equal(r.endOffset, 0); r = editor.dom.createRng(); r.setStart(editor.getBody(), 0); r.setEnd(editor.getBody(), 1); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody(), "Start container before first nonEditable."); equal(r.endContainer, editor.getBody(), "End container is after first nonEditable."); equal(r.startOffset, 0); equal(r.endOffset, 1); r = editor.dom.createRng(); r.setStart(editor.getBody(), 0); r.setEnd(editor.getBody(), 2); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody(), "Start container before first nonEditable."); equal(r.endContainer, editor.getBody(), "End container is after second nonEditable."); equal(r.startOffset, 0); equal(r.endOffset, 2); r = editor.dom.createRng(); r.setStart(editor.getBody(), 1); r.setEnd(editor.getBody(), 1); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody(), "Start container is before second nonEditable."); equal(r.endContainer, editor.getBody(), "End container is div before second nonEditable."); equal(r.startOffset, 1); equal(r.endOffset, 1); r = editor.dom.createRng(); r.setStart(editor.getBody(), 2); r.setEnd(editor.getBody(), 2); editor.selection.setRng(r); r = editor.selection.getRng(true); equal(r.startContainer, editor.getBody(), "Start container is after last nonEditable."); equal(r.endContainer, editor.getBody(), "End container is after last nonEditable."); equal(r.startOffset, 2); equal(r.endOffset, 2); }); } else { test("Skipped ie_selection tests as not running in IE.", function() { ok(true, "Dummy assert"); }); }