| 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: editor</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 | <!--[if gte IE 6]> |
| 9 | <script type="text/javascript" src="../../../_dev/firebuglite/firebuglite.js"></script> |
| 10 | <![endif]--> |
| 11 | <script type="text/javascript" src="../test.js"></script> |
| 12 | <script type="text/javascript"> |
| 13 | //<![CDATA[ |
| 14 | |
| 15 | function prepareEditor( elementId, mode, config, callback, context ) |
| 16 | { |
| 17 | CKEDITOR.on( 'instanceReady', |
| 18 | function( evt ) |
| 19 | { |
| 20 | var isMe = mode == CKEDITOR.ELEMENT_MODE_REPLACE ? |
| 21 | evt.editor.name == elementId |
| 22 | : evt.editor.element.$ == |
| 23 | document.getElementById( elementId ); |
| 24 | if ( isMe ) |
| 25 | { |
| 26 | callback.call( context, evt.editor ); |
| 27 | } |
| 28 | }, this ); |
| 29 | |
| 30 | mode = mode || CKEDITOR.ELEMENT_MODE_REPLACE; |
| 31 | switch( mode ) |
| 32 | { |
| 33 | case CKEDITOR.ELEMENT_MODE_REPLACE : |
| 34 | CKEDITOR.replace( elementId, config ); |
| 35 | break; |
| 36 | case CKEDITOR.ELEMENT_MODE_APPENDTO : |
| 37 | CKEDITOR.appendTo( elementId, config ); |
| 38 | break; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | |
| 43 | CKEDITOR.test.addTestCase( ( function() |
| 44 | { |
| 45 | |
| 46 | // Local references. |
| 47 | var assert = CKEDITOR.test.assert, |
| 48 | arrayAssert = YAHOO.util.ArrayAssert; |
| 49 | |
| 50 | var doc = new CKEDITOR.dom.document( document ); |
| 51 | |
| 52 | /** |
| 53 | * IE always returning CRLF for linefeed, so remove it when retrieve pre-formated text from text area. |
| 54 | * @param {Object} id |
| 55 | */ |
| 56 | function getTextAreaValue( id ) |
| 57 | { |
| 58 | return CKEDITOR.document.getById( id ).getValue().replace(/\r/gi,''); |
| 59 | } |
| 60 | |
| 61 | // In these tests, we may "reset" the writer rules to avoid it formatting |
| 62 | // the output, making the assertion easier to the done. We don't need to |
| 63 | // test formatting features here, so this is ok. |
| 64 | var getDataProcessor = function() |
| 65 | { |
| 66 | var dataProcessor = new CKEDITOR.htmlDataProcessor(); |
| 67 | dataProcessor.writer._.rules = []; |
| 68 | return dataProcessor; |
| 69 | }; |
| 70 | |
| 71 | |
| 72 | /** |
| 73 | * Make assumption by compare the formatted element content and the content |
| 74 | * inside pre-formated textarea. |
| 75 | * @param {Object} containerId |
| 76 | * @param {Object} textareaId |
| 77 | */ |
| 78 | function assumeElementContentAreSame( container, textareaId ) |
| 79 | { |
| 80 | //Assume result document content |
| 81 | var html = getDataProcessor().toDataFormat( container.getHtml() ); |
| 82 | assert.areSame( getTextAreaValue( textareaId ) , html ); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Set the range with the start/end position specified by the locator, which in form of bookmark2. |
| 87 | * @param {Object} range |
| 88 | * @param {Array} startPosition range start path including offset |
| 89 | * @param {Array|Boolean} endPositoin range end path including offset or is collapsed |
| 90 | */ |
| 91 | function setRange( range, startPosition, endPositoin ) |
| 92 | { |
| 93 | var bm = { |
| 94 | end : null, |
| 95 | start : null, |
| 96 | is2: true, |
| 97 | startOffset : 0, |
| 98 | endoffset : 0 |
| 99 | }; |
| 100 | bm.start = startPosition.slice( 0, startPosition.length - 1 ); |
| 101 | bm.startOffset = startPosition[ startPosition.length -1]; |
| 102 | if( endPositoin === true ) |
| 103 | { |
| 104 | bm.end = bm.start.slice(); |
| 105 | bm.endOffset = bm.startOffset; |
| 106 | } |
| 107 | else |
| 108 | { |
| 109 | bm.end = endPositoin.slice( 0, endPositoin.length - 1 ); |
| 110 | bm.endOffset = endPositoin[ endPositoin.length -1 ]; |
| 111 | } |
| 112 | range.moveToBookmark( bm ); |
| 113 | } |
| 114 | |
| 115 | return { |
| 116 | |
| 117 | /** |
| 118 | * Test insert element at position which dtd schema not allowed. |
| 119 | */ |
| 120 | test_insertElement : function() |
| 121 | { |
| 122 | var insertingHtml = '<table><tr><td>text</td></tr></table>'; |
| 123 | prepareEditor( 'editor1', null, null, function( editor ) |
| 124 | { |
| 125 | this.resume( function() |
| 126 | { |
| 127 | editor.on( 'focus', function( evt ){ |
| 128 | this.resume( function(){ |
| 129 | |
| 130 | editor.loadSnapshot(getTextAreaValue('source1')); |
| 131 | var range = new CKEDITOR.dom.range(editor.document), sel = editor.getSelection(); |
| 132 | |
| 133 | // Set range collapsed between two list itemms. |
| 134 | setRange(range, [1, 0, 1], true); |
| 135 | sel.selectRanges([range]); |
| 136 | var element = CKEDITOR.dom.element.createFromHtml(insertingHtml, editor.document); |
| 137 | editor.insertElement(element); |
| 138 | assert.areSame(getTextAreaValue('result1'), editor.getData(), 'Content after inserting table element doesn\'t match.'); |
| 139 | }); |
| 140 | evt.removeListener(); |
| 141 | }, this ); |
| 142 | editor.focus(); |
| 143 | this.wait(); |
| 144 | } ); |
| 145 | }, this ); |
| 146 | this.wait(); |
| 147 | }, |
| 148 | |
| 149 | name : document.title |
| 150 | }; |
| 151 | })() ); |
| 152 | |
| 153 | //]]> |
| 154 | </script> |
| 155 | </head> |
| 156 | <body> |
| 157 | <textarea id="editor1"></textarea> |
| 158 | <textarea id="source1"><ul><li>item1</li><li>item2</li></ul></textarea> |
| 159 | <textarea id="result1"><ul> |
| 160 | <li> |
| 161 | item1</li> |
| 162 | </ul> |
| 163 | <table> |
| 164 | <tbody> |
| 165 | <tr> |
| 166 | <td> |
| 167 | text</td> |
| 168 | </tr> |
| 169 | </tbody> |
| 170 | </table> |
| 171 | <ul> |
| 172 | <li> |
| 173 | item2</li> |
| 174 | </ul> |
| 175 | </textarea> |
| 176 | </body> |
| 177 | </html> |