Changeset 618
- Timestamp:
- 12/14/06 12:20:09 (6 years ago)
- Files:
-
- 1 modified
-
trunk/plugins/Forms/forms.js (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/Forms/forms.js
r419 r618 5 5 6 6 function Forms(editor) { 7 this.editor = editor;8 var cfg = editor.config;9 var bl = Forms.btnList;10 var self = this;11 // register the toolbar buttons provided by this plugin7 this.editor = editor; 8 var cfg = editor.config; 9 var bl = Forms.btnList; 10 var self = this; 11 // register the toolbar buttons provided by this plugin 12 12 var toolbar = ["linebreak"]; 13 for (var i = 0; i < bl.length; ++i) { 14 var btn = bl[i]; 15 if (!btn) { 16 toolbar.push("separator"); 17 } else { 18 var id = btn[0]; 19 cfg.registerButton(id, HTMLArea._lc(btn[1]), editor.imgURL("ed_" + btn[0] + ".gif", "Forms"), false, 20 function(editor, id) { 21 // dispatch button press event 22 self.buttonPress(editor, id); 23 }); 24 toolbar.push(id); 25 } 26 } 27 // add a new line in the toolbar 28 cfg.toolbar.push(toolbar); 13 for (var i = 0; i < bl.length; ++i) { 14 var btn = bl[i]; 15 if (!btn) { 16 toolbar.push("separator"); 17 } else { 18 var id = btn[0]; 19 if (i<3) 20 cfg.registerButton(id, HTMLArea._lc(btn[1]), editor.imgURL("ed_" + btn[0] + ".gif", "Forms"), false, 21 function(editor, id) { 22 // dispatch button press event 23 self.buttonPress(editor, id); 24 }); 25 else 26 cfg.registerButton(id, HTMLArea._lc(btn[1]), editor.imgURL("ed_" + btn[0] + ".gif", "Forms"), false, 27 function(editor, id) { 28 // dispatch button press event 29 self.buttonPress(editor, id); 30 },"form"); 31 toolbar.push(id); 32 } 33 } 34 // add a new line in the toolbar 35 cfg.toolbar.push(toolbar); 29 36 } 30 37 31 38 Forms._pluginInfo = { 32 39 name : "Forms", 33 origin : "version: 1.0, by Nelson Bright, BrightWork, Inc., http://www.brightworkweb.com",34 version : "2.0",35 developer : "Udo Schmal",36 developer_url : "",37 sponsor : "L.N.Schaffrath NeueMedien",38 sponsor_url : "http://www.schaffrath-neuemedien.de/",39 c_owner : "Udo Schmal & Schaffrath-NeueMedien",40 license : "htmlArea"40 origin : "version: 1.0, by Nelson Bright, BrightWork, Inc., http://www.brightworkweb.com", 41 version : "2.0", 42 developer : "Udo Schmal", 43 developer_url : "", 44 sponsor : "L.N.Schaffrath NeueMedien", 45 sponsor_url : "http://www.schaffrath-neuemedien.de/", 46 c_owner : "Udo Schmal & Schaffrath-NeueMedien", 47 license : "htmlArea" 41 48 }; 42 49 43 50 // the list of buttons added by this plugin 44 51 Forms.btnList = [ 45 // form properties button46 null, // separator47 ["form", "Form"],48 null,// separator49 // form elements50 ["textarea", "Textarea"],51 ["select", "Selection Field"],52 ["checkbox", "Checkbox"],53 ["radio", "Radio Button"],54 ["text", "Text Field"],52 // form properties button 53 null, // separator 54 ["form", "Form"], 55 null, // separator 56 // form elements 57 ["textarea", "Textarea"], 58 ["select", "Selection Field"], 59 ["checkbox", "Checkbox"], 60 ["radio", "Radio Button"], 61 ["text", "Text Field"], 55 62 ["password", "Password Field"], 56 63 ["file", "File Field"], 57 ["button", "Button"],64 ["button", "Button"], 58 65 ["submit", "Submit Button"], 59 ["reset", "Reset Button"], 60 ["image", "Image Button"],61 ["hidden", "Hidden Field"],66 ["reset", "Reset Button"], 67 ["image", "Image Button"], 68 ["hidden", "Hidden Field"], 62 69 ["label", "Label"], 63 70 ["fieldset", "Field Set"] 64 ];71 ]; 65 72 66 73 Forms.prototype._lc = function(string) { … … 82 89 Forms.prototype.buttonPress = function(editor,button_id, node) { 83 90 function optionValues(text,value) { 84 this.text = text;85 this.value = value;86 }91 this.text = text; 92 this.value = value; 93 } 87 94 var outparam = new Object(); 88 95 var type = button_id; … … 90 97 var range = editor._createRange(sel); 91 98 if (button_id=="form") { //Form 92 // see if selection is inside an existing 'form' tag93 var pe = editor.getParentElement();94 var frm = null;95 while (pe && (pe.nodeType == 1) && (pe.tagName.toLowerCase() != 'body')) {96 if(pe.tagName.toLowerCase() == "form") {97 frm = pe;98 break;99 } else 99 // see if selection is inside an existing 'form' tag 100 var pe = editor.getParentElement(); 101 var frm = null; 102 while (pe && (pe.nodeType == 1) && (pe.tagName.toLowerCase() != 'body')) { 103 if(pe.tagName.toLowerCase() == "form") { 104 frm = pe; 105 break; 106 } else 100 107 pe = pe.parentNode; 101 }102 if (frm) { 108 } 109 if (frm) { 103 110 outparam.f_name = frm.name; 104 111 outparam.f_action = frm.action; … … 108 115 } else {; 109 116 outparam.f_name = ""; 110 outparam.f_action = "";111 outparam.f_method = "";117 outparam.f_action = ""; 118 outparam.f_method = ""; 112 119 outparam.f_enctype = ""; 113 120 outparam.f_target = ""; 114 121 } 115 editor._popupDialog("plugin://Forms/form", function(param) {116 if (param) {117 if(frm) {118 frm.name= param["f_name"];122 editor._popupDialog("plugin://Forms/form", function(param) { 123 if (param) { 124 if(frm) { 125 frm.name = param["f_name"]; 119 126 setAttr(frm, "action", param["f_action"]); 120 127 setAttr(frm, "method", param["f_method"]); 121 128 setAttr(frm, "enctype",param["f_enctype"]); 122 129 setAttr(frm, "target", param["f_target"]); 123 } else {130 } else { 124 131 frm = '<form name="' + param["f_name"] + '"'; 125 132 if (param["f_action"] != "") frm += ' action="' + param["f_action"] + '"'; 126 if (param["f_method"] != "") frm += ' method="' + param["f_method"] + '"';133 if (param["f_method"] != "") frm += ' method="' + param["f_method"] + '"'; 127 134 if (param["f_enctype"] != "") frm += ' enctype="' + param["f_enctype"] + '"'; 128 135 if (param["f_target"] != "") frm += ' target="' + param["f_target"] + '"'; 129 136 frm += '>'; 130 editor.surroundHTML(frm, ' </form>');137 editor.surroundHTML(frm, ' </form>'); 131 138 } 132 139 } 133 }, outparam);134 140 }, outparam); 141 135 142 } else { // form element (checkbox, radio, text, password, textarea, select, button, submit, reset, image, hidden) 136 var tagName = "";137 // see if selection is an form element138 if (typeof node == "undefined") {139 node = editor.getParentElement();140 var tag = node.tagName.toLowerCase()143 var tagName = ""; 144 // see if selection is an form element 145 if (typeof node == "undefined") { 146 node = editor.getParentElement(); 147 var tag = node.tagName.toLowerCase() 141 148 if (node && (tag == "legend")) { 142 149 node = node.parentElement; 143 150 tag = node.tagName.toLowerCase(); 144 151 } 145 if (node && !(tag == "textarea" || tag == "select" || tag == "input" || tag == "label" || tag == "fieldset"))146 node = null;147 }148 149 if(node) {150 type = node.tagName.toLowerCase();152 if (node && !(tag == "textarea" || tag == "select" || tag == "input" || tag == "label" || tag == "fieldset")) 153 node = null; 154 } 155 156 if(node) { 157 type = node.tagName.toLowerCase(); 151 158 outparam.f_name = node.name; 152 159 tagName = node.tagName; … … 157 164 switch (type) { 158 165 case "textarea": 159 outparam.f_cols = node.cols;160 outparam.f_rows = node.rows;161 outparam.f_text = node.innerHTML;166 outparam.f_cols = node.cols; 167 outparam.f_rows = node.rows; 168 outparam.f_text = node.innerHTML; 162 169 outparam.f_wrap = node.getAttribute("wrap"); 163 170 outparam.f_readOnly = node.getAttribute("readOnly"); … … 165 172 outparam.f_tabindex = node.getAttribute("tabindex"); 166 173 outparam.f_accesskey = node.getAttribute("accesskey"); 167 break;174 break; 168 175 case "select": 169 outparam.f_size = parseInt(node.size);170 outparam.f_multiple = node.getAttribute("multiple");171 outparam.f_disabled = node.getAttribute("disabled"); 172 outparam.f_tabindex = node.getAttribute("tabindex"); 173 var a_options = new Array(); 174 for (var i=0; i<=node.options.length-1; i++) {176 outparam.f_size = parseInt(node.size); 177 outparam.f_multiple = node.getAttribute("multiple"); 178 outparam.f_disabled = node.getAttribute("disabled"); 179 outparam.f_tabindex = node.getAttribute("tabindex"); 180 var a_options = new Array(); 181 for (var i=0; i<=node.options.length-1; i++) { 175 182 a_options[i] = new optionValues(node.options[i].text, node.options[i].value); 176 }177 outparam.f_options = a_options;178 break;179 case "text":180 case "password":181 outparam.f_value = node.value;182 outparam.f_size = node.size;183 outparam.f_maxLength = node.maxLength;183 } 184 outparam.f_options = a_options; 185 break; 186 case "text": 187 case "password": 188 outparam.f_value = node.value; 189 outparam.f_size = node.size; 190 outparam.f_maxLength = node.maxLength; 184 191 outparam.f_readOnly = node.getAttribute("readOnly"); 185 192 outparam.f_disabled = node.getAttribute("disabled"); 186 193 outparam.f_tabindex = node.getAttribute("tabindex"); 187 194 outparam.f_accesskey = node.getAttribute("accesskey"); 188 break;189 case "hidden":190 outparam.f_value = node.value; 191 break; 192 case "submit":193 case "reset":194 outparam.f_value = node.value;195 outparam.f_disabled = node.getAttribute("disabled"); 196 outparam.f_tabindex = node.getAttribute("tabindex"); 197 outparam.f_accesskey = node.getAttribute("accesskey"); 198 break;199 case "checkbox":200 case "radio": 201 outparam.f_value = node.value;202 outparam.f_checked = node.checked;203 outparam.f_disabled = node.getAttribute("disabled"); 204 outparam.f_tabindex = node.getAttribute("tabindex"); 205 outparam.f_accesskey = node.getAttribute("accesskey"); 206 break;207 case "button": 208 outparam.f_value = node.value;209 outparam.f_onclick = node.getAttribute("onclick");210 outparam.f_disabled = node.getAttribute("disabled"); 211 outparam.f_tabindex = node.getAttribute("tabindex"); 212 outparam.f_accesskey = node.getAttribute("accesskey"); 213 break;214 case "image":215 outparam.f_value = node.value;216 outparam.f_src = node.src;217 outparam.f_disabled = node.getAttribute("disabled"); 218 outparam.f_tabindex = node.getAttribute("tabindex"); 219 outparam.f_accesskey = node.getAttribute("accesskey"); 220 break;195 break; 196 case "hidden": 197 outparam.f_value = node.value; 198 break; 199 case "submit": 200 case "reset": 201 outparam.f_value = node.value; 202 outparam.f_disabled = node.getAttribute("disabled"); 203 outparam.f_tabindex = node.getAttribute("tabindex"); 204 outparam.f_accesskey = node.getAttribute("accesskey"); 205 break; 206 case "checkbox": 207 case "radio": 208 outparam.f_value = node.value; 209 outparam.f_checked = node.checked; 210 outparam.f_disabled = node.getAttribute("disabled"); 211 outparam.f_tabindex = node.getAttribute("tabindex"); 212 outparam.f_accesskey = node.getAttribute("accesskey"); 213 break; 214 case "button": 215 outparam.f_value = node.value; 216 outparam.f_onclick = node.getAttribute("onclick"); 217 outparam.f_disabled = node.getAttribute("disabled"); 218 outparam.f_tabindex = node.getAttribute("tabindex"); 219 outparam.f_accesskey = node.getAttribute("accesskey"); 220 break; 221 case "image": 222 outparam.f_value = node.value; 223 outparam.f_src = node.src; 224 outparam.f_disabled = node.getAttribute("disabled"); 225 outparam.f_tabindex = node.getAttribute("tabindex"); 226 outparam.f_accesskey = node.getAttribute("accesskey"); 227 break; 221 228 case "file": 222 229 outparam.f_disabled = node.getAttribute("disabled"); 223 230 outparam.f_tabindex = node.getAttribute("tabindex"); 224 231 outparam.f_accesskey = node.getAttribute("accesskey"); 225 break;232 break; 226 233 case "label": 227 234 outparam.f_text = node.innerHTML; … … 235 242 outparam.f_text = ""; 236 243 break; 237 } 238 } else {244 } 245 } else { 239 246 outparam.f_name = ""; 240 247 switch (button_id) { … … 252 259 outparam.f_options = ""; 253 260 outparam.f_cols = "20"; 254 outparam.f_rows = "4";255 outparam.f_multiple = "false";256 outparam.f_value = "";257 outparam.f_size = "";258 outparam.f_maxLength = "";259 outparam.f_checked = "";260 outparam.f_src = "";261 outparam.f_onclick = "";261 outparam.f_rows = "4"; 262 outparam.f_multiple = "false"; 263 outparam.f_value = ""; 264 outparam.f_size = ""; 265 outparam.f_maxLength = ""; 266 outparam.f_checked = ""; 267 outparam.f_src = ""; 268 outparam.f_onclick = ""; 262 269 outparam.f_wrap = ""; 263 270 outparam.f_readOnly = "false"; … … 268 275 outparam.f_text = ""; 269 276 outparam.f_legend = ""; 270 }271 editor._popupDialog("plugin://Forms/" + tagName + ".html", function(param) {272 if (param) {277 } 278 editor._popupDialog("plugin://Forms/" + tagName + ".html", function(param) { 279 if (param) { 273 280 if(param["f_cols"]) 274 281 if (isNaN(parseInt(param["f_cols"],10)) || parseInt(param["f_cols"],10) <= 0) … … 283 290 if(isNaN(parseInt(param["f_maxLength"],10)) || parseInt(param["f_maxLength"],10) <= 0) 284 291 param["f_maxLength"] = ""; 285 if(node) {292 if(node) { 286 293 //prepare existing Element 287 294 for (field in param) { 288 295 alert(field.substring(2,20) + '=' + param[field]); 289 if ((field=="f_text") || (field=="f_options") || (field=="f_onclick") || (field=="f_checked"))continue;296 if ((field=="f_text") || (field=="f_options") || (field=="f_onclick") || (field=="f_checked"))continue; 290 297 if (param[field] != "") 291 298 node.setAttribute(field.substring(2,20), param[field]); 292 299 else 293 300 node.removeAttribute(field.substring(2,20)); 294 }295 if (type == "textarea") {301 } 302 if (type == "textarea") { 296 303 node.innerHTML = param["f_text"]; 297 } else if(type == "select") {298 node.options.length = 0;299 var optionsList = param["f_options"];300 for (i=0; i<= optionsList.length-1; i++) {301 node.options[i] = new Option(optionsList[i].text, optionsList[i].value)302 }303 } else if(type == "label") {304 node.innerHTML = param["f_text"];304 } else if(type == "select") { 305 node.options.length = 0; 306 var optionsList = param["f_options"]; 307 for (i=0; i<= optionsList.length-1; i++) { 308 node.options[i] = new Option(optionsList[i].text, optionsList[i].value) 309 } 310 } else if(type == "label") { 311 node.innerHTML = param["f_text"]; 305 312 } else if(type == "fieldset") { 306 313 if(outparam.f_text != "") { 307 if(node.firstChild.tagName.toLowerCase()=="legend")314 if(node.firstChild.tagName.toLowerCase()=="legend") 308 315 node.firstChild.innerHTML = param["f_text"]; 309 316 } else {}// not implemented jet 310 317 } else if((type == "checkbox") || (type == "radio")) { //input 311 318 if(param["f_checked"]!="") 312 node.checked = true;319 node.checked = true; 313 320 else 314 321 node.checked = false; 315 322 } else { 316 323 if(param["f_onclick"]){ 317 node.onclick = "";318 if(param["f_onclick"]!="") 319 node.onclick = param["f_onclick"];324 node.onclick = ""; 325 if(param["f_onclick"]!="") 326 node.onclick = param["f_onclick"]; 320 327 } 321 }328 } 322 329 } else { 323 330 //create Element 324 331 var text = ""; 325 332 for (field in param) { 326 if (!param[field]) continue;333 if (!param[field]) continue; 327 334 if ((param[field]=="") || (field=="f_text")|| (field=="f_options"))continue; 328 335 text += " " + field.substring(2,20) + '="' + param[field] + '"'; 329 }330 331 if(type == "textarea") {332 text = '<textarea' + text + '>' + param["f_text"] + '</textarea>';333 } else if(type == "select") {334 text = '<select' + text + '>';335 var optionsList = param["f_options"];336 for (i=0; i<= optionsList.length-1; i++) {337 text += '<option value="'+optionsList[i].value+'">'+optionsList[i].text+'</option>';338 }339 text += '</select>';336 } 337 338 if(type == "textarea") { 339 text = '<textarea' + text + '>' + param["f_text"] + '</textarea>'; 340 } else if(type == "select") { 341 text = '<select' + text + '>'; 342 var optionsList = param["f_options"]; 343 for (i=0; i<= optionsList.length-1; i++) { 344 text += '<option value="'+optionsList[i].value+'">'+optionsList[i].text+'</option>'; 345 } 346 text += '</select>'; 340 347 } else if(type == "label") { 341 348 text = '<label' + text + '>' + param["f_text"] + '</label>'; … … 343 350 text = '<fieldset' + text + '>'; 344 351 if (param["f_legend"] != "") text += '<legend>' + param["f_text"] + '</legend>'; 345 text += '</fieldset>';346 } else {347 text = '<input type="'+type+'"' + text + '>';348 }349 editor.insertHTML(text);352 text += '</fieldset>'; 353 } else { 354 text = '<input type="'+type+'"' + text + '>'; 355 } 356 editor.insertHTML(text); 350 357 } 351 358 } 352 }, outparam);353 } 359 }, outparam); 360 } 354 361 };
