JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.0
[ckeditor.git] / _source / plugins / forms / plugin.js
diff --git a/_source/plugins/forms/plugin.js b/_source/plugins/forms/plugin.js
new file mode 100644 (file)
index 0000000..66d3cec
--- /dev/null
@@ -0,0 +1,193 @@
+/*\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
+/**\r
+ * @file Forms Plugin\r
+ */\r
+\r
+CKEDITOR.plugins.add( 'forms',\r
+{\r
+       init : function( editor )\r
+       {\r
+               var lang = editor.lang;\r
+\r
+               editor.addCss(\r
+                       'form' +\r
+                       '{' +\r
+                               'border: 1px dotted #FF0000;' +\r
+                               'padding: 2px;' +\r
+                       '}' );\r
+\r
+               // All buttons use the same code to register. So, to avoid\r
+               // duplications, let's use this tool function.\r
+               var addButtonCommand = function( buttonName, commandName, dialogFile )\r
+               {\r
+                       editor.addCommand( commandName, new CKEDITOR.dialogCommand( commandName ) );\r
+\r
+                       editor.ui.addButton( buttonName,\r
+                               {\r
+                                       label : lang.common[ buttonName.charAt(0).toLowerCase() + buttonName.slice(1) ],\r
+                                       command : commandName\r
+                               });\r
+                       CKEDITOR.dialog.add( commandName, dialogFile );\r
+               };\r
+\r
+               var dialogPath = this.path + 'dialogs/';\r
+               addButtonCommand( 'Form',                       'form',                 dialogPath + 'form.js' );\r
+               addButtonCommand( 'Checkbox',           'checkbox',             dialogPath + 'checkbox.js' );\r
+               addButtonCommand( 'Radio',                      'radio',                dialogPath + 'radio.js' );\r
+               addButtonCommand( 'TextField',          'textfield',    dialogPath + 'textfield.js' );\r
+               addButtonCommand( 'Textarea',           'textarea',             dialogPath + 'textarea.js' );\r
+               addButtonCommand( 'Select',                     'select',               dialogPath + 'select.js' );\r
+               addButtonCommand( 'Button',                     'button',               dialogPath + 'button.js' );\r
+               addButtonCommand( 'ImageButton',        'imagebutton',  CKEDITOR.plugins.getPath('image') + 'dialogs/image.js' );\r
+               addButtonCommand( 'HiddenField',        'hiddenfield',  dialogPath + 'hiddenfield.js' );\r
+\r
+               // If the "menu" plugin is loaded, register the menu items.\r
+               if ( editor.addMenuItems )\r
+               {\r
+                       editor.addMenuItems(\r
+                               {\r
+                                       form :\r
+                                       {\r
+                                               label : lang.form.menu,\r
+                                               command : 'form',\r
+                                               group : 'form'\r
+                                       },\r
+\r
+                                       checkbox :\r
+                                       {\r
+                                               label : lang.checkboxAndRadio.checkboxTitle,\r
+                                               command : 'checkbox',\r
+                                               group : 'checkbox'\r
+                                       },\r
+\r
+                                       radio :\r
+                                       {\r
+                                               label : lang.checkboxAndRadio.radioTitle,\r
+                                               command : 'radio',\r
+                                               group : 'radio'\r
+                                       },\r
+\r
+                                       textfield :\r
+                                       {\r
+                                               label : lang.textfield.title,\r
+                                               command : 'textfield',\r
+                                               group : 'textfield'\r
+                                       },\r
+\r
+                                       hiddenfield :\r
+                                       {\r
+                                               label : lang.hidden.title,\r
+                                               command : 'hiddenfield',\r
+                                               group : 'hiddenfield'\r
+                                       },\r
+\r
+                                       imagebutton :\r
+                                       {\r
+                                               label : lang.image.titleButton,\r
+                                               command : 'imagebutton',\r
+                                               group : 'imagebutton'\r
+                                       },\r
+\r
+                                       button :\r
+                                       {\r
+                                               label : lang.button.title,\r
+                                               command : 'button',\r
+                                               group : 'button'\r
+                                       },\r
+\r
+                                       select :\r
+                                       {\r
+                                               label : lang.select.title,\r
+                                               command : 'select',\r
+                                               group : 'select'\r
+                                       },\r
+\r
+                                       textarea :\r
+                                       {\r
+                                               label : lang.textarea.title,\r
+                                               command : 'textarea',\r
+                                               group : 'textarea'\r
+                                       }\r
+                               });\r
+               }\r
+\r
+               // If the "contextmenu" plugin is loaded, register the listeners.\r
+               if ( editor.contextMenu )\r
+               {\r
+                       editor.contextMenu.addListener( function( element )\r
+                               {\r
+                                       if ( element && element.hasAscendant( 'form' ) )\r
+                                               return { form : CKEDITOR.TRISTATE_OFF };\r
+                               });\r
+\r
+                       editor.contextMenu.addListener( function( element )\r
+                               {\r
+                                       if ( element )\r
+                                       {\r
+                                               var name = element.getName();\r
+\r
+                                               if ( name == 'select' )\r
+                                                       return { select : CKEDITOR.TRISTATE_OFF };\r
+\r
+                                               if ( name == 'textarea' )\r
+                                                       return { textarea : CKEDITOR.TRISTATE_OFF };\r
+\r
+                                               if ( name == 'input' )\r
+                                               {\r
+                                                       var type = element.getAttribute( 'type' );\r
+\r
+                                                       if ( type == 'text' || type == 'password' )\r
+                                                               return { textfield : CKEDITOR.TRISTATE_OFF };\r
+\r
+                                                       if ( type == 'button' || type == 'submit' || type == 'reset' )\r
+                                                               return { button : CKEDITOR.TRISTATE_OFF };\r
+\r
+                                                       if ( type == 'checkbox' )\r
+                                                               return { checkbox : CKEDITOR.TRISTATE_OFF };\r
+\r
+                                                       if ( type == 'radio' )\r
+                                                               return { radio : CKEDITOR.TRISTATE_OFF };\r
+\r
+                                                       if ( type == 'image' )\r
+                                                               return { imagebutton : CKEDITOR.TRISTATE_OFF };\r
+                                               }\r
+\r
+                                               if ( name == 'img' && element.getAttribute( '_cke_real_element_type' ) == 'hiddenfield' )\r
+                                                       return { hiddenfield : CKEDITOR.TRISTATE_OFF };\r
+                                       }\r
+                               });\r
+               }\r
+       },\r
+       requires : [ 'image' ]\r
+} );\r
+\r
+if ( CKEDITOR.env.ie )\r
+{\r
+       CKEDITOR.dom.element.prototype.hasAttribute = function( name )\r
+       {\r
+               var $attr = this.$.attributes.getNamedItem( name );\r
+\r
+               if ( this.getName() == 'input' )\r
+               {\r
+                       switch ( name )\r
+                       {\r
+                               case 'class' :\r
+                                       return this.$.className.length > 0;\r
+                               case 'checked' :\r
+                                       return !!this.$.checked;\r
+                               case 'value' :\r
+                                       var type = this.getAttribute( 'type' );\r
+                                       if ( type == 'checkbox' || type == 'radio' )\r
+                                               return this.$.value != 'on';\r
+                                       break;\r
+                               default:\r
+                       }\r
+               }\r
+\r
+               return !!( $attr && $attr.specified );\r
+       };\r
+}\r