Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/ckeditor/plugins/my_link/plugin.js
Show First 20 Lines • Show All 624 Lines • ▼ Show 20 Line(s) | |||||
advAttr( 'advTitle', 'title' ); | advAttr( 'advTitle', 'title' ); | ||||
advAttr( 'advContentType', 'type' ); | advAttr( 'advContentType', 'type' ); | ||||
advAttr( 'advCSSClasses', 'class' ); | advAttr( 'advCSSClasses', 'class' ); | ||||
advAttr( 'advCharset', 'charset' ); | advAttr( 'advCharset', 'charset' ); | ||||
advAttr( 'advStyles', 'style' ); | advAttr( 'advStyles', 'style' ); | ||||
advAttr( 'advRel', 'rel' ); | advAttr( 'advRel', 'rel' ); | ||||
} | } | ||||
var selection = editor.getSelection(); | |||||
// Browser need the "href" fro copy/paste link to work. (#6641) | // 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 ) | if ( !this._.selectedElement ) { | ||||
{ | var range = selection.getRanges(1)[0]; | ||||
// Create element if current selection is collapsed. | |||||
var selection = editor.getSelection(), | // Use link URL as text with a collapsed cursor. | ||||
ranges = selection.getRanges( true ); | if ( range.collapsed ) { | ||||
if ( ranges.length == 1 && ranges[0].collapsed ) | |||||
{ | |||||
// Short mailto link text view (#5736). | // Short mailto link text view (#5736). | ||||
var text = new CKEDITOR.dom.text( data.type == 'email' ? | var text = new CKEDITOR.dom.text(data.type == 'email' ? data.email.address : attributes['data-cke-saved-href'], editor.document); | ||||
data.email.address : attributes[ 'data-cke-saved-href' ], editor.document ); | range.insertNode(text); | ||||
ranges[0].insertNode( text ); | range.selectNodeContents(text); | ||||
ranges[0].selectNodeContents( text ); | |||||
selection.selectRanges( ranges ); | |||||
} | } | ||||
// Apply style. | // Apply style. | ||||
var style = new CKEDITOR.style( { element : 'a', attributes : attributes } ); | var style = new CKEDITOR.style({element: 'a', attributes: attributes}); | ||||
style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why. | style.type = CKEDITOR.STYLE_INLINE; // need to override... dunno why. | ||||
style.apply( editor.document ); | style.applyToRange(range); | ||||
range.select(); | |||||
} | } | ||||
else | else { | ||||
{ | |||||
// We're only editing an existing link, so just overwrite the attributes. | // We're only editing an existing link, so just overwrite the attributes. | ||||
var element = this._.selectedElement, | var element = this._.selectedElement, | ||||
href = element.data( 'cke-saved-href' ), | href = element.data('cke-saved-href'), | ||||
textView = element.getHtml(); | textView = element.getHtml(); | ||||
// IE BUG: Setting the name attribute to an existing link doesn't work. | element.setAttributes(attributes); | ||||
// Must re-create the link from weired syntax to workaround. | element.removeAttributes(removeAttributes); | ||||
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 ); | |||||
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). | // 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). | // Short mailto link text view (#5736). | ||||
element.setHtml( data.type == 'email' ? | element.setHtml(data.type == 'email' ? data.email.address : attributes['data-cke-saved-href']); | ||||
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; | delete this._.selectedElement; | ||||
} | } | ||||
}; | }; | ||||
} | } | ||||
} | } | ||||
); | ); | ||||
} | } | ||||
)(); | )(); |