| 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: Enterkey</title> |
| 5 | <link rel="stylesheet" type="text/css" href="../../test.css" /> |
| 6 | <script type="text/javascript" src="../../../../ckeditor_source.js"></script> |
| 7 | <script type="text/javascript" src="../../test.js"></script> |
| 8 | <script type="text/javascript"> |
| 9 | //<![CDATA[ |
| 10 | /** |
| 11 | * Load the editor and wait for fully interactable. |
| 12 | * @param {Object} elementId |
| 13 | * @parma {Object} mode |
| 14 | * @param {Object} config |
| 15 | * @param {Object} callback Continuation with {@param editor}. |
| 16 | * @param {Object} context |
| 17 | */ |
| 18 | function prepareEditor( elementId, mode, config, callback, context ) |
| 19 | { |
| 20 | CKEDITOR.on( 'instanceReady', |
| 21 | function( evt ) |
| 22 | { |
| 23 | var isMe = mode == CKEDITOR.ELEMENT_MODE_REPLACE ? |
| 24 | evt.editor.name == elementId |
| 25 | : evt.editor.element.$ == |
| 26 | document.getElementById( elementId ); |
| 27 | if ( isMe ) |
| 28 | { |
| 29 | var editor = evt.editor; |
| 30 | // Force result data unformatted. |
| 31 | editor.dataProcessor.writer._.rules = {}; |
| 32 | // Force remove tail br. |
| 33 | editor.dataProcessor.htmlFilter.addRules( { |
| 34 | elements : { |
| 35 | 'br' : function( br ){ |
| 36 | var parent = br.parent, |
| 37 | length = parent.children.length, |
| 38 | lastChild = parent.children[ length - 1 ]; |
| 39 | if( lastChild == br ) |
| 40 | return false; |
| 41 | } |
| 42 | } |
| 43 | } ); |
| 44 | callback.call( context, editor ); |
| 45 | } |
| 46 | }, this ); |
| 47 | |
| 48 | mode = mode || CKEDITOR.ELEMENT_MODE_REPLACE; |
| 49 | switch( mode ) |
| 50 | { |
| 51 | case CKEDITOR.ELEMENT_MODE_REPLACE : |
| 52 | CKEDITOR.replace( elementId, config ); |
| 53 | break; |
| 54 | case CKEDITOR.ELEMENT_MODE_APPENDTO : |
| 55 | CKEDITOR.appendTo( elementId, config ); |
| 56 | break; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | function getTextAreaValue( id ) |
| 61 | { |
| 62 | return CKEDITOR.document.getById( id ).getValue(); |
| 63 | } |
| 64 | |
| 65 | CKEDITOR.test.addTestCase( ( function() |
| 66 | { |
| 67 | |
| 68 | // Local references. |
| 69 | var assert = CKEDITOR.test.assert, |
| 70 | doc = CKEDITOR.document, |
| 71 | action = YAHOO.util.UserAction, |
| 72 | selector = YAHOO.util.Selector; |
| 73 | |
| 74 | /** |
| 75 | * Set the range with the start/end position specified by the locator, which in form of bookmark2. |
| 76 | * @param {Object} range |
| 77 | * @param {Array} startPosition range start path including offset |
| 78 | * @param {Array|Boolean} endPositoin range end path including offset or is collapsed |
| 79 | */ |
| 80 | function setRange( range, startPosition, endPositoin ) |
| 81 | { |
| 82 | var bm = { |
| 83 | end : null, |
| 84 | start : null, |
| 85 | is2: true, |
| 86 | startOffset : 0, |
| 87 | endoffset : 0 |
| 88 | }; |
| 89 | bm.start = startPosition.slice( 0, startPosition.length - 1 ); |
| 90 | bm.startOffset = startPosition[ startPosition.length -1]; |
| 91 | if( endPositoin === true ) |
| 92 | { |
| 93 | bm.end = bm.start.slice(); |
| 94 | bm.endOffset = bm.startOffset; |
| 95 | } |
| 96 | else |
| 97 | { |
| 98 | bm.end = endPositoin.slice( 0, endPositoin.length - 1 ); |
| 99 | bm.endOffset = endPositoin[ endPositoin.length -1 ]; |
| 100 | } |
| 101 | range.moveToBookmark( bm ); |
| 102 | } |
| 103 | |
| 104 | return { |
| 105 | |
| 106 | /** |
| 107 | * Test press enter key right after existing line break inside <pre>. |
| 108 | */ |
| 109 | test_ticket_3949 : function() |
| 110 | { |
| 111 | prepareEditor( 'test_ticket_3949_editor', null, |
| 112 | { enterMode : CKEDITOR.ENTER_BR }, |
| 113 | function( editor ) |
| 114 | { |
| 115 | this.resume( function() |
| 116 | { |
| 117 | editor.focus(); |
| 118 | |
| 119 | var doc = editor.document, |
| 120 | range = new CKEDITOR.dom.range( doc ); |
| 121 | |
| 122 | // <pre>line1^\nline2</pre> |
| 123 | setRange( range, [ 1, 0, 0, 5 ], true ); |
| 124 | var sel = editor.getSelection(); |
| 125 | sel.selectRanges( [ range ] ); |
| 126 | // 'Enter key' triggering. |
| 127 | editor.specialKeys[ 13 ]( editor ); |
| 128 | this.wait( function(){ |
| 129 | assert.areSame( |
| 130 | getTextAreaValue( 'test_ticket_3949_result' ), |
| 131 | editor.getData(), |
| 132 | 'Enter key result not correct.' ); |
| 133 | }, 1000 ); |
| 134 | |
| 135 | } ); |
| 136 | }, this ); |
| 137 | this.wait(); |
| 138 | }, |
| 139 | |
| 140 | name :document.title |
| 141 | }; |
| 142 | } )() ); |
| 143 | //]]> |
| 144 | </script> |
| 145 | </head> |
| 146 | <body> |
| 147 | <textarea id="test_ticket_3949_editor"><pre>line1 |
| 148 | line2</pre></textarea> |
| 149 | <textarea id="test_ticket_3949_result"><pre>line1 |
| 150 | |
| 151 | line2</pre></textarea> |
| 152 | </body> |
| 153 | </html> |