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 1 | Cell 2 |
Cell 3 | Cell 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 = '. |
. |