X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fplugins%2Flink%2Fdialogs%2Flink.js;h=a6596169d046d380e35028fedeefa790e7edfba1;hb=4e70ea24db840898be8cc21c950363a52a2a6aba;hp=94ee042e9ba10b218a5f7ef0807f108c3e1bd856;hpb=1056598c95187351dc58f4991d331e2258d038b5;p=ckeditor.git diff --git a/_source/plugins/link/dialogs/link.js b/_source/plugins/link/dialogs/link.js index 94ee042..a659616 100644 --- a/_source/plugins/link/dialogs/link.js +++ b/_source/plugins/link/dialogs/link.js @@ -235,37 +235,27 @@ CKEDITOR.dialog.add( 'link', function( editor ) advAttr( 'advTabIndex', 'tabindex' ); advAttr( 'advTitle', 'title' ); advAttr( 'advContentType', 'type' ); - advAttr( 'advCSSClasses', 'class' ); + CKEDITOR.plugins.link.synAnchorSelector ? + retval.adv.advCSSClasses = getLinkClass( element ) + : advAttr( 'advCSSClasses', 'class' ); advAttr( 'advCharset', 'charset' ); advAttr( 'advStyles', 'style' ); advAttr( 'advRel', 'rel' ); } // Find out whether we have any anchors in the editor. - // Get all IMG elements in CK document. - var elements = editor.document.getElementsByTag( 'img' ), - realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ), - anchors = retval.anchors = []; + var anchorList = new CKEDITOR.dom.nodeList( editor.document.$.anchors ), + anchors = retval.anchors = [], + item; - for ( var i = 0; i < elements.count() ; i++ ) + for ( var i = 0, count = anchorList.count(); i < count; i++ ) { - var item = elements.getItem( i ); - if ( item.data( 'cke-realelement' ) && item.data( 'cke-real-element-type' ) == 'anchor' ) - anchors.push( editor.restoreRealElement( item ) ); - } - - for ( i = 0 ; i < realAnchors.count() ; i++ ) - anchors.push( realAnchors.getItem( i ) ); - - for ( i = 0 ; i < anchors.length ; i++ ) - { - item = anchors[ i ]; + item = anchorList.getItem( i ); anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) }; } // Record down the selected element in the dialog. this._.selectedElement = element; - return retval; }; @@ -369,6 +359,12 @@ CKEDITOR.dialog.add( 'link', function( editor ) return 'String.fromCharCode(' + encodedChars.join( ',' ) + ')'; } + function getLinkClass( ele ) + { + var className = ele.getAttribute( 'class' ); + return className ? className.replace( /\s*(?:cke_anchor_empty|cke_anchor)(?:\s*$)?/g, '' ) : ''; + } + var commonLang = editor.lang.common, linkLang = editor.lang.link; @@ -1151,8 +1147,6 @@ CKEDITOR.dialog.add( 'link', function( editor ) ], onShow : function() { - this.fakeObj = false; - var editor = this.getParentEditor(), selection = editor.getSelection(), element = null; @@ -1160,14 +1154,6 @@ CKEDITOR.dialog.add( 'link', function( editor ) // Fill in all the relevant fields if there's already one link selected. if ( ( element = plugin.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) ) selection.selectElement( element ); - else if ( ( element = selection.getSelectedElement() ) && element.is( 'img' ) - && element.data( 'cke-real-element-type' ) - && element.data( 'cke-real-element-type' ) == 'anchor' ) - { - this.fakeObj = element; - element = editor.restoreRealElement( this.fakeObj ); - selection.selectElement( this.fakeObj ); - } else element = null; @@ -1302,10 +1288,7 @@ CKEDITOR.dialog.add( 'link', function( editor ) advAttr( 'advAccessKey', 'accessKey' ); if ( data.adv[ 'advName' ] ) - { attributes[ 'name' ] = attributes[ 'data-cke-saved-name' ] = data.adv[ 'advName' ]; - attributes[ 'class' ] = ( attributes[ 'class' ] ? attributes[ 'class' ] + ' ' : '' ) + 'cke_anchor'; - } else removeAttributes = removeAttributes.concat( [ 'data-cke-saved-name', 'name' ] ); @@ -1350,25 +1333,12 @@ CKEDITOR.dialog.add( 'link', function( editor ) href = element.data( 'cke-saved-href' ), textView = element.getHtml(); - // IE BUG: Setting the name attribute to an existing link doesn't work. - // Must re-create the link from weired syntax to workaround. - if ( CKEDITOR.env.ie && !( CKEDITOR.document.$.documentMode >= 8 ) && attributes.name != element.getAttribute( 'name' ) ) - { - var newElement = new CKEDITOR.dom.element( '', - editor.document ); - - selection = editor.getSelection(); - - element.copyAttributes( newElement, { name : 1 } ); - element.moveChildren( newElement ); - newElement.replace( element ); - element = newElement; - - selection.selectElement( element ); - } - element.setAttributes( attributes ); element.removeAttributes( removeAttributes ); + + if ( data.adv && data.adv.advName && CKEDITOR.plugins.link.synAnchorSelector ) + element.addClass( element.getChildCount() ? 'cke_anchor' : 'cke_anchor_empty' ); + // Update text view when user changes protocol (#4612). if ( href == textView || data.type == 'email' && textView.indexOf( '@' ) != -1 ) { @@ -1376,14 +1346,6 @@ CKEDITOR.dialog.add( 'link', function( editor ) element.setHtml( data.type == 'email' ? data.email.address : attributes[ 'data-cke-saved-href' ] ); } - // Make the element display as an anchor if a name has been set. - if ( element.getAttribute( 'name' ) ) - element.addClass( 'cke_anchor' ); - else - element.removeClass( 'cke_anchor' ); - - if ( this.fakeObj ) - editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj ); delete this._.selectedElement; }