Ticket #3582: 3582_9.patch

File 3582_9.patch, 16.9 KB (added by fredck, 13 months ago)
  • _source/plugins/elementspath/plugin.js

     
    124124 
    125125                                        while ( element ) 
    126126                                        { 
    127                                                 var ignore = 0; 
     127                                                var ignore = 0, 
     128                                                        name; 
     129 
     130                                                if ( element.data( 'cke-real-element-type' ) ) 
     131                                                        name = element.data( 'cke-real-element-type' ); 
     132                                                else 
     133                                                        name = element.getName(); 
     134 
    128135                                                for ( var i = 0; i < filters.length; i++ ) 
    129136                                                { 
    130                                                         if ( filters[ i ]( element ) === false ) 
     137                                                        var ret = filters[ i ]( element, name ); 
     138                                                        if ( ret === false ) 
    131139                                                        { 
    132140                                                                ignore = 1; 
    133141                                                                break; 
    134142                                                        } 
     143                                                        name = ret || name; 
    135144                                                } 
    136145 
    137146                                                if ( !ignore ) 
    138147                                                { 
    139148                                                        var index = elementsList.push( element ) - 1; 
    140                                                         var name; 
    141                                                         if ( element.data( 'cke-real-element-type' ) ) 
    142                                                                 name = element.data( 'cke-real-element-type' ); 
    143                                                         else 
    144                                                                 name = element.getName(); 
    145149 
    146150                                                        // Use this variable to add conditional stuff to the 
    147151                                                        // HTML (because we are doing it in reverse order... unshift). 
  • _source/plugins/htmldataprocessor/plugin.js

     
    9595        delete blockLikeTags.pre; 
    9696        var defaultDataFilterRules = 
    9797        { 
    98                 elements : { 
    99                         a : function( element ) 
    100                         { 
    101                                 var attrs = element.attributes; 
    102                                 if ( attrs && attrs[ 'data-cke-saved-name' ] ) 
    103                                         attrs[ 'class' ] = ( attrs[ 'class' ] ? attrs[ 'class' ] + ' ' : '' ) + 'cke_anchor'; 
    104                         } 
    105                 }, 
     98                elements : {}, 
    10699                attributeNames : 
    107100                [ 
    108101                        // Event attributes (onXYZ) must not be directly set. They can become 
  • _source/plugins/link/dialogs/anchor.js

     
    66CKEDITOR.dialog.add( 'anchor', function( editor ) 
    77{ 
    88        // Function called in onShow to load selected element. 
    9         var loadElements = function( editor, selection, element ) 
     9        var loadElements = function( element ) 
    1010        { 
    11                 this.editMode = true; 
    12                 this.editObj = element; 
     11                this._.selectedElement = element; 
    1312 
    14                 var attributeValue = this.editObj.getAttribute( 'name' ); 
    15                 if ( attributeValue ) 
    16                         this.setValueOf( 'info','txtName', attributeValue ); 
    17                 else 
    18                         this.setValueOf( 'info','txtName', "" ); 
     13                var attributeValue = element.data( 'cke-saved-name' ); 
     14                this.setValueOf( 'info','txtName', attributeValue || '' ); 
    1915        }; 
    2016 
     17        function createFakeAnchor( editor, anchor ) 
     18        { 
     19                return editor.createFakeElement( anchor, 'cke_anchor', 'a' ); 
     20        } 
     21 
    2122        return { 
    2223                title : editor.lang.anchor.title, 
    2324                minWidth : 300, 
    2425                minHeight : 60, 
    2526                onOk : function() 
    2627                { 
    27                         // Always create a new anchor, because of IE BUG. 
    28                         var name = this.getValueOf( 'info', 'txtName' ), 
    29                                 element = CKEDITOR.env.ie && !( CKEDITOR.document.$.documentMode >= 8 ) ? 
    30                                 editor.document.createElement( '<a name="' + CKEDITOR.tools.htmlEncode( name ) + '">' ) : 
    31                                 editor.document.createElement( 'a' ); 
     28                        var name = this.getValueOf( 'info', 'txtName' ); 
     29                        var attributes = 
     30                        { 
     31                                name : name, 
     32                                'data-cke-saved-name' : name 
     33                        }; 
    3234 
    33                         // Move contents and attributes of old anchor to new anchor. 
    34                         if ( this.editMode ) 
     35                        if ( this._.selectedElement ) 
    3536                        { 
    36                                 this.editObj.copyAttributes( element, { name : 1 } ); 
    37                                 this.editObj.moveChildren( element ); 
     37                                if ( this._.selectedElement.data( 'cke-realelement' ) ) 
     38                                { 
     39                                        var newFake = createFakeAnchor( editor, editor.document.createElement( 'a', { attributes: attributes } ) ); 
     40                                        newFake.replace( this._.selectedElement ); 
     41                                } 
     42                                else 
     43                                        this._.selectedElement.setAttributes( attributes ); 
    3844                        } 
     45                        else 
     46                        { 
     47                                var sel = editor.getSelection(), 
     48                                                range = sel && sel.getRanges()[ 0 ]; 
    3949 
    40                         // Set name. 
    41                         element.data( 'cke-saved-name', false ); 
    42                         element.setAttribute( 'name', name ); 
     50                                // Empty anchor 
     51                                if ( range.collapsed ) 
     52                                { 
     53                                        var anchor = editor.document.createElement( 'a', { attributes: attributes } ); 
    4354 
    44                         // Insert a new anchor. 
    45                         var fakeElement = editor.createFakeElement( element, 'cke_anchor', 'anchor' ); 
    46                         if ( !this.editMode ) 
    47                                 editor.insertElement( fakeElement ); 
    48                         else 
    49                         { 
    50                                 fakeElement.replace( this.fakeObj ); 
    51                                 editor.getSelection().selectElement( fakeElement ); 
     55                                        // IE needs the anchor to have a special class. 
     56                                        if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) 
     57                                        { 
     58                                                anchor.addClass( 'cke_anchor_empty' ); 
     59 
     60                                                if ( CKEDITOR.env.version < 8 ) 
     61                                                        anchor.setAttribute( 'contentEditable', 'false' ); 
     62                                        } 
     63 
     64                                        // Transform the anchor into a fake element for browsers that need it. 
     65                                        if ( CKEDITOR.plugins.link.fakeAnchor ) 
     66                                                anchor = createFakeAnchor( editor, anchor ); 
     67 
     68                                        range.insertNode( anchor ); 
     69                                } 
     70                                else 
     71                                { 
     72                                        // Apply style. 
     73                                        var style = new CKEDITOR.style( { element : 'a', attributes : attributes } ); 
     74                                        style.type = CKEDITOR.STYLE_INLINE; 
     75                                        style.apply( editor.document ); 
     76                                } 
    5277                        } 
     78                }, 
    5379 
    54                         return true; 
     80                onHide : function() 
     81                { 
     82                        delete this._.selectedElement; 
    5583                }, 
     84 
    5685                onShow : function() 
    5786                { 
    58                         this.editObj = false; 
    59                         this.fakeObj = false; 
    60                         this.editMode = false; 
     87                        var selection = editor.getSelection(), 
     88                                fullySelected = selection.getSelectedElement(), 
     89                                partialSelected; 
    6190 
    62                         var selection = editor.getSelection(); 
    63                         var element = selection.getSelectedElement(); 
    64                         if ( element && element.data( 'cke-real-element-type' ) && element.data( 'cke-real-element-type' ) == 'anchor' ) 
     91                        // Detect the anchor under selection. 
     92                        if ( fullySelected ) 
    6593                        { 
    66                                 this.fakeObj = element; 
    67                                 element = editor.restoreRealElement( this.fakeObj ); 
    68                                 loadElements.apply( this, [ editor, selection, element ] ); 
    69                                 selection.selectElement( this.fakeObj ); 
     94                                if ( CKEDITOR.plugins.link.fakeAnchor ) 
     95                                { 
     96                                        var realElement = CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, fullySelected ); 
     97                                        realElement && loadElements.call( this, realElement ); 
     98                                        this._.selectedElement = fullySelected; 
     99                                } 
     100                                else if ( fullySelected.is( 'a' ) && fullySelected.hasAttribute( 'name' ) ) 
     101                                        loadElements.call( this, fullySelected ); 
    70102                        } 
     103                        else 
     104                        { 
     105                                partialSelected = CKEDITOR.plugins.link.getSelectedLink( editor ); 
     106                                if ( partialSelected ) 
     107                                { 
     108                                        loadElements.call( this, partialSelected ); 
     109                                        selection.selectElement( partialSelected ); 
     110                                } 
     111                        } 
     112 
    71113                        this.getContentElement( 'info', 'txtName' ).focus(); 
    72114                }, 
    73115                contents : [ 
  • _source/plugins/link/dialogs/link.js

     
    242242                } 
    243243 
    244244                // Find out whether we have any anchors in the editor. 
    245                 // Get all IMG elements in CK document. 
    246                 var elements = editor.document.getElementsByTag( 'img' ), 
    247                         realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ), 
    248                         anchors = retval.anchors = []; 
     245                var anchorList = new CKEDITOR.dom.nodeList( editor.document.$.anchors ), 
     246                        anchors = retval.anchors = [], 
     247                        item; 
    249248 
    250                 for ( var i = 0; i < elements.count() ; i++ ) 
     249                for ( var i = 0, count = anchorList.count(); i < count; i++ ) 
    251250                { 
    252                         var item = elements.getItem( i ); 
    253                         if ( item.data( 'cke-realelement' ) && item.data( 'cke-real-element-type' ) == 'anchor' ) 
    254                                 anchors.push( editor.restoreRealElement( item ) ); 
    255                 } 
    256  
    257                 for ( i = 0 ; i < realAnchors.count() ; i++ ) 
    258                         anchors.push( realAnchors.getItem( i ) ); 
    259  
    260                 for ( i = 0 ; i < anchors.length ; i++ ) 
    261                 { 
    262                         item = anchors[ i ]; 
     251                        item = anchorList.getItem( i ); 
    263252                        anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) }; 
    264253                } 
    265254 
    266255                // Record down the selected element in the dialog. 
    267256                this._.selectedElement = element; 
    268  
    269257                return retval; 
    270258        }; 
    271259 
     
    11511139                ], 
    11521140                onShow : function() 
    11531141                { 
    1154                         this.fakeObj = false; 
    1155  
    11561142                        var editor = this.getParentEditor(), 
    11571143                                selection = editor.getSelection(), 
    11581144                                element = null; 
     
    11601146                        // Fill in all the relevant fields if there's already one link selected. 
    11611147                        if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) ) 
    11621148                                selection.selectElement( element ); 
    1163                         else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' ) 
    1164                                         && element.data( 'cke-real-element-type' ) 
    1165                                         && element.data( 'cke-real-element-type' ) == 'anchor' ) 
    1166                         { 
    1167                                 this.fakeObj = element; 
    1168                                 element = editor.restoreRealElement( this.fakeObj ); 
    1169                                 selection.selectElement( this.fakeObj ); 
    1170                         } 
    11711149                        else 
    11721150                                element = null; 
    11731151 
     
    13021280                                advAttr( 'advAccessKey', 'accessKey' ); 
    13031281 
    13041282                                if ( data.adv[ 'advName' ] ) 
    1305                                 { 
    13061283                                        attributes[ 'name' ] = attributes[ 'data-cke-saved-name' ] = data.adv[ 'advName' ]; 
    1307                                         attributes[ 'class' ] = ( attributes[ 'class' ] ? attributes[ 'class' ] + ' ' : '' ) + 'cke_anchor'; 
    1308                                 } 
    13091284                                else 
    13101285                                        removeAttributes = removeAttributes.concat( [ 'data-cke-saved-name', 'name' ] ); 
    13111286 
     
    13501325                                        href = element.data( 'cke-saved-href' ), 
    13511326                                        textView = element.getHtml(); 
    13521327 
    1353                                 // IE BUG: Setting the name attribute to an existing link doesn't work. 
    1354                                 // Must re-create the link from weired syntax to workaround. 
    1355                                 if ( CKEDITOR.env.ie && !( CKEDITOR.document.$.documentMode >= 8 ) && attributes.name != element.getAttribute( 'name' ) ) 
    1356                                 { 
    1357                                         var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">', 
    1358                                                         editor.document ); 
    1359  
    1360                                         selection = editor.getSelection(); 
    1361  
    1362                                         element.copyAttributes( newElement, { name : 1 } ); 
    1363                                         element.moveChildren( newElement ); 
    1364                                         newElement.replace( element ); 
    1365                                         element = newElement; 
    1366  
    1367                                         selection.selectElement( element ); 
    1368                                 } 
    1369  
    13701328                                element.setAttributes( attributes ); 
    13711329                                element.removeAttributes( removeAttributes ); 
    13721330                                // Update text view when user changes protocol (#4612). 
     
    13761334                                        element.setHtml( data.type == 'email' ? 
    13771335                                                data.email.address : attributes[ 'data-cke-saved-href' ] ); 
    13781336                                } 
    1379                                 // Make the element display as an anchor if a name has been set. 
    1380                                 if ( element.getAttribute( 'name' ) ) 
    1381                                         element.addClass( 'cke_anchor' ); 
    1382                                 else 
    1383                                         element.removeClass( 'cke_anchor' ); 
    13841337 
    1385                                 if ( this.fakeObj ) 
    1386                                         editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj ); 
    1387  
    13881338                                delete this._.selectedElement; 
    13891339                        } 
    13901340                }, 
  • _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 side = editor.lang.dir == 'rtl' ? 'right' : 'left'; 
     33 
     34                var side = ( editor.lang.dir == 'rtl' ? 'right' : 'left' ); 
     35                var basicCss =  
     36                        'background:url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ') no-repeat ' + side + ' center;' + 
     37                        'border:1px dotted #00f;'; 
     38 
    3439                editor.addCss( 
     40                        'a.cke_anchor,a.cke_anchor_empty' + 
     41                        // IE6 breaks with the following selectors. 
     42                        ( ( CKEDITOR.env.ie && CKEDITOR.env.version < 7 ) ? '' : 
     43                                ',a[name],a[data-cke-saved-name]' ) + 
     44                        '{' + 
     45                                basicCss + 
     46                                'padding-' + side + ':18px;' + 
     47                                // Show the arrow cursor for the anchor image (FF at least). 
     48                                'cursor:auto;' + 
     49                        '}' + 
     50                        ( ( CKEDITOR.env.ie && CKEDITOR.env.version > 8 ) ? 'a[name]:empty,' : '' ) + 
     51                        'a.cke_anchor_empty' + 
     52                        '{' + 
     53                                // Make empty anchor selectable on IE. 
     54                                'display:inline-block;' + 
     55                        '}' + 
    3556                        'img.cke_anchor' + 
    3657                        '{' + 
    37                                 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' + 
    38                                 'background-position: center center;' + 
    39                                 'background-repeat: no-repeat;' + 
    40                                 'border: 1px solid #a9a9a9;' + 
    41                                 'width: 18px !important;' + 
    42                                 'height: 18px !important;' + 
    43                         '}\n' + 
    44                         'a.cke_anchor' + 
    45                         '{' + 
    46                                 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' + 
    47                                 'background-position: ' + side + ' center;' + 
    48                                 'background-repeat: no-repeat;' + 
    49                                 'border: 1px solid #a9a9a9;' + 
    50                                 'padding-' + side + ': 18px;' + 
    51                         '}' 
    52                         ); 
     58                                basicCss + 
     59                                'width:16px;' + 
     60                                'min-height:15px;' + 
     61                                // The default line-height on IE. 
     62                                'height:1.15em;' + 
     63                                // Opera works better with "middle" (even if not perfect) 
     64                                'vertical-align:' + ( CKEDITOR.env.opera ? 'middle' : 'text-bottom' ) + ';' + 
     65                        '}'); 
    5366 
    5467                // Register selection change handler for the unlink button. 
    5568                 editor.on( 'selectionChange', function( evt ) 
     
    7386                                if ( !element.isReadOnly() ) 
    7487                                { 
    7588                                        if ( element.is( 'a' ) ) 
    76                                                 evt.data.dialog =  ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) ) ? 'anchor' : 'link'; 
    77                                         else if ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'anchor' ) 
     89                                        { 
     90                                                evt.data.dialog = ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) ) ? 'anchor' : 'link'; 
     91                                                editor.getSelection().selectElement( element ); 
     92                                        } 
     93                                        else if ( CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, element ) ) 
    7894                                                evt.data.dialog = 'anchor'; 
    7995                                } 
    8096                        }); 
     
    117133                                        if ( !element || element.isReadOnly() ) 
    118134                                                return null; 
    119135 
    120                                         var isAnchor = ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'anchor' ); 
     136                                        var isAnchor = CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, element ); 
    121137 
    122138                                        if ( !isAnchor ) 
    123139                                        { 
     
    139155                // Register a filter to displaying placeholders after mode change. 
    140156 
    141157                var dataProcessor = editor.dataProcessor, 
    142                         dataFilter = dataProcessor && dataProcessor.dataFilter; 
     158                        dataFilter = dataProcessor && dataProcessor.dataFilter, 
     159                        htmlFilter = dataProcessor && dataProcessor.htmlFilter, 
     160                        pathFilters = editor._.elementsPath.filters; 
    143161 
    144162                if ( dataFilter ) 
    145163                { 
     
    150168                                                a : function( element ) 
    151169                                                { 
    152170                                                        var attributes = element.attributes; 
    153                                                         if ( attributes.name && !attributes.href ) 
    154                                                                 return editor.createFakeParserElement( element, 'cke_anchor', 'anchor' ); 
     171                                                        if ( !attributes.name ) 
     172                                                                return; 
     173 
     174                                                        var isEmpty = !element.children.length; 
     175 
     176                                                        if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) 
     177                                                        { 
     178                                                                // IE needs a specific class name to be applied 
     179                                                                // to the anchors, for appropriate styling. 
     180                                                                var ieClass = isEmpty ? 'cke_anchor_empty' : 'cke_anchor'; 
     181                                                                var cls = attributes[ 'class' ]; 
     182                                                                if ( attributes.name && ( !cls || cls.indexOf( ieClass ) < 0 ) ) 
     183                                                                        attributes[ 'class' ] = ( cls || '' ) + ' ' + ieClass; 
     184 
     185                                                                if ( isEmpty && CKEDITOR.env.version < 8 ) 
     186                                                                { 
     187                                                                        attributes.contenteditable = 'false'; 
     188                                                                        attributes[ 'data-cke-editable' ] = 1; 
     189                                                                } 
     190                                                        } 
     191                                                        else if ( CKEDITOR.plugins.link.fakeAnchor && isEmpty ) 
     192                                                                return editor.createFakeParserElement( element, 'cke_anchor', 'a' ); 
    155193                                                } 
    156194                                        } 
    157195                                }); 
    158196                } 
     197 
     198                if ( CKEDITOR.env.ie && htmlFilter ) 
     199                { 
     200                        htmlFilter.addRules( 
     201                                { 
     202                                        elements : 
     203                                        { 
     204                                                a : function( element ) 
     205                                                { 
     206                                                        delete element.attributes.contenteditable; 
     207                                                } 
     208                                        } 
     209                                }); 
     210                } 
     211 
     212                if ( pathFilters ) 
     213                { 
     214                        pathFilters.push( function( element, name ) 
     215                                { 
     216                                        if ( name == 'a' ) 
     217                                        { 
     218                                                if ( CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, element ) ||  
     219                                                        ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) ) ) 
     220                                                { 
     221                                                        return 'anchor'; 
     222                                                } 
     223                                        } 
     224                                }); 
     225                } 
    159226        }, 
    160227 
    161228        requires : [ 'fakeobjects' ] 
     
    196263                        return root.getAscendant( 'a', true ); 
    197264                } 
    198265                catch( e ) { return null; } 
     266        }, 
     267 
     268        // Opera and WebKit don't make it possible to select empty anchors. Fake 
     269        // elements must be used for them. 
     270        fakeAnchor : CKEDITOR.env.opera || CKEDITOR.env.webkit, 
     271 
     272        tryRestoreFakeAnchor : function( editor, element ) 
     273        { 
     274                if ( element && element.data( 'cke-real-element-type' ) && element.data( 'cke-real-element-type' ) == 'a' ) 
     275                { 
     276                        var link  = editor.restoreRealElement( element ); 
     277                        if ( link.data( 'cke-saved-name' ) ) 
     278                                return link; 
     279                } 
    199280        } 
    200281}; 
    201282 
© 2003 – 2011 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy