| 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: font</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( [ 'font' , 'htmldataprocessor' ] ); |
| 13 | |
| 14 | CKEDITOR.test.addTestCase( ( function() |
| 15 | { |
| 16 | |
| 17 | // Local references. |
| 18 | var assert = CKEDITOR.test.assert, |
| 19 | arrayAssert = YAHOO.util.ArrayAssert, |
| 20 | doc = new CKEDITOR.dom.document( document ); |
| 21 | |
| 22 | testFontNames = [ |
| 23 | { 'family' : 'Arial,Helvetica,sans-serif' }, |
| 24 | { 'family' : 'Comic Sans MS,cursive' }, |
| 25 | { 'family' : 'Courier New,Courier,monospace' } |
| 26 | ]; |
| 27 | |
| 28 | /** |
| 29 | * IE always returning CRLF for linefeed, so remove it when retrieve pre-formated text from text area. |
| 30 | * @param {Object} id |
| 31 | */ |
| 32 | function getTextAreaValue( id ) |
| 33 | { |
| 34 | return CKEDITOR.document.getById( id ).getValue().replace(/\r/gi,''); |
| 35 | } |
| 36 | |
| 37 | // In these tests, we may "reset" the writer rules to avoid it formatting |
| 38 | // the output, making the assertion easier to the done. We don't need to |
| 39 | // test formatting features here, so this is ok. |
| 40 | var getDataProcessor = function() |
| 41 | { |
| 42 | var dataProcessor = new CKEDITOR.htmlDataProcessor(); |
| 43 | dataProcessor.writer._.rules = []; |
| 44 | return dataProcessor; |
| 45 | }; |
| 46 | |
| 47 | /** |
| 48 | * Lightweight way of apply the given style on the range. |
| 49 | * @param {Object} range |
| 50 | * @param {Object} name The font family name to be applied. |
| 51 | * @param {Boolean} isRemove |
| 52 | */ |
| 53 | function applyStyle( range, name, isRemove) |
| 54 | { |
| 55 | var style = new CKEDITOR.style( CKEDITOR.config.font_style, name ); |
| 56 | if( isRemove ) |
| 57 | style.removeFromRange( range ); |
| 58 | else |
| 59 | style.applyToRange( range ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Make assumption by compare the formatted element content and the content |
| 64 | * inside pre-formated textarea. |
| 65 | * @param {Object} container |
| 66 | * @param {Object} textareaId |
| 67 | */ |
| 68 | function assumeElementContentAreSame( container, textareaId ) |
| 69 | { |
| 70 | //Assume result document content |
| 71 | var html = getDataProcessor().toDataFormat( container.getHtml() ); |
| 72 | assert.areSame( getTextAreaValue( textareaId ) , html ); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Set the range with the start/end position specified by the locator, which in form of bookmark2. |
| 77 | * @param {Object} range |
| 78 | * @param {Array} startPosition range start path including offset |
| 79 | * @param {Array|Boolean} endPositoin range end path including offset or is collapsed |
| 80 | */ |
| 81 | function setRange( range, startPosition, endPositoin ) |
| 82 | { |
| 83 | var bm = { |
| 84 | end : null, |
| 85 | start : null, |
| 86 | is2: true, |
| 87 | startOffset : 0, |
| 88 | endoffset : 0 |
| 89 | }; |
| 90 | bm.start = startPosition.slice( 0, startPosition.length - 1 ); |
| 91 | bm.startOffset = startPosition[ startPosition.length -1]; |
| 92 | if( endPositoin === true ) |
| 93 | { |
| 94 | bm.end = bm.start.slice(); |
| 95 | bm.endOffset = bm.startOffset; |
| 96 | } |
| 97 | else |
| 98 | { |
| 99 | bm.end = endPositoin.slice( 0, endPositoin.length - 1 ); |
| 100 | bm.endOffset = endPositoin[ endPositoin.length -1 ]; |
| 101 | } |
| 102 | range.moveToBookmark( bm ); |
| 103 | } |
| 104 | |
| 105 | return { |
| 106 | |
| 107 | /** |
| 108 | * Test change font styles across table. |
| 109 | */ |
| 110 | test_applyFontFamily : function() |
| 111 | { |
| 112 | var innerDoc = new CKEDITOR.dom.document( |
| 113 | document.getElementById( 'innerFrame' ). |
| 114 | contentWindow.document ), |
| 115 | range = new CKEDITOR.dom.range( innerDoc ); |
| 116 | |
| 117 | setRange( range, [ 1, 0 ], [ 1, 3 ] ); |
| 118 | applyStyle( range, testFontNames[ 0 ] ); |
| 119 | applyStyle( range, testFontNames[ 1 ] ); |
| 120 | applyStyle( range, testFontNames[ 2 ] ); |
| 121 | assumeElementContentAreSame( innerDoc.getBody(), 'applyFontResult1' ); |
| 122 | }, |
| 123 | |
| 124 | name : document.title |
| 125 | }; |
| 126 | })() ); |
| 127 | |
| 128 | //]]> |
| 129 | </script> |
| 130 | </head> |
| 131 | <body> |
| 132 | <iframe id="innerFrame" src="data1.htm"></iframe> |
| 133 | <textarea id="applyFontResult1"><span style="font-family: Courier New,Courier,monospace;">text</span><table><tbody><tr><td><span style="font-family: Courier New,Courier,monospace;">paragraph</span></td></tr></tbody></table><span style="font-family: Courier New,Courier,monospace;">text</span></textarea> |
| 134 | </body> |
| 135 | </html> |
| 136 | No newline at end of file |