Ticket #3582: 3582_5.patch

File 3582_5.patch, 14.0 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/dialog/plugin.js

     
    927927                                var editor = this._.editor;
    928928                                editor.focus();
    929929
    930                                 if ( editor.mode == 'wysiwyg' && CKEDITOR.env.ie )
     930                                if ( editor.mode == 'wysiwyg' )
    931931                                {
    932932                                        var selection = editor.getSelection();
    933933                                        selection && selection.unlock( true );
     
    29882988                         */
    29892989                        openDialog : function( dialogName, callback )
    29902990                        {
    2991                                 if ( this.mode == 'wysiwyg' && CKEDITOR.env.ie )
     2991                                if ( this.mode == 'wysiwyg' )
    29922992                                {
    29932993                                        var selection = this.getSelection();
    29942994                                        selection && selection.lock();
  • _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
    2117        return {
     
    2420                minHeight : 60,
    2521                onOk : function()
    2622                {
    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' );
    32 
    33                         // Move contents and attributes of old anchor to new anchor.
    34                         if ( this.editMode )
     23                        var name = this.getValueOf( 'info', 'txtName' );
     24                        var attributes =
    3525                        {
    36                                 this.editObj.copyAttributes( element, { name : 1 } );
    37                                 this.editObj.moveChildren( element );
    38                         }
     26                                name : name,
     27                                'data-cke-saved-name' : name
     28                        };
    3929
    40                         // Set name.
    41                         element.data( 'cke-saved-name', false );
    42                         element.setAttribute( 'name', name );
    43 
    44                         // Insert a new anchor.
    45                         var fakeElement = editor.createFakeElement( element, 'cke_anchor', 'anchor' );
    46                         if ( !this.editMode )
    47                                 editor.insertElement( fakeElement );
     30                        if ( this._.selectedElement )
     31                                this._.selectedElement.setAttributes( attributes );
    4832                        else
    4933                        {
    50                                 fakeElement.replace( this.fakeObj );
    51                                 editor.getSelection().selectElement( fakeElement );
     34                                // Apply style.
     35                                var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
     36                                style.type = CKEDITOR.STYLE_INLINE;
     37                                style.apply( editor.document );
    5238                        }
     39                },
    5340
    54                         return true;
     41                onHide : function()
     42                {
     43                        delete this._.selectedElement;
    5544                },
     45
    5646                onShow : function()
    5747                {
    58                         this.editObj = false;
    59                         this.fakeObj = false;
    60                         this.editMode = false;
     48                        var selection = editor.getSelection(),
     49                                fullySelected = selection.getSelectedElement(),
     50                                partialSelected;
    6151
    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' )
     52                        // Detect the anchor under selection.
     53                        if ( fullySelected && fullySelected.is( 'a' ) && fullySelected.hasAttribute( 'name' ) )
     54                                loadElements.call( this, fullySelected );
     55                        else
    6556                        {
    66                                 this.fakeObj = element;
    67                                 element = editor.restoreRealElement( this.fakeObj );
    68                                 loadElements.apply( this, [ editor, selection, element ] );
    69                                 selection.selectElement( this.fakeObj );
    70                         }
     57                                partialSelected = CKEDITOR.plugins.link.getSelectedLink( editor );
     58                                if ( partialSelected )
     59                                {
     60                                        loadElements.call( this, partialSelected );
     61                                        selection.selectElement( partialSelected );
     62                                }
     63                        }
     64
    7165                        this.getContentElement( 'info', 'txtName' ).focus();
    7266                },
    7367                contents : [
  • _source/plugins/wysiwygarea/plugin.js

     
    6262                if ( range.checkReadOnly() )
    6363                        return;
    6464
    65                 if ( CKEDITOR.env.ie )
    66                 {
    67                         var selIsLocked = selection.isLocked;
     65                var selIsLocked = selection.isLocked;
     66                selIsLocked && selection.unlock();
    6867
    69                         if ( selIsLocked )
    70                                 selection.unlock();
    71 
     68                if ( CKEDITOR.env.ie )
     69                {
    7270                        var $sel = selection.getNative();
    7371
    7472                        // Delete control selections to avoid IE bugs on pasteHTML.
     
    9997                        }
    10098                        catch (e) {}
    10199
    102                         if ( selIsLocked )
    103                                 this.getSelection().lock();
    104100                }
    105101                else
    106102                        this.document.$.execCommand( 'inserthtml', false, data );
    107103
     104                selIsLocked && this.getSelection().lock();
     105
    108106                // Webkit does not scroll to the cursor position after pasting (#5558)
    109107                if ( CKEDITOR.env.webkit )
    110108                {
     
    635633                                                        var element = evt.data.getTarget(),
    636634                                                                data = { element : element, dialog : '' };
    637635                                                        editor.fire( 'doubleclick', data );
    638                                                         data.dialog && editor.openDialog( data.dialog );
    639                                                 });
     636                                                        data.dialog && editor.openDialog( data.dialog, function()
     637                                                        {
     638                                                                // Fully embrace the element under click in the to-be-locked selection.
     639                                                                element && editor.getSelection().selectElement( element )
     640                                                        });
     641                                                });
    640642
    641643                                                // Prevent automatic submission in IE #6336
    642644                                                CKEDITOR.env.ie && domDocument.on( 'click', function( evt )
  • _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/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

     
    3131
    3232                // Add the CSS styles for anchor placeholders.
    3333                var side = editor.lang.dir == 'rtl' ? 'right' : 'left';
    34                 editor.addCss(
    35                         'img.cke_anchor' +
     34                var anchorCss =
    3635                        '{' +
    37                                 'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ');' +
    38                                 'background-position: center center;' +
    39                                 'background-repeat: no-repeat;' +
     36                                'background: url(' + CKEDITOR.getUrl( this.path + 'images/anchor.gif' ) + ') no-repeat ' + side + ' center;' +
    4037                                '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;' +
    5038                                'padding-' + side + ': 18px;' +
    51                         '}'
    52                         );
     39                        '}';
    5340
     41                var emptyAnchorCss = '{display:inline-block;height:18px;}';
     42
     43                editor.addCss( ( CKEDITOR.env.ie6Compat ? 'a.cke_anchor' : 'a[name]' ) + anchorCss );
     44                editor.addCss( ( CKEDITOR.env.ie6Compat ? 'a.cke_anchor' : CKEDITOR.env.ie7Compat? 'a[name]' : 'a[name]:empty' )+ emptyAnchorCss );
     45
    5446                // Register selection change handler for the unlink button.
    5547                 editor.on( 'selectionChange', function( evt )
    5648                        {
     
    141133                var dataProcessor = editor.dataProcessor,
    142134                        dataFilter = dataProcessor && dataProcessor.dataFilter;
    143135
    144                 if ( dataFilter )
     136                if ( dataFilter && CKEDITOR.env.ie6Compat )
    145137                {
    146138                        dataFilter.addRules(
    147139                                {
     
    149141                                        {
    150142                                                a : function( element )
    151143                                                {
    152                                                         var attributes = element.attributes;
    153                                                         if ( attributes.name && !attributes.href )
    154                                                                 return editor.createFakeParserElement( element, 'cke_anchor', 'anchor' );
     144                                                        var attributes = element.attributes,
     145                                                                cls = attributes[ 'class' ];
     146                                                        if ( attributes.name && ( !cls || cls.indexOf( 'cke_anchor' ) < 0 ) )
     147                                                                attributes[ 'class' ] = ( cls || '' ) + ' cke_anchor';
    155148                                                }
    156149                                        }
    157150                                });
     
    240233        linkShowAdvancedTab : true,
    241234        linkShowTargetTab : true
    242235} );
     236
     237// Present a[name] as "cke_anchor" in IE6.
     238CKEDITOR.env.ie6Compat && ( function()
     239{
     240        function markAnchor( org )
     241        {
     242                var attrGet = org == elementProto.getAttribute;
     243
     244                return function( name, val )
     245                {
     246                        if ( this.getDocument().equals( CKEDITOR.document ) )
     247                                return org.apply( this, arguments );
     248
     249                        var retval = org.apply( this, arguments );
     250                        if ( this.is( 'a' ) )
     251                        {
     252                                if ( name == 'name' )
     253                                        this[ val ? 'addClass' : 'removeClass' ]( 'cke_anchor' );
     254                                else if ( name == 'class' && this.$.getAttribute( 'name' ) )
     255                                        attrGet ? retval = retval.replace( /\s*cke_anchor\s*/, '' ) : this.addClass( 'cke_anchor' );
     256                        }
     257                        return retval;
     258                };
     259        }
     260
     261        var elementProto = CKEDITOR.dom.element.prototype,
     262                methods = [ 'getAttribute','setAttribute', 'removeAttribute' ];
     263        for ( var i = 0; i < methods.length; i++ )
     264                elementProto[ methods[ i ] ] = CKEDITOR.tools.override( elementProto[ methods [ i ] ], markAnchor );
     265
     266} )();
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy