]>
git.immae.eu Git - perso/Immae/Projets/packagist/piedsjaloux-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 function getSelectedAnchor( selection
) {
23 var range
= selection
.getRanges()[ 0 ],
24 element
= selection
.getSelectedElement();
26 // In case of table cell selection, we want to shrink selection from td to a element.
27 range
.shrink( CKEDITOR
.SHRINK_ELEMENT
);
28 element
= range
.getEnclosedNode();
30 if ( element
&& element
.type
=== CKEDITOR
.NODE_ELEMENT
&&
31 ( element
.data( 'cke-real-element-type' ) === 'anchor' || element
.is( 'a' ) ) ) {
37 title: editor
.lang
.link
.anchor
.title
,
41 var name
= CKEDITOR
.tools
.trim( this.getValueOf( 'info', 'txtName' ) );
45 'data-cke-saved-name': name
48 if ( this._
.selectedElement
) {
49 if ( this._
.selectedElement
.data( 'cke-realelement' ) ) {
50 var newFake
= createFakeAnchor( editor
, attributes
);
51 newFake
.replace( this._
.selectedElement
);
53 // Selecting fake element for IE. (http://dev.ckeditor.com/ticket/11377)
54 if ( CKEDITOR
.env
.ie
) {
55 editor
.getSelection().selectElement( newFake
);
58 this._
.selectedElement
.setAttributes( attributes
);
61 var sel
= editor
.getSelection(),
62 range
= sel
&& sel
.getRanges()[ 0 ];
65 if ( range
.collapsed
) {
66 var anchor
= createFakeAnchor( editor
, attributes
);
67 range
.insertNode( anchor
);
69 if ( CKEDITOR
.env
.ie
&& CKEDITOR
.env
.version
< 9 )
70 attributes
[ 'class' ] = 'cke_anchor';
73 var style
= new CKEDITOR
.style( { element: 'a', attributes: attributes
} );
74 style
.type
= CKEDITOR
.STYLE_INLINE
;
75 style
.applyToRange( range
);
81 delete this._
.selectedElement
;
85 var sel
= editor
.getSelection(),
86 fullySelected
= getSelectedAnchor( sel
),
87 fakeSelected
= fullySelected
&& fullySelected
.data( 'cke-realelement' ),
88 linkElement
= fakeSelected
?
89 CKEDITOR
.plugins
.link
.tryRestoreFakeAnchor( editor
, fullySelected
) :
90 CKEDITOR
.plugins
.link
.getSelectedLink( editor
);
93 loadElements
.call( this, linkElement
);
94 !fakeSelected
&& sel
.selectElement( linkElement
);
96 if ( fullySelected
) {
97 this._
.selectedElement
= fullySelected
;
101 this.getContentElement( 'info', 'txtName' ).focus();
105 label: editor
.lang
.link
.anchor
.title
,
110 label: editor
.lang
.link
.anchor
.name
,
112 validate: function() {
113 if ( !this.getValue() ) {
114 alert( editor
.lang
.link
.anchor
.errorName
); // jshint ignore:line