JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0
[ckeditor.git] / _source / plugins / link / dialogs / anchor.js
diff --git a/_source/plugins/link/dialogs/anchor.js b/_source/plugins/link/dialogs/anchor.js
new file mode 100644 (file)
index 0000000..12528f0
--- /dev/null
@@ -0,0 +1,98 @@
+/*\r
+Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+For licensing, see LICENSE.html or http://ckeditor.com/license\r
+*/\r
+\r
+CKEDITOR.dialog.add( 'anchor', function( editor )\r
+{\r
+       // Function called in onShow to load selected element.\r
+       var loadElements = function( editor, selection, element )\r
+       {\r
+               this.editMode = true;\r
+               this.editObj = element;\r
+\r
+               var attributeValue = this.editObj.getAttribute( 'name' );\r
+               if ( attributeValue )\r
+                       this.setValueOf( 'info','txtName', attributeValue );\r
+               else\r
+                       this.setValueOf( 'info','txtName', "" );\r
+       };\r
+\r
+       return {\r
+               title : editor.lang.anchor.title,\r
+               minWidth : 300,\r
+               minHeight : 60,\r
+               onOk : function()\r
+               {\r
+                       // Always create a new anchor, because of IE BUG.\r
+                       var name = this.getValueOf( 'info', 'txtName' ),\r
+                               element = CKEDITOR.env.ie ?\r
+                               editor.document.createElement( '<a name="' + CKEDITOR.tools.htmlEncode( name ) + '">' ) :\r
+                               editor.document.createElement( 'a' );\r
+\r
+                       // Move contents and attributes of old anchor to new anchor.\r
+                       if ( this.editMode )\r
+                       {\r
+                               this.editObj.copyAttributes( element, { name : 1 } );\r
+                               this.editObj.moveChildren( element );\r
+                       }\r
+\r
+                       // Set name.\r
+                       element.removeAttribute( '_cke_saved_name' );\r
+                       element.setAttribute( 'name', name );\r
+\r
+                       // Insert a new anchor.\r
+                       var fakeElement = editor.createFakeElement( element, 'cke_anchor', 'anchor' );\r
+                       if ( !this.editMode )\r
+                               editor.insertElement( fakeElement );\r
+                       else\r
+                       {\r
+                               fakeElement.replace( this.fakeObj );\r
+                               editor.getSelection().selectElement( fakeElement );\r
+                       }\r
+\r
+                       return true;\r
+               },\r
+               onShow : function()\r
+               {\r
+                       this.editObj = false;\r
+                       this.fakeObj = false;\r
+                       this.editMode = false;\r
+\r
+                       var selection = editor.getSelection();\r
+                       var element = selection.getSelectedElement();\r
+                       if ( element && element.getAttribute( '_cke_real_element_type' ) && element.getAttribute( '_cke_real_element_type' ) == 'anchor' )\r
+                       {\r
+                               this.fakeObj = element;\r
+                               element = editor.restoreRealElement( this.fakeObj );\r
+                               loadElements.apply( this, [ editor, selection, element ] );\r
+                               selection.selectElement( this.fakeObj );\r
+                       }\r
+                       this.getContentElement( 'info', 'txtName' ).focus();\r
+               },\r
+               contents : [\r
+                       {\r
+                               id : 'info',\r
+                               label : editor.lang.anchor.title,\r
+                               accessKey : 'I',\r
+                               elements :\r
+                               [\r
+                                       {\r
+                                               type : 'text',\r
+                                               id : 'txtName',\r
+                                               label : editor.lang.anchor.name,\r
+                                               validate : function()\r
+                                               {\r
+                                                       if ( !this.getValue() )\r
+                                                       {\r
+                                                               alert( editor.lang.anchor.errorName );\r
+                                                               return false;\r
+                                                       }\r
+                                                       return true;\r
+                                               }\r
+                                       }\r
+                               ]\r
+                       }\r
+               ]\r
+       };\r
+} );\r