Ticket #3591: 3591_3.patch

File 3591_3.patch, 2.3 KB (added by Garry Yao, 15 years ago)
  • _source/plugins/htmldataprocessor/plugin.js

     
    77{
    88        var defaultDataFilterRules =
    99        {
    10                 elementNames :
    11                 [
    12                         // Elements that cause problems in wysiwyg mode.
    13                         [ ( /^(object|embed|param)$/ ), 'cke:$1' ]
    14                 ],
    15 
    1610                attributeNames :
    1711                [
    1812                        // Event attributes (onXYZ) must not be directly set. They can become
     
    5650                                        }
    5751                                },
    5852
     53                                // Restore param elements into self-closing.
     54                                param : function( param )
     55                                {
     56                                        param.children = [];
     57                                        param.isEmpty = true;
     58                                        return param;
     59                                },
     60
    5961                                img : function( element )
    6062                                {
    6163                                        var attribs = element.attributes;
     
    105107        }
    106108
    107109        var protectAttributeRegex = /<(?:a|area|img|input).*?\s((?:href|src|name)\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|(?:[^ "'>]+)))/gi;
    108 
     110        var protectElementNamesRegex = /(<[/]?)(object|embed|param)(.*?>)/gi;
     111        var protectSelfClosingRegex = /(<)(cke:param)(.*?)\/(>)/gi;
    109112        function protectAttributes( html )
    110113        {
    111114                return html.replace( protectAttributeRegex, '$& _cke_saved_$1' );
    112115        }
    113 
     116        function protectElementsNames( html )
     117        {
     118                return html.replace( protectElementNamesRegex, '$1cke:$2$3');
     119        }
     120        function protectSelfClosingElements( html )
     121        {
     122                return html.replace( protectSelfClosingRegex, '$1$2$3$4 $1/$2$4' );
     123        }
    114124        CKEDITOR.plugins.add( 'htmldataprocessor',
    115125        {
    116126                requires : [ 'htmlwriter' ],
     
    145155                        // the code.
    146156                        data = protectAttributes( data );
    147157
     158                        // Certain elements has problem during native DOM operation, we transform them into
     159                        // their 'agent' intead, prefixing with 'cke:' to become a custom element.
     160                        data = protectElementsNames( data );
     161
     162                        // All none-IE browsers don't accept self-closed custom elements, treating them as
     163                        // an open tag, now converting them to avoid ambiguous.
     164                        data = protectSelfClosingElements( data );
     165
    148166                        // Call the browser to help us fixing a possibly invalid HTML
    149167                        // structure.
    150                         var div = document.createElement( 'div' );
     168                        var div = document.createElement( 'body' );
    151169                        div.innerHTML = data;
    152170
    153171                        // Now use our parser to make further fixes to the structure, as
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy