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 /** 7 * @file Forms Plugin 8 */ 9 10 CKEDITOR.plugins.add( 'forms', 11 { 12 init : function( editor ) 13 { 14 var lang = editor.lang; 15 16 editor.addCss( 17 'form' + 18 '{' + 19 'border: 1px dotted #FF0000;' + 20 'padding: 2px;' + 21 '}' ); 22 23 // All buttons use the same code to register. So, to avoid 24 // duplications, let's use this tool function. 25 var addButtonCommand = function( buttonName, commandName, dialogFile ) 26 { 27 editor.addCommand( commandName, new CKEDITOR.dialogCommand( commandName ) ); 28 29 editor.ui.addButton( buttonName, 30 { 31 label : lang.common[ buttonName.charAt(0).toLowerCase() + buttonName.slice(1) ], 32 command : commandName 33 }); 34 CKEDITOR.dialog.add( commandName, dialogFile ); 35 }; 36 37 var dialogPath = this.path + 'dialogs/'; 38 addButtonCommand( 'Form', 'form', dialogPath + 'form.js' ); 39 addButtonCommand( 'Checkbox', 'checkbox', dialogPath + 'checkbox.js' ); 40 addButtonCommand( 'Radio', 'radio', dialogPath + 'radio.js' ); 41 addButtonCommand( 'TextField', 'textfield', dialogPath + 'textfield.js' ); 42 addButtonCommand( 'Textarea', 'textarea', dialogPath + 'textarea.js' ); 43 addButtonCommand( 'Select', 'select', dialogPath + 'select.js' ); 44 addButtonCommand( 'Button', 'button', dialogPath + 'button.js' ); 45 addButtonCommand( 'ImageButton', 'imagebutton', CKEDITOR.plugins.getPath('image') + 'dialogs/image.js' ); 46 addButtonCommand( 'HiddenField', 'hiddenfield', dialogPath + 'hiddenfield.js' ); 47 48 // If the "menu" plugin is loaded, register the menu items. 49 if ( editor.addMenuItems ) 50 { 51 editor.addMenuItems( 52 { 53 form : 54 { 55 label : lang.form.menu, 56 command : 'form', 57 group : 'form' 58 }, 59 60 checkbox : 61 { 62 label : lang.checkboxAndRadio.checkboxTitle, 63 command : 'checkbox', 64 group : 'checkbox' 65 }, 66 67 radio : 68 { 69 label : lang.checkboxAndRadio.radioTitle, 70 command : 'radio', 71 group : 'radio' 72 }, 73 74 textfield : 75 { 76 label : lang.textfield.title, 77 command : 'textfield', 78 group : 'textfield' 79 }, 80 81 hiddenfield : 82 { 83 label : lang.hidden.title, 84 command : 'hiddenfield', 85 group : 'hiddenfield' 86 }, 87 88 imagebutton : 89 { 90 label : lang.image.titleButton, 91 command : 'imagebutton', 92 group : 'imagebutton' 93 }, 94 95 button : 96 { 97 label : lang.button.title, 98 command : 'button', 99 group : 'button' 100 }, 101 102 select : 103 { 104 label : lang.select.title, 105 command : 'select', 106 group : 'select' 107 }, 108 109 textarea : 110 { 111 label : lang.textarea.title, 112 command : 'textarea', 113 group : 'textarea' 114 } 115 }); 116 } 117 118 // If the "contextmenu" plugin is loaded, register the listeners. 119 if ( editor.contextMenu ) 120 { 121 editor.contextMenu.addListener( function( element ) 122 { 123 if ( element && element.hasAscendant( 'form' ) ) 124 return { form : CKEDITOR.TRISTATE_OFF }; 125 }); 126 127 editor.contextMenu.addListener( function( element ) 128 { 129 if ( element ) 130 { 131 var name = element.getName(); 132 133 if ( name == 'select' ) 134 return { select : CKEDITOR.TRISTATE_OFF }; 135 136 if ( name == 'textarea' ) 137 return { textarea : CKEDITOR.TRISTATE_OFF }; 138 139 if ( name == 'input' ) 140 { 141 var type = element.getAttribute( 'type' ); 142 143 if ( type == 'text' || type == 'password' ) 144 return { textfield : CKEDITOR.TRISTATE_OFF }; 145 146 if ( type == 'button' || type == 'submit' || type == 'reset' ) 147 return { button : CKEDITOR.TRISTATE_OFF }; 148 149 if ( type == 'checkbox' ) 150 return { checkbox : CKEDITOR.TRISTATE_OFF }; 151 152 if ( type == 'radio' ) 153 return { radio : CKEDITOR.TRISTATE_OFF }; 154 155 if ( type == 'image' ) 156 return { imagebutton : CKEDITOR.TRISTATE_OFF }; 157 } 158 159 if ( name == 'img' && element.getAttribute( '_cke_real_element_type' ) == 'hiddenfield' ) 160 return { hiddenfield : CKEDITOR.TRISTATE_OFF }; 161 } 162 }); 163 } 164 }, 165 requires : [ 'image' ] 166 } ); 167