1 /* 2 Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 6 CKEDITOR.dialog.add( 'anchor', function( editor ) 7 { 8 // Function called in onShow to load selected element. 9 var loadElements = function( editor, selection, element ) 10 { 11 this.editMode = true; 12 this.editObj = element; 13 14 var attributeValue = this.editObj.getAttribute( 'name' ); 15 if ( attributeValue ) 16 this.setValueOf( 'info','txtName', attributeValue ); 17 else 18 this.setValueOf( 'info','txtName', "" ); 19 }; 20 21 return { 22 title : editor.lang.anchor.title, 23 minWidth : 300, 24 minHeight : 60, 25 onOk : function() 26 { 27 // Always create a new anchor, because of IE BUG. 28 var name = this.getValueOf( 'info', 'txtName' ), 29 element = CKEDITOR.env.ie ? 30 editor.document.createElement( '<a name="' + CKEDITOR.tools.htmlEncode( name ) + '">' ) : 31 editor.document.createElement( 'a' ); 32 33 // Move contents and attributes of old anchor to new anchor. 34 if ( this.editMode ) 35 { 36 this.editObj.copyAttributes( element, { name : 1 } ); 37 this.editObj.moveChildren( element ); 38 } 39 40 // Set name. 41 element.removeAttribute( '_cke_saved_name' ); 42 element.setAttribute( 'name', name ); 43 44 // Insert a new anchor. 45 var fakeElement = editor.createFakeElement( element, 'cke_anchor', 'anchor' ); 46 if ( !this.editMode ) 47 editor.insertElement( fakeElement ); 48 else 49 { 50 fakeElement.replace( this.fakeObj ); 51 editor.getSelection().selectElement( fakeElement ); 52 } 53 54 return true; 55 }, 56 onShow : function() 57 { 58 this.editObj = false; 59 this.fakeObj = false; 60 this.editMode = false; 61 62 var selection = editor.getSelection(); 63 var element = selection.getSelectedElement(); 64 if ( element && element.getAttribute( '_cke_real_element_type' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' ) 65 { 66 this.fakeObj = element; 67 element = editor.restoreRealElement( this.fakeObj ); 68 loadElements.apply( this, [ editor, selection, element ] ); 69 selection.selectElement( this.fakeObj ); 70 } 71 this.getContentElement( 'info', 'txtName' ).focus(); 72 }, 73 contents : [ 74 { 75 id : 'info', 76 label : editor.lang.anchor.title, 77 accessKey : 'I', 78 elements : 79 [ 80 { 81 type : 'text', 82 id : 'txtName', 83 label : editor.lang.anchor.name, 84 validate : function() 85 { 86 if ( !this.getValue() ) 87 { 88 alert( editor.lang.anchor.errorName ); 89 return false; 90 } 91 return true; 92 } 93 } 94 ] 95 } 96 ] 97 }; 98 } ); 99