Ticket #4513: 4513.patch

File 4513.patch, 4.4 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/link/dialogs/link.js

     
    8484
    8585        var parseLink = function( editor, element )
    8686        {
    87                 var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) : '',
     87                var href = ( element  && ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) ) || '',
    8888                        emailMatch,
    8989                        anchorMatch,
    9090                        urlMatch,
     
    351351                return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')';
    352352        }
    353353
     354        function getPartialSelectedElement( editor, tagName )
     355        {
     356                try
     357                {
     358                        var selection = editor.getSelection(),
     359                                ranges = selection.getRanges(),
     360                                range = ranges[0];
     361
     362                        /*  Have to deal with the following cases: (#4513)
     363                                 <a href="#">li^nk</a>
     364                                 <a href="#">[link]</a>
     365                                 text[<a href="#">link]</a>
     366                                 <a href="#">li[nk</a>]
     367                                 ...
     368                        */
     369
     370                        range.trim( false, false, true );
     371                       
     372                        var selectedStartNode = range.getTouchedStartNode(),
     373                                selectedEndNode = range.getTouchedEndNode(),
     374                                elementAtStart = selectedStartNode.getAscendant( tagName, true ),
     375                                elementAtEnd = selectedEndNode.getAscendant( tagName, true );
     376
     377                        if( elementAtStart.equals( elementAtEnd ) )
     378                                return elementAtStart;
     379
     380                }
     381                catch(er)
     382                {
     383                        return null;
     384                }
     385        }
     386
    354387        return {
    355388                title : editor.lang.link.title,
    356389                minWidth : 350,
     
    11191152
    11201153                        var editor = this.getParentEditor(),
    11211154                                selection = editor.getSelection(),
    1122                                 ranges = selection.getRanges(),
    1123                                 element = null,
    1124                                 me = this;
    1125                         // Fill in all the relevant fields if there's already one link selected.
    1126                         if ( ranges.length == 1 )
    1127                         {
     1155                                element = null;
    11281156
    1129                                 var rangeRoot = ranges[0].getCommonAncestor( true );
    1130                                 element = rangeRoot.getAscendant( 'a', true );
    1131                                 if ( element && element.getAttribute( 'href' ) )
    1132                                 {
    1133                                         selection.selectElement( element );
    1134                                 }
    1135                                 else if ( ( element = rangeRoot.getAscendant( 'img', true ) ) &&
    1136                                                  element.getAttribute( '_cke_real_element_type' ) &&
    1137                                                  element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
    1138                                 {
    1139                                         this.fakeObj = element;
    1140                                         element = editor.restoreRealElement( this.fakeObj );
    1141                                         selection.selectElement( this.fakeObj );
    1142                                 }
    1143                                 else
    1144                                         element = null;
    1145                         }
     1157                        // Fill in all the relevant fields if there's already one link selected.
     1158                        if ( ( element = getPartialSelectedElement( editor, 'a' ) ) && element.hasAttribute( 'href' ) )
     1159                                selection.selectElement( element );
     1160                        else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' )
     1161                                        && element.getAttribute( '_cke_real_element_type' )
     1162                                        && element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
     1163                        {
     1164                                this.fakeObj = element;
     1165                                element = editor.restoreRealElement( this.fakeObj );
     1166                                selection.selectElement( this.fakeObj );
     1167                        }
     1168                        else
     1169                                element = null;
    11461170
    11471171                        this.setupContent( parseLink.apply( this, [ editor, element ] ) );
    11481172                },
  • _source/core/dom/range.js

     
    712712                                this.setEndAt( endNode,  CKEDITOR.POSITION_AFTER_END );
    713713                },
    714714
    715                 trim : function( ignoreStart, ignoreEnd )
     715                /**
     716                 *      Favor element as range containers over text node,
     717                 * optionally break text node into two when necessary.   
     718                 * @param ignoreStart Avoid trimming at the front.
     719                 * @param ignoreEnd Avoid trimming at the end.
     720                 * @param noSplit Don't split up in middle of text node (No DOM change). 
     721                 */
     722                trim : function( ignoreStart, ignoreEnd, noSplit )
    716723                {
    717724                        var startContainer = this.startContainer,
    718725                                startOffset = this.startOffset,
     
    736743                                }
    737744                                // In other case, we split the text node and insert the new
    738745                                // node at the split point.
    739                                 else
     746                                else if( !noSplit )
    740747                                {
    741748                                        var nextText = startContainer.split( startOffset );
    742749
     
    775782                                }
    776783                                // In other case, we split the text node and insert the new
    777784                                // node at the split point.
    778                                 else
     785                                else if ( !noSplit )
    779786                                {
    780787                                        endContainer.split( endOffset );
    781788
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy