Ticket #5547: image-width-and-height-attributes.patch

File image-width-and-height-attributes.patch, 4.8 KB (added by James Wilson, 10 years ago)

Patch for CKEditor 4.4.7 source code

  • plugins/image/dialogs/image.js

    diff --git a/plugins/image/dialogs/image.js b/plugins/image/dialogs/image.js
    index 456df17..0959eb1 100644
    a b  
    599599                                                                                commit: function( type, element, internalCommit ) {
    600600                                                                                        var value = this.getValue();
    601601                                                                                        if ( type == IMAGE ) {
    602                                                                                                 if ( value && editor.activeFilter.check( 'img{width,height}' ) )
    603                                                                                                         element.setStyle( 'width', CKEDITOR.tools.cssLength( value ) );
    604                                                                                                 else
     602                                                                                                if ( value ) {
     603                                                                                                        if ( editor.activeFilter.check( 'img[width]' ) ) {
     604                                                                                                                element.setAttribute( 'width', value );
     605                                                                                                                element.removeStyle( 'width' );
     606                                                                                                        } else if ( editor.activeFilter.check( 'img{width}' ) ) {
     607                                                                                                                element.setStyle( 'width', CKEDITOR.tools.cssLength( value ) );
     608                                                                                                                element.removeAttribute( 'width' );
     609                                                                                                        }
     610                                                                                                } else {
     611                                                                                                        element.removeAttribute( 'width' );
    605612                                                                                                        element.removeStyle( 'width' );
    606 
    607                                                                                                 !internalCommit && element.removeAttribute( 'width' );
     613                                                                                                }
    608614                                                                                        } else if ( type == PREVIEW ) {
    609615                                                                                                var aMatch = value.match( regexGetSize );
    610616                                                                                                if ( !aMatch ) {
    611617                                                                                                        var oImageOriginal = this.getDialog().originalElement;
    612618                                                                                                        if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' )
    613                                                                                                                 element.setStyle( 'width', oImageOriginal.$.width + 'px' );
     619                                                                                                                if ( editor.activeFilter.check( 'img[width]' ) ) {
     620                                                                                                                        element.setAttribute( 'width',  oImageOriginal.$.width );
     621                                                                                                                        element.removeStyle( 'width' );
     622                                                                                                                } else if ( editor.activeFilter.check( 'img{width}' ) ) {
     623                                                                                                                        element.setStyle( 'width',  oImageOriginal.$.width + 'px' );
     624                                                                                                                        element.removeAttribute( 'width' );
     625                                                                                                                }
     626                                                                                                        }
    614627                                                                                                } else {
    615                                                                                                         element.setStyle( 'width', CKEDITOR.tools.cssLength( value ) );
     628                                                                                                        if ( editor.activeFilter.check( 'img[width]' ) ) {
     629                                                                                                                element.setAttribute( 'width',  value );
     630                                                                                                                element.removeStyle( 'width' );
     631                                                                                                        } else if ( editor.activeFilter.check( 'img{width}' ) ) {
     632                                                                                                                element.setStyle( 'width',  CKEDITOR.tools.cssLength( value ) );
     633                                                                                                                element.removeAttribute( 'width' );
     634                                                                                                        }
    616635                                                                                                }
    617636                                                                                        } else if ( type == CLEANUP ) {
    618637                                                                                                element.removeAttribute( 'width' );
     
    640659                                                                                commit: function( type, element, internalCommit ) {
    641660                                                                                        var value = this.getValue();
    642661                                                                                        if ( type == IMAGE ) {
    643                                                                                                 if ( value && editor.activeFilter.check( 'img{width,height}' ) )
    644                                                                                                         element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) );
    645                                                                                                 else
    646                                                                                                         element.removeStyle( 'height' );
    647 
    648                                                                                                 !internalCommit && element.removeAttribute( 'height' );
     662                                                                                                if ( value ) {
     663                                                                                                        if ( editor.activeFilter.check( 'img[height]' ) ) {
     664                                                                                                                element.setAttribute( 'height', value );
     665                                                                                                                element.removeStyle( 'height' );
     666                                                                                                        } else if ( editor.activeFilter.check( 'img{height}' ) ) {
     667                                                                                                                element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) );
     668                                                                                                                element.removeAttribute( 'height' );
     669                                                                                                        }
     670                                                                                                } else {
     671                                                                                                        element.removeAttribute( 'width' );
     672                                                                                                        element.removeStyle( 'width' );
     673                                                                                                }
    649674                                                                                        } else if ( type == PREVIEW ) {
    650675                                                                                                var aMatch = value.match( regexGetSize );
    651676                                                                                                if ( !aMatch ) {
    652677                                                                                                        var oImageOriginal = this.getDialog().originalElement;
    653                                                                                                         if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' )
    654                                                                                                                 element.setStyle( 'height', oImageOriginal.$.height + 'px' );
     678                                                                                                        if ( oImageOriginal.getCustomData( 'isReady' ) == 'true' ) {
     679                                                                                                                if ( editor.activeFilter.check( 'img[height]' ) ) {
     680                                                                                                                        element.setAttribute( 'height',  oImageOriginal.$.height );
     681                                                                                                                        element.removeStyle( 'height' );
     682                                                                                                                } else if ( editor.activeFilter.check( 'img{height}' ) ) {
     683                                                                                                                        element.setStyle( 'height',  oImageOriginal.$.height + 'px' );
     684                                                                                                                        element.removeAttribute( 'height' );
     685                                                                                                                }
     686                                                                                                        }
    655687                                                                                                } else {
    656                                                                                                         element.setStyle( 'height', CKEDITOR.tools.cssLength( value ) );
     688                                                                                                        if ( editor.activeFilter.check( 'img[height]' ) ) {
     689                                                                                                                element.setAttribute( 'height',  value );
     690                                                                                                                element.removeStyle( 'height' );
     691                                                                                                        } else if ( editor.activeFilter.check( 'img{height}' ) ) {
     692                                                                                                                element.setStyle( 'height',  CKEDITOR.tools.cssLength( value ) );
     693                                                                                                                element.removeAttribute( 'height' );
     694                                                                                                        }
    657695                                                                                                }
    658696                                                                                        } else if ( type == CLEANUP ) {
    659697                                                                                                element.removeAttribute( 'height' );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy