Ticket #7981: 7981.patch

File 7981.patch, 15.6 KB (added by Garry Yao, 12 years ago)
  • _source/plugins/dialog/plugin.js

     
    23292329                                {
    23302330                                                this.setValue = CKEDITOR.tools.override( this.setValue, function( org )
    23312331                                                {
    2332                                                                 return function( val ){ org.call( this, elementDefinition.setValue.call( this, val ) ); };
     2332                                                        return function( val, noChange ){ org.call( this, elementDefinition.setValue.apply( this, arguments ), noChange ); };
    23332333                                                } );
    23342334                                }
    23352335
  • _source/core/htmlparser/element.js

     
    6060        };
    6161};
    6262
     63/**
     64 *  Object presentation of  CSS style declaration text.
     65 *  @param {CKEDITOR.htmlParser.element|String} elementOrStyleText A html parser element or the inline style text.
     66 */
     67CKEDITOR.htmlParser.cssStyle = function()
     68{
     69         var styleText, arg = arguments[ 0 ],rules = {};
     70        styleText = arg instanceof CKEDITOR.htmlParser.element ? arg.attributes.style : arg;
     71
     72   // html-encoded quote might be introduced by 'font-family'
     73   // from MS-Word which confused the following regexp. e.g.
     74   //'font-family: "Lucida, Console"'
     75   ( styleText || '' )
     76           .replace( /"/g, '"' )
     77           .replace( /\s*([^ :;]+)\s*:\s*([^;]+)\s*(?=;|$)/g,
     78                        function( match, name, value )
     79                        {
     80                                name == 'font-family' && ( value = value.replace( /["']/g, '' ) );
     81                                rules[ name.toLowerCase() ] = value;
     82                        });
     83
     84        return {
     85                rules : rules,
     86                /**
     87                 *  Apply the styles onto the specified element or object.
     88                 * @param {CKEDITOR.htmlParser.element|CKEDITOR.dom.element|Object} obj
     89                 */
     90                populate : function( obj ){
     91                        var style = this.toString();
     92                         if ( style )
     93                         {
     94                                 obj instanceof CKEDITOR.dom.element ?
     95                                        obj.setAttribute( 'style', style ) :
     96                                  obj instanceof CKEDITOR.htmlParser.element ?
     97                                        obj.attributes.style = style :
     98                                  obj.style = style;
     99                         }
     100                },
     101                toString :function()
     102                {
     103                        var output = [];
     104                        for ( var i in rules )
     105                                rules[ i ] && output.push( i, ':', rules[ i ], ';' );
     106                        return output.join( '' );
     107                }
     108        };
     109};
     110
    63111(function()
    64112{
    65113        // Used to sort attribute entries in an array, where the first element of
  • _source/plugins/iframe/plugin.js

     
    1 /*
     1/*
    22Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
    33For licensing, see LICENSE.html or http://ckeditor.com/license
    44*/
    55
    66(function()
    77{
    8         function createFakeElement( editor, realElement )
    9         {
    10                 var fakeElement = editor.createFakeParserElement( realElement, 'cke_iframe', 'iframe', true ),
    11                         fakeStyle = fakeElement.attributes.style || '';
    12 
    13                 var width = realElement.attributes.width,
    14                         height = realElement.attributes.height;
    15 
    16                 if ( typeof width != 'undefined' )
    17                         fakeStyle += 'width:' + CKEDITOR.tools.cssLength( width ) + ';';
    18 
    19                 if ( typeof height != 'undefined' )
    20                         fakeStyle += 'height:' + CKEDITOR.tools.cssLength( height ) + ';';
    21 
    22                 fakeElement.attributes.style = fakeStyle;
    23 
    24                 return fakeElement;
    25         }
    26 
    278        CKEDITOR.plugins.add( 'iframe',
    289        {
    2910                requires : [ 'dialog', 'fakeobjects' ],
     
    9677                                        {
    9778                                                iframe : function( element )
    9879                                                {
    99                                                         return createFakeElement( editor, element );
     80                                                        return editor.createFakeParserElement( element, 'cke_iframe', 'iframe', true );
    10081                                                }
    10182                                        }
    10283                                });
  • _source/plugins/flash/plugin.js

     
    77{
    88        var flashFilenameRegex = /\.swf(?:$|\?)/i;
    99
    10         var cssifyLength = CKEDITOR.tools.cssLength;
    11 
    1210        function isFlashEmbed( element )
    1311        {
    1412                var attributes = element.attributes;
     
    1816
    1917        function createFakeElement( editor, realElement )
    2018        {
    21                 var fakeElement = editor.createFakeParserElement( realElement, 'cke_flash', 'flash', true ),
    22                         fakeStyle = fakeElement.attributes.style || '';
    23 
    24                 var width = realElement.attributes.width,
    25                         height = realElement.attributes.height;
    26 
    27                 if ( typeof width != 'undefined' )
    28                         fakeStyle = fakeElement.attributes.style = fakeStyle + 'width:' + cssifyLength( width ) + ';';
    29 
    30                 if ( typeof height != 'undefined' )
    31                         fakeStyle = fakeElement.attributes.style = fakeStyle + 'height:' + cssifyLength( height ) + ';';
    32 
    33                 return fakeElement;
     19                return editor.createFakeParserElement( realElement, 'cke_flash', 'flash', true );
    3420        }
    3521
    3622        CKEDITOR.plugins.add( 'flash',
  • _source/plugins/iframe/dialogs/iframe.js

     
    5050                        title : iframeLang.title,
    5151                        minWidth : 350,
    5252                        minHeight : 260,
    53                         onLoad : function()
    54                         {
    55                                 var dialog = this,
    56                                         styles = dialog.getContentElement( 'advanced', 'advStyles' );
    57 
    58                                 styles && styles.on( 'change', function()
    59                                         {
    60                                                 // Synchronize width value.
    61                                                 var width = this.getStyle( 'width', '' ),
    62                                                         txtWidth = dialog.getContentElement( 'info', 'width' );
    63 
    64                                                 txtWidth && txtWidth.setValue( width, true );
    65 
    66                                                 // Synchronize height value.
    67                                                 var height = this.getStyle( 'height', '' ),
    68                                                         txtHeight = dialog.getContentElement( 'info', 'height' );
    69 
    70                                                 txtHeight && txtHeight.setValue( height, true );
    71                                         });
    72                         },
    7353                        onShow : function()
    7454                        {
    7555                                // Clear previously saved elements.
     
    8363                                        var iframeNode = editor.restoreRealElement( fakeImage );
    8464                                        this.iframeNode = iframeNode;
    8565
    86                                         this.setupContent( iframeNode, fakeImage );
     66                                        this.setupContent( iframeNode );
    8767                                }
    88 
    89                                 // Call the onChange method for the widht and height fields so
    90                                 // they get reflected into the Advanced tab.
    91                                 var widthInput = this.getContentElement( 'info', 'width' ),
    92                                         heightInput = this.getContentElement( 'info', 'height' );
    93                                 widthInput && widthInput.onChange();
    94                                 heightInput && heightInput.onChange();
    9568                        },
    9669                        onOk : function()
    9770                        {
     
    152125                                                                        style : 'width:100%',
    153126                                                                        labelLayout : 'vertical',
    154127                                                                        label : commonLang.width,
    155                                                                         validate : CKEDITOR.dialog.validate.cssLength( editor.lang.common.invalidCssLength ),
     128                                                                        validate : CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength ),
    156129                                                                        getValue : defaultToPixel,
    157                                                                         setup : function( iframeNode, fakeImage )
    158                                                                         {
    159                                                                                 loadValue.apply( this, arguments );
    160                                                                                 fakeImage && this.setValue( fakeImage.getStyle( 'width' ) );
    161                                                                         },
    162                                                                         commit : function( iframeNode, extraStyles )
    163                                                                         {
    164                                                                                 commitValue.apply( this, arguments );
    165                                                                                 var val = this.getValue();
    166                                                                                 val && ( extraStyles.width = val );
    167                                                                         },
    168                                                                         onChange : function()
    169                                                                         {
    170                                                                                 var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' ),
    171                                                                                         value = this.getValue();
    172                                                                                 styles && styles.updateStyle( 'width', value );
    173                                                                         }
    174                                                                 },
    175                                                                 {
     130                                                                        setup : loadValue,
     131                                                                        commit : commitValue
     132                                                                },
     133                                                                {
    176134                                                                        id : 'height',
    177135                                                                        type : 'text',
    178136                                                                        style : 'width:100%',
    179137                                                                        labelLayout : 'vertical',
    180138                                                                        label : commonLang.height,
    181                                                                         validate : CKEDITOR.dialog.validate.cssLength( editor.lang.common.invalidCssLength ),
     139                                                                        validate : CKEDITOR.dialog.validate.htmlLength( editor.lang.common.invalidHtmlLength ),
    182140                                                                        getValue : defaultToPixel,
    183                                                                         setup : function( iframeNode, fakeImage )
    184                                                                         {
    185                                                                                 loadValue.apply( this, arguments );
    186                                                                                 fakeImage && this.setValue( fakeImage.getStyle( 'height' ) );
    187                                                                         },
    188                                                                         commit : function( iframeNode, extraStyles )
    189                                                                         {
    190                                                                                 commitValue.apply( this, arguments );
    191                                                                                 var val = this.getValue();
    192                                                                                 val && ( extraStyles.height = val );
    193                                                                         },
    194                                                                         onChange : function()
    195                                                                         {
    196                                                                                 var styles = this.getDialog().getContentElement( 'advanced', 'advStyles' ),
    197                                                                                         value = this.getValue();
    198                                                                                 styles && styles.updateStyle( 'height', value );
    199                                                                         }
    200                                                                 },
    201                                                                 {
     141                                                                        setup : loadValue,
     142                                                                        commit : commitValue
     143                                                                },
     144                                                                {
    202145                                                                        id : 'align',
    203146                                                                        type : 'select',
    204147                                                                        'default' : '',
  • _source/plugins/fakeobjects/plugin.js

     
    1 /*
     1/*
    22Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
    33For licensing, see LICENSE.html or http://ckeditor.com/license
    44*/
    55
    66(function()
    77{
     8        var cssStyle = CKEDITOR.htmlParser.cssStyle,
     9                        cssLength = CKEDITOR.tools.cssLength;
     10
    811        var htmlFilterRules =
    912        {
    1013                elements :
     
    1619                                        realFragment = realHtml && new CKEDITOR.htmlParser.fragment.fromHtml( decodeURIComponent( realHtml ) ),
    1720                                        realElement = realFragment && realFragment.children[ 0 ];
    1821
    19                                 // If we have width/height in the element, we must move it into
    20                                 // the real element.
     22                                // Width/height in the fake object are subjected to clone into the real element.
    2123                                if ( realElement && element.attributes[ 'data-cke-resizable' ] )
    2224                                {
    23                                         var style = element.attributes.style;
     25                                        var styles = new cssStyle( element ).rules,
     26                                                realAttrs = realElement.attributes,
    2427
    25                                         if ( style )
    26                                         {
    27                                                 // Get the width from the style.
    28                                                 var match = /(?:^|\s)width\s*:\s*(.*?)(:?;|$)/i.exec( style ),
    29                                                         width = match && match[1];
     28                                                width = styles.width,
     29                                                height = styles.height;
    3030
    31                                                 // Get the height from the style.
    32                                                 match = /(?:^|\s)height\s*:\s*(.*?)(:?;|$)/i.exec( style );
    33                                                 var height = match && match[1];
    34 
    35                                                 if ( width )
    36                                                         realElement.attributes.width = width;
    37 
    38                                                 if ( height )
    39                                                         realElement.attributes.height = height;
    40                                         }
    41                                 }
     31                                        width && ( realAttrs.width = width );
     32                                        height && ( realAttrs.height = height );
     33                                }
    4234
    4335                                return realElement;
    4436                        }
     
    5850                                htmlFilter.addRules( htmlFilterRules );
    5951                }
    6052        });
    61 })();
    6253
    63 CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable )
    64 {
    65         var lang = this.lang.fakeobjects,
    66                 label = lang[ realElementType ] || lang.unknown;
     54        CKEDITOR.editor.prototype.createFakeElement = function( realElement, className, realElementType, isResizable )
     55        {
     56                var lang = this.lang.fakeobjects,
     57                        label = lang[ realElementType ] || lang.unknown;
    6758
    68         var attributes =
    69         {
    70                 'class' : className,
    71                 src : CKEDITOR.getUrl( 'images/spacer.gif' ),
    72                 'data-cke-realelement' : encodeURIComponent( realElement.getOuterHtml() ),
    73                 'data-cke-real-node-type' : realElement.type,
    74                 alt : label,
    75                 title : label,
    76                 align : realElement.getAttribute( 'align' ) || ''
    77         };
     59                var attributes =
     60                {
     61                        'class' : className,
     62                        src : CKEDITOR.getUrl( 'images/spacer.gif' ),
     63                        'data-cke-realelement' : encodeURIComponent( realElement.getOuterHtml() ),
     64                        'data-cke-real-node-type' : realElement.type,
     65                        alt : label,
     66                        title : label,
     67                        align : realElement.getAttribute( 'align' ) || ''
     68                };
    7869
    79         if ( realElementType )
    80                 attributes[ 'data-cke-real-element-type' ] = realElementType;
     70                if ( realElementType )
     71                        attributes[ 'data-cke-real-element-type' ] = realElementType;
    8172
    82         if ( isResizable )
    83                 attributes[ 'data-cke-resizable' ] = isResizable;
     73                if ( isResizable )
     74                {
     75                        attributes[ 'data-cke-resizable' ] = isResizable;
    8476
    85         return this.document.createElement( 'img', { attributes : attributes } );
    86 };
     77                        var fakeStyle = new cssStyle();
     78
     79                        var width = realElement.getAttribute( 'width' ),
     80                                height = realElement.getAttribute( 'height' );
     81
     82                        width && ( fakeStyle.rules.width = cssLength( width ) );
     83                        height && ( fakeStyle.rules.height = cssLength( height ) );
     84                        fakeStyle.populate( attributes );
     85                }
     86
     87                return this.document.createElement( 'img', { attributes : attributes } );
     88        };
    8789
    88 CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable )
    89 {
    90         var lang = this.lang.fakeobjects,
    91                 label = lang[ realElementType ] || lang.unknown,
    92                 html;
     90        CKEDITOR.editor.prototype.createFakeParserElement = function( realElement, className, realElementType, isResizable )
     91        {
     92                var lang = this.lang.fakeobjects,
     93                        label = lang[ realElementType ] || lang.unknown,
     94                        html;
    9395
    94         var writer = new CKEDITOR.htmlParser.basicWriter();
    95         realElement.writeHtml( writer );
    96         html = writer.getHtml();
     96                var writer = new CKEDITOR.htmlParser.basicWriter();
     97                realElement.writeHtml( writer );
     98                html = writer.getHtml();
    9799
    98         var attributes =
    99         {
    100                 'class' : className,
    101                 src : CKEDITOR.getUrl( 'images/spacer.gif' ),
    102                 'data-cke-realelement' : encodeURIComponent( html ),
    103                 'data-cke-real-node-type' : realElement.type,
    104                 alt : label,
    105                 title : label,
    106                 align : realElement.attributes.align || ''
    107         };
     100                var attributes =
     101                {
     102                        'class' : className,
     103                        src : CKEDITOR.getUrl( 'images/spacer.gif' ),
     104                        'data-cke-realelement' : encodeURIComponent( html ),
     105                        'data-cke-real-node-type' : realElement.type,
     106                        alt : label,
     107                        title : label,
     108                        align : realElement.attributes.align || ''
     109                };
    108110
    109         if ( realElementType )
    110                 attributes[ 'data-cke-real-element-type' ] = realElementType;
     111                if ( realElementType )
     112                        attributes[ 'data-cke-real-element-type' ] = realElementType;
    111113
    112         if ( isResizable )
    113                 attributes[ 'data-cke-resizable' ] = isResizable;
     114                if ( isResizable )
     115                {
     116                        attributes[ 'data-cke-resizable' ] = isResizable;
     117                        var realAttrs = realElement.attributes,
     118                                fakeStyle = new cssStyle();
    114119
    115         return new CKEDITOR.htmlParser.element( 'img', attributes );
    116 };
     120                        var width = realAttrs.width,
     121                                height = realAttrs.height;
     122
     123                        width != undefined && ( fakeStyle.rules.width =  cssLength( width ) );
     124                        height != undefined && ( fakeStyle.rules.height = cssLength ( height ) );
     125                        fakeStyle.populate( attributes );
     126                }
     127
     128                return new CKEDITOR.htmlParser.element( 'img', attributes );
     129        };
    117130
    118 CKEDITOR.editor.prototype.restoreRealElement = function( fakeElement )
    119 {
    120         if ( fakeElement.data( 'cke-real-node-type' ) != CKEDITOR.NODE_ELEMENT )
    121                 return null;
     131        CKEDITOR.editor.prototype.restoreRealElement = function( fakeElement )
     132        {
     133                if ( fakeElement.data( 'cke-real-node-type' ) != CKEDITOR.NODE_ELEMENT )
     134                        return null;
    122135
    123         return CKEDITOR.dom.element.createFromHtml(
    124                 decodeURIComponent( fakeElement.data( 'cke-realelement' ) ),
    125                 this.document );
    126 };
     136                var element = CKEDITOR.dom.element.createFromHtml(
     137                        decodeURIComponent( fakeElement.data( 'cke-realelement' ) ),
     138                        this.document );
     139
     140                if ( fakeElement.data( 'cke-resizable') )
     141                {
     142                        var width = fakeElement.getStyle( 'width' ),
     143                                height = fakeElement.getStyle( 'height' );
     144
     145                        width && element.setAttribute( 'width', width );
     146                        height && element.setAttribute( 'height', height );
     147                }
     148               
     149                return element;
     150        }
     151
     152})();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy