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