Index: trunk/extensions/SemanticForms/includes/SF_GlobalFunctions.php |
— | — | @@ -141,6 +141,9 @@ |
142 | 142 | 'ext.semanticforms.autogrow' => $sfgResourceTemplate + array( |
143 | 143 | 'scripts' => 'libs/SF_autogrow.js', |
144 | 144 | ), |
| 145 | + 'ext.semanticforms.preview' => $sfgResourceTemplate + array( |
| 146 | + 'scripts' => 'libs/SF_ajax_form_preview.js', |
| 147 | + ), |
145 | 148 | ); |
146 | 149 | } |
147 | 150 | |
Index: trunk/extensions/SemanticForms/includes/SF_Utils.php |
— | — | @@ -178,6 +178,7 @@ |
179 | 179 | $wgOut->addModules( 'ext.semanticforms.main' ); |
180 | 180 | $wgOut->addModules( 'ext.semanticforms.fancybox' ); |
181 | 181 | $wgOut->addModules( 'ext.semanticforms.autogrow' ); |
| 182 | + $wgOut->addModules( 'ext.semanticforms.preview' ); |
182 | 183 | $wgOut->addModules( 'ext.smw.tooltips' ); |
183 | 184 | $wgOut->addModules( 'ext.smw.sorttable' ); |
184 | 185 | } |
Index: trunk/extensions/SemanticForms/libs/SemanticForms.js |
— | — | @@ -210,7 +210,109 @@ |
211 | 211 | }; |
212 | 212 | })( jQuery ); |
213 | 213 | |
| 214 | + |
214 | 215 | /* |
| 216 | + * Functions to register/unregister methods for the initialisation/validation |
| 217 | + * of inputs |
| 218 | + */ |
| 219 | + |
| 220 | +// Initialise data object to hold initialisation and validation data |
| 221 | +function setupSF() { |
| 222 | + |
| 223 | + jQuery("#sfForm").data("SemanticForms",{ |
| 224 | + initialisation : new Array(), |
| 225 | + validation : new Array |
| 226 | + }); |
| 227 | + |
| 228 | +} |
| 229 | + |
| 230 | +// Register a validation method |
| 231 | +// |
| 232 | +// More than one method may be registered for one input by subsequent calls to |
| 233 | +// registerValidation. |
| 234 | +// |
| 235 | +// @param valfunction The validation functions. Must take a string (the input's id) and an object as parameters |
| 236 | +// @param param The parameter object given to the validation function |
| 237 | +jQuery.fn.registerValidation = function(valfunction, param) { |
| 238 | + |
| 239 | + if ( ! this.attr("id") ) return this; |
| 240 | + |
| 241 | + if ( ! jQuery("#sfForm").data("SemanticForms") ) { |
| 242 | + setupSF(); |
| 243 | + } |
| 244 | + |
| 245 | + if ( ! jQuery("#sfForm").data("SemanticForms").validation[this.attr("id")] ) { |
| 246 | + jQuery("#sfForm").data("SemanticForms").validation[this.attr("id")] = new Array(); |
| 247 | + } |
| 248 | + |
| 249 | + jQuery("#sfForm").data("SemanticForms").validation[this.attr("id")].push({ |
| 250 | + valfunction : valfunction, |
| 251 | + parameters : param |
| 252 | + }); |
| 253 | + |
| 254 | + return this; |
| 255 | +}; |
| 256 | + |
| 257 | +// Register an initialisation method |
| 258 | +// |
| 259 | +// 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 | +// element referenced by /this/ is not part of a multipleTemplateStarter. |
| 262 | +// |
| 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 | +jQuery.fn.registerInitialisation = function( inifunction, param ) { |
| 266 | + |
| 267 | + // return if element has no id |
| 268 | + if ( ! this.attr("id") ) return this; |
| 269 | + |
| 270 | + // setup data structure if necessary |
| 271 | + if ( ! jQuery("#sfForm").data("SemanticForms") ) { |
| 272 | + setupSF(); |
| 273 | + } |
| 274 | + |
| 275 | + // if no initialisation function for this input registered yet, create entry |
| 276 | + if ( ! jQuery("#sfForm").data("SemanticForms").initialisation[this.attr("id")] ) { |
| 277 | + jQuery("#sfForm").data("SemanticForms").initialisation[this.attr("id")] = new Array(); |
| 278 | + } |
| 279 | + |
| 280 | + // record initialisation function |
| 281 | + jQuery("#sfForm").data("SemanticForms").initialisation[this.attr("id")].push({ |
| 282 | + inifunction : inifunction, |
| 283 | + parameters : param |
| 284 | + }); |
| 285 | + |
| 286 | + // execute initialisation if input is not part of multipleTemplateStarter |
| 287 | + if ( this.closest(".multipleTemplateStarter").length == 0 ) { |
| 288 | + var input = this; |
| 289 | + // ensure inifunction is only exectued after doc structure is complete |
| 290 | + jQuery(function(){inifunction ( input.attr("id"), param )}); |
| 291 | + } |
| 292 | + |
| 293 | + return this; |
| 294 | +}; |
| 295 | + |
| 296 | +// Unregister all validation methods for the element referenced by /this/ |
| 297 | +jQuery.fn.unregisterValidation = function() { |
| 298 | + |
| 299 | + if ( this.attr("id") && jQuery("#sfForm").data("SemanticForms") ) { |
| 300 | + delete jQuery("#sfForm").data("SemanticForms").validation[this.attr("id")]; |
| 301 | + } |
| 302 | + |
| 303 | + return this; |
| 304 | +} |
| 305 | + |
| 306 | +// Unregister all initialisation methods for the element referenced by /this/ |
| 307 | +jQuery.fn.unregisterInitialisation = function() { |
| 308 | + |
| 309 | + if ( this.attr("id") && jQuery("#sfForm").data("SemanticForms") ) { |
| 310 | + delete jQuery("#sfForm").data("SemanticForms").initialisation[this.attr("id")]; |
| 311 | + } |
| 312 | + |
| 313 | + return this; |
| 314 | +} |
| 315 | + |
| 316 | +/* |
215 | 317 | * Functions for handling 'show on select' |
216 | 318 | */ |
217 | 319 | |
— | — | @@ -409,7 +511,7 @@ |
410 | 512 | } |
411 | 513 | } |
412 | 514 | |
413 | | -function validateAll() { |
| 515 | +window.validateAll = function () { |
414 | 516 | var num_errors = 0; |
415 | 517 | |
416 | 518 | // Remove all old error messages. |
— | — | @@ -447,6 +549,25 @@ |
448 | 550 | if (! jQuery(this).validateDateField() ) num_errors += 1; |
449 | 551 | }); |
450 | 552 | |
| 553 | + // call registered validation functions |
| 554 | + var sfdata = jQuery("#sfForm").data('SemanticForms'); |
| 555 | + |
| 556 | + if (sfdata) { // found data object? |
| 557 | + |
| 558 | + // for every registered input |
| 559 | + for ( var id in sfdata.validation ) { |
| 560 | + |
| 561 | + // if input is not part of multipleTemplateStarter |
| 562 | + if ( jQuery("#" + id).closest(".multipleTemplateStarter").length == 0 ) { |
| 563 | + |
| 564 | + for ( var i in sfdata.validation[id]) { // every validation method for that input |
| 565 | + if (! sfdata.validation[id][i].valfunction(id, sfdata.validation[id][i].parameters) ) |
| 566 | + num_errors += 1; |
| 567 | + } |
| 568 | + } |
| 569 | + } |
| 570 | + } |
| 571 | + |
451 | 572 | if (num_errors > 0) { |
452 | 573 | // add error header, if it's not there already |
453 | 574 | if (jQuery("#form_error_header").size() == 0) { |
— | — | @@ -489,10 +610,42 @@ |
490 | 611 | function() { |
491 | 612 | if (this.name) |
492 | 613 | this.name = this.name.replace(/\[num\]/g, '[' + num_elements + ']'); |
493 | | - if (this.id) |
494 | | - this.id = this.id.replace(/input_/g, 'input_' + num_elements + '_') |
| 614 | + |
| 615 | + if (this.id) { |
| 616 | + |
| 617 | + var old_id = this.id; |
| 618 | + |
| 619 | + this.id = this.id.replace(/input_/g, 'input_' + num_elements + '_'); |
| 620 | + |
| 621 | + // register initialisation and validation methods for new inputs |
| 622 | + |
| 623 | + var sfdata = jQuery("#sfForm").data('SemanticForms'); |
| 624 | + if (sfdata) { // found data object? |
| 625 | + |
| 626 | + // for every initialisation method for input with id old_id |
| 627 | + for ( var i in sfdata.initialisation[old_id] ) { |
| 628 | + |
| 629 | + // take initialisation method and register for new input |
| 630 | + jQuery(this).registerInitialisation( |
| 631 | + sfdata.initialisation[old_id][i].inifunction, |
| 632 | + sfdata.initialisation[old_id][i].parameters |
| 633 | + ); |
| 634 | + } |
| 635 | + |
| 636 | + // for every validation method for input with id old_id |
| 637 | + for ( i in sfdata.validation[old_id] ) { |
| 638 | + |
| 639 | + // take validation method and register for new input |
| 640 | + jQuery(this).registerValidation( |
| 641 | + sfdata.validation[old_id][i].valfunction, |
| 642 | + sfdata.validation[old_id][i].parameters |
| 643 | + ); |
| 644 | + } |
| 645 | + } |
| 646 | + } |
495 | 647 | } |
496 | 648 | ); |
| 649 | + |
497 | 650 | new_div.find('a').attr('href', function() { |
498 | 651 | return this.href.replace(/input_/g, 'input_' + num_elements + '_'); |
499 | 652 | }); |
— | — | @@ -515,6 +668,17 @@ |
516 | 669 | |
517 | 670 | // Enable the new remover |
518 | 671 | new_div.find('.remover').click( function() { |
| 672 | + |
| 673 | + // unregister initialisation and validation for deleted inputs |
| 674 | + // probably unnecessary as the used id's will never be assigned a second |
| 675 | + // time, but it's the clean solution (if only to free memory) |
| 676 | + jQuery(this).parent().find("input, select, textarea").each( |
| 677 | + function() { |
| 678 | + jQuery(this).unregisterInitialisation(); |
| 679 | + jQuery(this).unregisterValidation(); |
| 680 | + } |
| 681 | + ); |
| 682 | + |
519 | 683 | jQuery(this).parent().remove(); |
520 | 684 | }); |
521 | 685 | |
— | — | @@ -542,6 +706,27 @@ |
543 | 707 | |
544 | 708 | // Handle AutoGrow as well. |
545 | 709 | new_div.find('.autoGrow').autoGrow(); |
| 710 | + |
| 711 | + // initialise new inputs |
| 712 | + new_div.find("input, select, textarea").each( |
| 713 | + function() { |
| 714 | + |
| 715 | + if (this.id) { |
| 716 | + |
| 717 | + var sfdata = jQuery("#sfForm").data('SemanticForms'); |
| 718 | + if (sfdata) { // if anything registered at all |
| 719 | + |
| 720 | + for ( var i in sfdata.initialisation[this.id] ) { // every initialisation method for this input |
| 721 | + sfdata.initialisation[this.id][i].inifunction( |
| 722 | + this.id, |
| 723 | + sfdata.initialisation[this.id][i].parameters |
| 724 | + ) |
| 725 | + } |
| 726 | + } |
| 727 | + } |
| 728 | + } |
| 729 | + ); |
| 730 | + |
546 | 731 | } |
547 | 732 | |
548 | 733 | var num_elements = 0; |
Index: trunk/extensions/SemanticForms/libs/SF_ajax_form_preview.js |
— | — | @@ -35,7 +35,7 @@ |
36 | 36 | } |
37 | 37 | |
38 | 38 | function ajaxFormPreviewClick(){ajaxFormPreviewRun(this)} |
39 | | - |
| 39 | + |
40 | 40 | function ajaxFormPreviewRun(btn){ |
41 | 41 | |
42 | 42 | wkPreview = document.getElementById('wikiPreview'); |
— | — | @@ -181,7 +181,7 @@ |
182 | 182 | if (currentfr && !window.opera){ |
183 | 183 | |
184 | 184 | if (currentfr.contentDocument) { //ns6 syntax |
185 | | - doc = currentfr.contentDocument; |
| 185 | + doc = currentfr.contentDocument; |
186 | 186 | } else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax |
187 | 187 | doc = currentfr.Document; |
188 | 188 | } |
— | — | @@ -199,14 +199,14 @@ |
200 | 200 | visible.style.border="0px"; |
201 | 201 | |
202 | 202 | pv = visible; |
203 | | - |
| 203 | + |
204 | 204 | while (pv.previousSibling) { |
205 | 205 | pv = pv.previousSibling; |
206 | 206 | if (pv.style) pv.style.display="none"; |
207 | 207 | } |
208 | 208 | |
209 | 209 | pv = visible; |
210 | | - |
| 210 | + |
211 | 211 | while (pv.nextSibling) { |
212 | 212 | pv = pv.nextSibling; |
213 | 213 | if (pv.style) pv.style.display="none"; |
— | — | @@ -245,4 +245,5 @@ |
246 | 246 | } |
247 | 247 | |
248 | 248 | if (wgAction=='formedit' || wgCanonicalSpecialPageName == 'FormEdit') |
249 | | - addOnloadHook(ajaxFormPreviewInit); |
| 249 | +// addOnloadHook(ajaxFormPreviewInit); |
| 250 | + jQuery(function(){ajaxFormPreviewInit()}); |