Ticket #2766: 2766.patch

File 2766.patch, 28.9 KB (added by Martin Kou, 15 years ago)
  • _source/plugins/fakeobjects/plugin.js

     
    2626
    2727(function()
    2828{
    29         CKEDITOR.plugins.add( 'fakeobjects',
     29        var flashExtensionRegex = /\.swf($|#|\?)/i,
     30                emptyElements = { base:1,col:1,meta:1,link:1,hr:1,br:1,param:1,img:1,area:1,input:1 },
     31                makeTagOpenerHtml = function( tagName, attributes, selfClosing )
    3032                {
    31                         init : function( editor, pluginPath )
    32                         {
    33                                 var flashExtensionRegex = /\.swf($|#|\?)/i,
    34                                         emptyElements = { base:1,col:1,meta:1,link:1,hr:1,br:1,param:1,img:1,area:1,input:1 },
    35                                         objectTypes =
    36                                         [
    37                                                 {
    38                                                         match : function( nodeName, attributes )
    39                                                         {
    40                                                                 return nodeName == 'embed' && ( attributes.type == 'application/x-shockwave-flash' || flashExtensionRegex.test( attributes.src || '' ) );
    41                                                         },
    42                                                         cssClass : 'flash',
    43                                                         priority : 10
    44                                                 },
    45                                                 {
    46                                                         match : function( nodeName, attributes )
    47                                                         {
    48                                                                 return ( nodeName == 'a' && attributes.name != null && attributes.name != '' );
    49                                                         },
    50                                                         cssClass : 'anchor',
    51                                                         priority : 10
    52                                                 },
    53                                                 {
    54                                                         match : function( nodeName, attributes )
    55                                                         {
    56                                                                 if ( nodeName == 'div' && attributes.style && attributes.style.pageBreakAfter == 'always' )
    57                                                                         if ( attributes.firstChild )
    58                                                                         {
    59                                                                                 var element = new CKEDITOR.dom.element( attributes.firstChild );
    60                                                                                 return ( element && element.getName() == 'span');
    61                                                                         }
    62                                                                 return false;
    63                                                         },
    64                                                         cssClass : 'pagebreak',
    65                                                         priority : 10
    66                                                 },
    67                                                 {
    68                                                         match : function( nodeName, attributes )
    69                                                         {
    70                                                                 return nodeName == 'embed' || nodeName == 'object';
    71                                                         },
    72                                                         cssClass : 'object',
    73                                                         priority : 0x100000000
    74                                                 }
    75                                         ],
    76                                         makeTagOpenerHtml = function( tagName, attributes, selfClosing )
    77                                         {
    78                                                 var attribStr = [], html = [ '<' + tagName ];
    79                                                 for ( var i in attributes )
    80                                                         attribStr.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '"');
    81                                                 if ( attribStr.length > 0 )
    82                                                         html.push( ' ', attribStr.join( ' ' ) );
    83                                                 if ( emptyElements[ tagName ] || selfClosing )
    84                                                         html.push( ' /' );
    85                                                 html.push( '>' );
    86                                                 return html.join( '' );
    87                                         },
    88                                         cssWidthRegex = /width\s*:\s*([0-9]+)\s*(?:[\w%]+)?\s*;?/i,
    89                                         cssHeightRegex = /height\s*:\s*([0-9]+)\s*(?:[\w%]+)?\s*;?/i;
     33                        var attribStr = [], html = [ '<' + tagName ];
     34                        for ( var i in attributes )
     35                                attribStr.push( i + '="' + CKEDITOR.tools.htmlEncode( attributes[i] ) + '"');
     36                        if ( attribStr.length > 0 )
     37                                html.push( ' ', attribStr.join( ' ' ) );
     38                        if ( emptyElements[ tagName ] || selfClosing )
     39                                html.push( ' /' );
     40                        html.push( '>' );
     41                        return html.join( '' );
     42                },
     43                cssWidthRegex = /width\s*:\s*([0-9]+)\s*(?:[\w%]+)?\s*;?/i,
     44                cssHeightRegex = /height\s*:\s*([0-9]+)\s*(?:[\w%]+)?\s*;?/i;
    9045
    91                                 var copyParser = function()
    92                                 {
    93                                         this._ = { html : null };
    94                                         this.output = [];
     46        var copyParser = function()
     47        {
     48                this._ = { html : null };
     49                this.output = [];
    9550
    96                                         CKEDITOR.htmlParser.call( this );
    97                                 };
    98                                 copyParser.prototype = {
    99                                         onTagOpen : function( tagName, attributes, selfClosing )
    100                                         {
    101                                                 this.output.push( makeTagOpenerHtml( tagName, attributes, selfClosing ) );
    102                                         },
     51                CKEDITOR.htmlParser.call( this );
     52        };
     53        copyParser.prototype = {
     54                onTagOpen : function( tagName, attributes, selfClosing )
     55                {
     56                        this.output.push( makeTagOpenerHtml( tagName, attributes, selfClosing ) );
     57                },
    10358
    104                                         onTagClose : function( tagName )
    105                                         {
    106                                                 if ( !emptyElements[ tagName] )
    107                                                         this.output.push( '</' + tagName + '>' );
    108                                         },
     59                onTagClose : function( tagName )
     60                {
     61                        if ( !emptyElements[ tagName] )
     62                                this.output.push( '</' + tagName + '>' );
     63                },
    10964
    110                                         onText : function( text )
     65                onText : function( text )
     66                {
     67                        this.output.push( text );
     68                },
     69
     70                onComment : function( comment )
     71                {
     72                        this.output.push( '<!--' + comment + '-->' );
     73                },
     74
     75                parse : function( html )
     76                {
     77                        this._.html = html;
     78                        return CKEDITOR.htmlParser.prototype.parse.apply( this, arguments );
     79                }
     80        };
     81
     82        /**
     83         * Manages element placeholders in WYSIWYG area.
     84         * @constructor
     85         * @example
     86         */
     87        CKEDITOR.plugins.fakeobjects = function()
     88        {
     89                this._ =
     90                {
     91                        objectTypes : [
     92                                {
     93                                        match : function( nodeName, attributes )
    11194                                        {
    112                                                 this.output.push( text );
     95                                                return nodeName == 'embed' &&
     96                                                        ( attributes.type == 'application/x-shockwave-flash' || flashExtensionRegex.test( attributes.src || '' ) );
    11397                                        },
    114 
    115                                         onComment : function( comment )
     98                                        cssClass : 'flash',
     99                                        priority : 10
     100                                },
     101                                {
     102                                        match : function( nodeName, attributes )
    116103                                        {
    117                                                 this.output.push( '<!--' + comment + '-->' );
     104                                                return ( nodeName == 'a' && attributes.name != null && attributes.name != '' );
    118105                                        },
    119 
    120                                         parse : function( html )
    121                                         {
    122                                                 this._.html = html;
    123                                                 return CKEDITOR.htmlParser.prototype.parse.apply( this, arguments );
    124                                         }
    125                                 };
    126                                
    127                                 /**
    128                                  * Manages element placeholders in WYSIWYG area.
    129                                  * @namespace
    130                                  * @example
    131                                  */
    132                                 CKEDITOR.plugins.fakeobjects =
     106                                        cssClass : 'anchor',
     107                                        priority : 10
     108                                },
    133109                                {
    134                                         /**
    135                                          * Converts an element into a placeholder &lt;img&gt; element, for adding
    136                                          * into the WYSIWYG area.
    137                                          * @param {CKEDITOR.dom.element} element Input DOM element.
    138                                          * @returns {CKEDITOR.dom.element} The placeholder &lt;img&gt; element.
    139                                          * @example
    140                                          */
    141                                         protectElement : function( element )
     110                                        match : function( nodeName, attributes )
    142111                                        {
    143                                                 var $ = element.$.cloneNode( true ),
    144                                                         doc = $.ownerDocument,
    145                                                         temp = doc.createElement( 'div' ),
    146                                                         html;
    147 
    148                                                 // Get the object's HTML code.
    149                                                 temp.appendChild( $ );
    150                                                 html = temp.innerHTML;
    151 
    152                                                 // Get the fake element's CSS class.
    153                                                 var cssClass = 'unknown';
    154                                                 var realElementType = element.getName();
    155                                                 for ( var i = 0 ; i < objectTypes.length ; i++ )
    156                                                 {
    157                                                         if ( objectTypes[i].match( element.getName(), element.$ ) )
     112                                                if ( nodeName == 'div' && attributes.style && attributes.style.pageBreakAfter == 'always' )
     113                                                        if ( attributes.firstChild )
    158114                                                        {
    159                                                                 cssClass = 'cke_fakeobject' + ' ' + objectTypes[i].cssClass;
    160                                                                 realElementType = objectTypes[i].cssClass;
    161                                                                 break;
     115                                                                var element = new CKEDITOR.dom.element( attributes.firstChild );
     116                                                                return ( element && element.getName() == 'span');
    162117                                                        }
    163                                                 }
    164 
    165                                                 // Make the fake element.
    166                                                 var fakeRawElement = doc.createElement( 'img' ),
    167                                                         cssText = $.style.cssText,
    168                                                         widthMatch = cssText.match( cssWidthRegex ),
    169                                                         heightMatch = cssText.match( cssHeightRegex );
    170                                                 fakeRawElement.className = cssClass;
    171                                                 fakeRawElement.src = CKEDITOR.getUrl( 'images/spacer.gif' );
    172                                                 if ( widthMatch)
    173                                                         fakeRawElement.style.width = widthMatch[1] + 'px';
    174                                                 if ( heightMatch )
    175                                                         fakeRawElement.style.height = heightMatch[1] + 'px';
    176                                                 fakeRawElement.setAttribute( '_cke_protected_html', encodeURIComponent( html ) );
    177                                                 fakeRawElement.setAttribute( '_cke_real_element_type', realElementType );
    178                                                 return new CKEDITOR.dom.element( fakeRawElement );
     118                                                return false;
    179119                                        },
    180 
    181                                         /**
    182                                          * Converts a placeholder &lt;img&gt; element back to the real element.
    183                                          * @param {CKEDITOR.dom.element} fakeImgElement The placeholder &lt;img&gt;.
    184                                          * @returns {CKEDITOR.dom.element} The real element.
    185                                          * @example
    186                                          */
    187                                         restoreElement : function( fakeImgElement )
     120                                        cssClass : 'pagebreak',
     121                                        priority : 10
     122                                },
     123                                {
     124                                        match : function( nodeName, attributes )
    188125                                        {
    189                                                 var html = decodeURIComponent( fakeImgElement.getAttribute( '_cke_protected_html' ) ),
    190                                                         realElement = CKEDITOR.dom.element.createFromHtml( html, editor.document );
     126                                                return nodeName == 'embed' || nodeName == 'object';
     127                                        },
     128                                        cssClass : 'object',
     129                                        priority : 0x100000000
     130                                }
     131                        ]
     132                };
     133        };
     134        CKEDITOR.plugins.fakeobjects.prototype =
     135        {
     136                /**
     137                 * Converts an element into a placeholder &lt;img&gt; element, for adding
     138                 * into the WYSIWYG area.
     139                 * @param {CKEDITOR.dom.element} element Input DOM element.
     140                 * @returns {CKEDITOR.dom.element} The placeholder &lt;img&gt; element.
     141                 * @example
     142                 */
     143                protectElement : function( element )
     144                {
     145                        var $ = element.$.cloneNode( true ),
     146                                doc = $.ownerDocument,
     147                                temp = doc.createElement( 'div' ),
     148                                html;
    191149
    192                                                 if ( fakeImgElement.$.style.width )
    193                                                         realElement.setStyle( 'width', fakeImgElement.$.style.width );
    194                                                 if ( fakeImgElement.$.style.height )
    195                                                         realElement.setStyle( 'height', fakeImgElement.$.style.height );
     150                        // Get the object's HTML code.
     151                        temp.appendChild( $ );
     152                        html = temp.innerHTML;
    196153
    197                                                 return realElement;
    198                                         },
     154                        // Get the fake element's CSS class.
     155                        var cssClass = 'unknown';
     156                        var realElementType = element.getName();
     157                        for ( var i = 0 ; i < this._.objectTypes.length ; i++ )
     158                        {
     159                                if ( this._.objectTypes[i].match( element.getName(), element.$ ) )
     160                                {
     161                                        cssClass = 'cke_fakeobject' + ' ' + this._.objectTypes[i].cssClass;
     162                                        realElementType = this._.objectTypes[i].cssClass;
     163                                        break;
     164                                }
     165                        }
    199166
    200                                         /**
    201                                          * Converts protectable elements in an HTML string to placeholders.
    202                                          * @param {String} html HTML with protectable elements.
    203                                          * @returns {String} HTML with placeholders.
    204                                          * @example
    205                                          */
    206                                         protectHtml : function( html )
    207                                         {
    208                                                 var parser = new CKEDITOR.htmlParser(),
    209                                                         tagDepth = 0, processedHtml = [],
    210                                                         protectedHtml = [], inProtection = false;
     167                        // Make the fake element.
     168                        var fakeRawElement = doc.createElement( 'img' ),
     169                                cssText = $.style.cssText,
     170                                widthMatch = cssText.match( cssWidthRegex ),
     171                                heightMatch = cssText.match( cssHeightRegex );
     172                        fakeRawElement.className = cssClass;
     173                        fakeRawElement.src = CKEDITOR.getUrl( 'images/spacer.gif' );
     174                        if ( widthMatch)
     175                                fakeRawElement.style.width = widthMatch[1] + 'px';
     176                        if ( heightMatch )
     177                                fakeRawElement.style.height = heightMatch[1] + 'px';
     178                        fakeRawElement.setAttribute( '_cke_protected_html', encodeURIComponent( html ) );
     179                        fakeRawElement.setAttribute( '_cke_real_element_type', realElementType );
     180                        return new CKEDITOR.dom.element( fakeRawElement );
     181                },
    211182
    212                                                 parser.onTagOpen = function( tagName, attributes, selfClosing )
    213                                                 {
    214                                                         if ( inProtection )
    215                                                         {
    216                                                                 protectedHtml.push( makeTagOpenerHtml( tagName, attributes, selfClosing ) );
    217                                                                 if ( !( emptyElements[ tagName ] || selfClosing ) )
    218                                                                         tagDepth++;
    219                                                                 if ( tagDepth < 1 )
    220                                                                 {
    221                                                                         inProtection = false;
    222                                                                         processedHtml.push( encodeURIComponent( protectedHtml.join( '' ) ), '" />' );
    223                                                                         protectedHtml = [];
    224                                                                 }
    225                                                                 return;
    226                                                         }
     183                /**
     184                 * Converts a placeholder &lt;img&gt; element back to the real element.
     185                 * @param {CKEDITOR.dom.element} fakeImgElement The placeholder &lt;img&gt;.
     186                 * @returns {CKEDITOR.dom.element} The real element.
     187                 * @example
     188                 */
     189                restoreElement : function( fakeImgElement )
     190                {
     191                        var html = decodeURIComponent( fakeImgElement.getAttribute( '_cke_protected_html' ) ),
     192                                realElement = CKEDITOR.dom.element.createFromHtml( html, editor.document );
    227193
    228                                                         for ( var i = 0 ; i < objectTypes.length ; i++ )
    229                                                         {
    230                                                                 if ( objectTypes[i].match( tagName, attributes ) )
    231                                                                 {
    232                                                                         inProtection = true;
    233                                                                         tagDepth = 0;
     194                        if ( fakeImgElement.$.style.width )
     195                                realElement.setStyle( 'width', fakeImgElement.$.style.width );
     196                        if ( fakeImgElement.$.style.height )
     197                                realElement.setStyle( 'height', fakeImgElement.$.style.height );
    234198
    235                                                                         // Get the original object's width and height.
    236                                                                         var styles = attributes.style || '',
    237                                                                                 widthMatch = styles.match( cssWidthRegex ),
    238                                                                                 heightMatch = styles.match( cssHeightRegex );
     199                        return realElement;
     200                },
    239201
    240                                                                         // Create the fake <img> tag.
    241                                                                         processedHtml.push( '<img src="',
    242                                                                                 CKEDITOR.getUrl( 'images/spacer.gif' ),
    243                                                                                 '" ',
    244                                                                                 'class="cke_fakeobject ' + objectTypes[i].cssClass + '" ',
    245                                                                                 '_cke_real_element_type="' + objectTypes[i].cssClass + '"' );
     202                /**
     203                 * Converts protectable elements in an HTML string to placeholders.
     204                 * @param {String} html HTML with protectable elements.
     205                 * @returns {String} HTML with placeholders.
     206                 * @example
     207                 */
     208                protectHtml : function( html )
     209                {
     210                        var parser = new CKEDITOR.htmlParser(),
     211                                tagDepth = 0, processedHtml = [],
     212                                protectedHtml = [], inProtection = false,
     213                                objectTypes = this._.objectTypes;
    246214
    247                                                                         if ( widthMatch || heightMatch )
    248                                                                         {
    249                                                                                 processedHtml.push( 'style="',
    250                                                                                         widthMatch ? 'width:' + widthMatch[1] + 'px;' : '',
    251                                                                                         heightMatch ? 'height:' + heightMatch[1] + 'px;' : '',
    252                                                                                         '" ' );
    253                                                                         }
     215                        parser.onTagOpen = function( tagName, attributes, selfClosing )
     216                        {
     217                                if ( inProtection )
     218                                {
     219                                        protectedHtml.push( makeTagOpenerHtml( tagName, attributes, selfClosing ) );
     220                                        if ( !( emptyElements[ tagName ] || selfClosing ) )
     221                                                tagDepth++;
     222                                        if ( tagDepth < 1 )
     223                                        {
     224                                                inProtection = false;
     225                                                processedHtml.push( encodeURIComponent( protectedHtml.join( '' ) ), '" />' );
     226                                                protectedHtml = [];
     227                                        }
     228                                        return;
     229                                }
    254230
    255                                                                         processedHtml.push( '_cke_protected_html="' );
    256                                                                         arguments.callee.call( this, tagName, attributes, selfClosing );
    257                                                                         return;
    258                                                                 }
    259                                                         }
     231                                for ( var i = 0 ; i < objectTypes.length ; i++ )
     232                                {
     233                                        if ( objectTypes[i].match( tagName, attributes ) )
     234                                        {
     235                                                inProtection = true;
     236                                                tagDepth = 0;
    260237
    261                                                         processedHtml.push( makeTagOpenerHtml( tagName, attributes ) );
    262                                                 };
     238                                                // Get the original object's width and height.
     239                                                var styles = attributes.style || '',
     240                                                        widthMatch = styles.match( cssWidthRegex ),
     241                                                        heightMatch = styles.match( cssHeightRegex );
    263242
    264                                                 parser.onText = function( text )
    265                                                 {
    266                                                         inProtection ? protectedHtml.push( text ) : processedHtml.push( text );
    267                                                 };
     243                                                // Create the fake <img> tag.
     244                                                processedHtml.push( '<img src="',
     245                                                        CKEDITOR.getUrl( 'images/spacer.gif' ),
     246                                                        '" ',
     247                                                        'class="cke_fakeobject ' + objectTypes[i].cssClass + '" ',
     248                                                        '_cke_real_element_type="' + objectTypes[i].cssClass + '"' );
    268249
    269                                                 parser.onComment = function( comment )
     250                                                if ( widthMatch || heightMatch )
    270251                                                {
    271                                                         inProtection ? protectedHtml.push( '<!--' + comment + '-->' ) : processedHtml.push( '<!--' + comment + '-->' );
    272                                                 };
     252                                                        processedHtml.push( 'style="',
     253                                                                widthMatch ? 'width:' + widthMatch[1] + 'px;' : '',
     254                                                                heightMatch ? 'height:' + heightMatch[1] + 'px;' : '',
     255                                                                '" ' );
     256                                                }
    273257
    274                                                 parser.onTagClose = function( tagName )
    275                                                 {
    276                                                         if ( inProtection )
    277                                                         {
    278                                                                 if ( !emptyElements[ tagName ] )
    279                                                                         tagDepth--;
    280                                                                 protectedHtml.push( '</' + tagName + '>' );
    281                                                                 if ( tagDepth < 1 )
    282                                                                 {
    283                                                                         inProtection = false;
    284                                                                         processedHtml.push( encodeURIComponent( protectedHtml.join( '' ) ), '" />' );
    285                                                                         protectedHtml = [];
    286                                                                 }
    287                                                         }
    288                                                         else
    289                                                                 processedHtml.push( '</' + tagName + '>' );
    290                                                 };
     258                                                processedHtml.push( '_cke_protected_html="' );
     259                                                arguments.callee.call( this, tagName, attributes, selfClosing );
     260                                                return;
     261                                        }
     262                                }
    291263
    292                                                 parser.parse( html );
    293                                                 return processedHtml.join( '' );
    294                                         },
    295                                         /**
    296                                          * Updates HTML into a placeholder
    297                                          * @param {CKEDITOR.dom.element} fakeImgElement The placeholder &lt;img&gt;.
    298                                          * @param {CKEDITOR.dom.element} element Input DOM element.
    299                                          * @returns {String} encoded HTML.
    300                                          * @example
    301                                          */
    302                                         updateFakeElement : function( fakeElement, realElement )
    303                                         {
    304                                                 var $ = realElement.$.cloneNode( true ),
    305                                                         doc = $.ownerDocument,
    306                                                         temp = doc.createElement( 'div' ),
    307                                                         html;
     264                                processedHtml.push( makeTagOpenerHtml( tagName, attributes ) );
     265                        };
    308266
    309                                                 // Get the object's HTML code.
    310                                                 temp.appendChild( $ );
    311                                                 html = temp.innerHTML;
    312                                                 fakeElement.setAttribute( '_cke_protected_html', encodeURIComponent( html ) );
    313                                                 return html;
    314                                         },
    315                                        
    316                                         /**
    317                                          * Restores placeholders in an HTML string back to their original elements.
    318                                          * @param {String} html HTML with placeholders.
    319                                          * @returns {String} Restored HTML.
    320                                          * @example
    321                                          */
    322                                         restoreHtml : function( html )
     267                        parser.onText = function( text )
     268                        {
     269                                inProtection ? protectedHtml.push( text ) : processedHtml.push( text );
     270                        };
     271
     272                        parser.onComment = function( comment )
     273                        {
     274                                inProtection ? protectedHtml.push( '<!--' + comment + '-->' ) : processedHtml.push( '<!--' + comment + '-->' );
     275                        };
     276
     277                        parser.onTagClose = function( tagName )
     278                        {
     279                                if ( inProtection )
     280                                {
     281                                        if ( !emptyElements[ tagName ] )
     282                                                tagDepth--;
     283                                        protectedHtml.push( '</' + tagName + '>' );
     284                                        if ( tagDepth < 1 )
    323285                                        {
    324                                                 var parser = new copyParser(),
    325                                                         innerParser = new copyParser();
    326                                                
    327                                                 innerParser.onTagOpen = function( tagName, attributes, selfClosing )
    328                                                 {
    329                                                         if ( !this.done )
    330                                                         {
    331                                                                 var styles = attributes.style || '';
     286                                                inProtection = false;
     287                                                processedHtml.push( encodeURIComponent( protectedHtml.join( '' ) ), '" />' );
     288                                                protectedHtml = [];
     289                                        }
     290                                }
     291                                else
     292                                        processedHtml.push( '</' + tagName + '>' );
     293                        };
    332294
    333                                                                 styles = styles.replace( cssWidthRegex, '' ).replace( cssHeightRegex, '' );
    334                                                                 if ( this.width )
    335                                                                         styles += 'width:' + this.width + ';';
    336                                                                 if ( this.height )
    337                                                                         styles += 'height:' + this.height + ';';
    338                                                                 attributes.style = styles;
     295                        parser.parse( html );
     296                        return processedHtml.join( '' );
     297                },
     298                /**
     299                 * Updates HTML into a placeholder
     300                 * @param {CKEDITOR.dom.element} fakeImgElement The placeholder &lt;img&gt;.
     301                 * @param {CKEDITOR.dom.element} element Input DOM element.
     302                 * @returns {String} encoded HTML.
     303                 * @example
     304                 */
     305                updateFakeElement : function( fakeElement, realElement )
     306                {
     307                        var $ = realElement.$.cloneNode( true ),
     308                                doc = $.ownerDocument,
     309                                temp = doc.createElement( 'div' ),
     310                                html;
    339311
    340                                                                 this.done = true;
    341                                                         }
     312                        // Get the object's HTML code.
     313                        temp.appendChild( $ );
     314                        html = temp.innerHTML;
     315                        fakeElement.setAttribute( '_cke_protected_html', encodeURIComponent( html ) );
     316                        return html;
     317                },
     318               
     319                /**
     320                 * Restores placeholders in an HTML string back to their original elements.
     321                 * @param {String} html HTML with placeholders.
     322                 * @returns {String} Restored HTML.
     323                 * @example
     324                 */
     325                restoreHtml : function( html )
     326                {
     327                        var parser = new copyParser(),
     328                                innerParser = new copyParser();
     329                       
     330                        innerParser.onTagOpen = function( tagName, attributes, selfClosing )
     331                        {
     332                                if ( !this.done )
     333                                {
     334                                        var styles = attributes.style || '';
    342335
    343                                                         return copyParser.prototype.onTagOpen.apply( this, arguments );
    344                                                 };
     336                                        styles = styles.replace( cssWidthRegex, '' ).replace( cssHeightRegex, '' );
     337                                        if ( this.width )
     338                                                styles += 'width:' + this.width + ';';
     339                                        if ( this.height )
     340                                                styles += 'height:' + this.height + ';';
     341                                        attributes.style = styles;
    345342
    346                                                 parser.onTagOpen = function( tagName, attributes, selfClosing )
    347                                                 {
    348                                                         if ( tagName == 'img' && attributes._cke_protected_html !== undefined )
    349                                                         {
    350                                                                 var styles = attributes.style || '',
    351                                                                         protectedHtml = decodeURIComponent( attributes._cke_protected_html ),
    352                                                                         widthMatch = styles.match( cssWidthRegex ),
    353                                                                         heightMatch = styles.match( cssHeightRegex );
     343                                        this.done = true;
     344                                }
    354345
    355                                                                 if ( widthMatch || heightMatch )
    356                                                                 {
    357                                                                         innerParser.width = widthMatch[1] + 'px';
    358                                                                         innerParser.height = heightMatch[1] + 'px';
    359                                                                         innerParser.parse( protectedHtml );
    360                                                                         protectedHtml = innerParser.output.join( '' );
    361                                                                 }
     346                                return copyParser.prototype.onTagOpen.apply( this, arguments );
     347                        };
    362348
    363                                                                 this.output.push( protectedHtml );
    364                                                                 return;
    365                                                         }
    366                                                         return copyParser.prototype.onTagOpen.apply( this, arguments );
    367                                                 };
     349                        parser.onTagOpen = function( tagName, attributes, selfClosing )
     350                        {
     351                                if ( tagName == 'img' && attributes._cke_protected_html !== undefined )
     352                                {
     353                                        var styles = attributes.style || '',
     354                                                protectedHtml = decodeURIComponent( attributes._cke_protected_html ),
     355                                                widthMatch = styles.match( cssWidthRegex ),
     356                                                heightMatch = styles.match( cssHeightRegex );
    368357
    369                                                 parser.parse( html );
    370                                                 return parser.output.join( '' );
    371                                         },
    372 
    373                                         /**
    374                                          * Adds an object type to be displayed by placeholders.
    375                                          * @param {Function} matchFunc A predicate function to determine whether
    376                                          * an object needs to be replaced by placeholders or not. The function
    377                                          * should have the following signature:
    378                                          * <blockquote>function( tagName, attributes )</blockquote>
    379                                          * In which tagName is the object's tag name, and attributes is an object
    380                                          * storing all the object's attributes.
    381                                          * @param {String} cssClass The CSS class that should be added to the
    382                                          * placeholder &lt;img&gt; for representing this type of object.
    383                                          * @param {Number} priority (Optional) An integer representing the
    384                                          * priority of this type of object. If an element matches the descriptions
    385                                          * of two object types, the object type of <strong>lower</strong> priority
    386                                          * takes precedance.
    387                                          * @example
    388                                          */
    389                                         addObjectType : function( matchFunc, cssClass, priority )
     358                                        if ( widthMatch || heightMatch )
    390359                                        {
    391                                                 if ( priority === undefined )
    392                                                         priority = 10;
     360                                                innerParser.width = widthMatch[1] + 'px';
     361                                                innerParser.height = heightMatch[1] + 'px';
     362                                                innerParser.parse( protectedHtml );
     363                                                protectedHtml = innerParser.output.join( '' );
     364                                        }
    393365
    394                                                 var obj = {
    395                                                         match : matchFunc,
    396                                                         cssClass : cssClass,
    397                                                         priority : priority
    398                                                 };
     366                                        this.output.push( protectedHtml );
     367                                        return;
     368                                }
     369                                return copyParser.prototype.onTagOpen.apply( this, arguments );
     370                        };
    399371
    400                                                 for ( var i = objectTypes.length - 1 ; i >= 0 ; i-- )
    401                                                 {
    402                                                         if ( objectTypes[i].priority < priority )
    403                                                         {
    404                                                                 objectTypes.splice( i + 1, 0, obj );
    405                                                                 return;
    406                                                         }
    407                                                 }
     372                        parser.parse( html );
     373                        return parser.output.join( '' );
     374                },
    408375
    409                                                 objectTypes.unshift( obj );
    410                                         }
    411                                 };
     376                /**
     377                 * Adds an object type to be displayed by placeholders.
     378                 * @param {Function} matchFunc A predicate function to determine whether
     379                 * an object needs to be replaced by placeholders or not. The function
     380                 * should have the following signature:
     381                 * <blockquote>function( tagName, attributes )</blockquote>
     382                 * In which tagName is the object's tag name, and attributes is an object
     383                 * storing all the object's attributes.
     384                 * @param {String} cssClass The CSS class that should be added to the
     385                 * placeholder &lt;img&gt; for representing this type of object.
     386                 * @param {Number} priority (Optional) An integer representing the
     387                 * priority of this type of object. If an element matches the descriptions
     388                 * of two object types, the object type of <strong>lower</strong> priority
     389                 * takes precedance.
     390                 * @example
     391                 */
     392                addObjectType : function( matchFunc, cssClass, priority )
     393                {
     394                        if ( priority === undefined )
     395                                priority = 10;
     396
     397                        var obj = {
     398                                match : matchFunc,
     399                                cssClass : cssClass,
     400                                priority : priority
     401                        };
     402
     403                        for ( var i = this._.objectTypes.length - 1 ; i >= 0 ; i-- )
     404                        {
     405                                if ( this._.objectTypes[i].priority < priority )
     406                                {
     407                                        this._.objectTypes.splice( i + 1, 0, obj );
     408                                        return;
     409                                }
    412410                        }
     411
     412                        this._.objectTypes.unshift( obj );
     413                }
     414        };
     415
     416        CKEDITOR.plugins.add( 'fakeobjects',
     417                {
     418                        init : function( editor, pluginPath )
     419                        {
     420                                editor.fakeobjects = new CKEDITOR.plugins.fakeobjects();
     421                        }
    413422                } );
    414423})();
  • _source/plugins/link/dialogs/anchor.js

     
    1919 * == END LICENSE ==
    2020 */
    2121
    22 CKEDITOR.dialog.add( 'anchor', function( editor ){
     22CKEDITOR.dialog.add( 'anchor', function( editor )
    2323{
    2424        // Function called in onShow to load selected element.
    2525        var loadElements = function( editor, selection, ranges, element )
     
    5656                                this.restoreSelection();
    5757                                this.clearSavedSelection();
    5858
    59                                 var fakeElement = CKEDITOR.plugins.fakeobjects.protectElement( this.editObj );
     59                                var fakeElement = editor.fakeobjects.protectElement( this.editObj );
    6060                                editor.insertElement( fakeElement );
    6161                        }
    6262                        else
    63                                 CKEDITOR.plugins.fakeobjects.updateFakeElement( this.fakeObj, this.editObj );
     63                                editor.fakeobjects.updateFakeElement( this.fakeObj, this.editObj );
    6464                        return true;
    6565                },
    6666                onShow : function()
     
    8484                                if ( element && element.getAttribute( '_cke_real_element_type' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
    8585                                {
    8686                                        this.fakeObj = element;
    87                                         element = CKEDITOR.plugins.fakeobjects.restoreElement( this.fakeObj );
     87                                        element = editor.fakeobjects.restoreElement( this.fakeObj );
    8888                                        loadElements.apply( this, [ editor, selection, ranges, element ] );
    8989                                        selection.selectElement( this.fakeObj );
    9090                                        this.saveSelection();
     
    123123                        }
    124124                ]
    125125        };
    126 };
    127 
    128 });
     126} );
  • _source/plugins/link/dialogs/link.js

     
    670670                                if ( element.getAttribute( '_cke_protected_html' ) && element.getAttribute( '_cke_real_element_type' ) == "anchor" )
    671671                                {
    672672                                        var domElement = new CKEDITOR.dom.element( element );
    673                                         domElement = CKEDITOR.plugins.fakeobjects.restoreElement( domElement );
     673                                        domElement = editor.fakeobjects.restoreElement( domElement );
    674674                                        anchors.push( domElement );
    675675                                }
    676676                        }
     
    719719                                if ( element && element.getAttribute( '_cke_real_element_type' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
    720720                                {
    721721                                        this.fakeObj = element;
    722                                         element = CKEDITOR.plugins.fakeobjects.restoreElement( this.fakeObj );
     722                                        element = editor.fakeobjects.restoreElement( this.fakeObj );
    723723                                        loadLink.apply( this, [ editor, selection, ranges, element ] );
    724724                                        selection.selectElement( this.fakeObj );
    725725                                        this.saveSelection();
     
    856856                                // We're only editing an existing link, so just overwrite the attributes.
    857857                                this._.selectedElement.setAttributes( attributes );
    858858                                if ( this.fakeObj )
    859                                         CKEDITOR.plugins.fakeobjects.updateFakeElement( this.fakeObj, this._.selectedElement );
     859                                        editor.fakeobjects.updateFakeElement( this.fakeObj, this._.selectedElement );
    860860
    861861                                delete this._.selectedElement;
    862862                        }
  • _source/plugins/link/plugin.js

     
    5959                                        command.state = CKEDITOR.TRISTATE_DISABLED;
    6060                                command.fire( 'state' );
    6161                        } );
    62         }
     62        },
     63
     64        requires : [ 'fakeobjects' ]
    6365} );
    6466
    6567CKEDITOR.unlinkCommand = function(){};
  • _source/plugins/pagebreak/plugin.js

     
    4646                var breakObject = CKEDITOR.dom.element.createFromHtml( '<div style="page-break-after: always;"><span style="display: none;">&nbsp;</span></div>' );
    4747
    4848                if ( getProtected )
    49                         return CKEDITOR.plugins.fakeobjects.protectElement( breakObject );
     49                        return editor.fakeobjects.protectElement( breakObject );
    5050                else
    5151                        return breakObject;
    5252        },
  • _source/plugins/wysiwygarea/plugin.js

     
    247247                                                                data = protectUrls( data );
    248248
    249249                                                                // Replace tags with fake elements.
    250                                                                 data = CKEDITOR.plugins.fakeobjects.protectHtml( data );
     250                                                                data = editor.fakeobjects.protectHtml( data );
    251251
    252252                                                                data =
    253253                                                                        editor.config.docType +
     
    300300                                                                data = protectUrlsRestore( data );
    301301
    302302                                                                // Restore fake elements.
    303                                                                 data = CKEDITOR.plugins.fakeobjects.restoreHtml( data );
     303                                                                data = editor.fakeobjects.restoreHtml( data );
    304304
    305305                                                                return data;
    306306                                                        },
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy