+++ /dev/null
-/*\r
-Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.\r
-For licensing, see LICENSE.html or http://ckeditor.com/license\r
-*/\r
-\r
-(function()\r
-{\r
- // Regex to scan for at the end of blocks, which are actually placeholders.\r
- // Safari transforms the to \xa0. (#4172)\r
- var tailNbspRegex = /^[\t\r\n ]*(?: |\xa0)$/;\r
-\r
- var protectedSourceMarker = '{cke_protected}';\r
-\r
- // Return the last non-space child node of the block (#4344).\r
- function lastNoneSpaceChild( block )\r
- {\r
- var lastIndex = block.children.length,\r
- last = block.children[ lastIndex - 1 ];\r
- while ( last && last.type == CKEDITOR.NODE_TEXT && !CKEDITOR.tools.trim( last.value ) )\r
- last = block.children[ --lastIndex ];\r
- return last;\r
- }\r
-\r
- function trimFillers( block, fromSource )\r
- {\r
- // If the current node is a block, and if we're converting from source or\r
- // we're not in IE then search for and remove any tailing BR node.\r
- //\r
- // Also, any at the end of blocks are fillers, remove them as well.\r
- // (#2886)\r
- var children = block.children, lastChild = lastNoneSpaceChild( block );\r
- if ( lastChild )\r
- {\r
- if ( ( fromSource || !CKEDITOR.env.ie ) && lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br' )\r
- children.pop();\r
- if ( lastChild.type == CKEDITOR.NODE_TEXT && tailNbspRegex.test( lastChild.value ) )\r
- children.pop();\r
- }\r
- }\r
-\r
- function blockNeedsExtension( block, fromSource, extendEmptyBlock )\r
- {\r
- if( !fromSource && ( !extendEmptyBlock ||\r
- typeof extendEmptyBlock == 'function' && ( extendEmptyBlock( block ) === false ) ) )\r
- return false;\r
-\r
- // 1. For IE version >=8, empty blocks are displayed correctly themself in wysiwiyg;\r
- // 2. For the rest, at least table cell and list item need no filler space.\r
- // (#6248)\r
- if ( fromSource && CKEDITOR.env.ie &&\r
- ( document.documentMode > 7\r
- || block.name in CKEDITOR.dtd.tr\r
- || block.name in CKEDITOR.dtd.$listItem ) )\r
- return false;\r
-\r
- var lastChild = lastNoneSpaceChild( block );\r
-\r
- return !lastChild || lastChild &&\r
- ( lastChild.type == CKEDITOR.NODE_ELEMENT && lastChild.name == 'br'\r
- // Some of the controls in form needs extension too,\r
- // to move cursor at the end of the form. (#4791)\r
- || block.name == 'form' && lastChild.name == 'input' );\r
- }\r
-\r
- function getBlockExtension( isOutput, emptyBlockFiller )\r
- {\r
- return function( node )\r
- {\r
- trimFillers( node, !isOutput );\r
-\r
- if ( blockNeedsExtension( node, !isOutput, emptyBlockFiller ) )\r
- {\r
- if ( isOutput || CKEDITOR.env.ie )\r
- node.add( new CKEDITOR.htmlParser.text( '\xa0' ) );\r
- else\r
- node.add( new CKEDITOR.htmlParser.element( 'br', {} ) );\r
- }\r
- };\r
- }\r
-\r
- var dtd = CKEDITOR.dtd;\r
-\r
- // Define orders of table elements.\r
- var tableOrder = [ 'caption', 'colgroup', 'col', 'thead', 'tfoot', 'tbody' ];\r
-\r
- // Find out the list of block-like tags that can contain <br>.\r
- var blockLikeTags = CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent );\r
- for ( var i in blockLikeTags )\r
- {\r
- if ( ! ( 'br' in dtd[i] ) )\r
- delete blockLikeTags[i];\r
- }\r
- // We just avoid filler in <pre> right now.\r
- // TODO: Support filler for <pre>, line break is also occupy line height.\r
- delete blockLikeTags.pre;\r
- var defaultDataFilterRules =\r
- {\r
- elements : {},\r
- attributeNames :\r
- [\r
- // Event attributes (onXYZ) must not be directly set. They can become\r
- // active in the editing area (IE|WebKit).\r
- [ ( /^on/ ), 'data-cke-pa-on' ]\r
- ]\r
- };\r
-\r
- var defaultDataBlockFilterRules = { elements : {} };\r
-\r
- for ( i in blockLikeTags )\r
- defaultDataBlockFilterRules.elements[ i ] = getBlockExtension();\r
-\r
- var defaultHtmlFilterRules =\r
- {\r
- elementNames :\r
- [\r
- // Remove the "cke:" namespace prefix.\r
- [ ( /^cke:/ ), '' ],\r
-\r
- // Ignore <?xml:namespace> tags.\r
- [ ( /^\?xml:namespace$/ ), '' ]\r
- ],\r
-\r
- attributeNames :\r
- [\r
- // Attributes saved for changes and protected attributes.\r
- [ ( /^data-cke-(saved|pa)-/ ), '' ],\r
-\r
- // All "data-cke-" attributes are to be ignored.\r
- [ ( /^data-cke-.*/ ), '' ],\r
-\r
- [ 'hidefocus', '' ]\r
- ],\r
-\r
- elements :\r
- {\r
- $ : function( element )\r
- {\r
- var attribs = element.attributes;\r
-\r
- if ( attribs )\r
- {\r
- // Elements marked as temporary are to be ignored.\r
- if ( attribs[ 'data-cke-temp' ] )\r
- return false;\r
-\r
- // Remove duplicated attributes - #3789.\r
- var attributeNames = [ 'name', 'href', 'src' ],\r
- savedAttributeName;\r
- for ( var i = 0 ; i < attributeNames.length ; i++ )\r
- {\r
- savedAttributeName = 'data-cke-saved-' + attributeNames[ i ];\r
- savedAttributeName in attribs && ( delete attribs[ attributeNames[ i ] ] );\r
- }\r
- }\r
-\r
- return element;\r
- },\r
-\r
- // The contents of table should be in correct order (#4809).\r
- table : function( element )\r
- {\r
- var children = element.children;\r
- children.sort( function ( node1, node2 )\r
- {\r
- return node1.type == CKEDITOR.NODE_ELEMENT && node2.type == node1.type ?\r
- CKEDITOR.tools.indexOf( tableOrder, node1.name ) > CKEDITOR.tools.indexOf( tableOrder, node2.name ) ? 1 : -1 : 0;\r
- } );\r
- },\r
-\r
- embed : function( element )\r
- {\r
- var parent = element.parent;\r
-\r
- // If the <embed> is child of a <object>, copy the width\r
- // and height attributes from it.\r
- if ( parent && parent.name == 'object' )\r
- {\r
- var parentWidth = parent.attributes.width,\r
- parentHeight = parent.attributes.height;\r
- parentWidth && ( element.attributes.width = parentWidth );\r
- parentHeight && ( element.attributes.height = parentHeight );\r
- }\r
- },\r
- // Restore param elements into self-closing.\r
- param : function( param )\r
- {\r
- param.children = [];\r
- param.isEmpty = true;\r
- return param;\r
- },\r
-\r
- // Remove empty link but not empty anchor.(#3829)\r
- a : function( element )\r
- {\r
- if ( !( element.children.length ||\r
- element.attributes.name ||\r
- element.attributes[ 'data-cke-saved-name' ] ) )\r
- {\r
- return false;\r
- }\r
- },\r
-\r
- // Remove dummy span in webkit.\r
- span: function( element )\r
- {\r
- if ( element.attributes[ 'class' ] == 'Apple-style-span' )\r
- delete element.name;\r
- },\r
-\r
- // Empty <pre> in IE is reported with filler node ( ).\r
- pre : function( element ) { CKEDITOR.env.ie && trimFillers( element ); },\r
-\r
- html : function( element )\r
- {\r
- delete element.attributes.contenteditable;\r
- delete element.attributes[ 'class' ];\r
- },\r
-\r
- body : function( element )\r
- {\r
- delete element.attributes.spellcheck;\r
- delete element.attributes.contenteditable;\r
- },\r
-\r
- style : function( element )\r
- {\r
- var child = element.children[ 0 ];\r
- child && child.value && ( child.value = CKEDITOR.tools.trim( child.value ));\r
-\r
- if ( !element.attributes.type )\r
- element.attributes.type = 'text/css';\r
- },\r
-\r
- title : function( element )\r
- {\r
- var titleText = element.children[ 0 ];\r
- titleText && ( titleText.value = element.attributes[ 'data-cke-title' ] || '' );\r
- }\r
- },\r
-\r
- attributes :\r
- {\r
- 'class' : function( value, element )\r
- {\r
- // Remove all class names starting with "cke_".\r
- return CKEDITOR.tools.ltrim( value.replace( /(?:^|\s+)cke_[^\s]*/g, '' ) ) || false;\r
- }\r
- }\r
- };\r
-\r
- if ( CKEDITOR.env.ie )\r
- {\r
- // IE outputs style attribute in capital letters. We should convert\r
- // them back to lower case, while not hurting the values (#5930)\r
- defaultHtmlFilterRules.attributes.style = function( value, element )\r
- {\r
- return value.replace( /(^|;)([^\:]+)/g, function( match )\r
- {\r
- return match.toLowerCase();\r
- });\r
- };\r
- }\r
-\r
- function protectReadOnly( element )\r
- {\r
- var attrs = element.attributes;\r
-\r
- // We should flag that the element was locked by our code so\r
- // it'll be editable by the editor functions (#6046).\r
- if ( attrs.contenteditable != "false" )\r
- attrs[ 'data-cke-editable' ] = attrs.contenteditable ? 'true' : 1;\r
-\r
- attrs.contenteditable = "false";\r
- }\r
- function unprotectReadyOnly( element )\r
- {\r
- var attrs = element.attributes;\r
- switch( attrs[ 'data-cke-editable' ] )\r
- {\r
- case 'true': attrs.contenteditable = 'true'; break;\r
- case '1': delete attrs.contenteditable; break;\r
- }\r
- }\r
- // Disable form elements editing mode provided by some browers. (#5746)\r
- for ( i in { input : 1, textarea : 1 } )\r
- {\r
- defaultDataFilterRules.elements[ i ] = protectReadOnly;\r
- defaultHtmlFilterRules.elements[ i ] = unprotectReadyOnly;\r
- }\r
-\r
- var protectElementRegex = /<(a|area|img|input)\b([^>]*)>/gi,\r
- protectAttributeRegex = /\b(href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+))/gi;\r
-\r
- var protectElementsRegex = /(?:<style(?=[ >])[^>]*>[\s\S]*<\/style>)|(?:<(:?link|meta|base)[^>]*>)/gi,\r
- encodedElementsRegex = /<cke:encoded>([^<]*)<\/cke:encoded>/gi;\r
-\r
- var protectElementNamesRegex = /(<\/?)((?:object|embed|param|html|body|head|title)[^>]*>)/gi,\r
- unprotectElementNamesRegex = /(<\/?)cke:((?:html|body|head|title)[^>]*>)/gi;\r
-\r
- var protectSelfClosingRegex = /<cke:(param|embed)([^>]*?)\/?>(?!\s*<\/cke:\1)/gi;\r
-\r
- function protectAttributes( html )\r
- {\r
- return html.replace( protectElementRegex, function( element, tag, attributes )\r
- {\r
- return '<' + tag + attributes.replace( protectAttributeRegex, function( fullAttr, attrName )\r
- {\r
- // We should not rewrite the existed protected attributes, e.g. clipboard content from editor. (#5218)\r
- if ( attributes.indexOf( 'data-cke-saved-' + attrName ) == -1 )\r
- return ' data-cke-saved-' + fullAttr + ' ' + fullAttr;\r
-\r
- return fullAttr;\r
- }) + '>';\r
- });\r
- }\r
-\r
- function protectElements( html )\r
- {\r
- return html.replace( protectElementsRegex, function( match )\r
- {\r
- return '<cke:encoded>' + encodeURIComponent( match ) + '</cke:encoded>';\r
- });\r
- }\r
-\r
- function unprotectElements( html )\r
- {\r
- return html.replace( encodedElementsRegex, function( match, encoded )\r
- {\r
- return decodeURIComponent( encoded );\r
- });\r
- }\r
-\r
- function protectElementsNames( html )\r
- {\r
- return html.replace( protectElementNamesRegex, '$1cke:$2');\r
- }\r
-\r
- function unprotectElementNames( html )\r
- {\r
- return html.replace( unprotectElementNamesRegex, '$1$2' );\r
- }\r
-\r
- function protectSelfClosingElements( html )\r
- {\r
- return html.replace( protectSelfClosingRegex, '<cke:$1$2></cke:$1>' );\r
- }\r
-\r
- function protectPreFormatted( html )\r
- {\r
- return html.replace( /(<pre\b[^>]*>)(\r\n|\n)/g, '$1$2$2' );\r
- }\r
-\r
- function protectRealComments( html )\r
- {\r
- return html.replace( /<!--(?!{cke_protected})[\s\S]+?-->/g, function( match )\r
- {\r
- return '<!--' + protectedSourceMarker +\r
- '{C}' +\r
- encodeURIComponent( match ).replace( /--/g, '%2D%2D' ) +\r
- '-->';\r
- });\r
- }\r
-\r
- function unprotectRealComments( html )\r
- {\r
- return html.replace( /<!--\{cke_protected\}\{C\}([\s\S]+?)-->/g, function( match, data )\r
- {\r
- return decodeURIComponent( data );\r
- });\r
- }\r
-\r
- function unprotectSource( html, editor )\r
- {\r
- var store = editor._.dataStore;\r
-\r
- return html.replace( /<!--\{cke_protected\}([\s\S]+?)-->/g, function( match, data )\r
- {\r
- return decodeURIComponent( data );\r
- }).replace( /\{cke_protected_(\d+)\}/g, function( match, id )\r
- {\r
- return store && store[ id ] || '';\r
- });\r
- }\r
-\r
- function protectSource( data, editor )\r
- {\r
- var protectedHtml = [],\r
- protectRegexes = editor.config.protectedSource,\r
- store = editor._.dataStore || ( editor._.dataStore = { id : 1 } ),\r
- tempRegex = /<\!--\{cke_temp(comment)?\}(\d*?)-->/g;\r
-\r
- var regexes =\r
- [\r
- // Script tags will also be forced to be protected, otherwise\r
- // IE will execute them.\r
- ( /<script[\s\S]*?<\/script>/gi ),\r
-\r
- // <noscript> tags (get lost in IE and messed up in FF).\r
- /<noscript[\s\S]*?<\/noscript>/gi\r
- ]\r
- .concat( protectRegexes );\r
-\r
- // First of any other protection, we must protect all comments\r
- // to avoid loosing them (of course, IE related).\r
- // Note that we use a different tag for comments, as we need to\r
- // transform them when applying filters.\r
- data = data.replace( (/<!--[\s\S]*?-->/g), function( match )\r
- {\r
- return '<!--{cke_tempcomment}' + ( protectedHtml.push( match ) - 1 ) + '-->';\r
- });\r
-\r
- for ( var i = 0 ; i < regexes.length ; i++ )\r
- {\r
- data = data.replace( regexes[i], function( match )\r
- {\r
- match = match.replace( tempRegex, // There could be protected source inside another one. (#3869).\r
- function( $, isComment, id )\r
- {\r
- return protectedHtml[ id ];\r
- }\r
- );\r
-\r
- // Avoid protecting over protected, e.g. /\{.*?\}/\r
- return ( /cke_temp(comment)?/ ).test( match ) ? match\r
- : '<!--{cke_temp}' + ( protectedHtml.push( match ) - 1 ) + '-->';\r
- });\r
- }\r
- data = data.replace( tempRegex, function( $, isComment, id )\r
- {\r
- return '<!--' + protectedSourceMarker +\r
- ( isComment ? '{C}' : '' ) +\r
- encodeURIComponent( protectedHtml[ id ] ).replace( /--/g, '%2D%2D' ) +\r
- '-->';\r
- }\r
- );\r
-\r
- // Different protection pattern is used for those that\r
- // live in attributes to avoid from being HTML encoded.\r
- return data.replace( /(['"]).*?\1/g, function ( match )\r
- {\r
- return match.replace( /<!--\{cke_protected\}([\s\S]+?)-->/g, function( match, data )\r
- {\r
- store[ store.id ] = decodeURIComponent( data );\r
- return '{cke_protected_'+ ( store.id++ ) + '}';\r
- });\r
- });\r
- }\r
-\r
- CKEDITOR.plugins.add( 'htmldataprocessor',\r
- {\r
- requires : [ 'htmlwriter' ],\r
-\r
- init : function( editor )\r
- {\r
- var dataProcessor = editor.dataProcessor = new CKEDITOR.htmlDataProcessor( editor );\r
-\r
- dataProcessor.writer.forceSimpleAmpersand = editor.config.forceSimpleAmpersand;\r
-\r
- dataProcessor.dataFilter.addRules( defaultDataFilterRules );\r
- dataProcessor.dataFilter.addRules( defaultDataBlockFilterRules );\r
- dataProcessor.htmlFilter.addRules( defaultHtmlFilterRules );\r
-\r
- var defaultHtmlBlockFilterRules = { elements : {} };\r
- for ( i in blockLikeTags )\r
- defaultHtmlBlockFilterRules.elements[ i ] = getBlockExtension( true, editor.config.fillEmptyBlocks );\r
-\r
- dataProcessor.htmlFilter.addRules( defaultHtmlBlockFilterRules );\r
- },\r
-\r
- onLoad : function()\r
- {\r
- ! ( 'fillEmptyBlocks' in CKEDITOR.config ) && ( CKEDITOR.config.fillEmptyBlocks = 1 );\r
- }\r
- });\r
-\r
- CKEDITOR.htmlDataProcessor = function( editor )\r
- {\r
- this.editor = editor;\r
-\r
- this.writer = new CKEDITOR.htmlWriter();\r
- this.dataFilter = new CKEDITOR.htmlParser.filter();\r
- this.htmlFilter = new CKEDITOR.htmlParser.filter();\r
- };\r
-\r
- CKEDITOR.htmlDataProcessor.prototype =\r
- {\r
- toHtml : function( data, fixForBody )\r
- {\r
- // The source data is already HTML, but we need to clean\r
- // it up and apply the filter.\r
-\r
- data = protectSource( data, this.editor );\r
-\r
- // Before anything, we must protect the URL attributes as the\r
- // browser may changing them when setting the innerHTML later in\r
- // the code.\r
- data = protectAttributes( data );\r
-\r
- // Protect elements than can't be set inside a DIV. E.g. IE removes\r
- // style tags from innerHTML. (#3710)\r
- data = protectElements( data );\r
-\r
- // Certain elements has problem to go through DOM operation, protect\r
- // them by prefixing 'cke' namespace. (#3591)\r
- data = protectElementsNames( data );\r
-\r
- // All none-IE browsers ignore self-closed custom elements,\r
- // protecting them into open-close. (#3591)\r
- data = protectSelfClosingElements( data );\r
-\r
- // Compensate one leading line break after <pre> open as browsers\r
- // eat it up. (#5789)\r
- data = protectPreFormatted( data );\r
-\r
- // Call the browser to help us fixing a possibly invalid HTML\r
- // structure.\r
- var div = new CKEDITOR.dom.element( 'div' );\r
- // Add fake character to workaround IE comments bug. (#3801)\r
- div.setHtml( 'a' + data );\r
- data = div.getHtml().substr( 1 );\r
-\r
- // Unprotect "some" of the protected elements at this point.\r
- data = unprotectElementNames( data );\r
-\r
- data = unprotectElements( data );\r
-\r
- // Restore the comments that have been protected, in this way they\r
- // can be properly filtered.\r
- data = unprotectRealComments( data );\r
-\r
- // Now use our parser to make further fixes to the structure, as\r
- // well as apply the filter.\r
- var fragment = CKEDITOR.htmlParser.fragment.fromHtml( data, fixForBody ),\r
- writer = new CKEDITOR.htmlParser.basicWriter();\r
-\r
- fragment.writeHtml( writer, this.dataFilter );\r
- data = writer.getHtml( true );\r
-\r
- // Protect the real comments again.\r
- data = protectRealComments( data );\r
-\r
- return data;\r
- },\r
-\r
- toDataFormat : function( html, fixForBody )\r
- {\r
- var writer = this.writer,\r
- fragment = CKEDITOR.htmlParser.fragment.fromHtml( html, fixForBody );\r
-\r
- writer.reset();\r
-\r
- fragment.writeHtml( writer, this.htmlFilter );\r
-\r
- var data = writer.getHtml( true );\r
-\r
- // Restore those non-HTML protected source. (#4475,#4880)\r
- data = unprotectRealComments( data );\r
- data = unprotectSource( data, this.editor );\r
-\r
- return data;\r
- }\r
- };\r
-})();\r
-\r
-/**\r
- * Whether to force using "&" instead of "&amp;" in elements attributes\r
- * values, it's not recommended to change this setting for compliance with the\r
- * W3C XHTML 1.0 standards (<a href="http://www.w3.org/TR/xhtml1/#C_12">C.12, XHTML 1.0</a>).\r
- * @name CKEDITOR.config.forceSimpleAmpersand\r
- * @name CKEDITOR.config.forceSimpleAmpersand\r
- * @type Boolean\r
- * @default false\r
- * @example\r
- * config.forceSimpleAmpersand = false;\r
- */\r
-\r
-/**\r
- * Whether a filler text (non-breaking space entity - ) will be inserted into empty block elements in HTML output,\r
- * this is used to render block elements properly with line-height; When a function is instead specified,\r
- * it'll be passed a {@link CKEDITOR.htmlParser.element} to decide whether adding the filler text\r
- * by expecting a boolean return value.\r
- * @name CKEDITOR.config.fillEmptyBlocks\r
- * @since 3.5\r
- * @type Boolean\r
- * @default true\r
- * @example\r
- * config.fillEmptyBlocks = false; // Prevent filler nodes in all empty blocks.\r
- *\r
- * // Prevent filler node only in float cleaners.\r
- * config.fillEmptyBlocks = function( element )\r
- * {\r
- * if ( element.attributes[ 'class' ].indexOf ( 'clear-both' ) != -1 )\r
- * return false;\r
- * }\r
- */\r