Mimimum syndical pour en faire un produit zope / cmf.
[ckeditor.git] / skins / ckeditor / _source / plugins / link / dialogs / anchor.js
diff --git a/skins/ckeditor/_source/plugins/link/dialogs/anchor.js b/skins/ckeditor/_source/plugins/link/dialogs/anchor.js
new file mode 100644 (file)
index 0000000..1fbcc2a
--- /dev/null
@@ -0,0 +1,144 @@
+/*\r
+Copyright (c) 2003-2011, 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( element )\r
+       {\r
+               this._.selectedElement = element;\r
+\r
+               var attributeValue = element.data( 'cke-saved-name' );\r
+               this.setValueOf( 'info','txtName', attributeValue || '' );\r
+       };\r
+\r
+       function createFakeAnchor( editor, anchor )\r
+       {\r
+               return editor.createFakeElement( anchor, 'cke_anchor', 'anchor' );\r
+       }\r
+\r
+       return {\r
+               title : editor.lang.anchor.title,\r
+               minWidth : 300,\r
+               minHeight : 60,\r
+               onOk : function()\r
+               {\r
+                       var name = this.getValueOf( 'info', 'txtName' );\r
+                       var attributes =\r
+                       {\r
+                               name : name,\r
+                               'data-cke-saved-name' : name\r
+                       };\r
+\r
+                       if ( this._.selectedElement )\r
+                       {\r
+                               if ( this._.selectedElement.data( 'cke-realelement' ) )\r
+                               {\r
+                                       var newFake = createFakeAnchor( editor, editor.document.createElement( 'a', { attributes: attributes } ) );\r
+                                       newFake.replace( this._.selectedElement );\r
+                               }\r
+                               else\r
+                                       this._.selectedElement.setAttributes( attributes );\r
+                       }\r
+                       else\r
+                       {\r
+                               var sel = editor.getSelection(),\r
+                                               range = sel && sel.getRanges()[ 0 ];\r
+\r
+                               // Empty anchor\r
+                               if ( range.collapsed )\r
+                               {\r
+                                       if ( CKEDITOR.plugins.link.synAnchorSelector )\r
+                                               attributes[ 'class' ] = 'cke_anchor_empty';\r
+\r
+                                       if ( CKEDITOR.plugins.link.emptyAnchorFix )\r
+                                       {\r
+                                               attributes[ 'contenteditable' ] = 'false';\r
+                                               attributes[ 'data-cke-editable' ] = 1;\r
+                                       }\r
+\r
+                                       var anchor = editor.document.createElement( 'a', { attributes: attributes } );\r
+\r
+                                       // Transform the anchor into a fake element for browsers that need it.\r
+                                       if ( CKEDITOR.plugins.link.fakeAnchor )\r
+                                               anchor = createFakeAnchor( editor, anchor );\r
+\r
+                                       range.insertNode( anchor );\r
+                               }\r
+                               else\r
+                               {\r
+                                       if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 )\r
+                                               attributes['class'] = 'cke_anchor';\r
+\r
+                                       // Apply style.\r
+                                       var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );\r
+                                       style.type = CKEDITOR.STYLE_INLINE;\r
+                                       style.apply( editor.document );\r
+                               }\r
+                       }\r
+               },\r
+\r
+               onHide : function()\r
+               {\r
+                       delete this._.selectedElement;\r
+               },\r
+\r
+               onShow : function()\r
+               {\r
+                       var selection = editor.getSelection(),\r
+                               fullySelected = selection.getSelectedElement(),\r
+                               partialSelected;\r
+\r
+                       // Detect the anchor under selection.\r
+                       if ( fullySelected )\r
+                       {\r
+                               if ( CKEDITOR.plugins.link.fakeAnchor )\r
+                               {\r
+                                       var realElement = CKEDITOR.plugins.link.tryRestoreFakeAnchor( editor, fullySelected );\r
+                                       realElement && loadElements.call( this, realElement );\r
+                                       this._.selectedElement = fullySelected;\r
+                               }\r
+                               else if ( fullySelected.is( 'a' ) && fullySelected.hasAttribute( 'name' ) )\r
+                                       loadElements.call( this, fullySelected );\r
+                       }\r
+                       else\r
+                       {\r
+                               partialSelected = CKEDITOR.plugins.link.getSelectedLink( editor );\r
+                               if ( partialSelected )\r
+                               {\r
+                                       loadElements.call( this, partialSelected );\r
+                                       selection.selectElement( partialSelected );\r
+                               }\r
+                       }\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
+                                               required: true,\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