Ticket #3582: 3582_8.patch

File 3582_8.patch, 16.7 KB (added by Frederico Caldeira Knabben, 13 years 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 )
     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                        'a.cke_anchor_empty' +
     51                        '{' +
     52                                // Make empty anchor selectable on IE.
     53                                'display:inline-block;' +
     54                        '}' +
    3555                        'img.cke_anchor' +
    3656                        '{' +
    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                         );
     57                                basicCss +
     58                                'width:16px;' +
     59                                'min-height:15px;' +
     60                                // The default line-height on IE.
     61                                'height:1.15em;' +
     62                                // Opera works better with "middle" (even if not perfect)
     63                                'vertical-align:' + ( CKEDITOR.env.opera ? 'middle' : 'text-bottom' ) + ';' +
     64                        '}');
    5365
    5466                // Register selection change handler for the unlink button.
    5567                 editor.on( 'selectionChange', function( evt )
     
    7385                                if ( !element.isReadOnly() )
    7486                                {
    7587                                        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' )
     88                                        {
     89                                                evt.data.dialog = ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) ) ? 'anchor' : 'link';
     90                                                editor.getSelection().selectElement( element );
     91                                        }
     92                                        else if ( CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, element ) )
    7893                                                evt.data.dialog = 'anchor';
    7994                                }
    8095                        });
     
    117132                                        if ( !element || element.isReadOnly() )
    118133                                                return null;
    119134
    120                                         var isAnchor = ( element.is( 'img' ) && element.data( 'cke-real-element-type' ) == 'anchor' );
     135                                        var isAnchor = CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, element );
    121136
    122137                                        if ( !isAnchor )
    123138                                        {
     
    139154                // Register a filter to displaying placeholders after mode change.
    140155
    141156                var dataProcessor = editor.dataProcessor,
    142                         dataFilter = dataProcessor && dataProcessor.dataFilter;
     157                        dataFilter = dataProcessor && dataProcessor.dataFilter,
     158                        htmlFilter = dataProcessor && dataProcessor.htmlFilter,
     159                        pathFilters = editor._.elementsPath.filters;
    143160
    144161                if ( dataFilter )
    145162                {
     
    150167                                                a : function( element )
    151168                                                {
    152169                                                        var attributes = element.attributes;
    153                                                         if ( attributes.name && !attributes.href )
    154                                                                 return editor.createFakeParserElement( element, 'cke_anchor', 'anchor' );
     170                                                        if ( !attributes.name )
     171                                                                return;
     172
     173                                                        var isEmpty = !element.children.length;
     174
     175                                                        if ( CKEDITOR.env.ie )
     176                                                        {
     177                                                                // IE needs a specific class name to be applied
     178                                                                // to the anchors, for appropriate styling.
     179                                                                var ieClass = isEmpty ? 'cke_anchor_empty' : 'cke_anchor';
     180                                                                var cls = attributes[ 'class' ];
     181                                                                if ( attributes.name && ( !cls || cls.indexOf( ieClass ) < 0 ) )
     182                                                                        attributes[ 'class' ] = ( cls || '' ) + ' ' + ieClass;
     183
     184                                                                if ( isEmpty && CKEDITOR.env.version < 8 )
     185                                                                {
     186                                                                        attributes.contenteditable = 'false';
     187                                                                        attributes[ 'data-cke-editable' ] = 1;
     188                                                                }
     189                                                        }
     190                                                        else if ( CKEDITOR.plugins.link.fakeAnchor && isEmpty )
     191                                                                return editor.createFakeParserElement( element, 'cke_anchor', 'a' );
    155192                                                }
    156193                                        }
    157194                                });
    158195                }
     196
     197                if ( CKEDITOR.env.ie && htmlFilter )
     198                {
     199                        htmlFilter.addRules(
     200                                {
     201                                        elements :
     202                                        {
     203                                                a : function( element )
     204                                                {
     205                                                        delete element.attributes.contenteditable;
     206                                                }
     207                                        }
     208                                });
     209                }
     210
     211                if ( pathFilters )
     212                {
     213                        pathFilters.push( function( element, name )
     214                                {
     215                                        if ( name == 'a' )
     216                                        {
     217                                                if ( CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, element ) ||
     218                                                        ( element.getAttribute( 'name' ) && !element.getAttribute( 'href' ) ) )
     219                                                {
     220                                                        return 'anchor';
     221                                                }
     222                                        }
     223                                });
     224                }
    159225        },
    160226
    161227        requires : [ 'fakeobjects' ]
     
    196262                        return root.getAscendant( 'a', true );
    197263                }
    198264                catch( e ) { return null; }
     265        },
     266
     267        // Opera and WebKit don't make it possible to select empty anchors. Fake
     268        // elements must be used for them.
     269        fakeAnchor : CKEDITOR.env.opera || CKEDITOR.env.webkit,
     270
     271        tryRestoreFakeAnchor : function( editor, element )
     272        {
     273                if ( element && element.data( 'cke-real-element-type' ) && element.data( 'cke-real-element-type' ) == 'a' )
     274                {
     275                        var link  = editor.restoreRealElement( element );
     276                        if ( link.data( 'cke-saved-name' ) )
     277                                return link;
     278                }
    199279        }
    200280};
    201281
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy