| 1 | <!DOCTYPE html> |
|---|
| 2 | <!-- |
|---|
| 3 | Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. |
|---|
| 4 | For licensing, see LICENSE.html or http://ckeditor.com/license |
|---|
| 5 | --> |
|---|
| 6 | <html> |
|---|
| 7 | <head> |
|---|
| 8 | <title>testcase</title> |
|---|
| 9 | <meta content="text/html; charset=utf-8" http-equiv="content-type" /> |
|---|
| 10 | <script type="text/javascript" src="../ckeditor_source.js"></script> |
|---|
| 11 | |
|---|
| 12 | </head> |
|---|
| 13 | <body> |
|---|
| 14 | <h1 class="samples"> |
|---|
| 15 | Testcase for handling of whitespace at start of textareas using innerHTML |
|---|
| 16 | </h1> |
|---|
| 17 | |
|---|
| 18 | <script> |
|---|
| 19 | function encode(text) |
|---|
| 20 | { |
|---|
| 21 | text = text.replace( />/g, '>'); |
|---|
| 22 | text = text.replace( /</g, '<'); |
|---|
| 23 | return text; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | performTest('New line at start', '<textarea>\nsome text</textarea>'); |
|---|
| 28 | performTest('Whitespace at start', '<textarea> some text</textarea>'); |
|---|
| 29 | |
|---|
| 30 | performTest('New line at end', '<textarea>some text\n</textarea>'); |
|---|
| 31 | performTest('Whitespace at end', '<textarea>some text </textarea>'); |
|---|
| 32 | |
|---|
| 33 | function performTest(title, sampleData) |
|---|
| 34 | { |
|---|
| 35 | document.write('<p style="white-space:pre">' + title + '. Original data:<br>' + encode(sampleData) + '</p>') |
|---|
| 36 | |
|---|
| 37 | var div = new CKEDITOR.dom.element( 'div' ); |
|---|
| 38 | div.setHtml( sampleData ); |
|---|
| 39 | var data = div.getHtml(); |
|---|
| 40 | data = data.toLowerCase(); // not interested about IE's casing issues |
|---|
| 41 | |
|---|
| 42 | if ( sampleData != data) |
|---|
| 43 | document.write('<p style="background-color:red">Test failed.</p><p style="white-space:pre">Returned data:<br>' + encode(data) + '</p>') |
|---|
| 44 | else |
|---|
| 45 | document.write('<p style="background-color:green">Test OK</p>') |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | </script> |
|---|
| 49 | </body> |
|---|
| 50 | </html> |
|---|