| 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: basicstyles</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 | CKEDITOR.plugins.load( [ 'basicstyles' , 'htmldataprocessor' ] ); |
| 13 | |
| 14 | CKEDITOR.test.addTestCase( ( function() |
| 15 | { |
| 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 | * IE always returning CRLF for linefeed, so remove it when retrieve pre-formated text from text area. |
| 25 | * @param {Object} id |
| 26 | */ |
| 27 | function getTextAreaValue( id ) |
| 28 | { |
| 29 | return CKEDITOR.document.getById( id ).getValue().replace(/\r/gi,''); |
| 30 | } |
| 31 | |
| 32 | // In these tests, we may "reset" the writer rules to avoid it formatting |
| 33 | // the output, making the assertion easier to the done. We don't need to |
| 34 | // test formatting features here, so this is ok. |
| 35 | var getDataProcessor = function() |
| 36 | { |
| 37 | var dataProcessor = new CKEDITOR.htmlDataProcessor(); |
| 38 | dataProcessor.writer._.rules = []; |
| 39 | return dataProcessor; |
| 40 | }; |
| 41 | |
| 42 | /** |
| 43 | * Lightweight way of apply the given style on the range. |
| 44 | * @param {Object} range |
| 45 | * @param {Object} styleName The core style name which will be applied. |
| 46 | * @param {Boolean} isRemove |
| 47 | */ |
| 48 | function applyStyle( range, name , isRemove) |
| 49 | { |
| 50 | var style = new CKEDITOR.style( CKEDITOR.config[ 'coreStyles_' + name ] ); |
| 51 | if( isRemove ) |
| 52 | style.removeFromRange( range ); |
| 53 | else |
| 54 | style.applyToRange( range ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Make assumption by compare the formatted element content and the content |
| 59 | * inside pre-formated textarea. |
| 60 | * @param {Object} containerId |
| 61 | * @param {Object} textareaId |
| 62 | */ |
| 63 | function assumeElementContentAreSame( container, textareaId ) |
| 64 | { |
| 65 | //Assume result document content |
| 66 | var html = getDataProcessor().toDataFormat( container.getHtml() ); |
| 67 | assert.areSame( getTextAreaValue( textareaId ) , html ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Set the range with the start/end position specified by the locator, which in form of bookmark2. |
| 72 | * @param {Object} range |
| 73 | * @param {Array} startPosition range start path including offset |
| 74 | * @param {Array|Boolean} endPositoin range end path including offset or is collapsed |
| 75 | */ |
| 76 | function setRange( range, startPosition, endPositoin ) |
| 77 | { |
| 78 | var bm = { |
| 79 | end : null, |
| 80 | start : null, |
| 81 | is2: true, |
| 82 | startOffset : 0, |
| 83 | endoffset : 0 |
| 84 | }; |
| 85 | bm.start = startPosition.slice( 0, startPosition.length - 1 ); |
| 86 | bm.startOffset = startPosition[ startPosition.length -1]; |
| 87 | if( endPositoin === true ) |
| 88 | { |
| 89 | bm.end = bm.start.slice(); |
| 90 | bm.endOffset = bm.startOffset; |
| 91 | } |
| 92 | else |
| 93 | { |
| 94 | bm.end = endPositoin.slice( 0, endPositoin.length - 1 ); |
| 95 | bm.endOffset = endPositoin[ endPositoin.length -1 ]; |
| 96 | } |
| 97 | range.moveToBookmark( bm ); |
| 98 | } |
| 99 | |
| 100 | return { |
| 101 | |
| 102 | /** |
| 103 | * Test apply inline within the first list item. |
| 104 | */ |
| 105 | test_ticket_3243 : function() |
| 106 | { |
| 107 | var innerDoc = new CKEDITOR.dom.document( |
| 108 | document.getElementById( 'test_ticket_3243_frame' ). |
| 109 | contentWindow.document ), |
| 110 | range = new CKEDITOR.dom.range( innerDoc ); |
| 111 | |
| 112 | setRange( range, [ 1, 0, 0, 0, 0 ], [ 1, 0, 0, 0, 6 ] ); |
| 113 | applyStyle( range, 'bold' ); |
| 114 | assumeElementContentAreSame( innerDoc.getBody(), 'test_ticket_3243_resultContent' ); |
| 115 | |
| 116 | }, |
| 117 | name : document.title |
| 118 | }; |
| 119 | })() ); |
| 120 | |
| 121 | //]]> |
| 122 | </script> |
| 123 | </head> |
| 124 | <body> |
| 125 | <iframe id="test_ticket_3243_frame" src="dataFrames/list.htm"></iframe> |
| 126 | <textarea id="test_ticket_3243_resultContent"><ol><li><strong>text</strong></li><li>text<ol><li>level2</li></ol></li></ol></textarea> |
| 127 | </body> |
| 128 | </html> |