]>
git.immae.eu Git - perso/Immae/Projets/packagist/ludivine-ckeditor-component.git/blob - sources/plugins/link/dialogs/anchor.js
2 * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
6 CKEDITOR
.dialog
.add( 'anchor', function( editor
) {
7 // Function called in onShow to load selected element.
8 var loadElements = function( element
) {
9 this._
.selectedElement
= element
;
11 var attributeValue
= element
.data( 'cke-saved-name' );
12 this.setValueOf( 'info', 'txtName', attributeValue
|| '' );
15 function createFakeAnchor( editor
, attributes
) {
16 return editor
.createFakeElement( editor
.document
.createElement( 'a', {
17 attributes: attributes
18 } ), 'cke_anchor', 'anchor' );
22 title: editor
.lang
.link
.anchor
.title
,
26 var name
= CKEDITOR
.tools
.trim( this.getValueOf( 'info', 'txtName' ) );
30 'data-cke-saved-name': name
33 if ( this._
.selectedElement
) {
34 if ( this._
.selectedElement
.data( 'cke-realelement' ) ) {
35 var newFake
= createFakeAnchor( editor
, attributes
);
36 newFake
.replace( this._
.selectedElement
);
38 // Selecting fake element for IE. (#11377)
39 if ( CKEDITOR
.env
.ie
)
40 editor
.getSelection().selectElement( newFake
);
42 this._
.selectedElement
.setAttributes( attributes
);
45 var sel
= editor
.getSelection(),
46 range
= sel
&& sel
.getRanges()[ 0 ];
49 if ( range
.collapsed
) {
50 var anchor
= createFakeAnchor( editor
, attributes
);
51 range
.insertNode( anchor
);
53 if ( CKEDITOR
.env
.ie
&& CKEDITOR
.env
.version
< 9 )
54 attributes
[ 'class' ] = 'cke_anchor';
57 var style
= new CKEDITOR
.style( { element: 'a', attributes: attributes
} );
58 style
.type
= CKEDITOR
.STYLE_INLINE
;
59 editor
.applyStyle( style
);
65 delete this._
.selectedElement
;
69 var sel
= editor
.getSelection(),
70 fullySelected
= sel
.getSelectedElement(),
71 fakeSelected
= fullySelected
&& fullySelected
.data( 'cke-realelement' ),
72 linkElement
= fakeSelected
?
73 CKEDITOR
.plugins
.link
.tryRestoreFakeAnchor( editor
, fullySelected
) :
74 CKEDITOR
.plugins
.link
.getSelectedLink( editor
);
77 loadElements
.call( this, linkElement
);
78 !fakeSelected
&& sel
.selectElement( linkElement
);
81 this._
.selectedElement
= fullySelected
;
84 this.getContentElement( 'info', 'txtName' ).focus();
88 label: editor
.lang
.link
.anchor
.title
,
93 label: editor
.lang
.link
.anchor
.name
,
95 validate: function() {
96 if ( !this.getValue() ) {
97 alert( editor
.lang
.link
.anchor
.errorName
); // jshint ignore:line