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( editor, selection, element )
\r
11 this.editMode = true;
\r
12 this.editObj = element;
\r
14 var attributeValue = this.editObj.getAttribute( 'name' );
\r
15 if ( attributeValue )
\r
16 this.setValueOf( 'info','txtName', attributeValue );
\r
18 this.setValueOf( 'info','txtName', "" );
\r
22 title : editor.lang.anchor.title,
\r
27 // Always create a new anchor, because of IE BUG.
\r
28 var name = this.getValueOf( 'info', 'txtName' ),
\r
29 element = CKEDITOR.env.ie && !( CKEDITOR.document.$.documentMode >= 8 ) ?
\r
30 editor.document.createElement( '<a name="' + CKEDITOR.tools.htmlEncode( name ) + '">' ) :
\r
31 editor.document.createElement( 'a' );
\r
33 // Move contents and attributes of old anchor to new anchor.
\r
34 if ( this.editMode )
\r
36 this.editObj.copyAttributes( element, { name : 1 } );
\r
37 this.editObj.moveChildren( element );
\r
41 element.data( 'cke-saved-name', false );
\r
42 element.setAttribute( 'name', name );
\r
44 // Insert a new anchor.
\r
45 var fakeElement = editor.createFakeElement( element, 'cke_anchor', 'anchor' );
\r
46 if ( !this.editMode )
\r
47 editor.insertElement( fakeElement );
\r
50 fakeElement.replace( this.fakeObj );
\r
51 editor.getSelection().selectElement( fakeElement );
\r
58 this.editObj = false;
\r
59 this.fakeObj = false;
\r
60 this.editMode = false;
\r
62 var selection = editor.getSelection();
\r
63 var element = selection.getSelectedElement();
\r
64 if ( element && element.data( 'cke-real-element-type' ) && element.data( 'cke-real-element-type' ) == 'anchor' )
\r
66 this.fakeObj = element;
\r
67 element = editor.restoreRealElement( this.fakeObj );
\r
68 loadElements.apply( this, [ editor, selection, element ] );
\r
69 selection.selectElement( this.fakeObj );
\r
71 this.getContentElement( 'info', 'txtName' ).focus();
\r
76 label : editor.lang.anchor.title,
\r
83 label : editor.lang.anchor.name,
\r
85 validate : function()
\r
87 if ( !this.getValue() )
\r
89 alert( editor.lang.anchor.errorName );
\r