Ticket #6735: 6375_3.patch

File 6375_3.patch, 6.8 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/wysiwygarea/plugin.js

     
    2525                                || element.isBlockBoundary() && CKEDITOR.dtd.$empty[ element.getName() ];
    2626        }
    2727
    28         function checkReadOnly( selection )
    29         {
    30                 if ( selection.getType() == CKEDITOR.SELECTION_ELEMENT )
    31                         return selection.getSelectedElement().isReadOnly();
    32                 else
    33                         return selection.getCommonAncestor().isReadOnly();
    34         }
    35 
    3628        function onInsertHtml( evt )
    3729        {
    3830                if ( this.mode == 'wysiwyg' )
    3931                {
    4032                        this.focus();
    4133
    42                         var selection = this.getSelection();
    43                         if ( checkReadOnly( selection ) )
     34                        // HTML insertion only considers the first range.
     35                        var selection = this.getSelection(),
     36                                range = selection.getRanges()[ 0 ];
     37
     38                        if ( range.checkReadOnly() )
    4439                                return;
    4540
    4641                        var data = evt.data;
     
    6762                                        // (#6005), we need to make some checks and eventually
    6863                                        // delete the selection first.
    6964
    70                                         var range = selection.getRanges()[0],
     65                                        range = selection.getRanges()[0],
    7166                                                endContainer = range && range.endContainer;
    7267
    7368                                        if ( endContainer &&
     
    116111                        this.focus();
    117112
    118113                        var selection = this.getSelection();
    119                         if ( checkReadOnly( selection ) )
    120                                 return;
    121114
    122115                        this.fire( 'saveSnapshot' );
    123116
     
    137130                        {
    138131                                range = ranges[ i ];
    139132
    140                                 // Remove the original contents.
    141                                 range.deleteContents();
     133                                if ( !range.checkReadOnly() )
     134                                {
     135                                        // Remove the original contents.
     136                                        range.deleteContents();
    142137
    143                                 clone = !i && element || element.clone( 1 );
     138                                        clone = !i && element || element.clone( 1 );
    144139
    145                                 // If we're inserting a block at dtd-violated position, split
    146                                 // the parent blocks until we reach blockLimit.
    147                                 var current, dtd;
    148                                 if ( isBlock )
    149                                 {
    150                                         while ( ( current = range.getCommonAncestor( 0, 1 ) )
    151                                                         && ( dtd = CKEDITOR.dtd[ current.getName() ] )
    152                                                         && !( dtd && dtd [ elementName ] ) )
    153                                         {
    154                                                 // Split up inline elements.
    155                                                 if ( current.getName() in CKEDITOR.dtd.span )
    156                                                         range.splitElement( current );
    157                                                 // If we're in an empty block which indicate a new paragraph,
    158                                                 // simply replace it with the inserting block.(#3664)
    159                                                 else if ( range.checkStartOfBlock()
    160                                                          && range.checkEndOfBlock() )
    161                                                 {
    162                                                         range.setStartBefore( current );
    163                                                         range.collapse( true );
    164                                                         current.remove();
    165                                                 }
    166                                                 else
    167                                                         range.splitBlock();
    168                                         }
    169                                 }
     140                                        // If we're inserting a block at dtd-violated position, split
     141                                        // the parent blocks until we reach blockLimit.
     142                                        var current, dtd;
     143                                        if ( isBlock )
     144                                        {
     145                                                while ( ( current = range.getCommonAncestor( 0, 1 ) )
     146                                                                && ( dtd = CKEDITOR.dtd[ current.getName() ] )
     147                                                                && !( dtd && dtd [ elementName ] ) )
     148                                                {
     149                                                        // Split up inline elements.
     150                                                        if ( current.getName() in CKEDITOR.dtd.span )
     151                                                                range.splitElement( current );
     152                                                        // If we're in an empty block which indicate a new paragraph,
     153                                                        // simply replace it with the inserting block.(#3664)
     154                                                        else if ( range.checkStartOfBlock()
     155                                                                        && range.checkEndOfBlock() )
     156                                                        {
     157                                                                range.setStartBefore( current );
     158                                                                range.collapse( true );
     159                                                                current.remove();
     160                                                        }
     161                                                        else
     162                                                                range.splitBlock();
     163                                                }
     164                                        }
    170165
    171                                 // Insert the new node.
    172                                 range.insertNode( clone );
     166                                        // Insert the new node.
     167                                        range.insertNode( clone );
     168                                        i && ranges.pop();
    173169
    174                                 // Save the last element reference so we can make the
    175                                 // selection later.
    176                                 if ( !lastElement )
    177                                         lastElement = clone;
    178                         }
     170                                        // Save the last element reference so we can make the
     171                                        // selection later.
     172                                        if ( !lastElement )
     173                                                lastElement = clone;
     174                                }
     175                        }
    179176
    180                         range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );
     177                        if ( lastElement )
     178                        {
     179                                range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );
    181180
    182                         // If we're inserting a block element immediatelly followed by
    183                         // another block element, the selection must move there. (#3100,#5436)
    184                         if ( isBlock )
    185                         {
    186                                 var next = lastElement.getNext( notWhitespaceEval ),
    187                                         nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();
     181                                // If we're inserting a block element immediatelly followed by
     182                                // another block element, the selection must move there. (#3100,#5436)
     183                                if ( isBlock )
     184                                {
     185                                        var next = lastElement.getNext( notWhitespaceEval ),
     186                                                nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();
    188187
    189                                 // Check if it's a block element that accepts text.
    190                                 if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] )
    191                                         range.moveToElementEditStart( next );
    192                         }
     188                                        // Check if it's a block element that accepts text.
     189                                        if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] )
     190                                                range.moveToElementEditStart( next );
     191                                }
     192                        }
    193193
    194                         selection.selectRanges( [ range ] );
     194                        selection.selectRanges( ranges );
    195195
    196196                        if ( selIsLocked )
    197197                                this.getSelection().lock();
  • _source/core/dom/range.js

     
    17451745                },
    17461746
    17471747                /**
     1748                 * Check if elements at which the range boundaries anchor are read-only,
     1749                 * with respect to "contenteditable" attribute.
     1750                 */
     1751                checkReadOnly : ( function()
     1752                {
     1753                        function checkPathEditable( node, anotherEnd )
     1754                        {
     1755                                while( node )
     1756                                {
     1757                                        if ( node.type == CKEDITOR.NODE_ELEMENT )
     1758                                        {
     1759                                                if ( node.getAttribute( 'contentEditable' ) == 'false'
     1760                                                        && !node.getCustomData( '_cke_notReadOnly' ) )
     1761                                                        return 0;
     1762                                                else if ( node.is( 'body' )
     1763                                                        || node.getAttribute( 'contentEditable' ) == 'true'
     1764                                                                && ( node.contains( anotherEnd ) || node.equals( anotherEnd ) ) )
     1765                                                {
     1766                                                        break;
     1767                                                }
     1768                                        }
     1769                                        node = node.getParent();
     1770                                }
     1771
     1772                                return 1;
     1773                        }
     1774
     1775                        return function()
     1776                        {
     1777                                var startNode = this.startContainer,
     1778                                        endNode = this.endContainer;
     1779
     1780                                // Check if elements path at both boundaries are editable.
     1781                                return !( checkPathEditable( startNode, endNode ) && checkPathEditable( endNode, startNode ) )
     1782                        };
     1783                })(),
     1784
     1785                /**
    17481786                 * Moves the range boundaries to the first/end editing point inside an
    17491787                 * element. For example, in an element tree like
    17501788                 * "<p><b><i></i></b> Text</p>", the start editing point is
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy