2 Copyright (c) 2003-2011, 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 = this.getValueOf( 'info', 'txtName' );
\r
32 'data-cke-saved-name' : name
\r
35 if ( this._.selectedElement )
\r
37 if ( this._.selectedElement.data( 'cke-realelement' ) )
\r
39 var newFake = createFakeAnchor( editor, editor.document.createElement( 'a', { attributes: attributes } ) );
\r
40 newFake.replace( this._.selectedElement );
\r
43 this._.selectedElement.setAttributes( attributes );
\r
47 var sel = editor.getSelection(),
\r
48 range = sel && sel.getRanges()[ 0 ];
\r
51 if ( range.collapsed )
\r
53 if ( CKEDITOR.plugins.link.synAnchorSelector )
\r
54 attributes[ 'class' ] = 'cke_anchor_empty';
\r
56 if ( CKEDITOR.plugins.link.emptyAnchorFix )
\r
58 attributes[ 'contenteditable' ] = 'false';
\r
59 attributes[ 'data-cke-editable' ] = 1;
\r
62 var anchor = editor.document.createElement( 'a', { attributes: attributes } );
\r
64 // Transform the anchor into a fake element for browsers that need it.
\r
65 if ( CKEDITOR.plugins.link.fakeAnchor )
\r
66 anchor = createFakeAnchor( editor, anchor );
\r
68 range.insertNode( anchor );
\r
72 if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 )
\r
73 attributes['class'] = 'cke_anchor';
\r
76 var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
\r
77 style.type = CKEDITOR.STYLE_INLINE;
\r
78 style.apply( editor.document );
\r
85 delete this._.selectedElement;
\r
90 var selection = editor.getSelection(),
\r
91 fullySelected = selection.getSelectedElement(),
\r
94 // Detect the anchor under selection.
\r
95 if ( fullySelected )
\r
97 if ( CKEDITOR.plugins.link.fakeAnchor )
\r
99 var realElement = CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, fullySelected );
\r
100 realElement && loadElements.call( this, realElement );
\r
101 this._.selectedElement = fullySelected;
\r
103 else if ( fullySelected.is( 'a' ) && fullySelected.hasAttribute( 'name' ) )
\r
104 loadElements.call( this, fullySelected );
\r
108 partialSelected = CKEDITOR.plugins.link.getSelectedLink( editor );
\r
109 if ( partialSelected )
\r
111 loadElements.call( this, partialSelected );
\r
112 selection.selectElement( partialSelected );
\r
116 this.getContentElement( 'info', 'txtName' ).focus();
\r
121 label : editor.lang.anchor.title,
\r
128 label : editor.lang.anchor.name,
\r
130 validate : function()
\r
132 if ( !this.getValue() )
\r
134 alert( editor.lang.anchor.errorName );
\r