2 Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
\r
3 For licensing, see LICENSE.html or http://ckeditor.com/license
\r
6 CKEDITOR.dialog.add( 'anchor', function( editor )
\r
8 // Function called in onShow to load selected element.
\r
9 var loadElements = function( element )
\r
11 this._.selectedElement = element;
\r
13 var attributeValue = element.data( 'cke-saved-name' );
\r
14 this.setValueOf( 'info','txtName', attributeValue || '' );
\r
17 function createFakeAnchor( editor, anchor )
\r
19 return editor.createFakeElement( anchor, 'cke_anchor', 'anchor' );
\r
23 title : editor.lang.anchor.title,
\r
28 var name = CKEDITOR.tools.trim( this.getValueOf( 'info', 'txtName' ) );
\r
33 'data-cke-saved-name' : name
\r
36 if ( this._.selectedElement )
\r
38 if ( this._.selectedElement.data( 'cke-realelement' ) )
\r
40 var newFake = createFakeAnchor( editor, editor.document.createElement( 'a', { attributes: attributes } ) );
\r
41 newFake.replace( this._.selectedElement );
\r
44 this._.selectedElement.setAttributes( attributes );
\r
48 var sel = editor.getSelection(),
\r
49 range = sel && sel.getRanges()[ 0 ];
\r
52 if ( range.collapsed )
\r
54 if ( CKEDITOR.plugins.link.synAnchorSelector )
\r
55 attributes[ 'class' ] = 'cke_anchor_empty';
\r
57 if ( CKEDITOR.plugins.link.emptyAnchorFix )
\r
59 attributes[ 'contenteditable' ] = 'false';
\r
60 attributes[ 'data-cke-editable' ] = 1;
\r
63 var anchor = editor.document.createElement( 'a', { attributes: attributes } );
\r
65 // Transform the anchor into a fake element for browsers that need it.
\r
66 if ( CKEDITOR.plugins.link.fakeAnchor )
\r
67 anchor = createFakeAnchor( editor, anchor );
\r
69 range.insertNode( anchor );
\r
73 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 )
\r
74 attributes['class'] = 'cke_anchor';
\r
77 var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
\r
78 style.type = CKEDITOR.STYLE_INLINE;
\r
79 style.apply( editor.document );
\r
86 delete this._.selectedElement;
\r
91 var selection = editor.getSelection(),
\r
92 fullySelected = selection.getSelectedElement(),
\r
95 // Detect the anchor under selection.
\r
96 if ( fullySelected )
\r
98 if ( CKEDITOR.plugins.link.fakeAnchor )
\r
100 var realElement = CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, fullySelected );
\r
101 realElement && loadElements.call( this, realElement );
\r
102 this._.selectedElement = fullySelected;
\r
104 else if ( fullySelected.is( 'a' ) && fullySelected.hasAttribute( 'name' ) )
\r
105 loadElements.call( this, fullySelected );
\r
109 partialSelected = CKEDITOR.plugins.link.getSelectedLink( editor );
\r
110 if ( partialSelected )
\r
112 loadElements.call( this, partialSelected );
\r
113 selection.selectElement( partialSelected );
\r
117 this.getContentElement( 'info', 'txtName' ).focus();
\r
122 label : editor.lang.anchor.title,
\r
129 label : editor.lang.anchor.name,
\r
131 validate : function()
\r
133 if ( !this.getValue() )
\r
135 alert( editor.lang.anchor.errorName );
\r