| 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"></script> |
| 8 | <script type="text/javascript" src="../../test.js"></script> |
| 9 | <script type="text/javascript"> |
| 10 | |
| 11 | CKEDITOR.plugins.load( [ 'htmldataprocessor', 'htmlwriter', 'domiterator'] ); |
| 12 | |
| 13 | |
| 14 | </script> |
| 15 | <script type="text/javascript"> |
| 16 | //<![CDATA[ |
| 17 | |
| 18 | /** |
| 19 | * IE always returning CRLF for linefeed, so remove it when retrieve pre-formated text from text area. |
| 20 | * @param {Object} id |
| 21 | */ |
| 22 | function getTextAreaValue( id ) |
| 23 | { |
| 24 | return CKEDITOR.document.getById( id ).getValue().replace(/\r/gi,''); |
| 25 | } |
| 26 | |
| 27 | CKEDITOR.test.addTestCase( (function() |
| 28 | { |
| 29 | |
| 30 | // Local references. |
| 31 | var assert = CKEDITOR.test.assert, |
| 32 | arrayAssert = YAHOO.util.ArrayAssert; |
| 33 | |
| 34 | var doc = new CKEDITOR.dom.document( document ); |
| 35 | |
| 36 | // In these tests, we may "reset" the writer rules to avoid it formatting |
| 37 | // the output, making the assertion easier to the done. We don't need to |
| 38 | // test formatting features here, so this is ok. |
| 39 | var getDataProcessor = function() |
| 40 | { |
| 41 | var dataProcessor = new CKEDITOR.htmlDataProcessor(); |
| 42 | dataProcessor.writer._.rules = []; |
| 43 | return dataProcessor; |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * IE always returning CRLF for line-feed, so remove it when retrieving |
| 48 | * pre-formated text from text area. |
| 49 | */ |
| 50 | function getTextAreaValue( id ) |
| 51 | { |
| 52 | return CKEDITOR.document.getById( id ).getValue().replace( /\r/gi, '' ); |
| 53 | } |
| 54 | |
| 55 | function assumeElementContentAreSame( container, textareaId ) |
| 56 | { |
| 57 | if( typeof container == 'string' ) |
| 58 | container = doc.getById( container ); |
| 59 | //Assume result document content |
| 60 | var html = getDataProcessor().toDataFormat( container ); |
| 61 | assert.areSame( getTextAreaValue( textareaId ) , html ); |
| 62 | } |
| 63 | |
| 64 | function assumeElementAreSame( element, textareaId ) |
| 65 | { |
| 66 | if( typeof element == 'string' ) |
| 67 | element = doc.getById( element ); |
| 68 | //Assume result document content |
| 69 | var html = getDataProcessor().toDataFormat( element.getOuterHtml() ); |
| 70 | assert.areSame( getTextAreaValue( textareaId ) , html ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * |
| 75 | * @param {String|CKEDITOR.dom.range} containerId|range Either the id of html container which contents are treated as range, or a exisiting range object. |
| 76 | * @param {Object} iteratorOption |
| 77 | * @param {Array} expectedTagList block elements tagName list in iteration orders. |
| 78 | */ |
| 79 | function assumeIterationSameAs( containerIdOrRange, iteratorOption, expectedTagList ) |
| 80 | { |
| 81 | var range; |
| 82 | if( typeof containerIdOrRange == 'string' ) |
| 83 | { |
| 84 | range = new CKEDITOR.dom.range( doc ); |
| 85 | range.selectNodeContents( doc.getById( containerIdOrRange ) ); |
| 86 | } |
| 87 | else |
| 88 | range = containerIdOrRange; |
| 89 | |
| 90 | var iter = range.createIterator(); |
| 91 | CKEDITOR.tools.extend( iter, iteratorOption, true ); |
| 92 | var blockList = [], block; |
| 93 | while (( block = iter.getNextParagraph() ) ) |
| 94 | { |
| 95 | blockList.push( block.getName() ); |
| 96 | } |
| 97 | arrayAssert.itemsAreEqual( expectedTagList, blockList ); |
| 98 | } |
| 99 | |
| 100 | return { |
| 101 | |
| 102 | /** |
| 103 | * Test nested blocks |
| 104 | */ |
| 105 | test_toDataFormat5 : function() |
| 106 | { |
| 107 | var range = new CKEDITOR.dom.range( doc ), node = doc.getById( 'iterTarget5' ); |
| 108 | range.setStartBefore( node ); |
| 109 | range.setEndAfter( node ); |
| 110 | assumeIterationSameAs( range , null, [ 'div' , 'p' ] ); |
| 111 | assumeElementAreSame( 'iterTarget5', 'iterResult5' ); |
| 112 | }, |
| 113 | |
| 114 | name : document.title |
| 115 | }; |
| 116 | })() ); |
| 117 | |
| 118 | //]]> |
| 119 | </script> |
| 120 | </head> |
| 121 | <body> |
| 122 | |
| 123 | <div id="iterTarget5"><p>text</p></div> |
| 124 | <textarea id="iterResult5"><div id="iterTarget5"><p>text</p></div></textarea> |
| 125 | </body> |
| 126 | </html> |
| 127 | No newline at end of file |