| 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>CKEDITOR.dom.range</title> |
| 5 | <link rel="stylesheet" type="text/css" href="../../test.css" /> |
| 6 | <script type="text/javascript" src="../../../../ckeditor_source.js"></script> <!-- %REMOVE_LINE% |
| 7 | <script type="text/javascript" src="../../../ckeditor.js"></script> |
| 8 | %REMOVE_LINE% --> |
| 9 | <script type="text/javascript" src="../../test.js"></script> |
| 10 | <script type="text/javascript"> |
| 11 | //<![CDATA[ |
| 12 | |
| 13 | var tc; |
| 14 | |
| 15 | CKEDITOR.test.addTestCase( tc = ( function() |
| 16 | { |
| 17 | // Local references. |
| 18 | var assert = CKEDITOR.test.assert, |
| 19 | arrayAssert = YAHOO.util.ArrayAssert; |
| 20 | |
| 21 | var doc = new CKEDITOR.dom.document( document ); |
| 22 | |
| 23 | /** |
| 24 | * Set the range with the start/end position specified by the locator, which in form of bookmark2. |
| 25 | * @param {Object} range |
| 26 | * @param {Array} startPosition range start path including offset |
| 27 | * @param {Array|Boolean} endPositoin range end path including offset or is collapsed |
| 28 | */ |
| 29 | function setRange( range, startPosition, endPositoin ) |
| 30 | { |
| 31 | var bm = { |
| 32 | end : null, |
| 33 | start : null, |
| 34 | is2: true, |
| 35 | startOffset : 0, |
| 36 | endoffset : 0 |
| 37 | }; |
| 38 | bm.start = startPosition.slice( 0, startPosition.length - 1 ); |
| 39 | bm.startOffset = startPosition[ startPosition.length -1]; |
| 40 | if( endPositoin === true ) |
| 41 | { |
| 42 | bm.end = bm.start.slice(); |
| 43 | bm.endOffset = bm.startOffset; |
| 44 | } |
| 45 | else |
| 46 | { |
| 47 | bm.end = endPositoin.slice( 0, endPositoin.length - 1 ); |
| 48 | bm.endOffset = endPositoin[ endPositoin.length -1 ]; |
| 49 | } |
| 50 | range.moveToBookmark( bm ); |
| 51 | } |
| 52 | |
| 53 | function assumeRangeAreSame( range, startPosition, endPosition ){ |
| 54 | |
| 55 | var bm = range.createBookmark2(); |
| 56 | bm.start.push( bm.startOffset ); |
| 57 | bm.end.push( bm.endOffset ); |
| 58 | arrayAssert.itemsAreEqual( startPosition, bm.start , 'Start positon not correct.' ); |
| 59 | if( endPosition !== true ) |
| 60 | arrayAssert.itemsAreEqual( endPosition, bm.end, 'End position not correct.' ); |
| 61 | } |
| 62 | |
| 63 | return { |
| 64 | |
| 65 | /** |
| 66 | * Test avoid partial block selecting. |
| 67 | */ |
| 68 | test_enlarge_block: function() |
| 69 | { |
| 70 | var innerDoc = new CKEDITOR.dom.document( |
| 71 | document.getElementById( 'innerFrame' ). |
| 72 | contentWindow.document ), |
| 73 | range = new CKEDITOR.dom.range( innerDoc ); |
| 74 | //<body><div><p>^Inner</p>^</div></body> |
| 75 | setRange( range, [ 1, 0, 0, 0 ], [ 1, 0, 1 ] ); |
| 76 | //<body>^<div><p>Inner</p></div>^</body> |
| 77 | range.enlarge( CKEDITOR.ENLARGE_BLOCK_CONTENTS ); |
| 78 | assumeRangeAreSame( range, [1, 0 ], [1, 1 ] ); |
| 79 | }, |
| 80 | |
| 81 | /** |
| 82 | * Test avoid partial block selecting. |
| 83 | */ |
| 84 | test_enlarge_block2: function() |
| 85 | { |
| 86 | var innerDoc = new CKEDITOR.dom.document( |
| 87 | document.getElementById( 'innerFrame' ). |
| 88 | contentWindow.document ), |
| 89 | range = new CKEDITOR.dom.range( innerDoc ); |
| 90 | //<body><div><p>^Inner^</p></div></body> |
| 91 | setRange( range, [ 1, 0, 0, 0 ], [ 1, 0, 0, 1 ] ); |
| 92 | range.enlarge( CKEDITOR.ENLARGE_BLOCK_CONTENTS ); |
| 93 | //<body><div>^<p>Inner</p>^</div></body> |
| 94 | assumeRangeAreSame( range, [1, 0, 0 ], [1, 0, 1 ] ); |
| 95 | }, |
| 96 | |
| 97 | name : document.title |
| 98 | }; |
| 99 | })() ); |
| 100 | |
| 101 | //window.onload = tc.test_enlarge_block; |
| 102 | |
| 103 | //]]> |
| 104 | </script> |
| 105 | </head> |
| 106 | <iframe id="innerFrame" src="range_enlarge_block_data.htm"></iframe> |
| 107 | </html> |