Index: trunk/extensions/SemanticForms/libs/SemanticForms.js |
— | — | @@ -5,6 +5,7 @@ |
6 | 6 | * |
7 | 7 | * @author Yaron Koren |
8 | 8 | * @author Sanyam Goyal |
| 9 | + * @author Stephan Gambke |
9 | 10 | * @author Jeffrey Stuckman |
10 | 11 | * @author Harold Solbrig |
11 | 12 | * @author Eugene Mednikov |
— | — | @@ -212,16 +213,16 @@ |
213 | 214 | |
214 | 215 | |
215 | 216 | /* |
216 | | - * Functions to register/unregister methods for the initialisation/validation |
217 | | - * of inputs |
| 217 | + * Functions to register/unregister methods for the initialization and |
| 218 | + * validation of inputs. |
218 | 219 | */ |
219 | 220 | |
220 | | -// Initialise data object to hold initialisation and validation data |
| 221 | +// Initialize data object to hold initialization and validation data |
221 | 222 | function setupSF() { |
222 | 223 | |
223 | 224 | jQuery("#sfForm").data("SemanticForms",{ |
224 | | - initialisation : new Array(), |
225 | | - validation : new Array |
| 225 | + initFunctions : new Array(), |
| 226 | + validationFunctions : new Array |
226 | 227 | }); |
227 | 228 | |
228 | 229 | } |
— | — | @@ -229,11 +230,11 @@ |
230 | 231 | // Register a validation method |
231 | 232 | // |
232 | 233 | // More than one method may be registered for one input by subsequent calls to |
233 | | -// registerValidation. |
| 234 | +// SemanticForms_registerInputValidation. |
234 | 235 | // |
235 | 236 | // @param valfunction The validation functions. Must take a string (the input's id) and an object as parameters |
236 | 237 | // @param param The parameter object given to the validation function |
237 | | -jQuery.fn.registerValidation = function(valfunction, param) { |
| 238 | +jQuery.fn.SemanticForms_registerInputValidation = function(valfunction, param) { |
238 | 239 | |
239 | 240 | if ( ! this.attr("id") ) return this; |
240 | 241 | |
— | — | @@ -241,11 +242,11 @@ |
242 | 243 | setupSF(); |
243 | 244 | } |
244 | 245 | |
245 | | - if ( ! jQuery("#sfForm").data("SemanticForms").validation[this.attr("id")] ) { |
246 | | - jQuery("#sfForm").data("SemanticForms").validation[this.attr("id")] = new Array(); |
| 246 | + if ( ! jQuery("#sfForm").data("SemanticForms").validationFunctions[this.attr("id")] ) { |
| 247 | + jQuery("#sfForm").data("SemanticForms").validationFunctions[this.attr("id")] = new Array(); |
247 | 248 | } |
248 | 249 | |
249 | | - jQuery("#sfForm").data("SemanticForms").validation[this.attr("id")].push({ |
| 250 | + jQuery("#sfForm").data("SemanticForms").validationFunctions[this.attr("id")].push({ |
250 | 251 | valfunction : valfunction, |
251 | 252 | parameters : param |
252 | 253 | }); |
— | — | @@ -253,16 +254,16 @@ |
254 | 255 | return this; |
255 | 256 | }; |
256 | 257 | |
257 | | -// Register an initialisation method |
| 258 | +// Register an initialization method |
258 | 259 | // |
259 | 260 | // More than one method may be registered for one input by subsequent calls to |
260 | | -// registerInitialisation. This method also executes the inifunction if the |
| 261 | +// SemanticForms_registerInputInit. This method also executes the initFunction if the |
261 | 262 | // element referenced by /this/ is not part of a multipleTemplateStarter. |
262 | 263 | // |
263 | | -// @param inifunction The initialisation functions. Must take a string (the input's id) and an object as parameters |
264 | | -// @param param The parameter object given to the initialisation function |
265 | | -// @param noexecute If set, the initialisation method will not be executed here |
266 | | -jQuery.fn.registerInitialisation = function( inifunction, param, noexecute ) { |
| 264 | +// @param initFunction The initialization function. Must take a string (the input's id) and an object as parameters |
| 265 | +// @param param The parameter object given to the initialization function |
| 266 | +// @param noexecute If set, the initialization method will not be executed here |
| 267 | +jQuery.fn.SemanticForms_registerInputInit = function( initFunction, param, noexecute ) { |
267 | 268 | |
268 | 269 | // return if element has no id |
269 | 270 | if ( ! this.attr("id") ) return this; |
— | — | @@ -272,43 +273,44 @@ |
273 | 274 | setupSF(); |
274 | 275 | } |
275 | 276 | |
276 | | - // if no initialisation function for this input registered yet, create entry |
277 | | - if ( ! jQuery("#sfForm").data("SemanticForms").initialisation[this.attr("id")] ) { |
278 | | - jQuery("#sfForm").data("SemanticForms").initialisation[this.attr("id")] = new Array(); |
| 277 | + // if no initialization function for this input was registered yet, |
| 278 | + // create entry |
| 279 | + if ( ! jQuery("#sfForm").data("SemanticForms").initFunctions[this.attr("id")] ) { |
| 280 | + jQuery("#sfForm").data("SemanticForms").initFunctions[this.attr("id")] = new Array(); |
279 | 281 | } |
280 | 282 | |
281 | | - // record initialisation function |
282 | | - jQuery("#sfForm").data("SemanticForms").initialisation[this.attr("id")].push({ |
283 | | - inifunction : inifunction, |
| 283 | + // record initialization function |
| 284 | + jQuery("#sfForm").data("SemanticForms").initFunctions[this.attr("id")].push({ |
| 285 | + initFunction : initFunction, |
284 | 286 | parameters : param |
285 | 287 | }); |
286 | 288 | |
287 | | - // execute initialisation if input is not part of multipleTemplateStarter |
| 289 | + // execute initialization if input is not part of multipleTemplateStarter |
288 | 290 | // and if not forbidden |
289 | 291 | if ( this.closest(".multipleTemplateStarter").length == 0 && !noexecute) { |
290 | 292 | var input = this; |
291 | | - // ensure inifunction is only exectued after doc structure is complete |
292 | | - jQuery(function(){inifunction ( input.attr("id"), param )}); |
| 293 | + // ensure initFunction is only exectued after doc structure is complete |
| 294 | + jQuery(function() {initFunction ( input.attr("id"), param )}); |
293 | 295 | } |
294 | 296 | |
295 | 297 | return this; |
296 | 298 | }; |
297 | 299 | |
298 | 300 | // Unregister all validation methods for the element referenced by /this/ |
299 | | -jQuery.fn.unregisterValidation = function() { |
| 301 | +jQuery.fn.SemanticForms_unregisterInputValidation = function() { |
300 | 302 | |
301 | 303 | if ( this.attr("id") && jQuery("#sfForm").data("SemanticForms") ) { |
302 | | - delete jQuery("#sfForm").data("SemanticForms").validation[this.attr("id")]; |
| 304 | + delete jQuery("#sfForm").data("SemanticForms").validationFunctions[this.attr("id")]; |
303 | 305 | } |
304 | 306 | |
305 | 307 | return this; |
306 | 308 | } |
307 | 309 | |
308 | | -// Unregister all initialisation methods for the element referenced by /this/ |
309 | | -jQuery.fn.unregisterInitialisation = function() { |
| 310 | +// Unregister all initialization methods for the element referenced by /this/ |
| 311 | +jQuery.fn.SemanticForms_unregisterInputInit = function() { |
310 | 312 | |
311 | 313 | if ( this.attr("id") && jQuery("#sfForm").data("SemanticForms") ) { |
312 | | - delete jQuery("#sfForm").data("SemanticForms").initialisation[this.attr("id")]; |
| 314 | + delete jQuery("#sfForm").data("SemanticForms").initFunctions[this.attr("id")]; |
313 | 315 | } |
314 | 316 | |
315 | 317 | return this; |
— | — | @@ -557,13 +559,14 @@ |
558 | 560 | if (sfdata) { // found data object? |
559 | 561 | |
560 | 562 | // for every registered input |
561 | | - for ( var id in sfdata.validation ) { |
| 563 | + for ( var id in sfdata.validationFunctions ) { |
562 | 564 | |
563 | 565 | // if input is not part of multipleTemplateStarter |
564 | 566 | if ( jQuery("#" + id).closest(".multipleTemplateStarter").length == 0 ) { |
565 | 567 | |
566 | | - for ( var i in sfdata.validation[id]) { // every validation method for that input |
567 | | - if (! sfdata.validation[id][i].valfunction(id, sfdata.validation[id][i].parameters) ) |
| 568 | + // Call every validation method for this input. |
| 569 | + for ( var i in sfdata.validationFunctions[id]) { |
| 570 | + if (! sfdata.validationFunctions[id][i].valfunction(id, sfdata.validationFunctions[id][i].parameters) ) |
568 | 571 | num_errors += 1; |
569 | 572 | } |
570 | 573 | } |
— | — | @@ -619,29 +622,31 @@ |
620 | 623 | |
621 | 624 | this.id = this.id.replace(/input_/g, 'input_' + num_elements + '_'); |
622 | 625 | |
623 | | - // register initialisation and validation methods for new inputs |
| 626 | + // register initialization and validation methods for new inputs |
624 | 627 | |
625 | 628 | var sfdata = jQuery("#sfForm").data('SemanticForms'); |
626 | 629 | if (sfdata) { // found data object? |
627 | 630 | |
628 | | - // for every initialisation method for input with id old_id |
629 | | - for ( var i in sfdata.initialisation[old_id] ) { |
| 631 | + // For every initialization method for |
| 632 | + // input with id old_id, register the |
| 633 | + // method for the new input. |
| 634 | + for ( var i in sfdata.initFunctions[old_id] ) { |
630 | 635 | |
631 | | - // take initialisation method and register for new input |
632 | | - jQuery(this).registerInitialisation( |
633 | | - sfdata.initialisation[old_id][i].inifunction, |
634 | | - sfdata.initialisation[old_id][i].parameters, |
| 636 | + jQuery(this).SemanticForms_registerInputInit( |
| 637 | + sfdata.initFunctions[old_id][i].initFunction, |
| 638 | + sfdata.initFunctions[old_id][i].parameters, |
635 | 639 | true //do not yet execute |
636 | 640 | ); |
637 | 641 | } |
638 | 642 | |
639 | | - // for every validation method for input with id old_id |
640 | | - for ( i in sfdata.validation[old_id] ) { |
| 643 | + // For every validation method for the |
| 644 | + // input with ID old_id, register it |
| 645 | + // for the new input. |
| 646 | + for ( i in sfdata.validationFunctions[old_id] ) { |
641 | 647 | |
642 | | - // take validation method and register for new input |
643 | | - jQuery(this).registerValidation( |
644 | | - sfdata.validation[old_id][i].valfunction, |
645 | | - sfdata.validation[old_id][i].parameters |
| 648 | + jQuery(this).SemanticForms_registerInputValidation( |
| 649 | + sfdata.validationFunctions[old_id][i].valfunction, |
| 650 | + sfdata.validationFunctions[old_id][i].parameters |
646 | 651 | ); |
647 | 652 | } |
648 | 653 | } |
— | — | @@ -672,13 +677,14 @@ |
673 | 678 | // Enable the new remover |
674 | 679 | new_div.find('.remover').click( function() { |
675 | 680 | |
676 | | - // unregister initialisation and validation for deleted inputs |
677 | | - // probably unnecessary as the used id's will never be assigned a second |
678 | | - // time, but it's the clean solution (if only to free memory) |
| 681 | + // Unregister initialization and validation for deleted inputs - |
| 682 | + // probably unnecessary, since the used IDs will never be |
| 683 | + // assigned a second time, but it's the clean solution (if |
| 684 | + // only to free memory) |
679 | 685 | jQuery(this).parent().find("input, select, textarea").each( |
680 | 686 | function() { |
681 | | - jQuery(this).unregisterInitialisation(); |
682 | | - jQuery(this).unregisterValidation(); |
| 687 | + jQuery(this).SemanticForms_unregisterInputInit(); |
| 688 | + jQuery(this).SemanticForms_unregisterInputValidation(); |
683 | 689 | } |
684 | 690 | ); |
685 | 691 | |
— | — | @@ -710,7 +716,7 @@ |
711 | 717 | // Handle AutoGrow as well. |
712 | 718 | new_div.find('.autoGrow').autoGrow(); |
713 | 719 | |
714 | | - // initialise new inputs |
| 720 | + // Initialize new inputs |
715 | 721 | new_div.find("input, select, textarea").each( |
716 | 722 | function() { |
717 | 723 | |
— | — | @@ -718,11 +724,12 @@ |
719 | 725 | |
720 | 726 | var sfdata = jQuery("#sfForm").data('SemanticForms'); |
721 | 727 | if (sfdata) { // if anything registered at all |
722 | | - |
723 | | - for ( var i in sfdata.initialisation[this.id] ) { // every initialisation method for this input |
724 | | - sfdata.initialisation[this.id][i].inifunction( |
| 728 | + // Call every initialization method |
| 729 | + // for this input |
| 730 | + for ( var i in sfdata.initFunctions[this.id] ) { |
| 731 | + sfdata.initFunctions[this.id][i].initFunction( |
725 | 732 | this.id, |
726 | | - sfdata.initialisation[this.id][i].parameters |
| 733 | + sfdata.initFunctions[this.id][i].parameters |
727 | 734 | ) |
728 | 735 | } |
729 | 736 | } |