1fbcc2afe7c12feb9375a08abf527e7ab8c31a7c
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
6 CKEDITOR
.dialog
.add( 'anchor', function( editor
)
8 // Function called in onShow to load selected element.
9 var loadElements = function( element
)
11 this._
.selectedElement
= element
;
13 var attributeValue
= element
.data( 'cke-saved-name' );
14 this.setValueOf( 'info','txtName', attributeValue
|| '' );
17 function createFakeAnchor( editor
, anchor
)
19 return editor
.createFakeElement( anchor
, 'cke_anchor', 'anchor' );
23 title
: editor
.lang
.anchor
.title
,
28 var name
= this.getValueOf( 'info', 'txtName' );
32 'data-cke-saved-name' : name
35 if ( this._
.selectedElement
)
37 if ( this._
.selectedElement
.data( 'cke-realelement' ) )
39 var newFake
= createFakeAnchor( editor
, editor
.document
.createElement( 'a', { attributes
: attributes
} ) );
40 newFake
.replace( this._
.selectedElement
);
43 this._
.selectedElement
.setAttributes( attributes
);
47 var sel
= editor
.getSelection(),
48 range
= sel
&& sel
.getRanges()[ 0 ];
51 if ( range
.collapsed
)
53 if ( CKEDITOR
.plugins
.link
.synAnchorSelector
)
54 attributes
[ 'class' ] = 'cke_anchor_empty';
56 if ( CKEDITOR
.plugins
.link
.emptyAnchorFix
)
58 attributes
[ 'contenteditable' ] = 'false';
59 attributes
[ 'data-cke-editable' ] = 1;
62 var anchor
= editor
.document
.createElement( 'a', { attributes
: attributes
} );
64 // Transform the anchor into a fake element for browsers that need it.
65 if ( CKEDITOR
.plugins
.link
.fakeAnchor
)
66 anchor
= createFakeAnchor( editor
, anchor
);
68 range
.insertNode( anchor
);
72 if ( CKEDITOR
.env
.ie
&& CKEDITOR
.env
.version
< 9 )
73 attributes
['class'] = 'cke_anchor';
76 var style
= new CKEDITOR
.style( { element
: 'a', attributes
: attributes
} );
77 style
.type
= CKEDITOR
.STYLE_INLINE
;
78 style
.apply( editor
.document
);
85 delete this._
.selectedElement
;
90 var selection
= editor
.getSelection(),
91 fullySelected
= selection
.getSelectedElement(),
94 // Detect the anchor under selection.
97 if ( CKEDITOR
.plugins
.link
.fakeAnchor
)
99 var realElement
= CKEDITOR
.plugins
.link
.tryRestoreFakeAnchor( editor
, fullySelected
);
100 realElement
&& loadElements
.call( this, realElement
);
101 this._
.selectedElement
= fullySelected
;
103 else if ( fullySelected
.is( 'a' ) && fullySelected
.hasAttribute( 'name' ) )
104 loadElements
.call( this, fullySelected
);
108 partialSelected
= CKEDITOR
.plugins
.link
.getSelectedLink( editor
);
109 if ( partialSelected
)
111 loadElements
.call( this, partialSelected
);
112 selection
.selectElement( partialSelected
);
116 this.getContentElement( 'info', 'txtName' ).focus();
121 label
: editor
.lang
.anchor
.title
,
128 label
: editor
.lang
.anchor
.name
,
130 validate : function()
132 if ( !this.getValue() )
134 alert( editor
.lang
.anchor
.errorName
);