r79539 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79538‎ | r79539 | r79540 >
Date:00:19, 4 January 2011
Author:yaron
Status:deferred
Tags:
Comment:
Added Stephan Gambke to authors list, improved some of the comments (including "Americanising" the s's to z's), improved some of the new function and variable names for more clarity
Modified paths:
  • /trunk/extensions/SemanticForms/libs/SemanticForms.js (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/libs/SemanticForms.js
@@ -5,6 +5,7 @@
66 *
77 * @author Yaron Koren
88 * @author Sanyam Goyal
 9+ * @author Stephan Gambke
910 * @author Jeffrey Stuckman
1011 * @author Harold Solbrig
1112 * @author Eugene Mednikov
@@ -212,16 +213,16 @@
213214
214215
215216 /*
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.
218219 */
219220
220 -// Initialise data object to hold initialisation and validation data
 221+// Initialize data object to hold initialization and validation data
221222 function setupSF() {
222223
223224 jQuery("#sfForm").data("SemanticForms",{
224 - initialisation : new Array(),
225 - validation : new Array
 225+ initFunctions : new Array(),
 226+ validationFunctions : new Array
226227 });
227228
228229 }
@@ -229,11 +230,11 @@
230231 // Register a validation method
231232 //
232233 // More than one method may be registered for one input by subsequent calls to
233 -// registerValidation.
 234+// SemanticForms_registerInputValidation.
234235 //
235236 // @param valfunction The validation functions. Must take a string (the input's id) and an object as parameters
236237 // @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) {
238239
239240 if ( ! this.attr("id") ) return this;
240241
@@ -241,11 +242,11 @@
242243 setupSF();
243244 }
244245
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();
247248 }
248249
249 - jQuery("#sfForm").data("SemanticForms").validation[this.attr("id")].push({
 250+ jQuery("#sfForm").data("SemanticForms").validationFunctions[this.attr("id")].push({
250251 valfunction : valfunction,
251252 parameters : param
252253 });
@@ -253,16 +254,16 @@
254255 return this;
255256 };
256257
257 -// Register an initialisation method
 258+// Register an initialization method
258259 //
259260 // 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
261262 // element referenced by /this/ is not part of a multipleTemplateStarter.
262263 //
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 ) {
267268
268269 // return if element has no id
269270 if ( ! this.attr("id") ) return this;
@@ -272,43 +273,44 @@
273274 setupSF();
274275 }
275276
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();
279281 }
280282
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,
284286 parameters : param
285287 });
286288
287 - // execute initialisation if input is not part of multipleTemplateStarter
 289+ // execute initialization if input is not part of multipleTemplateStarter
288290 // and if not forbidden
289291 if ( this.closest(".multipleTemplateStarter").length == 0 && !noexecute) {
290292 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 )});
293295 }
294296
295297 return this;
296298 };
297299
298300 // Unregister all validation methods for the element referenced by /this/
299 -jQuery.fn.unregisterValidation = function() {
 301+jQuery.fn.SemanticForms_unregisterInputValidation = function() {
300302
301303 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")];
303305 }
304306
305307 return this;
306308 }
307309
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() {
310312
311313 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")];
313315 }
314316
315317 return this;
@@ -557,13 +559,14 @@
558560 if (sfdata) { // found data object?
559561
560562 // for every registered input
561 - for ( var id in sfdata.validation ) {
 563+ for ( var id in sfdata.validationFunctions ) {
562564
563565 // if input is not part of multipleTemplateStarter
564566 if ( jQuery("#" + id).closest(".multipleTemplateStarter").length == 0 ) {
565567
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) )
568571 num_errors += 1;
569572 }
570573 }
@@ -619,29 +622,31 @@
620623
621624 this.id = this.id.replace(/input_/g, 'input_' + num_elements + '_');
622625
623 - // register initialisation and validation methods for new inputs
 626+ // register initialization and validation methods for new inputs
624627
625628 var sfdata = jQuery("#sfForm").data('SemanticForms');
626629 if (sfdata) { // found data object?
627630
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] ) {
630635
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,
635639 true //do not yet execute
636640 );
637641 }
638642
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] ) {
641647
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
646651 );
647652 }
648653 }
@@ -672,13 +677,14 @@
673678 // Enable the new remover
674679 new_div.find('.remover').click( function() {
675680
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)
679685 jQuery(this).parent().find("input, select, textarea").each(
680686 function() {
681 - jQuery(this).unregisterInitialisation();
682 - jQuery(this).unregisterValidation();
 687+ jQuery(this).SemanticForms_unregisterInputInit();
 688+ jQuery(this).SemanticForms_unregisterInputValidation();
683689 }
684690 );
685691
@@ -710,7 +716,7 @@
711717 // Handle AutoGrow as well.
712718 new_div.find('.autoGrow').autoGrow();
713719
714 - // initialise new inputs
 720+ // Initialize new inputs
715721 new_div.find("input, select, textarea").each(
716722 function() {
717723
@@ -718,11 +724,12 @@
719725
720726 var sfdata = jQuery("#sfForm").data('SemanticForms');
721727 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(
725732 this.id,
726 - sfdata.initialisation[this.id][i].parameters
 733+ sfdata.initFunctions[this.id][i].parameters
727734 )
728735 }
729736 }

Status & tagging log