Ticket #3582: 3582.patch

File 3582.patch, 5.8 KB (added by alfonsoml, 19 months ago)

Proposed patch

  • _source/plugins/link/dialogs/anchor.js

     
    2626                { 
    2727                        // Always create a new anchor, because of IE BUG. 
    2828                        var name = this.getValueOf( 'info', 'txtName' ), 
    29                                 element = CKEDITOR.env.ie ? 
    30                                 editor.document.createElement( '<a name="' + CKEDITOR.tools.htmlEncode( name ) + '">' ) : 
    31                                 editor.document.createElement( 'a' ); 
     29                                element = CKEDITOR.env.ie6Compat ? 
     30                                        editor.document.createElement( '<a name="' + CKEDITOR.tools.htmlEncode( name ) + '">' ) : 
     31                                        editor.document.createElement( 'a' ), 
     32                                fakeElement, 
     33                                selection, 
     34                                ranges, 
     35                                tmpId, 
     36                                style, 
     37                                created; 
    3238 
    3339                        // Move contents and attributes of old anchor to new anchor. 
    3440                        if ( this.editMode ) 
     
    3642                                this.editObj.copyAttributes( element, { name : 1 } ); 
    3743                                this.editObj.moveChildren( element ); 
    3844                        } 
     45                        else 
     46                        { 
     47                                // Put selected text inside the anchor 
     48                                selection = editor.getSelection(); 
     49                                ranges = selection.getRanges( true ); 
     50                                if ( ranges.length == 1 && !ranges[0].collapsed ) 
     51                                { 
     52                                        tmpId = 'tmp' + CKEDITOR.tools.getNextNumber(); 
     53                                        style = new CKEDITOR.style( { element : 'a', attributes : {'id': tmpId} } ); 
     54                                        style.type = CKEDITOR.STYLE_INLINE; 
     55                                        style.apply( editor.document ); 
     56                                        created = editor.document.getById( tmpId ); 
     57                                        created.moveChildren( element ); 
    3958 
     59                                        selection.selectElement( created ); 
     60                                } 
     61                        } 
     62 
    4063                        // Set name. 
    4164                        element.removeAttribute( '_cke_saved_name' ); 
    4265                        element.setAttribute( 'name', name ); 
    4366 
    44                         // Insert a new anchor. 
    45                         var fakeElement = editor.createFakeElement( element, 'cke_anchor', 'anchor' ); 
    46                         if ( !this.editMode ) 
    47                                 editor.insertElement( fakeElement ); 
     67                        if ( element.$.childNodes.length==0 && ( !CKEDITOR.env.gecko ) ) 
     68                        { 
     69                                fakeElement = editor.createFakeElement( element, 'cke_anchor', 'anchor' ); 
     70                                // Insert a new anchor. 
     71                                if ( !this.editMode ) 
     72                                        editor.insertElement( fakeElement ); 
     73                                else 
     74                                { 
     75                                        fakeElement.replace( this.fakeObj ); 
     76                                        editor.getSelection().selectElement( fakeElement ); 
     77                                } 
     78                        } 
    4879                        else 
    4980                        { 
    50                                 fakeElement.replace( this.fakeObj ); 
    51                                 editor.getSelection().selectElement( fakeElement ); 
     81                                element.addClass( 'cke_anchor' ); 
     82                                if ( !this.editMode ) 
     83                                        editor.insertElement( element ); 
     84                                else 
     85                                { 
     86                                        element.replace( this.editObj ); 
     87                                        editor.getSelection().selectElement( element ); 
     88                                } 
    5289                        } 
    5390 
    5491                        return true; 
    5592                }, 
    5693                onShow : function() 
    5794                { 
    58                         this.editObj = false; 
    59                         this.fakeObj = false; 
    60                         this.editMode = false; 
     95                        this.editObj = this.fakeObj = this.editMode = false; 
    6196 
    62                         var selection = editor.getSelection(); 
    63                         var element = selection.getSelectedElement(); 
     97                        var selection = editor.getSelection(), 
     98                                element = selection.getSelectedElement(), 
     99                                link; 
     100 
    64101                        if ( element && element.getAttribute( '_cke_real_element_type' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 
    65102                        { 
    66103                                this.fakeObj = element; 
     
    68105                                loadElements.apply( this, [ editor, selection, element ] ); 
    69106                                selection.selectElement( this.fakeObj ); 
    70107                        } 
     108                        else 
     109                        { 
     110                                link = CKEDITOR.plugins.link.getSelectedLink( editor ); 
     111                                if ( link ) 
     112                                { 
     113                                        element = link; 
     114                                        loadElements.apply( this, [ editor, selection, element ] ); 
     115                                        selection.selectElement( link ); 
     116                                } 
     117                        } 
    71118                        this.getContentElement( 'info', 'txtName' ).focus(); 
    72119                }, 
    73120                contents : [ 
  • _source/plugins/link/plugin.js

     
    3030                CKEDITOR.dialog.add( 'anchor', this.path + 'dialogs/anchor.js' ); 
    3131 
    3232                // Add the CSS styles for anchor placeholders. 
     33                var background = 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' + 
     34                                'background-repeat: no-repeat;' + 
     35                                'border: 1px solid #a9a9a9;', 
     36                        anchorCss = '{' + 
     37                                background + 
     38                                'background-position: 0 center;' + 
     39                                'padding-left: 18px;' + 
     40                        '}'; 
     41 
    3342                editor.addCss( 
    3443                        'img.cke_anchor' + 
    3544                        '{' + 
    36                                 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' + 
     45                                background + 
    3746                                'background-position: center center;' + 
    38                                 'background-repeat: no-repeat;' + 
    39                                 'border: 1px solid #a9a9a9;' + 
    4047                                'width: 18px !important;' + 
    4148                                'height: 18px !important;' + 
    4249                        '}\n' + 
    4350                        'a.cke_anchor' + 
    44                         '{' + 
    45                                 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' + 
    46                                 'background-position: 0 center;' + 
    47                                 'background-repeat: no-repeat;' + 
    48                                 'border: 1px solid #a9a9a9;' + 
    49                                 'padding-left: 18px;' + 
    50                         '}' 
     51                        anchorCss + 
     52                        'a[name]' + 
     53                        anchorCss 
    5154                        ); 
    5255 
    5356                // Register selection change handler for the unlink button. 
     
    137140                var dataProcessor = editor.dataProcessor, 
    138141                        dataFilter = dataProcessor && dataProcessor.dataFilter; 
    139142 
    140                 if ( dataFilter ) 
     143                if ( dataFilter && ( !CKEDITOR.env.gecko ) ) 
    141144                { 
    142145                        dataFilter.addRules( 
    143146                                { 
     
    147150                                                { 
    148151                                                        var attributes = element.attributes; 
    149152                                                        if ( attributes.name && !attributes.href ) 
    150                                                                 return editor.createFakeParserElement( element, 'cke_anchor', 'anchor' ); 
     153                                                        { 
     154                                                                if (element.children.length==0) 
     155                                                                        return editor.createFakeParserElement( element, 'cke_anchor', 'anchor' ); 
     156                                                                attributes['class'] = (attributes['class'] || '') + ' cke_anchor'; 
     157                                                        } 
    151158                                                } 
    152159                                        } 
    153160                                }); 
© 2003 – 2011 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy