Ticket #2862: 2862_2.patch

File 2862_2.patch, 15.8 KB (added by Garry Yao, 15 years ago)
  • _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/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        /**
     17         * Save the css style defined this element for later restoring.
     18         * @param {CKEDITOR.dom.element} element
     19         */
     20        function saveStyles( element, isClean )
     21        {
     22               
     23                var savedStyles = {} , className , inlineStyle;
     24               
     25                if( ( className = element.getAttribute( 'class' ) ) )
     26                        savedStyles.className = className;
     27                if( ( inlineStyle = element.getAttribute( 'style' ) ) )
     28                {
     29                        savedStyles.inlineStyle = inlineStyle;
     30                }
     31                       
     32                element.setCustomData( 'cke_saved_style' , savedStyles );
     33               
     34                if( isClean )
     35                {
     36                        element.removeAttributes( [ 'style', 'class' ] );
     37                }
     38        }
     39       
     40        /**
     41         * Restore the saved css style for this element.
     42         * @param {CKEDITOR.dom.element} element
     43         */
     44        function restoreStyles( element )
     45        {
     46               
     47                //IE crashed on removing 'style' attribute from element.
     48                var savedStyles = element.getCustomData( 'cke_saved_style' );
     49                element.setAttribute( 'class' , savedStyles.className || '' );
     50                element.setAttribute( 'style' , savedStyles.inlineStyle || '' );
     51               
     52        }
     53       
     54        //TODO: Move to CKEDITOR.tools
     55        /**
     56         * Create a invisible placeholder node for record dom position.
     57         */
     58        function createMarkerNode()
     59        {
     60                var marker;
     61
     62                marker = doc.createElement( 'span' );
     63                marker.setAttribute( '_fck_marker', 1 );
     64                marker.setStyle( 'display', 'none' );
     65
     66                // For IE, it must have something inside, otherwise it may be
     67                // removed during DOM operations.
     68                marker.setHtml( ' ' );
     69                return marker;
     70        }
     71       
     72        CKEDITOR.plugins.add( 'fitwindow',
     73        {
     74                requires : [ 'editingblock' ],
     75
     76                init : function( editor )
     77                {
     78                        //touched elements recording
     79                        var touchedElements = [],
     80                                markerEl;
     81                                       
     82                        //Keep track of the need-to-restore data
     83                        var data,       //document content
     84                                bookmark, //selection range
     85                                scrollPos;      //scrollbar position
     86                       
     87                        /**
     88                         * Alter the element style while record the original styles prior to it.
     89                         */
     90                        function changeStyle( element, styles ){
     91                               
     92                                saveStyles( element );
     93                                element.setStyles( styles );
     94                                touchedElements.push( element );
     95                        }
     96                       
     97                        /**
     98                         * Restore the style of all elements that been marked as changed.
     99                         */
     100                        function restoreChangedStyles()
     101                        {
     102                                var i = 0, l = touchedElements.length;
     103                                for( ; i < l ; i++ )
     104                                {
     105                                        restoreStyles( touchedElements[ i ] );
     106                                }
     107                                touchedElements = [];
     108                        }
     109                       
     110                        /**
     111                         * Lift the whole editor to became the first child of body element,
     112                         * OR restore the editor to it's original position.
     113                         * @param {Boolean}
     114                         *            isRestore
     115                         */
     116                        function moveEditor( isRestore )
     117                        {
     118                                var ctEl = editor.container;
     119
     120                                if( isRestore )
     121                                {
     122                                        ctEl.insertAfter( markerEl );
     123                                        markerEl.remove();
     124                                        markerEl = null;
     125                                }
     126                                else
     127                                {
     128                                        markerEl = createMarkerNode();
     129                                        markerEl.insertBefore( ctEl );
     130                                        bodyEl.append( editor.container, true );
     131                                }
     132                        }
     133                       
     134                        function saveWYSIWYG()
     135                        {
     136                                bookmark = editor.document.getSelection()
     137                                                .createBookmarks( true );
     138                                // Get the dirty content along with bookmark
     139                                data = editor.getSnapshot();
     140                                saveScrollPosition( editor.document.$.documentElement );
     141                        }
     142                       
     143                        function restoreWYSIWYG()
     144                        {
     145                                //reload the mode for restoring the document content
     146                                editor.setMode( 'wysiwyg', true, data );
     147                                data = null;
     148                               
     149                                editor.on( 'contentDom', function(){
     150                                        editor.document.getSelection().selectBookmarks( bookmark );
     151                                        bookmark = null;
     152                                        restoreScrollPosition( editor.document.$.documentElement );
     153                                        editor.removeListener( 'contentDom', arguments.callee );
     154                                } );
     155                        }
     156                       
     157                       
     158                        function saveScrollPosition( element )
     159                        {
     160                                element = element.$ || element;
     161                                scrollPos = {
     162                                        'left' : element.scrollLeft + element.clientWidth,
     163                                        'top' : element.scrollTop + element.clientHeight
     164                                };
     165                        }
     166                       
     167                        function restoreScrollPosition( element )
     168                        {
     169                                element = element.$ || element;
     170                                var translatedScroll =
     171                                {
     172                                        'left' : ( scrollPos.left - element.clientWidth ),
     173                                        'top' : ( scrollPos.top - element.clientHeight )
     174                                };
     175                                element.scrollLeft = translatedScroll.left;
     176                                element.scrollTop = translatedScroll.top;
     177                                scrollPos = null;
     178                        }
     179                       
     180                        editor.addCommand(
     181                        'fitwindow' ,
     182                        {
     183                                exec : function ( editor )
     184                                {
     185                                        if ( this.state === CKEDITOR.TRISTATE_DISABLED )
     186                                        return;
     187                                       
     188                                        if( editor.mode == 'wysiwyg' )
     189                                        {
     190                                                var isRestoreWYSIWYG;
     191                                                // Kludge: reload the wysiwyg plugin for gecko and
     192                                                // webkit bug of original iframe content been
     193                                                // destroied when moving editor in dom.
     194                                                if( isRestoreWYSIWYG = ( CKEDITOR.env.gecko || CKEDITOR.env.webkit ) )
     195                                                        saveWYSIWYG();
     196                                        }
     197                                        else if( editor.mode == 'source' )
     198                                        {
     199                                                var editarea = editor._.modes.source._.getTextArea();
     200                                                saveScrollPosition( editarea );
     201                                        }
     202                                       
     203                                        //Begin to tranform
     204                                        if( this.state === CKEDITOR.TRISTATE_OFF )
     205                                        {
     206                                                moveEditor();
     207                                               
     208                                                //fix IE viewport scrolling
     209                                                if( CKEDITOR.env.ie )
     210                                                {
     211                                                        var view = new CKEDITOR.dom.element(doc.$.documentElement);
     212                                                        changeStyle( view, {
     213                                                                'overflow' :'hidden'
     214                                                        } );
     215                                                }
     216                                               
     217                                                changeStyle( bodyEl, {
     218                                                        'top' :'0px',
     219                                                        'left' :'0px',
     220                                                        'height' :'100%',
     221                                                        'width' :'100%',
     222                                                        'overflow' :'hidden',
     223                                                        'position' :'absolute',
     224                                                        'margin' :'0px'
     225                                                } );
     226                                               
     227                                                if (CKEDITOR.env.webkit )
     228                                                {
     229                                                        changeStyle( editor.container, {
     230                                                                'position' :'absolute',
     231                                                                'height' :'100%',
     232                                                                'width' :'100%',
     233                                                                'z-index' :'10'
     234                                                        } );
     235                                                }
     236                                               
     237                                                changeStyle( editor.container.getFirst(), {
     238                                                        'width' :'100%',
     239                                                        // Kludge: Fix IE table over-height on fit parent.
     240                                                        'height' :CKEDITOR.env.ie ? '90%' : '100%',
     241                                                        'z-index' :'10'
     242                                                } );
     243                                               
     244                                                // Fix IE 'source' mode bug of #2764
     245                                                if( editor.mode == 'source' && CKEDITOR.env.ie )
     246                                                {
     247                                                        changeStyle( editarea, {
     248                                                                'width' :editarea.getParent().$.clientWidth,
     249                                                                'height' :editarea.getParent().$.clientHeight
     250                                                        } );
     251                                                }
     252                                        }
     253                                        else if( this.state === CKEDITOR.TRISTATE_ON )
     254                                        {
     255                                                moveEditor( true );
     256                                                restoreChangedStyles();
     257                                        }
     258                                       
     259                                        if( editor.mode === 'wysiwyg' )
     260                                        {
     261                                                if( isRestoreWYSIWYG )
     262                                                {
     263                                                        restoreWYSIWYG( editor );
     264                                                }
     265                                        }
     266                                        else if( editor.mode == 'source' )
     267                                        {
     268                                                restoreScrollPosition( editarea );
     269                                        }
     270                                       
     271                                        // refresh command state
     272                                        this.toggleState();
     273                                }
     274                        });
     275
     276                        editor.ui.addButton( 'Maximize', {
     277                                        lablel :editor.lang.fitWindow,
     278                                        command :'fitwindow'
     279                                } );
     280                }
     281        });
     282       
     283})();
  • _source/plugins/toolbar/plugin.js

     
    211211                'Bold', 'Italic', 'Underline', 'Strike', '-',
    212212                'Subscript', 'Superscript', '-',
    213213                'SelectAll', 'RemoveFormat', '-',
    214                 'Smiley', 'HorizontalRule', 'SpecialChar', 'PageBreak'
     214                'Smiley', 'HorizontalRule', 'SpecialChar', 'PageBreak','-',
     215                'Maximize'
    215216        ]
    216217];
  • _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/plugins/selection/plugin.js

     
    618618                                                sel.addRange( nativeRange );
    619619                                        }
    620620                                },
    621 
    622                 createBookmarks : function()
     621        /**
     622                 * This method is a delegate to ceate bookmark for every ranges in this selection.
     623                 *
     624                 * @see CKEDITOR.dom.range::createBookmark
     625                 */
     626                createBookmarks : function ( serializable )
    623627                {
    624628                        var retval = [],
    625629                                ranges = this.getRanges();
     
    624628                        var retval = [],
    625629                                ranges = this.getRanges();
    626630                        for ( var i = 0 ; i < ranges.length ; i++ )
    627                                 retval.push( ranges[i].createBookmark() );
     631                                retval.push( ranges[ i ].createBookmark( serializable ) );
    628632                        return retval;
    629633                },
    630634
  • _source/core/dom/element.js

     
    347347
    348348                                                        return tabIndex;
    349349                                                        break;
     350                                                       
     351                                                case 'style' :
     352                                                        return this.$.style.cssText;
    350353                                        }
    351354
    352355                                        return standard.call( this, name );
  • _source/core/dom/range.js

     
    409409                        return docFrag;
    410410                },
    411411
    412                 // This is an "intrusive" way to create a bookmark. It includes <span> tags
    413                 // in the range boundaries. The advantage of it is that it is possible to
    414                 // handle DOM mutations when moving back to the bookmark.
    415                 // Attention: the inclusion of nodes in the DOM is a design choice and
    416                 // should not be changed as there are other points in the code that may be
    417                 // using those nodes to perform operations. See GetBookmarkNode.
    418                 createBookmark : function()
     412                /**
     413                 * This is an "intrusive" way to create a bookmark. It includes <span>
     414                 * tags in the range boundaries. The advantage of it is that it is
     415                 * possible to handle DOM mutations when moving back to the bookmark.
     416                 * Attention: the inclusion of nodes in the DOM is a design choice.
     417                 *
     418                 * @param serializeable {Boolean} If set to true will record the bookmark with startNode/endNode IDs for serializing purpose.
     419                 */
     420                createBookmark : function(serializeable)
    419421                {
    420                         var startNode, endNode;
     422                        var startNode , endNode;
    421423                        var clone;
    422424
    423425                        startNode = this.document.createElement( 'span' );
    424                         startNode.setAttribute( '_fck_bookmark', 1 );
    425                         startNode.setStyle( 'display', 'none' );
     426                        startNode.setAttribute( '_fck_bookmark' , 1 );
     427                        startNode.setStyle( 'display' , 'none' );
    426428
    427429                        // For IE, it must have something inside, otherwise it may be
    428430                        // removed during DOM operations.
     
    452454                        else
    453455                                this.moveToPosition( startNode, CKEDITOR.POSITION_AFTER_END );
    454456
     457                        if ( serializeable )
     458                        {
     459                                startNode.setAttribute( 'id' , ( new Date() ).valueOf()
     460                                                + Math.floor( Math.random() * 1000 ) + 'S' );
     461                                if ( endNode )
     462                                        endNode.setAttribute( 'id' , ( new Date() ).valueOf()
     463                                                        + Math.floor( Math.random() * 1000 ) + 'E' );
     464                        }
    455465                        return {
    456                                 startNode : startNode,
    457                                 endNode : endNode
     466                                startNode :serializeable ? startNode.getAttribute( 'id' )
     467                                                : startNode,
     468                                endNode :endNode ? ( serializeable ? endNode
     469                                                .getAttribute( 'id' ) : endNode ) : null
    458470                        };
    459471                },
    460472
     473                /**
     474                 * Move the range boundaries to where the bookmarks indicated.
     475                 *
     476                 * @see CKEDITOR.dom.range::createBookmark
     477                 * @param {Object} bookmark
     478                 *
     479                 */
    461480                moveToBookmark : function( bookmark )
    462481                {
    463                         // Set the range start at the bookmark start node position.
    464                         this.setStartBefore( bookmark.startNode );
     482                        var startNode = bookmark.startNode , endNode = bookmark.endNode;
     483
     484                        // Set the range startNodeart at the bookmark startNodeart node position.
     485                        this.setStartBefore( typeof startNode === 'string' ? ( startNode = this.document
     486                                        .getById( startNode ) ) : startNode );
    465487
    466488                        // Remove it, because it may interfere in the setEndBefore call.
    467                         bookmark.startNode.remove();
     489                        startNode.remove();
    468490
    469491                        // Set the range end at the bookmark end node position, or simply
    470492                        // collapse it if it is not available.
    471                         var endNode = bookmark.endNode;
    472493                        if ( endNode )
    473494                        {
    474                                 this.setEndBefore( endNode );
     495                                this.setEndBefore( typeof endNode === 'string' ?
     496                                                ( endNode = this.document.getById( endNode ) )
     497                                                : endNode );
    475498                                endNode.remove();
    476499                        }
    477500                        else
  • _source/core/command.js

     
    1919};
    2020
    2121CKEDITOR.event.implementOn( CKEDITOR.command.prototype );
     22
     23/*
     24 * Toggle the current state of command and refresh. 
     25 */
     26CKEDITOR.command.prototype.toggleState = function(){
     27        this.state = (this.state === CKEDITOR.TRISTATE_ON? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_ON);
     28        this.fire( 'state' );
     29};
  • _source/core/config.js

     
    146146         * @example
    147147         * config.plugins = 'basicstyles,button,htmldataprocessor,toolbar,wysiwygarea';
    148148         */
    149         plugins : 'basicstyles,button,elementspath,horizontalrule,htmldataprocessor,keystrokes,newpage,pagebreak,removeformat,smiley,sourcearea,specialchar,tab,toolbar,wysiwygarea',
     149        plugins : 'basicstyles,button,elementspath,horizontalrule,htmldataprocessor,keystrokes,newpage,pagebreak,removeformat,smiley,sourcearea,specialchar,tab,toolbar,wysiwygarea,fitwindow',
    150150
    151151        /**
    152152         * The theme to be used to build the UI.
  • _source/skins/default/toolbar.css

     
    305305{
    306306        background-position: 0 -880px;
    307307}
     308.cke_skin_default a.cke_button_fitwindow .cke_icon
     309{
     310        background-position: 0 -1040px;
     311}
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy