Ticket #2862: 2862_3.patch

File 2862_3.patch, 17.7 KB (added by Garry Yao, 15 years ago)
  • _source/plugins/fitwindow/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 "fitwindow" 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 doc = new CKEDITOR.dom.document( document ), bodyEl = doc.getBody();
     15       
     16        //Only one editor instance is allowed to be full screen at a time.
     17        var hasMaximized = false;
     18       
     19        function fitWindowCommand(editor)
     20        {
     21                this.editor = editor;
     22                CKEDITOR.tools.extend(this,
     23                {
     24                        // elements along with styles.
     25                        savedAttributes: [],
     26                        // Keep track of the need-to-restore data
     27                        restore:
     28                        {
     29                                // document content
     30                                content: '',
     31                                // selection range bookmark
     32                                bookmark: null,
     33                                // scrollbar position
     34                                scroll: null
     35                        },
     36                        // Whether pending the restoring due to asynchroniz loading of
     37                        // content.
     38                        restorePending: false
     39                });
     40        }
     41       
     42        fitWindowCommand.prototype =
     43        {
     44                /**
     45                 * Save the css style of the element for later restoring.
     46                 *
     47                 * @param {CKEDITOR.dom.element}        element
     48                 */
     49                saveStyles : function ( element )
     50                {
     51                        this.savedAttributes.push( {
     52                                element : element,
     53                                attributes : {
     54                                        'class' : element.getAttribute( 'class' ),
     55                                        'style' : element.getAttribute( 'style' )
     56                                }
     57                        } );
     58                },
     59               
     60                /**
     61                 * Restore the saved attributes for elements
     62                 */
     63                restoreAllStyles : function ()
     64                {
     65                        var i = 0, l = this.savedAttributes.length, attrs, element;
     66                        var attrName, attribute;
     67                        for ( ; i < l ; i++ )
     68                        {
     69                                attrs = this.savedAttributes[ i ].attributes;
     70                                element = this.savedAttributes[ i ].element;
     71
     72                                for ( attrName in attrs )
     73                                {
     74                                        if ( attrs[ attrName ] )
     75                                                element.setAttribute( attrName, attrs[ attrName ] );
     76                                        else
     77                                                element.removeAttribute( attrName );
     78                                }
     79                        }
     80                },
     81               
     82                /**
     83                 * Alter the element style while keep record of the original styles.
     84                 */
     85                changeStyle : function ( element, styles )
     86                {
     87                        this.saveStyles( element );
     88                        element.setStyles( styles );
     89                },
     90               
     91               
     92                /**
     93                 * Lift the whole editor to became the first child of body element,
     94                 * OR restore the editor to it's original position.
     95                 * @param {Boolean}
     96                 *            isRestore
     97                 */
     98                moveEditor : function ( isRestore )
     99                {
     100                        var ctEl = this.editor.container;
     101
     102                        if ( isRestore )
     103                        {
     104                                // place right after the CKeditor replacing element.
     105                                ctEl
     106                                        .insertAfter( CKEDITOR.document.getById( this.editor.name ) );
     107                        }
     108                        else
     109                        {
     110                                bodyEl.append( this.editor.container, true );
     111                        }
     112                },
     113               
     114                saveSelection : function ()
     115                {
     116                        if ( this.editor.mode === 'wysiwyg' )
     117                        {
     118                                var sel = this.editor.document.getSelection();
     119                                if ( sel )
     120                                {
     121                                        this.restore.bookmark = sel.createBookmarks( true );
     122                                }
     123                        }
     124                },
     125               
     126                restoreSelection : function ()
     127                {
     128                        if ( this.restore.bookmark && !this.restorePending )
     129                        {
     130                                var sel = this.editor.document.getSelection();
     131                                if ( sel )
     132                                {
     133                                        sel.selectBookmarks( this.restore.bookmark );
     134                                        delete this.restore.bookmark;
     135                                }
     136                        }
     137                },
     138               
     139                saveContent : function ()
     140                {
     141                        // Kludge: Fix for Gecko and Webkit bug of iframe reloads when moved
     142                        // around the DOM tree.
     143                        if ( this.editor.mode === 'wysiwyg'
     144                                && ( CKEDITOR.env.gecko || CKEDITOR.env.webkit ) )
     145                        {
     146                                // Get the dirty content along with bookmark
     147                                this.restore.content = this.editor.getSnapshot();
     148                                this.restorePending = true;
     149                        }
     150                },
     151               
     152                restoreContent : function ()
     153                {
     154                        if ( this.restore.content )
     155                        {
     156                                this.editor.on( 'mode', function()
     157                                {
     158                                        this.restorePending = false;
     159                                        this.restoreScrollPosition();
     160                                        this.restoreSelection();
     161                                        this.editor.removeListener( 'mode', arguments.callee );
     162                                        delete this.restore.content;
     163                                }, this );
     164
     165                                // reload document content
     166                                this.editor.setMode( 'wysiwyg', true, this.restore.content );
     167                        }
     168                },
     169               
     170                saveScrollPosition : function ( )
     171                {
     172                        if ( CKEDITOR.env.ie && this.editor.mode === 'wysiwyg' )
     173                                return;
     174                        var element = ( this.editor.mode === 'wysiwyg' )?
     175                                this.editor.document.$.documentElement :
     176                                this.editor._.modes.source._.getTextArea();
     177                               
     178                        element = element.$ || element;
     179                        this.restore.scroll = {
     180                                'element' : element,
     181                                'left' : element.scrollLeft + element.clientWidth,
     182                                'top' : element.scrollTop + element.clientHeight
     183                        };
     184                },
     185               
     186                restoreScrollPosition : function ()
     187                {
     188                        if(this.restore.scroll && !this.restorePending)
     189                        {
     190                                console.debug('mode1'+this.editor.mode);
     191                                var element = ( this.editor.mode === 'wysiwyg' ) ?
     192                                this.editor.document.$.documentElement :
     193                                this.editor._.modes.source._.getTextArea();
     194                                element = element.$ || element;
     195                                var translatedScroll =
     196                                {
     197                                        'left' : ( this.restore.scroll.left - element.clientWidth ),
     198                                        'top' : ( this.restore.scroll.top - element.clientHeight )
     199                                };
     200                                element.scrollLeft = translatedScroll.left;
     201                                element.scrollTop = translatedScroll.top;
     202                                delete this.restore.scroll;
     203                        }
     204                },
     205               
     206                onSave: function()
     207                {
     208                        this.saveSelection();
     209                        this.saveContent();
     210                        this.saveScrollPosition();
     211                },
     212                onRestore : function()
     213                {
     214                        this.restoreContent();
     215                        this.restoreScrollPosition();
     216                        this.restoreSelection();
     217                },
     218                exec : function( editor )
     219                {
     220                        if ( ! ( this.state === CKEDITOR.TRISTATE_DISABLED ) )
     221                        {
     222                                //Begin to tranform
     223                                if ( this.state === CKEDITOR.TRISTATE_OFF && !hasMaximized )
     224                                {
     225                                        this.onSave();
     226                                        this.moveEditor();
     227                                       
     228                                        // fix IE viewport scrolling
     229                                        if ( CKEDITOR.env.ie )
     230                                        {
     231                                               
     232                                                var view = new CKEDITOR.dom.element( doc.$.documentElement );
     233                                                this.changeStyle( view, {
     234                                                        'overflow' :'hidden'
     235                                                } );
     236                                        }
     237                                       
     238                                        this.changeStyle( bodyEl, {
     239                                                'top' : '0px',
     240                                                'left' : '0px',
     241                                                'height' : '100%',
     242                                                'width' : '100%',
     243                                                'overflow' : 'hidden',
     244                                                'position' : 'absolute',
     245                                                'margin' : '0px'
     246                                        } );
     247                                       
     248                                        if ( CKEDITOR.env.webkit )
     249                                        {
     250                                                this.changeStyle( editor.container, {
     251                                                        'position' : 'absolute',
     252                                                        'height' : '100%',
     253                                                        'width' : '100%',
     254                                                        'z-index' : '10'
     255                                                } );
     256                                        }
     257                                       
     258                                        this.changeStyle( editor.container.getFirst(), {
     259                                                'width' : '100%',
     260                                                // Kludge: Fix IE table over-height on fit parent.
     261                                                'height' : CKEDITOR.env.ie ? '90%' : '100%',
     262                                                'z-index' : '10'
     263                                        } );
     264                                       
     265                                        // Fix IE 'source' mode bug of #2764
     266                                        if( editor.mode == 'source' && CKEDITOR.env.ie )
     267                                        {
     268                                                var editareaEl = this.editor._.modes.source._.getTextArea();
     269                                                this.changeStyle( editareaEl, {
     270                                                        'width' : editareaEl.getParent().$.clientWidth,
     271                                                        'height' : editareaEl.getParent().$.clientHeight
     272                                                } );
     273                                        }
     274                                       
     275                                        this.onRestore();
     276                                        hasMaximized = true;
     277                                        // refresh command state
     278                                        this.toggleState();
     279                                }
     280                                else if( this.state === CKEDITOR.TRISTATE_ON )
     281                                {
     282                                        this.onSave();
     283                                        this.moveEditor( true );
     284                                        this.restoreAllStyles();
     285                                        this.onRestore();
     286                                        hasMaximized = false;
     287                                        // refresh command state
     288                                        this.toggleState();
     289                                }
     290                        }
     291                }
     292        };
     293       
     294        CKEDITOR.plugins.add( 'fitwindow',
     295        {
     296                requires : [ 'editingblock' ],
     297
     298                init : function( editor )
     299                {
     300                        editor.addCommand( 'fitwindow', new fitWindowCommand( editor ) );
     301                        editor.ui.addButton( 'Maximize', {
     302                                lablel :editor.lang.fitWindow,
     303                                command :'fitwindow'
     304                        } );
     305                       
     306                        if(editor.config.startupFitWindow)
     307                        {
     308                                editor.on( 'mode', function()
     309                                {
     310                                        // defer the execution to avoid DUP event registration in
     311                                        // event-handler.
     312                                        CKEDITOR.tools.setTimeout( function()
     313                                        {
     314                                                editor.getCommand( 'fitwindow' ).exec();
     315                                        }, 0 );
     316                                       
     317                                        editor.removeListener( 'mode', arguments.callee );
     318                                });
     319                        }
     320                }
     321        });
     322       
     323})();
     324
     325CKEDITOR.tools.extend( CKEDITOR.config,
     326{
     327        startupFitWindow : false
     328} );\ No newline at end of file
  • _source/plugins/toolbar/plugin.js

     
    214214                'Subscript', 'Superscript', '-',
    215215                'SelectAll', 'RemoveFormat', '-',
    216216                'Link', 'Unlink', 'Anchor', '-',
    217                 'Table', 'Smiley', 'HorizontalRule', 'SpecialChar', 'PageBreak'
     217                'Table', 'Smiley', 'HorizontalRule', 'SpecialChar', 'PageBreak', '-',
     218                'Maximize'
    218219        ]
    219220];
  • _source/plugins/selection/plugin.js

     
    624624                                        this.onSelectionSet && this.onSelectionSet();
    625625                                },
    626626
    627                 createBookmarks : function()
     627                createBookmarks : function( serializable )
    628628                {
    629629                        var retval = [],
    630630                                ranges = this.getRanges();
     
    629629                        var retval = [],
    630630                                ranges = this.getRanges();
    631631                        for ( var i = 0 ; i < ranges.length ; i++ )
    632                                 retval.push( ranges[i].createBookmark() );
     632                                retval.push( ranges[i].createBookmark( serializable ) );
    633633                        return retval;
    634634                },
    635635
  • _source/plugins/editingblock/plugin.js

     
    102102         * // Switch to "source" view.
    103103         * CKEDITOR.instances.editor1.setMode( 'source' );
    104104         */
    105         CKEDITOR.editor.prototype.setMode = function( mode )
     105        CKEDITOR.editor.prototype.setMode = function( mode, isReload, reloadData)
    106106        {
    107107                var data,
    108108                        holderElement = this.getThemeSpace( 'contents' ),
     
    111111                // Unload the previous mode.
    112112                if ( this.mode )
    113113                {
    114                         if ( mode == this.mode )
     114                        if (!isReload && ( mode == this.mode ) )
    115115                                return;
    116 
     116                               
    117117                        var currentMode = getMode( this );
    118                         data = currentMode.getData();
     118                        if (!isReload)
     119                                data = currentMode.getData();
     120                        else
     121                                data = reloadData;
     122                               
    119123                        currentMode.unload( holderElement );
    120124                        this.mode = '';
    121125                }
  • _source/plugins/sourcearea/plugin.js

     
    2222
    2323                                editor.addMode( 'source',
    2424                                        {
     25                                                '_': {
     26                                                       
     27                                                        getTextArea : function(){
     28                                                                return textarea;
     29                                                        }
     30                                                       
     31                                                },
    2532                                                load : function( holderElement, data )
    2633                                                {
    2734                                                        // Create the source area <textarea>.
  • _source/skins/default/toolbar.css

     
    310310{
    311311        background-position: 0 -880px;
    312312}
     313.cke_skin_default a.cke_button_fitwindow .cke_icon
     314{
     315        background-position: 0 -1040px;
     316}
    313317
    314318.cke_skin_default a.cke_button_numberedlist .cke_icon
    315319{
  • _source/core/dom/element.js

     
    379379
    380380                                                        return tabIndex;
    381381                                                        break;
     382                                                       
     383                                                case 'style' :
     384                                                        return this.$.style.cssText;
    382385                                        }
    383386
    384387                                        return standard.call( this, name );
     
    846849                                {
    847850                                        if ( name == 'class' )
    848851                                                name = 'className';
     852                                        else if ( name === 'style' )
     853                                        {
     854                                                if(this.$.style)
     855                                                        this.$.style.cssText = ' ';
     856                                                return;
     857                                        }
    849858                                        standard.call( this, name );
    850859                                };
    851860                        }
  • _source/core/dom/range.js

     
    360360                        return docFrag;
    361361                },
    362362
    363                 // This is an "intrusive" way to create a bookmark. It includes <span> tags
    364                 // in the range boundaries. The advantage of it is that it is possible to
    365                 // handle DOM mutations when moving back to the bookmark.
    366                 // Attention: the inclusion of nodes in the DOM is a design choice and
    367                 // should not be changed as there are other points in the code that may be
    368                 // using those nodes to perform operations. See GetBookmarkNode.
    369                 createBookmark : function()
     363                /**
     364                 * Creates a bookmark object, which can be later used to restore the
     365                 * range by using the moveToBookmark function.
     366                 * This is an "intrusive" way to create a bookmark. It includes <span> tags
     367                 * in the range boundaries. The advantage of it is that it is possible to
     368                 * handle DOM mutations when moving back to the bookmark.
     369                 * Attention: the inclusion of nodes in the DOM is a design choice and
     370                 * should not be changed as there are other points in the code that may be
     371                 * using those nodes to perform operations. See GetBookmarkNode.
     372                 * @param {Boolean} [serializable] Indicates that the bookmark nodes
     373                 *              must contain ids, which can be used to restore the range even
     374                 *              when these nodes suffer mutations (like a clonation or innerHTML
     375                 *              change).
     376                 * @returns {Object} And object representing a bookmark.
     377                 */
     378                createBookmark : function( serializable )
    370379                {
    371380                        var startNode, endNode;
     381                        var baseId;
    372382                        var clone;
    373383
    374384                        startNode = this.document.createElement( 'span' );
     
    379389                        // removed during DOM operations.
    380390                        startNode.setHtml( '&nbsp;' );
    381391
     392                        if ( serializable )
     393                        {
     394                                baseId = 'cke_bm_' + CKEDITOR.tools.getNextNumber();
     395                                startNode.setAttribute( 'id', baseId + 'S' );
     396                        }
     397
    382398                        // If collapsed, the endNode will not be created.
    383399                        if ( !this.collapsed )
    384400                        {
     
    385401                                endNode = startNode.clone();
    386402                                endNode.setHtml( '&nbsp;' );
    387403
     404                                if ( serializable )
     405                                        endNode.setAttribute( 'id', baseId + 'E' );
     406
    388407                                clone = this.clone();
    389408                                clone.collapse();
    390409                                clone.insertNode( endNode );
     
    404423                                this.moveToPosition( startNode, CKEDITOR.POSITION_AFTER_END );
    405424
    406425                        return {
    407                                 startNode : startNode,
    408                                 endNode : endNode
     426                                startNode : serializable ? baseId + 'S' : startNode,
     427                                endNode : serializable ? baseId + 'E' : endNode,
     428                                serializable : serializable
    409429                        };
    410430                },
    411431
     
    411431
    412432                moveToBookmark : function( bookmark )
    413433                {
     434                        var serializable = bookmark.serializable,
     435                                startNode       = serializable ? this.document.getById( bookmark.startNode ) : bookmark.startNode,
     436                                endNode         = serializable ? this.document.getById( bookmark.endNode ) : bookmark.endNode;
     437
    414438                        // Set the range start at the bookmark start node position.
    415                         this.setStartBefore( bookmark.startNode );
     439                        this.setStartBefore( startNode );
    416440
    417441                        // Remove it, because it may interfere in the setEndBefore call.
    418                         bookmark.startNode.remove();
     442                        startNode.remove();
    419443
    420444                        // Set the range end at the bookmark end node position, or simply
    421445                        // collapse it if it is not available.
    422                         var endNode = bookmark.endNode;
    423446                        if ( endNode )
    424447                        {
    425448                                this.setEndBefore( endNode );
  • _source/core/command.js

     
    55
    66CKEDITOR.command = function( editor, commandDefinition )
    77{
    8         this.state = CKEDITOR.TRISTATE_OFF;
     8        this.state = ( 'state' in commandDefinition ) ? commandDefinition.state : CKEDITOR.TRISTATE_OFF;
    99
    1010        this.exec = function()
    1111        {
     
    1818        CKEDITOR.event.call( this );
    1919};
    2020
     21CKEDITOR.command.prototype =
     22{
     23        setState : function( newState )
     24        {
     25                // Do nothing if there is no state change.
     26                if ( this.state == newState )
     27                        return false;
     28
     29                // Set the new state.
     30                this.state = newState;
     31
     32                // Fire the "state" event, so other parts of the code can react to the
     33                // change.
     34                this.fire( 'state' );
     35
     36                return true;
     37        },
     38       
     39        /*
     40         * Toggle the current state of command and refresh.
     41         */
     42        toggleState : function()
     43        {
     44                this.setState( this.state === CKEDITOR.TRISTATE_ON ?
     45                                CKEDITOR.TRISTATE_OFF
     46                                : CKEDITOR.TRISTATE_ON );
     47        }
     48}
     49
    2150CKEDITOR.event.implementOn( CKEDITOR.command.prototype );
  • _source/core/config.js

     
    147147         * config.plugins = 'basicstyles,button,htmldataprocessor,toolbar,wysiwygarea';
    148148         */
    149149
    150         plugins : 'basicstyles,button,elementspath,horizontalrule,htmldataprocessor,keystrokes,newpage,pagebreak,preview,removeformat,smiley,indent,link,list,sourcearea,table,specialchar,tab,toolbar,wysiwygarea',
     150        plugins : 'basicstyles,button,elementspath,horizontalrule,htmldataprocessor,keystrokes,newpage,pagebreak,preview,removeformat,smiley,indent,link,list,sourcearea,table,specialchar,tab,toolbar,wysiwygarea,fitwindow',
    151151
    152152        /**
    153153         * 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