| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 | <!-- |
| 3 | Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. |
| 4 | For licensing, see LICENSE.html or http://ckeditor.com/license |
| 5 | --> |
| 6 | <html xmlns="http://www.w3.org/1999/xhtml"> |
| 7 | <head> |
| 8 | <title></title> |
| 9 | <style type="text/css"> |
| 10 | textarea |
| 11 | { |
| 12 | border: 1px solid #ddd; |
| 13 | } |
| 14 | |
| 15 | #error |
| 16 | { |
| 17 | border: red 1px solid; |
| 18 | background-color: #ffffcc; |
| 19 | padding: 10px; |
| 20 | visibility: hidden; |
| 21 | } |
| 22 | </style> |
| 23 | <script type="text/javascript" src="../../_source/core/loader.js"></script> |
| 24 | <script type="text/javascript"> |
| 25 | |
| 26 | CKEDITOR.loader.load( 'core/xml' ); |
| 27 | |
| 28 | </script> |
| 29 | <script type="text/javascript"> |
| 30 | |
| 31 | function convert( xml ) |
| 32 | { |
| 33 | if ( !xml ) |
| 34 | { |
| 35 | hideError(); |
| 36 | return; |
| 37 | } |
| 38 | // Initialize the output. |
| 39 | var output = ''; |
| 40 | |
| 41 | var v3 = document.getElementById( 'v3' ); |
| 42 | v3.value = ''; |
| 43 | |
| 44 | xml = new CKEDITOR.xml( xml ); |
| 45 | |
| 46 | var templatesNode = xml.selectSingleNode( '/Templates' ); |
| 47 | |
| 48 | if ( !templatesNode ) |
| 49 | { |
| 50 | throwParsingError( 'The <Templates> node was not found' ); |
| 51 | return ; |
| 52 | } |
| 53 | |
| 54 | // Get the imagesBasePath attribute value. |
| 55 | var imagesBasePath = templatesNode.getAttribute( 'imagesBasePath' ); |
| 56 | |
| 57 | output += |
| 58 | '// Register a templates definition set named "default".\n' + |
| 59 | 'CKEDITOR.addTemplates( \'default\',\n' + |
| 60 | '{\n'; |
| 61 | |
| 62 | if ( imagesBasePath ) |
| 63 | { |
| 64 | // If using the default v2 path, use the default v3 as well. |
| 65 | if ( imagesBasePath == 'fck_template/images/' ) |
| 66 | imagesBasePath = 'CKEDITOR.plugins.getPath( \'templates\' ) + \'templates/images/\''; |
| 67 | else |
| 68 | imagesBasePath = "'" + imagesBasePath + "'"; |
| 69 | |
| 70 | output += |
| 71 | ' // The name of sub folder which holds the shortcut preview images of the templates.\n' + |
| 72 | ' imagesPath : CKEDITOR.getUrl( ' + imagesBasePath + ' ),\n' + |
| 73 | '\n'; |
| 74 | } |
| 75 | |
| 76 | output += |
| 77 | ' // The templates definitions.\n' + |
| 78 | ' templates :\n' + |
| 79 | ' ['; |
| 80 | |
| 81 | // Retrieve all <Template> nodes. |
| 82 | var templateNodes = xml.selectNodes( 'Template', templatesNode ); |
| 83 | |
| 84 | for ( var i = 0 ; i < templateNodes.length ; i++ ) |
| 85 | { |
| 86 | var templateNode = templateNodes[ i ]; |
| 87 | title = fixJsString( templateNode.getAttribute( 'title' ) ), |
| 88 | image = fixJsString( templateNode.getAttribute( 'image' ) ), |
| 89 | description = fixJsString( xml.getInnerXml( 'Description', templateNode ) ), |
| 90 | html = convertHtmlCData( xml.getInnerXml( 'Html', templateNode ) ); |
| 91 | |
| 92 | if ( i > 0 ) |
| 93 | output += ','; |
| 94 | |
| 95 | output += |
| 96 | '\n {\n'; |
| 97 | |
| 98 | title && ( output += |
| 99 | ' title: \'' + title + '\',\n' ); |
| 100 | |
| 101 | image && ( output += |
| 102 | ' image: \'' + image + '\',\n' ); |
| 103 | |
| 104 | description && ( output += |
| 105 | ' description: \'' + description + '\',\n' ); |
| 106 | |
| 107 | output += |
| 108 | ' html:\n' + |
| 109 | html + '\n' + |
| 110 | ' }'; |
| 111 | } |
| 112 | |
| 113 | output += |
| 114 | '\n ]\n' + |
| 115 | '});\n'; |
| 116 | |
| 117 | v3.value = output; |
| 118 | |
| 119 | hideError(); |
| 120 | } |
| 121 | |
| 122 | function fixJsString( str ) |
| 123 | { |
| 124 | return str && str.replace( /'/g, "\\'" ); |
| 125 | } |
| 126 | |
| 127 | function convertHtmlCData( html ) |
| 128 | { |
| 129 | if ( !html ) |
| 130 | return " ''"; |
| 131 | |
| 132 | var output = ''; |
| 133 | |
| 134 | // Remove the CDATA tag. |
| 135 | html = html.replace( /^\s*<!\[CDATA\[/, '' ); |
| 136 | html = html.replace( /\]\]>\s*$/, '' ); |
| 137 | |
| 138 | // Break the HTML lines. |
| 139 | var lines = html.split( /(?:\r\n)|\n|\r/ ); |
| 140 | |
| 141 | if ( lines.length && /^\s*$/.test( lines[ 0 ] ) ) |
| 142 | lines.shift(); |
| 143 | |
| 144 | if ( lines.length && /^\s*$/.test( lines[ lines.length - 1 ] ) ) |
| 145 | lines.pop(); |
| 146 | |
| 147 | // Find out how many tabs we must remove from the lines to remove the indentation. |
| 148 | var indentSize = 0; |
| 149 | for ( var i = 0 ; i < lines.length ; i++ ) |
| 150 | { |
| 151 | var tabs = lines[ i ].match( /^\t*/ )[0].length; |
| 152 | |
| 153 | if ( !i || tabs < indentSize ) |
| 154 | indentSize = tabs; |
| 155 | } |
| 156 | |
| 157 | // Now remove the indentation and output the line. |
| 158 | for ( var i = 0 ; i < lines.length ; i++ ) |
| 159 | { |
| 160 | var line = lines[ i ]; |
| 161 | |
| 162 | if ( indentSize ) |
| 163 | line = line.substr( indentSize ); |
| 164 | |
| 165 | if ( i ) |
| 166 | output += ' +\n'; |
| 167 | |
| 168 | line = line.replace( /^\t+/, function( match ) |
| 169 | { |
| 170 | output += match; |
| 171 | return ''; |
| 172 | }); |
| 173 | |
| 174 | line = line.replace( /\u00A0/g, ' ' ); |
| 175 | |
| 176 | output += ' \'' + line + '\''; |
| 177 | } |
| 178 | |
| 179 | return output; |
| 180 | } |
| 181 | |
| 182 | function throwParsingError( extraMessage ) |
| 183 | { |
| 184 | document.getElementById( 'extraError' ).innerHTML = extraMessage.replace( /</g, '<' ); |
| 185 | document.getElementById( 'error' ).style.visibility = 'visible'; |
| 186 | } |
| 187 | |
| 188 | function hideError() |
| 189 | { |
| 190 | document.getElementById( 'error' ).style.visibility = 'hidden'; |
| 191 | } |
| 192 | |
| 193 | window.onload = function() |
| 194 | { |
| 195 | var v2 = document.getElementById( 'v2' ); |
| 196 | v2.onchange = v2.onkeyup = v2.onpaste = function() |
| 197 | { |
| 198 | setTimeout( function() |
| 199 | { |
| 200 | convert( v2.value ); |
| 201 | }, 0 ); |
| 202 | }; |
| 203 | } |
| 204 | |
| 205 | </script> |
| 206 | </head> |
| 207 | <body> |
| 208 | <h1> |
| 209 | FCKeditor 2 Template Converter for CKEditor 3</h1> |
| 210 | <table style="width: 100%" cellspacing="10"> |
| 211 | <tr> |
| 212 | <td style="width: 50%"> |
| 213 | <p> |
| 214 | Paste the original FCKeditor 2 XML template here:<br /> |
| 215 | <textarea id="v2" style="width: 100%; height: 400px" wrap="off" spellcheck="false"></textarea></p> |
| 216 | </td> |
| 217 | <td style="width: 50%"> |
| 218 | <p> |
| 219 | Converted output for CKEditor 3 (double-click to select all):<br /> |
| 220 | <textarea id="v3" style="width: 100%; height: 400px" wrap="off" ondblclick="this.focus; this.select();" |
| 221 | readonly="readonly"></textarea></p> |
| 222 | </td> |
| 223 | </tr> |
| 224 | </table> |
| 225 | <p id="error"> |
| 226 | ERROR: It's not possible to parse the inputted template. <span id="extraError"></span> |
| 227 | </p> |
| 228 | </body> |
| 229 | </html> |