Ticket #1376: 1376_4.patch

File 1376_4.patch, 21.8 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/showblocks/plugin.js

     
    8989
    9090        var commandDefinition =
    9191        {
     92                readOnly : 1,
    9293                preserveState : true,
    9394                editorFocus : false,
    9495
  • _samples/readonly.html

     
     1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2<!--
     3Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
     4For licensing, see LICENSE.html or http://ckeditor.com/license
     5-->
     6<html xmlns="http://www.w3.org/1999/xhtml">
     7<head>
     8        <title>Read-only &mdash; CKEditor Sample</title>
     9        <meta content="text/html; charset=utf-8" http-equiv="content-type" />
     10        <!-- CKReleaser %REMOVE_LINE%
     11        <script type="text/javascript" src="../ckeditor.js"></script>
     12        CKReleaser %REMOVE_START% -->
     13        <script type="text/javascript" src="../ckeditor_source.js"></script>
     14        <!-- CKReleaser %REMOVE_END% -->
     15        <script src="sample.js" type="text/javascript"></script>
     16        <link href="sample.css" rel="stylesheet" type="text/css" />
     17        <script type="text/javascript">
     18        //<![CDATA[
     19
     20// The instanceReady event is fired, when an instance of CKEditor has finished
     21// its initialization.
     22CKEDITOR.on( 'instanceReady', function( ev )
     23{
     24        // Show the editor name and description in the browser status bar.
     25        document.getElementById( 'eMessage' ).innerHTML = '<p>Instance <code>' + ev.editor.name + '<\/code> loaded.<\/p>';
     26
     27        // Show this sample buttons.
     28         document.getElementById( 'eButtons' ).style.display = 'block';
     29});
     30
     31function toggleReadOnly( isReadOnly )
     32{
     33        // Get the editor instance that we want to interact with.
     34        var oEditor = CKEDITOR.instances.editor1;
     35
     36        // Change the read-only state of editor.
     37        // http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setReadOnly
     38        oEditor.setReadOnly( isReadOnly );
     39        alert( 'Editor is ' + ( isReadOnly ? 'now' : 'no longer' ) + " in read-only mode." );
     40}
     41
     42        //]]>
     43        </script>
     44
     45</head>
     46<body>
     47        <h1 class="samples">
     48                CKEditor Sample &mdash; Using CKEditor JavaScript API
     49        </h1>
     50        <div class="description">
     51        <p>
     52                This sample shows how to use the
     53                <a class="samples" href="http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setReadOnly">set read-only</a>
     54                API to put editor into an immutable state.
     55        </p>
     56        <p>
     57                For details on how to create this setup check the source code of this sample page.
     58        </p>
     59        </div>
     60
     61        <!-- This <div> holds alert messages to be display in the sample page. -->
     62        <div id="alerts">
     63                <noscript>
     64                        <p>
     65                                <strong>CKEditor requires JavaScript to run</strong>. In a browser with no JavaScript
     66                                support, like yours, you should still see the contents (HTML data) and you should
     67                                be able to edit it normally, without a rich editor interface.
     68                        </p>
     69                </noscript>
     70        </div>
     71        <form action="sample_posteddata.php" method="post">
     72                <textarea class="ckeditor" id="editor1" name="editor1" cols="100" rows="10">&lt;p&gt;This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href="http://ckeditor.com/"&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;</textarea>
     73                <div id="eMessage">
     74                </div>
     75                <div id="eButtons" style="display: none">
     76                        <input onclick="toggleReadOnly( 1 );" type="button" value="Turn on read-only" />
     77                        <input onclick="toggleReadOnly();" type="button" value="Turn off read-only" />
     78                </div>
     79        </form>
     80        <div id="footer">
     81                <hr />
     82                <p>
     83                        CKEditor - The text editor for the Internet - <a class="samples" href="http://ckeditor.com/">http://ckeditor.com</a>
     84                </p>
     85                <p id="copy">
     86                        Copyright &copy; 2003-2011, <a class="samples" href="http://cksource.com/">CKSource</a> - Frederico
     87                        Knabben. All rights reserved.
     88                </p>
     89        </div>
     90</body>
     91</html>
  • _source/plugins/about/plugin.js

     
    1111                var command = editor.addCommand( 'about', new CKEDITOR.dialogCommand( 'about' ) );
    1212                command.modes = { wysiwyg:1, source:1 };
    1313                command.canUndo = false;
     14                command.readOnly = 1;
    1415
    1516                editor.ui.addButton( 'About',
    1617                        {
  • _source/plugins/save/plugin.js

     
    1212        var saveCmd =
    1313        {
    1414                modes : { wysiwyg:1, source:1 },
     15                readOnly : 1,
    1516
    1617                exec : function( editor )
    1718                {
  • _source/plugins/showborders/plugin.js

     
    4040        {
    4141                preserveState : true,
    4242                editorFocus : false,
     43                readOnly: 1,
    4344
    4445                exec : function ( editor )
    4546                {
  • _source/plugins/basicstyles/plugin.js

     
    1717
    1818                        editor.attachStyleStateChange( style, function( state )
    1919                                {
    20                                         editor.getCommand( commandName ).setState( state );
     20                                        !editor.readOnly && editor.getCommand( commandName ).setState( state );
    2121                                });
    2222
    2323                        editor.addCommand( commandName, new CKEDITOR.styleCommand( style ) );
  • _source/plugins/editingblock/plugin.js

     
    113113                                        }, 0 );
    114114                                });
    115115
     116                        editor.readOnly = !!editor.config.readOnly;
     117                        editor.on( 'mode', function() { this.readOnly && this.fire( 'readonly' ); }, null, null, Infinity );
     118
    116119                        editor.on( 'destroy', function ()
    117120                        {
    118121                                // ->           currentMode.unload( holderElement );
    119122                                if ( this.mode )
    120123                                        this._.modes[ this.mode ].unload( this.getThemeSpace( 'contents' ) );
    121124                        });
     125
    122126                }
    123127        });
    124128
     
    151155         * // Switch to "source" view.
    152156         * CKEDITOR.instances.editor1.setMode( 'source' );
    153157         */
    154         CKEDITOR.editor.prototype.setMode = function( mode )
     158        CKEDITOR.editor.prototype.setMode = function( mode, forceReload )
    155159        {
    156160                this.fire( 'beforeSetMode', { newMode : mode } );
    157161
     
    162166                // Unload the previous mode.
    163167                if ( this.mode )
    164168                {
    165                         if ( mode == this.mode )
     169                        if ( !forceReload && mode == this.mode )
    166170                                return;
    167171
    168172                        this.fire( 'beforeModeUnload' );
     
    202206                if ( mode )
    203207                        mode.focus();
    204208        };
     209
     210        /**
     211         * Turn editor into read-only mode or restore it from read-only mode.
     212         * @param enable {Boolean}
     213         * @since 3.6
     214         * <strong>Note:</strong> current editing block will be reloaded.
     215         */
     216        CKEDITOR.editor.prototype.setReadOnly = function( enable )
     217        {
     218                this.readOnly = !!enable;
     219
     220                // Reload current mode, then fire the event on editor.
     221                this.on( 'mode', function( evt ) {  evt.removeListener(); enable && this.fire( 'readonly' ); }, this, null, Infinity );
     222                this.setMode( this.mode || this.config.startupMode, 1 );
     223        }
     224
    205225})();
    206226
    207227/**
     
    233253CKEDITOR.config.editingBlock = true;
    234254
    235255/**
     256 * Whether to start the editor in read-only mode.
     257 * @name CKEDITOR.config.readOnly
     258 * @see CKEDITOR.editor.setReadOnly
     259 * @type Boolean
     260 * @default false
     261 * @since 3.6
     262 * @example
     263 * config.readOnly = true;
     264 */
     265
     266/**
    236267 * Fired when a CKEDITOR instance is created, fully initialized and ready for interaction.
    237268 * @name CKEDITOR#instanceReady
    238269 * @event
  • _source/plugins/justify/plugin.js

     
    4949
    5050        function onSelectionChange( evt )
    5151        {
     52                if ( evt.editor.readOnly )
     53                        return;
     54
    5255                var command = evt.editor.getCommand( this.name );
    5356                command.state = getState.call( this, evt.editor, evt.data.path );
    5457                command.fire( 'state' );
  • _source/core/dom/range.js

     
    18701870                                                        return 0;
    18711871                                                }
    18721872                                                // Range enclosed entirely in an editable element.
    1873                                                 else if ( node.is( 'body' )
     1873                                                else if ( node.is( 'html' )
    18741874                                                        || node.getAttribute( 'contentEditable' ) == 'true'
    18751875                                                        && ( node.contains( anotherEnd ) || node.equals( anotherEnd ) ) )
    18761876                                                {
  • _source/plugins/selection/plugin.js

     
    9292        var selectAllCmd =
    9393        {
    9494                modes : { wysiwyg : 1, source : 1 },
     95                readOnly : 1,
    9596                exec : function( editor )
    9697                {
    9798                        switch ( editor.mode )
  • _source/plugins/menu/plugin.js

     
    9797                                                {
    9898                                                        var item = this.editor.getMenuItem( itemName );
    9999
    100                                                         if ( item )
     100                                                        if ( item && ( !item.command || this.editor.getCommand( item.command ).state ) )
    101101                                                        {
    102                                                                 item.state = listenerItems[ itemName ];
     102                                                                item.state =  listenerItems[ itemName ];
    103103                                                                this.add( item );
    104104                                                        }
    105105                                                }
  • _source/plugins/elementspath/plugin.js

     
    1515                toolbarFocus :
    1616                {
    1717                        editorFocus : false,
     18                        readOnly : 1,
    1819                        exec : function( editor )
    1920                        {
    2021                                var idBase = editor._.elementsPath.idBase;
  • _source/plugins/a11yhelp/plugin.js

     
    3737                                                                });
    3838                                        },
    3939                                        modes : { wysiwyg:1, source:1 },
     40                                        readOnly : 1,
    4041                                        canUndo : false
    4142                                });
    4243
  • _source/core/editor.js

     
    394394                }
    395395        };
    396396
    397         function updateCommandsMode()
     397        function updateCommands( evt )
    398398        {
    399399                var command,
    400400                        commands = this._.commands,
    401                         mode = this.mode;
     401                        mode = this.mode,
     402                        readOnlyEvent = evt.name == 'readonly';
    402403
    403404                for ( var name in commands )
    404405                {
    405406                        command = commands[ name ];
    406                         command[ command.startDisabled ? 'disable' : command.modes[ mode ] ? 'enable' : 'disable' ]();
     407                        command[ command.startDisabled ?
     408                                         'disable' : ( readOnlyEvent ? command.readOnly : command.modes[ mode ] ) ?
     409                                          'enable' : 'disable' ]();
    407410                }
    408411        }
    409412
     
    491494
    492495                        CKEDITOR.fire( 'instanceCreated', null, this );
    493496
    494                         this.on( 'mode', updateCommandsMode, null, null, 1 );
     497                        this.on( 'mode', updateCommands, null, null, 1 );
     498                        this.on( 'readonly', updateCommands, null, null, 1 );
    495499
    496500                        initConfig( this, instanceConfig );
    497501                };
  • _source/plugins/toolbar/plugin.js

     
    3636                toolbarFocus :
    3737                {
    3838                        modes : { wysiwyg : 1, source : 1 },
     39                        readOnly : 1,
    3940
    4041                        exec : function( editor )
    4142                        {
  • _source/plugins/print/plugin.js

     
    3737                        editor.document.$.execCommand( "Print" );
    3838        },
    3939        canUndo : false,
     40        readOnly : 1,
    4041        modes : { wysiwyg : !( CKEDITOR.env.opera ) }           // It is imposible to print the inner document in Opera.
    4142};
  • _source/plugins/richcombo/plugin.js

     
    135135                                },
    136136                                this );
    137137
     138                        editor.on( 'readonly', function()
     139                                {
     140                                        this.setState( CKEDITOR.TRISTATE_DISABLED );
     141                                        this.setValue( '' );
     142                                }, this );
     143
     144
    138145                        var keyDownFn = CKEDITOR.tools.addFunction( function( ev, element )
    139146                                {
    140147                                        ev = new CKEDITOR.dom.event( ev );
  • _source/plugins/button/plugin.js

     
    154154                                                modeStates[ mode ] != undefined ? modeStates[ mode ] :
    155155                                                        CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED );
    156156                                }, this);
     157
     158                        editor.on( 'readonly', function() { this.setState( CKEDITOR.TRISTATE_DISABLED ); }, this);
    157159                }
    158160                else if ( command )
    159161                {
  • _source/plugins/sourcearea/plugin.js

     
    4141                                                        textarea.addClass( 'cke_source' );
    4242                                                        textarea.addClass( 'cke_enable_context_menu' );
    4343
     44                                                        editor.readOnly && textarea.setAttribute( 'disabled', true );
     45
    4446                                                        var styles =
    4547                                                        {
    4648                                                                // IE7 has overflow the <textarea> from wrapping table cell.
     
    181183                {
    182184                        modes : { wysiwyg:1, source:1 },
    183185                        editorFocus : false,
    184 
     186                        readOnly : 1,
    185187                        exec : function( editor )
    186188                        {
    187189                                if ( editor.mode == 'wysiwyg' )
  • _source/plugins/clipboard/plugin.js

     
    293293                // keyboard paste or execCommand ) (#4874).
    294294                CKEDITOR.env.ie && ( depressBeforeEvent = 1 );
    295295
    296                 var retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED;
     296                var retval = CKEDITOR.TRISTATE_OFF;
     297                try { retval = editor.document.$.queryCommandEnabled( command ) ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED; }catch( er ){}
     298
    297299                depressBeforeEvent = 0;
    298300                return retval;
    299301        }
  • _source/plugins/undo/plugin.js

     
    9494                                        undoManager.onChange();
    9595                                });
    9696
     97                        editor.on( 'readonly', function()
     98                                {
     99                                        undoManager.enabled = 0;
     100                                        undoManager.onChange();
     101                                });
     102
    97103                        editor.ui.addButton( 'Undo',
    98104                                {
    99105                                        label : editor.lang.undo,
  • _source/plugins/enterkey/plugin.js

     
    1111
    1212                init : function( editor )
    1313                {
    14                         var specialKeys = editor.specialKeys;
    15                         specialKeys[ 13 ] = enter;
    16                         specialKeys[ CKEDITOR.SHIFT + 13 ] = shiftEnter;
     14                        editor.addCommand( 'enter', {
     15                                modes : { wysiwyg:1 },
     16                                editorFocus : false,
     17                                exec : enter
     18                        });
     19
     20                        editor.addCommand( 'shiftEnter', {
     21                                modes : { wysiwyg:1 },
     22                                editorFocus : false,
     23                                exec : shiftEnter
     24                        });
     25
     26                        var keystrokes = editor.keystrokeHandler.keystrokes;
     27                        keystrokes[ 13 ] = 'enter';
     28                        keystrokes[ CKEDITOR.SHIFT + 13 ] = 'shiftEnter';
    1729                }
    1830        });
    1931
  • _source/plugins/preview/plugin.js

     
    1313        {
    1414                modes : { wysiwyg:1, source:1 },
    1515                canUndo : false,
     16                readOnly : 1,
    1617                exec : function( editor )
    1718                {
    1819                        var sHTML,
  • _source/plugins/list/plugin.js

     
    218218
    219219        function onSelectionChange( evt )
    220220        {
     221                if ( evt.editor.readOnly )
     222                        return;
     223
    221224                var path = evt.data.path,
    222225                        blockLimit = path.blockLimit,
    223226                        elements = path.elements,
  • _source/plugins/blockquote/plugin.js

     
    2525
    2626        function onSelectionChange( evt )
    2727        {
    28                 var editor = evt.editor,
    29                         command = editor.getCommand( 'blockquote' );
     28                var editor = evt.editor;
     29                if ( editor.readOnly )
     30                        return;
     31
     32                var command = editor.getCommand( 'blockquote' );
    3033                command.state = getState( editor, evt.data.path );
    3134                command.fire( 'state' );
    3235        }
  • _source/plugins/wysiwygarea/plugin.js

     
    597597
    598598                                                body.spellcheck = !editor.config.disableNativeSpellChecker;
    599599
     600                                                var editable = !editor.readOnly;
     601
    600602                                                if ( CKEDITOR.env.ie )
    601603                                                {
    602604                                                        // Don't display the focus border.
     
    605607                                                        // Disable and re-enable the body to avoid IE from
    606608                                                        // taking the editing focus at startup. (#141 / #523)
    607609                                                        body.disabled = true;
    608                                                         body.contentEditable = true;
     610                                                        body.contentEditable = editable;
    609611                                                        body.removeAttribute( 'disabled' );
    610612                                                }
    611613                                                else
     
    617619                                                                // Prefer 'contentEditable' instead of 'designMode'. (#3593)
    618620                                                                if ( CKEDITOR.env.gecko && CKEDITOR.env.version >= 10900
    619621                                                                                || CKEDITOR.env.opera )
    620                                                                         domDocument.$.body.contentEditable = true;
     622                                                                        domDocument.$.body.contentEditable = editable;
    621623                                                                else if ( CKEDITOR.env.webkit )
    622                                                                         domDocument.$.body.parentNode.contentEditable = true;
     624                                                                        domDocument.$.body.parentNode.contentEditable = editable;
    623625                                                                else
    624                                                                         domDocument.$.designMode = 'on';
     626                                                                        domDocument.$.designMode = editable? 'off' : 'on';
    625627                                                        }, 0 );
    626628                                                }
    627629
    628                                                 CKEDITOR.env.gecko && CKEDITOR.tools.setTimeout( activateEditing, 0, null, editor );
     630                                                editable && CKEDITOR.env.gecko && CKEDITOR.tools.setTimeout( activateEditing, 0, null, editor );
    629631
    630632                                                domWindow       = editor.window = new CKEDITOR.dom.window( domWindow );
    631633                                                domDocument     = editor.document       = new CKEDITOR.dom.document( domDocument );
    632634
    633                                                 domDocument.on( 'dblclick', function( evt )
     635                                                editable && domDocument.on( 'dblclick', function( evt )
    634636                                                {
    635637                                                        var element = evt.data.getTarget(),
    636638                                                                data = { element : element, dialog : '' };
     
    711713
    712714                                                // IE standard compliant in editing frame doesn't focus the editor when
    713715                                                // clicking outside actual content, manually apply the focus. (#1659)
    714                                                 if ( CKEDITOR.env.ie
    715                                                         && domDocument.$.compatMode == 'CSS1Compat'
     716                                                if ( editable &&
     717                                                                CKEDITOR.env.ie && domDocument.$.compatMode == 'CSS1Compat'
    716718                                                                || CKEDITOR.env.gecko
    717719                                                                || CKEDITOR.env.opera )
    718720                                                {
     
    761763                                                        });
    762764
    763765                                                var keystrokeHandler = editor.keystrokeHandler;
    764                                                 if ( keystrokeHandler )
    765                                                         keystrokeHandler.attach( domDocument );
     766                                                // Prevent backspace from navigating off the page.
     767                                                !editable && ( keystrokeHandler.blockedKeystrokes[ 8 ] = 1 );
     768                                                keystrokeHandler.attach( domDocument );
    766769
    767770                                                if ( CKEDITOR.env.ie )
    768771                                                {
    769772                                                        domDocument.getDocumentElement().addClass( domDocument.$.compatMode );
    770773                                                        // Override keystrokes which should have deletion behavior
    771774                                                        //  on control types in IE . (#4047)
    772                                                         domDocument.on( 'keydown', function( evt )
     775                                                        editable && domDocument.on( 'keydown', function( evt )
    773776                                                        {
    774777                                                                var keyCode = evt.data.getKeystroke();
    775778
  • _source/plugins/bidi/plugin.js

     
    2222        {
    2323                var editor = evt.editor,
    2424                        path = evt.data.path;
     25
     26                if ( editor.readOnly )
     27                        return;
     28
    2529                var useComputedState = editor.config.useComputedState,
    2630                        selectedElement;
    2731
  • _source/plugins/maximize/plugin.js

     
    155155                        editor.addCommand( 'maximize',
    156156                                {
    157157                                        modes : { wysiwyg : 1, source : 1 },
     158                                        readOnly : 1,
    158159                                        editorFocus : false,
    159160                                        exec : function()
    160161                                        {
  • _source/plugins/indent/plugin.js

     
    1515
    1616        function onSelectionChange( evt )
    1717        {
     18                if ( evt.editor.readOnly )
     19                        return;
     20
    1821                var editor = evt.editor,
    1922                        elementPath = evt.data.path,
    2023                        list = elementPath && elementPath.contains( listNodeNames ),
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy