Changeset 341

Show
Ignore:
Timestamp:
2007-05-31 13:53:34 (20 months ago)
Author:
fredck
Message:

Fixed #220 : The creation of links or anchors in a selection that results on more than a single link created will not anymore leave temporary links in the source.

Location:
FCKeditor/trunk
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor/trunk/editor/dialog/fck_anchor.html

    r308 r341  
    111111 
    112112        // Create a new anchor preserving the current selection 
    113         oAnchor = oEditor.FCK.CreateLink( '#' ) ; 
    114         if ( !oAnchor ) 
     113        var aNewAnchors = oEditor.FCK.CreateLink( '#' ) ; 
     114 
     115        if ( aNewAnchors.length == 0 ) 
    115116        { 
    116117                // Nothing was selected, so now just create a normal A 
    117                 oAnchor = oEditor.FCK.InsertElement( 'a' ) ; 
     118                aNewAnchors.push( oEditor.FCK.InsertElement( 'a' ) ) ; 
    118119        } 
    119120        else 
    120121        { 
    121122                // Remove the fake href 
    122                 oAnchor.removeAttribute( 'href' ) ; 
    123         } 
    124         // Set the name 
    125         oAnchor.name = sNewName ; 
    126  
    127         // IE does require special processing to show the Anchor's image 
    128         // Opera doesn't allow to select empty anchors 
    129         if ( FCKBrowserInfo.IsIE || FCKBrowserInfo.IsOpera ) 
    130         { 
    131                 if ( oAnchor.innerHTML != '' ) 
     123                for ( var i = 0 ; i < aNewAnchors.length ; i++ ) 
     124                        aNewAnchors[i].removeAttribute( 'href' ) ; 
     125        } 
     126 
     127        // More than one anchors may have been created, so interact through all of them (see #220). 
     128        for ( var i = 0 ; i < aNewAnchors.length ; i++ ) 
     129        { 
     130                oAnchor = aNewAnchors[i] ; 
     131 
     132                // Set the name 
     133                oAnchor.name = sNewName ; 
     134 
     135                // IE does require special processing to show the Anchor's image 
     136                // Opera doesn't allow to select empty anchors 
     137                if ( FCKBrowserInfo.IsIE || FCKBrowserInfo.IsOpera ) 
    132138                { 
    133                         if ( FCKBrowserInfo.IsIE ) 
    134                                 oAnchor.className += ' FCK__AnchorC' ; 
     139                        if ( oAnchor.innerHTML != '' ) 
     140                        { 
     141                                if ( FCKBrowserInfo.IsIE ) 
     142                                        oAnchor.className += ' FCK__AnchorC' ; 
     143                        } 
     144                        else 
     145                        { 
     146                                // Create a fake image for both IE and Opera 
     147                                var oImg = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oAnchor.cloneNode(true) ) ; 
     148                                oImg.setAttribute( '_fckanchor', 'true', 0 ) ; 
     149 
     150                                oAnchor.parentNode.insertBefore( oImg, oAnchor ) ; 
     151                                oAnchor.parentNode.removeChild( oAnchor ) ; 
     152                        } 
     153 
    135154                } 
    136                 else 
    137                 { 
    138                         // Create a fake image for both IE and Opera 
    139                         var oImg = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__Anchor', oAnchor.cloneNode(true) ) ; 
    140                         oImg.setAttribute( '_fckanchor', 'true', 0 ) ; 
    141  
    142                         oAnchor.parentNode.insertBefore( oImg, oAnchor ) ; 
    143                         oAnchor.parentNode.removeChild( oAnchor ) ; 
    144                 } 
    145  
    146155        } 
    147156 
  • FCKeditor/trunk/editor/dialog/fck_image/fck_image.js

    r339 r341  
    251251                                oEditor.FCKSelection.SelectNode( oImage ) ; 
    252252 
    253                         oLink = oEditor.FCK.CreateLink( sLnkUrl ) ; 
     253                        oLink = oEditor.FCK.CreateLink( sLnkUrl )[0] ; 
    254254 
    255255                        if ( !bHasImage ) 
  • FCKeditor/trunk/editor/dialog/fck_link/fck_link.js

    r308 r341  
    503503        } 
    504504 
    505         // No link selected, so try to create one. 
    506         if ( !oLink ) 
    507                 oLink = oEditor.FCK.CreateLink( sUri ) ; 
    508  
    509         if ( oLink ) 
    510                 sInnerHtml = oLink.innerHTML ;          // Save the innerHTML (IE changes it if it is like an URL). 
    511         else 
    512         { 
    513                 // If no selection, use the uri as the link text (by dom, 2006-05-26) 
    514  
     505        // If no link is selected, create a new one (it may result in more than one link creation - #220). 
     506        var aLinks = oLink ? [ oLink ] : oEditor.FCK.CreateLink( sUri ) ; 
     507 
     508        // If no selection, no links are created, so use the uri as the link text (by dom, 2006-05-26) 
     509        var aHasSelection = ( aLinks.length > 0 ) ; 
     510        if ( !aHasSelection ) 
     511        { 
    515512                sInnerHtml = sUri; 
    516513 
     
    538535 
    539536                // Create a new (empty) anchor. 
    540                 oLink = oEditor.FCK.InsertElement( 'a' ) ; 
     537                aLinks = [ oEditor.FCK.InsertElement( 'a' ) ] ; 
    541538        } 
    542539 
    543540        oEditor.FCKUndo.SaveUndoStep() ; 
    544541 
    545         oLink.href = sUri ; 
    546         SetAttribute( oLink, '_fcksavedurl', sUri ) ; 
    547  
    548         // Accesible popups 
    549         if( GetE('cmbTarget').value == 'popup' ) 
    550         { 
    551                 SetAttribute( oLink, 'onclick_fckprotectedatt', " onclick=\"" + BuildOnClickPopup() + "\"") ; 
    552         } 
    553         else 
    554         { 
    555                 // Check if the previous onclick was for a popup: 
    556                 // In that case remove the onclick handler. 
    557                 var onclick = oLink.getAttribute( 'onclick_fckprotectedatt' ) ; 
    558                 if( oRegex.OnClickPopup.test( onclick ) ) 
    559                         SetAttribute( oLink, 'onclick_fckprotectedatt', '' ) ; 
    560         } 
    561  
    562         oLink.innerHTML = sInnerHtml ;          // Set (or restore) the innerHTML 
    563  
    564         // Target 
    565         if( GetE('cmbTarget').value != 'popup' ) 
    566                 SetAttribute( oLink, 'target', GetE('txtTargetFrame').value ) ; 
    567         else 
    568                 SetAttribute( oLink, 'target', null ) ; 
    569  
    570         // Advances Attributes 
    571         SetAttribute( oLink, 'id'               , GetE('txtAttId').value ) ; 
    572         SetAttribute( oLink, 'name'             , GetE('txtAttName').value ) ; 
    573         SetAttribute( oLink, 'dir'              , GetE('cmbAttLangDir').value ) ; 
    574         SetAttribute( oLink, 'lang'             , GetE('txtAttLangCode').value ) ; 
    575         SetAttribute( oLink, 'accesskey', GetE('txtAttAccessKey').value ) ; 
    576         SetAttribute( oLink, 'tabindex' , ( GetE('txtAttTabIndex').value > 0 ? GetE('txtAttTabIndex').value : null ) ) ; 
    577         SetAttribute( oLink, 'title'    , GetE('txtAttTitle').value ) ; 
    578         SetAttribute( oLink, 'type'             , GetE('txtAttContentType').value ) ; 
    579         SetAttribute( oLink, 'charset'  , GetE('txtAttCharSet').value ) ; 
    580  
    581         if ( oEditor.FCKBrowserInfo.IsIE ) 
    582         { 
    583                 var sClass = GetE('txtAttClasses').value ; 
    584                 // If it's also an anchor add an internal class 
    585                 if ( GetE('txtAttName').value.length != 0 ) 
    586                         sClass += ' FCK__AnchorC' ; 
    587                 SetAttribute( oLink, 'className', sClass ) ; 
    588  
    589                 oLink.style.cssText = GetE('txtAttStyle').value ; 
    590         } 
    591         else 
    592         { 
    593                 SetAttribute( oLink, 'class', GetE('txtAttClasses').value ) ; 
    594                 SetAttribute( oLink, 'style', GetE('txtAttStyle').value ) ; 
    595         } 
    596  
    597         // Select the link. 
    598         oEditor.FCKSelection.SelectNode(oLink); 
     542        for ( var i = 0 ; i < aLinks.length ; i++ ) 
     543        { 
     544                oLink = aLinks[i] ; 
     545 
     546                if ( aHasSelection ) 
     547                        sInnerHtml = oLink.innerHTML ;          // Save the innerHTML (IE changes it if it is like an URL). 
     548 
     549                oLink.href = sUri ; 
     550                SetAttribute( oLink, '_fcksavedurl', sUri ) ; 
     551 
     552                // Accesible popups 
     553                if( GetE('cmbTarget').value == 'popup' ) 
     554                { 
     555                        SetAttribute( oLink, 'onclick_fckprotectedatt', " onclick=\"" + BuildOnClickPopup() + "\"") ; 
     556                } 
     557                else 
     558                { 
     559                        // Check if the previous onclick was for a popup: 
     560                        // In that case remove the onclick handler. 
     561                        var onclick = oLink.getAttribute( 'onclick_fckprotectedatt' ) ; 
     562                        if( oRegex.OnClickPopup.test( onclick ) ) 
     563                                SetAttribute( oLink, 'onclick_fckprotectedatt', '' ) ; 
     564                } 
     565 
     566                oLink.innerHTML = sInnerHtml ;          // Set (or restore) the innerHTML 
     567 
     568                // Target 
     569                if( GetE('cmbTarget').value != 'popup' ) 
     570                        SetAttribute( oLink, 'target', GetE('txtTargetFrame').value ) ; 
     571                else 
     572                        SetAttribute( oLink, 'target', null ) ; 
     573 
     574                // Let's set the "id" only for the first link to avoid duplication. 
     575                if ( i == 0 ) 
     576                        SetAttribute( oLink, 'id', GetE('txtAttId').value ) ; 
     577 
     578                // Advances Attributes 
     579                SetAttribute( oLink, 'name'             , GetE('txtAttName').value ) ; 
     580                SetAttribute( oLink, 'dir'              , GetE('cmbAttLangDir').value ) ; 
     581                SetAttribute( oLink, 'lang'             , GetE('txtAttLangCode').value ) ; 
     582                SetAttribute( oLink, 'accesskey', GetE('txtAttAccessKey').value ) ; 
     583                SetAttribute( oLink, 'tabindex' , ( GetE('txtAttTabIndex').value > 0 ? GetE('txtAttTabIndex').value : null ) ) ; 
     584                SetAttribute( oLink, 'title'    , GetE('txtAttTitle').value ) ; 
     585                SetAttribute( oLink, 'type'             , GetE('txtAttContentType').value ) ; 
     586                SetAttribute( oLink, 'charset'  , GetE('txtAttCharSet').value ) ; 
     587 
     588                if ( oEditor.FCKBrowserInfo.IsIE ) 
     589                { 
     590                        var sClass = GetE('txtAttClasses').value ; 
     591                        // If it's also an anchor add an internal class 
     592                        if ( GetE('txtAttName').value.length != 0 ) 
     593                                sClass += ' FCK__AnchorC' ; 
     594                        SetAttribute( oLink, 'className', sClass ) ; 
     595 
     596                        oLink.style.cssText = GetE('txtAttStyle').value ; 
     597                } 
     598                else 
     599                { 
     600                        SetAttribute( oLink, 'class', GetE('txtAttClasses').value ) ; 
     601                        SetAttribute( oLink, 'style', GetE('txtAttStyle').value ) ; 
     602                } 
     603        } 
     604 
     605        // Select the (first) link. 
     606        oEditor.FCKSelection.SelectNode( aLinks[0] ); 
    599607 
    600608        return true ; 
  • FCKeditor/trunk/editor/_source/internals/fck_gecko.js

    r308 r341  
    208208FCK.CreateLink = function( url ) 
    209209{ 
     210        // Creates the array that will be returned. It contains one or more created links (see #220). 
     211        var aCreatedLinks = new Array() ; 
     212 
    210213        FCK.ExecuteNamedCommand( 'Unlink' ) ; 
    211214 
     
    218221                FCK.ExecuteNamedCommand( 'CreateLink', sTempUrl ) ; 
    219222 
    220                 // Retrieve the just created link using XPath. 
    221                 var oLink = this.EditorDocument.evaluate("//a[@href='" + sTempUrl + "']", this.EditorDocument.body, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue ; 
    222  
    223                 if ( oLink ) 
     223                // Retrieve the just created links using XPath. 
     224                var oLinksInteractor = this.EditorDocument.evaluate("//a[@href='" + sTempUrl + "']", this.EditorDocument.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null) ; 
     225 
     226                // Add all links to the returning array. 
     227                for ( var i = 0 ; i < oLinksInteractor.snapshotLength ; i++ ) 
    224228                { 
     229                        var oLink = oLinksInteractor.snapshotItem( i ) ; 
    225230                        oLink.href = url ; 
    226                         return oLink ; 
     231                        aCreatedLinks.push( oLink ) ; 
    227232                } 
    228233        } 
    229234 
    230         return null ; 
    231 } 
     235        return aCreatedLinks ; 
     236} 
  • FCKeditor/trunk/editor/_source/internals/fck_ie.js

    r308 r341  
    349349FCK.CreateLink = function( url ) 
    350350{ 
     351        // Creates the array that will be returned. It contains one or more created links (see #220). 
     352        var aCreatedLinks = new Array() ; 
     353 
    351354        // Remove any existing link in the selection. 
    352355        FCK.ExecuteNamedCommand( 'Unlink' ) ; 
     
    370373                        oLink.appendChild( oControl ) ; 
    371374                         
    372                         return oLink ; 
     375                        return [ oLink ] ; 
    373376                } 
    374377 
     
    402405                                } 
    403406 
    404                                 return oLink ; 
     407                                aCreatedLinks.push( oLink ) ; 
    405408                        } 
    406409                } 
    407410        } 
    408411 
    409         return null ; 
    410 } 
     412        return aCreatedLinks ; 
     413} 
  • FCKeditor/trunk/_whatsnew.html

    r339 r341  
    117117                        with dimensions set as styles was opened with the image manager and then the dialog was 
    118118                        canceled the dimensions in the style were lost.</li> 
     119                <li>[<a target="_blank" href="http://dev.fckeditor.net/ticket/220">#220</a>] The creation 
     120                        of links or anchors in a selection that results on more than a single link created 
     121                        will not anymore leave temporary links in the source. All links will be defined 
     122                        as expected.</li> 
    119123        </ul> 
    120124        <h3>