| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 3 | <head> |
| 4 | <title>Plugin: domiterator</title> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 6 | <link rel="stylesheet" type="text/css" href="../../test.css" /> |
| 7 | <script type="text/javascript" src="../../../../ckeditor_source.js"> |
| 8 | </script> |
| 9 | <script type="text/javascript" src="../../test.js"> |
| 10 | </script> |
| 11 | <script type="text/javascript"> |
| 12 | |
| 13 | CKEDITOR.plugins.load(['htmldataprocessor', 'htmlwriter', 'domiterator']); |
| 14 | |
| 15 | |
| 16 | </script> |
| 17 | <script type="text/javascript"> |
| 18 | //<![CDATA[ |
| 19 | |
| 20 | /** |
| 21 | * IE always returning CRLF for linefeed, so remove it when retrieve pre-formated text from text area. |
| 22 | * @param {Object} id |
| 23 | */ |
| 24 | function getTextAreaValue(id) |
| 25 | { |
| 26 | return CKEDITOR.document.getById(id).getValue().replace(/\r/gi, ''); |
| 27 | } |
| 28 | |
| 29 | CKEDITOR.test.addTestCase((function() |
| 30 | { |
| 31 | |
| 32 | // Local references. |
| 33 | var assert = CKEDITOR.test.assert, arrayAssert = YAHOO.util.ArrayAssert; |
| 34 | |
| 35 | var doc = new CKEDITOR.dom.document(document); |
| 36 | |
| 37 | // In these tests, we may "reset" the writer rules to avoid it formatting |
| 38 | // the output, making the assertion easier to the done. We don't need to |
| 39 | // test formatting features here, so this is ok. |
| 40 | var getDataProcessor = function() |
| 41 | { |
| 42 | var dataProcessor = new CKEDITOR.htmlDataProcessor(); |
| 43 | dataProcessor.writer._.rules = []; |
| 44 | return dataProcessor; |
| 45 | }; |
| 46 | |
| 47 | /** |
| 48 | * IE always returning CRLF for line-feed, so remove it when retrieving |
| 49 | * pre-formated text from text area. |
| 50 | */ |
| 51 | function getTextAreaValue(id) |
| 52 | { |
| 53 | return CKEDITOR.document.getById(id).getValue().replace(/\r/gi, ''); |
| 54 | } |
| 55 | |
| 56 | function assumeElementContentAreSame(container, textareaId) |
| 57 | { |
| 58 | if (typeof container == 'string') |
| 59 | container = doc.getById(container); |
| 60 | //Assume result document content |
| 61 | var html = getDataProcessor().toDataFormat(container); |
| 62 | assert.areSame(getTextAreaValue(textareaId), html); |
| 63 | } |
| 64 | |
| 65 | function assumeElementAreSame(element, textareaId) |
| 66 | { |
| 67 | if (typeof element == 'string') |
| 68 | element = doc.getById(element); |
| 69 | //Assume result document content |
| 70 | var html = getDataProcessor().toDataFormat( |
| 71 | { |
| 72 | getHtml: function() |
| 73 | { |
| 74 | |
| 75 | return element.getOuterHtml(); |
| 76 | } |
| 77 | }); |
| 78 | assert.areSame(getTextAreaValue(textareaId), html); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * |
| 83 | * @param {String|CKEDITOR.dom.range} containerId|range Either the id of html container which contents are treated as range, or a exisiting range object. |
| 84 | * @param {Object} iteratorOption |
| 85 | * @param {Array} expectedTagList block elements tagName list in iteration orders. |
| 86 | */ |
| 87 | function assumeIterationSameAs(containerIdOrRange, iteratorOption, expectedTagList) |
| 88 | { |
| 89 | var range; |
| 90 | if (typeof containerIdOrRange == 'string') |
| 91 | { |
| 92 | range = new CKEDITOR.dom.range(doc); |
| 93 | range.selectNodeContents(doc.getById(containerIdOrRange)); |
| 94 | } |
| 95 | else |
| 96 | range = containerIdOrRange; |
| 97 | |
| 98 | var iter = range.createIterator(); |
| 99 | CKEDITOR.tools.extend(iter, iteratorOption, true); |
| 100 | var blockList = [], block; |
| 101 | while ((block = iter.getNextParagraph())) |
| 102 | { |
| 103 | blockList.push(block.getName()); |
| 104 | } |
| 105 | arrayAssert.itemsAreEqual(expectedTagList, blockList); |
| 106 | } |
| 107 | |
| 108 | return { |
| 109 | |
| 110 | /** |
| 111 | * Test select none-paragraph nodes, looking for the established a new paragraph surrounding. |
| 112 | */ |
| 113 | test_noneParagraph: function() |
| 114 | { |
| 115 | var range = new CKEDITOR.dom.range(doc); |
| 116 | range.setStartAt(doc.getById('iterTarget9'), CKEDITOR.POSITION_AFTER_START); |
| 117 | range.setEndAt(doc.getById('iterTarget9'), CKEDITOR.POSITION_BEFORE_END); |
| 118 | assumeIterationSameAs(range, null, ['p']); |
| 119 | assumeElementAreSame(doc.getById('iterTarget9').getParent(), 'iterResult9'); |
| 120 | }, |
| 121 | |
| 122 | name: document.title |
| 123 | }; |
| 124 | })()); |
| 125 | |
| 126 | //]]> |
| 127 | </script> |
| 128 | </head> |
| 129 | <body> |
| 130 | <span id="iterTarget9">non-paragraph</span> |
| 131 | <p> |
| 132 | separating block |
| 133 | </p> |
| 134 | <textarea id="iterResult9"> |
| 135 | <p> |
| 136 | <span id="iterTarget9">non-paragraph</span> |
| 137 | </p> |
| 138 | </textarea> |
| 139 | </body> |
| 140 | </html> |