Ticket #2862: 2862_9.patch

File 2862_9.patch, 13.3 KB (added by Garry Yao, 15 years ago)
  • _source/plugins/sourcearea/plugin.js

     
    7373
    7474                                                        // Set the <textarea> value.
    7575                                                        this.loadData( data );
    76 
     76                                                        editor.sourceField = textarea;
    7777                                                        editor.mode = 'source';
    7878                                                        editor.fire( 'mode' );
    7979                                                },
  • _source/plugins/maximize/plugin.js

     
     1/*
     2Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
     3For licensing, see LICENSE.html or http://ckeditor.com/license
     4*/
     5
     6/**
     7 * @fileOverview The "maximize" plugin. Enable it will make the editor chrome
     8 *               being maximized and fullfill the view size. Disable it _restore
     9 *               editor chrome into original size.
     10 */
     11
     12( function()
     13{
     14        var body = CKEDITOR.document.getBody();
     15       
     16        //Only one editor instance is allowed to be full screen at a time.
     17        var hasMaximized = false;
     18       
     19        function maximizeCommand( editor )
     20        {
     21                this.editor = editor;
     22                // elements along with styles.
     23                this.savedAttributes = [];
     24                // Keep track of the need-to-_restore data
     25                this._ =
     26                {
     27                        restore :
     28                        {
     29                                // document content
     30                                content : '',
     31                                // selection range bookmark
     32                                bookmark : null,
     33                                // editor focus state
     34                                focus : false,
     35                                // scrollbar position
     36                                scroll : null
     37                        }
     38                };
     39                // Whether pending the restoring due to asynchroniz loading of
     40                // content.
     41                this.restorePending = false;
     42        }
     43       
     44        maximizeCommand.prototype =
     45        {
     46                /**
     47                 * Save the css style of the element for later restoring.
     48                 *
     49                 * @param {CKEDITOR.dom.element}        element
     50                 */
     51                saveStyles : function( element )
     52                {
     53                        this.savedAttributes.push( {
     54                                element : element,
     55                                attributes : {
     56                                        'class' : element.getAttribute( 'class' ),
     57                                        'style' : element.getAttribute( 'style' )
     58                                }
     59                        } );
     60                },
     61               
     62                /**
     63                 * _restore the saved attributes for elements
     64                 */
     65                restoreAllStyles : function()
     66                {
     67                        var i = 0, l = this.savedAttributes.length, attrs, element;
     68                        var attrName, attribute;
     69                        for ( ; i < l ; i++ )
     70                        {
     71                                attrs = this.savedAttributes[ i ].attributes;
     72                                element = this.savedAttributes[ i ].element;
     73
     74                                for ( attrName in attrs )
     75                                {
     76                                        if ( attrs[ attrName ] )
     77                                                element.setAttribute( attrName, attrs[ attrName ] );
     78                                        else
     79                                                element.removeAttribute( attrName );
     80                                }
     81                        }
     82                },
     83               
     84                /**
     85                 * Alter the element style while keep record of the original styles.
     86                 */
     87                changeStyle : function( element, styles )
     88                {
     89                        this.saveStyles( element );
     90                        element.setStyles( styles );
     91                },
     92               
     93               
     94                /**
     95                 * Lift the whole editor to became the first child of body element, OR
     96                 * _restore the editor to it's original position.
     97                 * @param {Boolean} isRestore
     98                 */
     99                moveEditor : function( isRestore )
     100                {
     101                        var container = this.editor.container;
     102
     103                        if ( isRestore )
     104                        {
     105                                // place right after the remembered previous sibling.
     106                                container.insertAfter( this.lastPreviousSibling );
     107                        }
     108                        else
     109                        {
     110                                this.lastPreviousSibling = this.editor.container.getPrevious();
     111                                body.append( this.editor.container, true );
     112                        }
     113                },
     114               
     115                saveSelection : function()
     116                {
     117                        if ( this.editor.mode == 'wysiwyg' )
     118                        {
     119                                var editorFocus = this.editor.focusManager.hasFocus;
     120                               
     121                                // IE failed to create selection on editor blur
     122                                if ( CKEDITOR.env.ie && !editorFocus )
     123                                        return;
     124                                       
     125                                var sel = this.editor.document.getSelection();
     126                                if ( sel )
     127                                {
     128                                        this._.restore.bookmark = sel.createBookmarks( true );
     129                                        this._.restore.focus = editorFocus;
     130                                }
     131                        }
     132                },
     133               
     134                restoreSelection : function()
     135                {
     136                        if ( this._.restore.bookmark && !this.restorePending )
     137                        {
     138                                var sel = this.editor.document.getSelection();
     139                                if ( sel )
     140                                {
     141                                        sel.selectBookmarks( this._.restore.bookmark );
     142                                       
     143                                        if ( this._.restore.focus )
     144                                        {
     145                                                this.editor.focus();
     146                                                this.editor.forceNextSelectionCheck();
     147                                        }
     148                                        else
     149                                                this.editor.checkSelection();
     150                                               
     151                                        delete this._.restore.focus;
     152                                        delete this._.restore.bookmark;
     153                                }
     154                        }
     155                },
     156               
     157                /**
     158                 * Force reconstruct the current mode with the saved content.
     159                 * @param {Object} data Content snapshot
     160                 */
     161                reloadMode : function( data )
     162                {
     163                        //Clear holder element
     164                        var holderElement = this.editor.getThemeSpace( 'contents' );
     165                        holderElement.setHtml( '' );
     166                        // Reload current mode.
     167                        var currentModeEditor = this.editor._.modes[ this.editor.mode ];
     168                        currentModeEditor.load( holderElement, data );
     169                },
     170       
     171                saveContent : function()
     172                {
     173                        // Kludge: Fix for Gecko and Webkit bug of iframe reloads when moved
     174                        // around the DOM tree.
     175                        if ( this.editor.mode == 'wysiwyg' && !CKEDITOR.env.ie )
     176                        {
     177                                // Get the dirty content along with bookmark
     178                                this._.restore.content = this.editor.getSnapshot();
     179                                this.restorePending = true;
     180                        }
     181                },
     182               
     183                restoreContent : function()
     184                {
     185                        if ( this._.restore.content )
     186                        {
     187                                this.editor.on( 'mode', function()
     188                                {
     189                                        this.restorePending = false;
     190                                        this.restoreScrollPosition();
     191                                        this.restoreSelection();
     192                                        this.editor.removeListener( 'mode', arguments.callee );
     193                                        delete this._.restore.content;
     194                                }, this );
     195
     196                                // reload document content
     197                                this.reloadMode( this._.restore.content );
     198                        }
     199                },
     200               
     201                getEditorElement : function()
     202                {
     203                        var element = ( this.editor.mode == 'wysiwyg' ) ?
     204                                this.editor.document.$.documentElement
     205                                : this.editor.sourceField;
     206
     207                        return element.$ || element;
     208                },
     209               
     210                saveScrollPosition : function( )
     211                {
     212                        if ( CKEDITOR.env.ie && this.editor.mode == 'wysiwyg' )
     213                                return;
     214                        var element = this.getEditorElement();
     215                        this._.restore.scroll =
     216                        {
     217                                'element' : element,
     218                                'left' : element.scrollLeft + element.clientWidth,
     219                                'leftScrolled' : !!element.scrollLeft,
     220                                'top' : element.scrollTop + element.clientHeight,
     221                                'topScrolled' : !!element.scrollTop
     222                        };
     223                },
     224               
     225                restoreScrollPosition : function()
     226                {
     227                        if ( this._.restore.scroll && !this.restorePending )
     228                        {
     229                                var element = this.getEditorElement();
     230                                var translatedScroll =
     231                                {
     232                                        'left' :  this._.restore.scroll.left - element.clientWidth ,
     233                                        'top' :  this._.restore.scroll.top - element.clientHeight
     234                                };
     235                                if( this._.restore.scroll.leftScrolled )
     236                                        element.scrollLeft = translatedScroll.left;
     237                                if( this._.restore.scroll.topScrolled )
     238                                        element.scrollTop = translatedScroll.top;
     239
     240                                delete this._.restore.scroll;
     241                        }
     242                },
     243               
     244                save: function()
     245                {
     246                        this.saveSelection();
     247                        this.saveContent();
     248                        this.saveScrollPosition();
     249                },
     250               
     251                restore : function()
     252                {
     253                        this.restoreContent();
     254                        this.restoreScrollPosition();
     255                        this.restoreSelection();
     256                },
     257               
     258                exec : function( editor )
     259                {
     260                       
     261                        if( this.state == CKEDITOR.TRISTATE_ON || !hasMaximized )
     262                        {
     263                                this.save();
     264                               
     265                                if ( this.state == CKEDITOR.TRISTATE_ON )
     266                                {
     267                                        this.moveEditor( true );
     268                                        this.restoreAllStyles();
     269                                        if( this.onWindowResize )
     270                                                new CKEDITOR.dom.window( window ).removeListener(
     271                                                'resize', this.onWindowResize );
     272                                        hasMaximized = false;
     273                                }
     274                                else
     275                                {
     276                                        this.moveEditor();
     277                                        // fix IE and Opera viewport scrolling
     278                                        if ( CKEDITOR.env.ie || CKEDITOR.env.opera )
     279                                        {
     280                                                var view = new CKEDITOR.dom.element(
     281                                                CKEDITOR.document.$.documentElement );
     282                                                this.changeStyle( view, {
     283                                                        'overflow' :'hidden'
     284                                                } );
     285                                        }
     286                                       
     287                                        this.changeStyle( body, {
     288                                                'top' : '0px',
     289                                                'left' : '0px',
     290                                                'height' : '100%',
     291                                                'width' : '100%',
     292                                                'overflow' : 'hidden',
     293                                                'position' : 'absolute',
     294                                                'margin' : '0px'
     295                                        } );
     296                                       
     297                                        if ( CKEDITOR.env.webkit )
     298                                        {
     299                                                this.changeStyle( editor.container, {
     300                                                        'position' : 'absolute',
     301                                                        'height' : '100%',
     302                                                        'width' : '100%',
     303                                                        'z-index' : '10'
     304                                                } );
     305                                        }
     306                                       
     307                                        var editorTable = editor.container.getElementsByTag( 'table' ).getItem( 0 );
     308                                       
     309                                        // IE and Opera are requiring manual viewport size caculation. 
     310                                        if( CKEDITOR.env.ie || CKEDITOR.env.opera )
     311                                        {
     312                                                var win = new CKEDITOR.dom.window( window ),
     313                                                        viewPortSize = win.getViewPaneSize();
     314                                               
     315                                                this.changeStyle( editorTable, {
     316                                                        'width' : viewPortSize.width + 'px',
     317                                                        'height' : viewPortSize.height + 'px'
     318                                                } );
     319                                               
     320                                                if( !this.onWindowResize )
     321                                                {
     322                                                        this.onWindowResize = function(){
     323                                                                viewPortSize =  win.getViewPaneSize();
     324                                                                editorTable.setStyle( 'width',  viewPortSize.width + 'px' );
     325                                                                editorTable.setStyle( 'height',  viewPortSize.height + 'px' );
     326                                                        }
     327                                                        win.on( 'resize' ,  this.onWindowResize );
     328                                                }
     329                                        }
     330                                        else
     331                                        {
     332                                                this.changeStyle( editorTable, {
     333                                                        'width' : '100%',
     334                                                        'height' : '100%'
     335                                                        } );
     336                                        }
     337                                       
     338                                       
     339                                        // Fix IE 'source' mode bug of #2764
     340                                        if( editor.mode == 'source' && CKEDITOR.env.ie )
     341                                        {
     342                                                var element = this.editor.sourceField;
     343                                                this.changeStyle( element , {
     344                                                        'width' : element.getParent().$.clientWidth,
     345                                                        'height' : element.getParent().$.clientHeight
     346                                                } );
     347                                        }
     348                                       
     349                                        hasMaximized = true;
     350                                }
     351                        }
     352                       
     353                        this.restore();
     354                        // refresh command state
     355                        this.toggleState();
     356                },
     357               
     358                canUndo: false
     359        };
     360       
     361        CKEDITOR.plugins.add( 'maximize',
     362        {
     363                requires : [ 'editingblock' ],
     364
     365                init : function( editor )
     366                {
     367                        editor.addCommand( 'maximize', new maximizeCommand( editor ) );
     368                        editor.ui.addButton( 'Maximize', {
     369                                label : editor.lang.maximize,
     370                                command : 'maximize'
     371                        } );
     372                       
     373                        if( editor.config.startupMaximize )
     374                        {
     375                                editor.on( 'mode', function( evt )
     376                                {
     377                                        evt.removeListener();
     378                                        editor.getCommand( 'maximize' ).exec();
     379                                } );
     380                        }
     381                }
     382        });
     383       
     384})();
     385
     386CKEDITOR.config.startupMaximize = false;
     387 No newline at end of file
  • _source/plugins/toolbar/plugin.js

     
    237237        '/',
    238238        ['Styles','Format','Font','FontSize'],
    239239        ['TextColor','BGColor'],
    240         ['ShowBlocks']
     240        ['Maximize','ShowBlocks']
    241241];
  • _source/plugins/selection/plugin.js

     
    147147        {
    148148                delete this._.selectionPreviousPath;
    149149        };
    150 
     150       
     151        /**
     152         * Force firing of the 'selectionChange' event.
     153         */
     154        CKEDITOR.editor.prototype.checkSelection = checkSelectionChange;
     155       
    151156        /**
    152157         * Gets the current selection from the document.
    153158         * @returns {CKEDITOR.dom.selection} A selection object.
  • _source/lang/en.js

     
    540540                bgColorTitle : 'Background Color',
    541541                auto : 'Automatic',
    542542                more : 'More Colors...'
    543         }
     543        },
     544        maximize : 'Maximize'
    544545};
  • _source/skins/default/icons.css

     
    279279{
    280280        background-position: 0 -160px;
    281281}
    282 
    283 .cke_skin_default .cke_button_save .cke_icon
     282.cke_skin_default a.cke_button_maximize .cke_icon
    284283{
    285         background-position: 0 -32px;
     284        background-position: 0 -1040px;
    286285}
  • _source/core/config.js

     
    151151         * config.plugins = 'basicstyles,button,htmldataprocessor,toolbar,wysiwygarea';
    152152         */
    153153
    154         plugins : 'basicstyles,blockquote,button,clipboard,colorbutton,contextmenu,elementspath,enterkey,entities,find,flash,font,format,forms,horizontalrule,htmldataprocessor,image,indent,justify,keystrokes,link,list,newpage,pagebreak,pastefromword,pastetext,preview,print,removeformat,save,smiley,showblocks,sourcearea,stylescombo,table,specialchar,tab,templates,toolbar,undo,wysiwygarea,wsc',
     154        plugins : 'basicstyles,blockquote,button,clipboard,colorbutton,contextmenu,elementspath,enterkey,entities,find,flash,font,format,forms,horizontalrule,htmldataprocessor,image,indent,justify,keystrokes,link,list,maximize,newpage,pagebreak,pastefromword,pastetext,preview,print,removeformat,smiley,showblocks,sourcearea,stylescombo,table,specialchar,tab,templates,toolbar,undo,wysiwygarea,wsc',
    155155
    156156        /**
    157157         * The theme to be used to build the UI.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy