Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F726941
D259.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jan 6, 3:34 AM
Size
4 KB
Mime Type
text/x-diff
Expires
Tue, Jan 7, 3:34 AM (2 d, 19 h ago)
Engine
blob
Format
Raw Data
Handle
537021
Attached To
D259: INP-1630 - Actualize link injection code in "my_link" plugin of CKEditor
D259.diff
View Options
Index: branches/5.2.x/core/ckeditor/plugins/my_link/plugin.js
===================================================================
--- branches/5.2.x/core/ckeditor/plugins/my_link/plugin.js
+++ branches/5.2.x/core/ckeditor/plugins/my_link/plugin.js
@@ -630,72 +630,48 @@
advAttr( 'advRel', 'rel' );
}
+ var selection = editor.getSelection();
// Browser need the "href" fro copy/paste link to work. (#6641)
- attributes.href = attributes[ 'data-cke-saved-href' ];
+ attributes.href = attributes['data-cke-saved-href'];
- if ( !this._.selectedElement )
- {
- // Create element if current selection is collapsed.
- var selection = editor.getSelection(),
- ranges = selection.getRanges( true );
- if ( ranges.length == 1 && ranges[0].collapsed )
- {
+ if ( !this._.selectedElement ) {
+ var range = selection.getRanges(1)[0];
+
+ // Use link URL as text with a collapsed cursor.
+ if ( range.collapsed ) {
// Short mailto link text view (#5736).
- var text = new CKEDITOR.dom.text( data.type == 'email' ?
- data.email.address : attributes[ 'data-cke-saved-href' ], editor.document );
- ranges[0].insertNode( text );
- ranges[0].selectNodeContents( text );
- selection.selectRanges( ranges );
+ var text = new CKEDITOR.dom.text(data.type == 'email' ? data.email.address : attributes['data-cke-saved-href'], editor.document);
+ range.insertNode(text);
+ range.selectNodeContents(text);
}
// Apply style.
- var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
- style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.
- style.apply( editor.document );
+ var style = new CKEDITOR.style({element: 'a', attributes: attributes});
+ style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why.
+ style.applyToRange(range);
+ range.select();
}
- else
- {
+ else {
// We're only editing an existing link, so just overwrite the attributes.
var element = this._.selectedElement,
- href = element.data( 'cke-saved-href' ),
+ 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( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">',
- editor.document );
+ element.setAttributes(attributes);
+ element.removeAttributes(removeAttributes);
- selection = editor.getSelection();
-
- element.copyAttributes( newElement, { name : 1 } );
- element.moveChildren( newElement );
- newElement.replace( element );
- element = newElement;
-
- selection.selectElement( element );
+ if ( data.adv && data.adv.advName && CKEDITOR.plugins.link.synAnchorSelector ) {
+ element.addClass(element.getChildCount() ? 'cke_anchor' : 'cke_anchor_empty');
}
- element.setAttributes( attributes );
- element.removeAttributes( removeAttributes );
// Update text view when user changes protocol (#4612).
- if ( href == textView || data.type == 'email' && textView.indexOf( '@' ) != -1 )
- {
+ if ( href == textView || data.type == 'email' && textView.indexOf('@') != -1 ) {
// Short mailto link text view (#5736).
- element.setHtml( data.type == 'email' ?
- data.email.address : attributes[ 'data-cke-saved-href' ] );
+ 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 );
+ selection.selectElement(element);
delete this._.selectedElement;
}
};
Event Timeline
Log In to Comment