Ticket #3026: 3026.patch

File 3026.patch, 7.9 KB (added by Martin Kou, 15 years ago)
  • _source/plugins/dialogui/plugin.js

     
    720720
    721721                                        htmlList.push( [ theirMatch[1], ' ', myMatch[1] || '', theirMatch[2] ].join( '' ) );
    722722                                };
    723                         })()
     723                        })(),
     724
     725                        /**
     726                         * An iframe element.
     727                         * @extends CKEDITOR.ui.dialog.uiElement
     728                         * @example
     729                         * @constructor
     730                         * @param {CKEDITOR.dialog} dialog
     731                         * Parent dialog object.
     732                         * @param {CKEDITOR.dialog.uiElementDefinition} elementDefinition
     733                         * The element definition. Accepted fields:
     734                         * <ul>
     735                         *      <li><strong>src</strong> (Required) The src field of the iframe. </li>
     736                         *      <li><strong>width</strong> (Required) The iframe's width.</li>
     737                         *      <li><strong>height</strong> (Required) The iframe's height.</li>
     738                         *      <li><strong>onContentLoad</strong> (Optional) A function to be executed
     739                         *      after the iframe's contents has finished loading.</li>
     740                         * </ul>
     741                         * @param {Array} htmlList
     742                         * List of HTML code to output to.
     743                         */
     744                        iframe : function( dialog, elementDefinition, htmlList )
     745                        {
     746                                if ( arguments.length < 3 )
     747                                        return;
     748
     749                                var _ = initPrivateObject.call( this, elementDefinition ),
     750                                        contentLoad = elementDefinition.onContentLoad && CKEDITOR.tools.bind( elementDefinition.onContentLoad, this ),
     751                                        cssWidth = CKEDITOR.tools.cssLength( elementDefinition.width ),
     752                                        cssHeight = CKEDITOR.tools.cssLength( elementDefinition.height );
     753                                _.frameId = CKEDITOR.tools.getNextNumber() + '_iframe';
     754
     755                                // IE BUG: Parent container does not resize to contain the iframe automatically.
     756                                dialog.on( 'load', function()
     757                                        {
     758                                                var iframe = CKEDITOR.document.getById( _.frameId ),
     759                                                        parentContainer = iframe.getParent();
     760
     761                                                parentContainer.setStyles(
     762                                                        {
     763                                                                width : cssWidth,
     764                                                                height : cssHeight
     765                                                        } );
     766                                        } );
     767
     768                                var attributes =
     769                                {
     770                                        src : '%2',
     771                                        id : _.frameId,
     772                                        frameborder : 0,
     773                                        allowtransparency : true
     774                                };
     775                                var myHtml = [];
     776
     777                                if ( typeof( elementDefinition.onContentLoad ) == 'function' )
     778                                        attributes.onload = 'CKEDITOR.tools.callFunction(%1);';
     779
     780                                CKEDITOR.ui.dialog.uiElement.call( this, dialog, elementDefinition, myHtml, 'iframe',
     781                                                {
     782                                                        width : cssWidth,
     783                                                        height : cssHeight
     784                                                }, attributes, '' );
     785
     786                                // Put a placeholder for the first time.
     787                                htmlList.push( '<div style="width:' + cssWidth + ';height:' + cssHeight + ';" id="' + this.domId + '"></div>' );
     788
     789                                // Iframe elements should be refreshed whenever it is shown.
     790                                myHtml = myHtml.join( '' );
     791                                dialog.on( 'show', function()
     792                                        {
     793                                                var iframe = CKEDITOR.document.getById( _.frameId ),
     794                                                        parentContainer = iframe.getParent(),
     795                                                        callIndex = CKEDITOR.tools.addFunction( contentLoad ),
     796                                                        html = myHtml.replace( '%1', callIndex ).replace( '%2', CKEDITOR.tools.htmlEncode( elementDefinition.src ) );
     797                                                parentContainer.setHtml( html );
     798                                        } );
     799                        }
    724800                }, true );
    725801
    726         CKEDITOR.ui.dialog.html.prototype = new CKEDITOR.ui.dialog.uiElement;
     802        CKEDITOR.ui.dialog.html.prototype = CKEDITOR.ui.dialog.iframe.prototype = new CKEDITOR.ui.dialog.uiElement;
    727803
    728804        CKEDITOR.ui.dialog.labeledElement.prototype = CKEDITOR.tools.extend( new CKEDITOR.ui.dialog.uiElement,
    729805                        /** @lends CKEDITOR.ui.dialog.labeledElement.prototype */
     
    12101286        CKEDITOR.dialog.addUIElement( 'file', commonBuilder );
    12111287        CKEDITOR.dialog.addUIElement( 'fileButton', commonBuilder );
    12121288        CKEDITOR.dialog.addUIElement( 'html', commonBuilder );
     1289        CKEDITOR.dialog.addUIElement( 'iframe', commonBuilder );
    12131290})();
  • _source/plugins/dialog/plugin.js

     
    878878                                this._.dialogDefinitions[name] = dialogDefinition;
    879879                        },
    880880
     881                        addIframe : function( name, title, src, width, height, onContentLoad )
     882                        {
     883                                var element =
     884                                {
     885                                        type : 'iframe',
     886                                        src : src,
     887                                        width : '100%',
     888                                        height : '100%'
     889                                }
     890                                if ( typeof( onContentLoad ) == 'function' )
     891                                        element.onContentLoad = onContentLoad;
     892
     893                                var definition =
     894                                {
     895                                        title : title,
     896                                        minWidth : width,
     897                                        minHeight : height,
     898                                        contents :
     899                                        [
     900                                                {
     901                                                        id : 'iframe',
     902                                                        label : title,
     903                                                        expand : true,
     904                                                        elements : [ element ]
     905                                                }
     906                                        ]
     907                                };
     908
     909                                return this.add( name, function(){ return definition; } );
     910                        },
     911
    881912                        exists : function( name )
    882913                        {
    883914                                return !!this._.dialogDefinitions[ name ];
     
    16201651
    16211652        (function()
    16221653        {
    1623                 var decimalRegex = /^\d+(?:\.\d+)?$/,
    1624                         fixLength = function( length )
    1625                         {
    1626                                 return length + ( decimalRegex.test( length ) ? 'px' : '' );
    1627                         };
    1628 
    16291654                CKEDITOR.ui.dialog =
    16301655                {
    16311656                        /**
     
    18071832                                                if ( widths )
    18081833                                                {
    18091834                                                        if ( widths[i] )
    1810                                                                 styles.push( 'width:' + fixLength( widths[i] ) );
     1835                                                                styles.push( 'width:' + CKEDITOR.tools.cssLength( widths[i] ) );
    18111836                                                }
    18121837                                                else
    18131838                                                        styles.push( 'width:' + Math.floor( 100 / childHtmlList.length ) + '%' );
    18141839                                                if ( height )
    1815                                                         styles.push( 'height:' + fixLength( height ) );
     1840                                                        styles.push( 'height:' + CKEDITOR.tools.cssLength( height ) );
    18161841                                                if ( elementDefinition && elementDefinition.padding != undefined )
    1817                                                         styles.push( 'padding:' + fixLength( elementDefinition.padding ) );
     1842                                                        styles.push( 'padding:' + CKEDITOR.tools.cssLength( elementDefinition.padding ) );
    18181843                                                if ( styles.length > 0 )
    18191844                                                        html.push( 'style="' + styles.join('; ') + '" ' );
    18201845                                                html.push( '>', childHtmlList[i], '</td>' );
     
    18731898                                        html.push( 'style="' );
    18741899                                        if ( elementDefinition && elementDefinition.expand )
    18751900                                                html.push( 'height:100%;' );
    1876                                         html.push( 'width:' + fixLength( width || '100%' ), ';' );
     1901                                        html.push( 'width:' + CKEDITOR.tools.cssLength( width || '100%' ), ';' );
    18771902                                        html.push( '"' );
    18781903                                        html.push( 'align="', CKEDITOR.tools.htmlEncode(
    18791904                                                ( elementDefinition && elementDefinition.align ) || ( dialog.getParentEditor().lang.dir == 'ltr' ? 'left' : 'right' ) ), '" ' );
     
    18841909                                                var styles = [];
    18851910                                                html.push( '<tr><td ' );
    18861911                                                if ( width )
    1887                                                         styles.push( 'width:' + fixLength( width || '100%' ) );
     1912                                                        styles.push( 'width:' + CKEDITOR.tools.cssLength( width || '100%' ) );
    18881913                                                if ( heights )
    1889                                                         styles.push( 'height:' + fixLength( heights[i] ) );
     1914                                                        styles.push( 'height:' + CKEDITOR.tools.cssLength( heights[i] ) );
    18901915                                                else if ( elementDefinition && elementDefinition.expand )
    18911916                                                        styles.push( 'height:' + Math.floor( 100 / childHtmlList.length ) + '%' );
    18921917                                                if ( elementDefinition && elementDefinition.padding != undefined )
    1893                                                         styles.push( 'padding:' + fixLength( elementDefinition.padding ) );
     1918                                                        styles.push( 'padding:' + CKEDITOR.tools.cssLength( elementDefinition.padding ) );
    18941919                                                if ( styles.length > 0 )
    18951920                                                        html.push( 'style="', styles.join( '; ' ), '" ' );
    18961921                                                html.push( ' class="cke_dialog_ui_vbox_child">', childHtmlList[i], '</td></tr>' );
  • _source/core/tools.js

     
    451451                {
    452452                        var fn = functions[ index ];
    453453                        return fn.apply( window, Array.prototype.slice.call( arguments, 1 ) );
    454                 }
     454                },
     455
     456                cssLength : (function()
     457                {
     458                        var decimalRegex = /^\d+(?:\.\d+)?$/;
     459                        return function( length )
     460                        {
     461                                return length + ( decimalRegex.test( length ) ? 'px' : '' );
     462                        };
     463                })()
    455464        };
    456465})();
    457466
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy