r100950 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100949‎ | r100950 | r100951 >
Date:06:17, 27 October 2011
Author:jpostlethwaite
Status:ok
Tags:fundraising 
Comment:
Adding jquery.validate.js to DonationInterface, under GlobalCollect. This will be a part of the module gc.form.core.validate
Modified paths:
  • /trunk/extensions/DonationInterface/globalcollect_gateway/modules/js (added) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/modules/js/jquery.validate.additional-methods.js (added) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/modules/js/jquery.validate.js (added) (history)
  • /trunk/extensions/DonationInterface/globalcollect_gateway/modules/js/validate.js (added) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/globalcollect_gateway/modules/js/jquery.validate.js
@@ -0,0 +1,1188 @@
 2+/**
 3+ * jQuery Validation Plugin 1.9.0
 4+ *
 5+ * http://bassistance.de/jquery-plugins/jquery-plugin-validation/
 6+ * http://docs.jquery.com/Plugins/Validation
 7+ *
 8+ * Copyright (c) 2006 - 2011 Jörn Zaefferer
 9+ *
 10+ * Dual licensed under the MIT and GPL licenses:
 11+ * http://www.opensource.org/licenses/mit-license.php
 12+ * http://www.gnu.org/licenses/gpl.html
 13+ */
 14+
 15+(function($) {
 16+
 17+$.extend($.fn, {
 18+ // http://docs.jquery.com/Plugins/Validation/validate
 19+ validate: function( options ) {
 20+
 21+ // if nothing is selected, return nothing; can't chain anyway
 22+ if (!this.length) {
 23+ options && options.debug && window.console && console.warn( "nothing selected, can't validate, returning nothing" );
 24+ return;
 25+ }
 26+
 27+ // check if a validator for this form was already created
 28+ var validator = $.data(this[0], 'validator');
 29+ if ( validator ) {
 30+ return validator;
 31+ }
 32+
 33+ // Add novalidate tag if HTML5.
 34+ this.attr('novalidate', 'novalidate');
 35+
 36+ validator = new $.validator( options, this[0] );
 37+ $.data(this[0], 'validator', validator);
 38+
 39+ if ( validator.settings.onsubmit ) {
 40+
 41+ var inputsAndButtons = this.find("input, button");
 42+
 43+ // allow suppresing validation by adding a cancel class to the submit button
 44+ inputsAndButtons.filter(".cancel").click(function () {
 45+ validator.cancelSubmit = true;
 46+ });
 47+
 48+ // when a submitHandler is used, capture the submitting button
 49+ if (validator.settings.submitHandler) {
 50+ inputsAndButtons.filter(":submit").click(function () {
 51+ validator.submitButton = this;
 52+ });
 53+ }
 54+
 55+ // validate the form on submit
 56+ this.submit( function( event ) {
 57+ if ( validator.settings.debug )
 58+ // prevent form submit to be able to see console output
 59+ event.preventDefault();
 60+
 61+ function handle() {
 62+ if ( validator.settings.submitHandler ) {
 63+ if (validator.submitButton) {
 64+ // insert a hidden input as a replacement for the missing submit button
 65+ var hidden = $("<input type='hidden'/>").attr("name", validator.submitButton.name).val(validator.submitButton.value).appendTo(validator.currentForm);
 66+ }
 67+ validator.settings.submitHandler.call( validator, validator.currentForm );
 68+ if (validator.submitButton) {
 69+ // and clean up afterwards; thanks to no-block-scope, hidden can be referenced
 70+ hidden.remove();
 71+ }
 72+ return false;
 73+ }
 74+ return true;
 75+ }
 76+
 77+ // prevent submit for invalid forms or custom submit handlers
 78+ if ( validator.cancelSubmit ) {
 79+ validator.cancelSubmit = false;
 80+ return handle();
 81+ }
 82+ if ( validator.form() ) {
 83+ if ( validator.pendingRequest ) {
 84+ validator.formSubmitted = true;
 85+ return false;
 86+ }
 87+ return handle();
 88+ } else {
 89+ validator.focusInvalid();
 90+ return false;
 91+ }
 92+ });
 93+ }
 94+
 95+ return validator;
 96+ },
 97+ // http://docs.jquery.com/Plugins/Validation/valid
 98+ valid: function() {
 99+ if ( $(this[0]).is('form')) {
 100+ return this.validate().form();
 101+ } else {
 102+ var valid = true;
 103+ var validator = $(this[0].form).validate();
 104+ this.each(function() {
 105+ valid &= validator.element(this);
 106+ });
 107+ return valid;
 108+ }
 109+ },
 110+ // attributes: space seperated list of attributes to retrieve and remove
 111+ removeAttrs: function(attributes) {
 112+ var result = {},
 113+ $element = this;
 114+ $.each(attributes.split(/\s/), function(index, value) {
 115+ result[value] = $element.attr(value);
 116+ $element.removeAttr(value);
 117+ });
 118+ return result;
 119+ },
 120+ // http://docs.jquery.com/Plugins/Validation/rules
 121+ rules: function(command, argument) {
 122+ var element = this[0];
 123+
 124+ if (command) {
 125+ var settings = $.data(element.form, 'validator').settings;
 126+ var staticRules = settings.rules;
 127+ var existingRules = $.validator.staticRules(element);
 128+ switch(command) {
 129+ case "add":
 130+ $.extend(existingRules, $.validator.normalizeRule(argument));
 131+ staticRules[element.name] = existingRules;
 132+ if (argument.messages)
 133+ settings.messages[element.name] = $.extend( settings.messages[element.name], argument.messages );
 134+ break;
 135+ case "remove":
 136+ if (!argument) {
 137+ delete staticRules[element.name];
 138+ return existingRules;
 139+ }
 140+ var filtered = {};
 141+ $.each(argument.split(/\s/), function(index, method) {
 142+ filtered[method] = existingRules[method];
 143+ delete existingRules[method];
 144+ });
 145+ return filtered;
 146+ }
 147+ }
 148+
 149+ var data = $.validator.normalizeRules(
 150+ $.extend(
 151+ {},
 152+ $.validator.metadataRules(element),
 153+ $.validator.classRules(element),
 154+ $.validator.attributeRules(element),
 155+ $.validator.staticRules(element)
 156+ ), element);
 157+
 158+ // make sure required is at front
 159+ if (data.required) {
 160+ var param = data.required;
 161+ delete data.required;
 162+ data = $.extend({required: param}, data);
 163+ }
 164+
 165+ return data;
 166+ }
 167+});
 168+
 169+// Custom selectors
 170+$.extend($.expr[":"], {
 171+ // http://docs.jquery.com/Plugins/Validation/blank
 172+ blank: function(a) {return !$.trim("" + a.value);},
 173+ // http://docs.jquery.com/Plugins/Validation/filled
 174+ filled: function(a) {return !!$.trim("" + a.value);},
 175+ // http://docs.jquery.com/Plugins/Validation/unchecked
 176+ unchecked: function(a) {return !a.checked;}
 177+});
 178+
 179+// constructor for validator
 180+$.validator = function( options, form ) {
 181+ this.settings = $.extend( true, {}, $.validator.defaults, options );
 182+ this.currentForm = form;
 183+ this.init();
 184+};
 185+
 186+$.validator.format = function(source, params) {
 187+ if ( arguments.length == 1 )
 188+ return function() {
 189+ var args = $.makeArray(arguments);
 190+ args.unshift(source);
 191+ return $.validator.format.apply( this, args );
 192+ };
 193+ if ( arguments.length > 2 && params.constructor != Array ) {
 194+ params = $.makeArray(arguments).slice(1);
 195+ }
 196+ if ( params.constructor != Array ) {
 197+ params = [ params ];
 198+ }
 199+ $.each(params, function(i, n) {
 200+ source = source.replace(new RegExp("\\{" + i + "\\}", "g"), n);
 201+ });
 202+ return source;
 203+};
 204+
 205+$.extend($.validator, {
 206+
 207+ defaults: {
 208+ messages: {},
 209+ groups: {},
 210+ rules: {},
 211+ errorClass: "error",
 212+ validClass: "valid",
 213+ errorElement: "label",
 214+ focusInvalid: true,
 215+ errorContainer: $( [] ),
 216+ errorLabelContainer: $( [] ),
 217+ onsubmit: true,
 218+ ignore: ":hidden",
 219+ ignoreTitle: false,
 220+ onfocusin: function(element, event) {
 221+ this.lastActive = element;
 222+
 223+ // hide error label and remove error class on focus if enabled
 224+ if ( this.settings.focusCleanup && !this.blockFocusCleanup ) {
 225+ this.settings.unhighlight && this.settings.unhighlight.call( this, element, this.settings.errorClass, this.settings.validClass );
 226+ this.addWrapper(this.errorsFor(element)).hide();
 227+ }
 228+ },
 229+ onfocusout: function(element, event) {
 230+ if ( !this.checkable(element) && (element.name in this.submitted || !this.optional(element)) ) {
 231+ this.element(element);
 232+ }
 233+ },
 234+ onkeyup: function(element, event) {
 235+ if ( element.name in this.submitted || element == this.lastElement ) {
 236+ this.element(element);
 237+ }
 238+ },
 239+ onclick: function(element, event) {
 240+ // click on selects, radiobuttons and checkboxes
 241+ if ( element.name in this.submitted )
 242+ this.element(element);
 243+ // or option elements, check parent select in that case
 244+ else if (element.parentNode.name in this.submitted)
 245+ this.element(element.parentNode);
 246+ },
 247+ highlight: function(element, errorClass, validClass) {
 248+ if (element.type === 'radio') {
 249+ this.findByName(element.name).addClass(errorClass).removeClass(validClass);
 250+ } else {
 251+ $(element).addClass(errorClass).removeClass(validClass);
 252+ }
 253+ },
 254+ unhighlight: function(element, errorClass, validClass) {
 255+ if (element.type === 'radio') {
 256+ this.findByName(element.name).removeClass(errorClass).addClass(validClass);
 257+ } else {
 258+ $(element).removeClass(errorClass).addClass(validClass);
 259+ }
 260+ }
 261+ },
 262+
 263+ // http://docs.jquery.com/Plugins/Validation/Validator/setDefaults
 264+ setDefaults: function(settings) {
 265+ $.extend( $.validator.defaults, settings );
 266+ },
 267+
 268+ messages: {
 269+ required: "This field is required.",
 270+ remote: "Please fix this field.",
 271+ email: "Please enter a valid email address.",
 272+ url: "Please enter a valid URL.",
 273+ date: "Please enter a valid date.",
 274+ dateISO: "Please enter a valid date (ISO).",
 275+ number: "Please enter a valid number.",
 276+ digits: "Please enter only digits.",
 277+ creditcard: "Please enter a valid credit card number.",
 278+ equalTo: "Please enter the same value again.",
 279+ accept: "Please enter a value with a valid extension.",
 280+ maxlength: $.validator.format("Please enter no more than {0} characters."),
 281+ minlength: $.validator.format("Please enter at least {0} characters."),
 282+ rangelength: $.validator.format("Please enter a value between {0} and {1} characters long."),
 283+ range: $.validator.format("Please enter a value between {0} and {1}."),
 284+ max: $.validator.format("Please enter a value less than or equal to {0}."),
 285+ min: $.validator.format("Please enter a value greater than or equal to {0}.")
 286+ },
 287+
 288+ autoCreateRanges: false,
 289+
 290+ prototype: {
 291+
 292+ init: function() {
 293+ this.labelContainer = $(this.settings.errorLabelContainer);
 294+ this.errorContext = this.labelContainer.length && this.labelContainer || $(this.currentForm);
 295+ this.containers = $(this.settings.errorContainer).add( this.settings.errorLabelContainer );
 296+ this.submitted = {};
 297+ this.valueCache = {};
 298+ this.pendingRequest = 0;
 299+ this.pending = {};
 300+ this.invalid = {};
 301+ this.reset();
 302+
 303+ var groups = (this.groups = {});
 304+ $.each(this.settings.groups, function(key, value) {
 305+ $.each(value.split(/\s/), function(index, name) {
 306+ groups[name] = key;
 307+ });
 308+ });
 309+ var rules = this.settings.rules;
 310+ $.each(rules, function(key, value) {
 311+ rules[key] = $.validator.normalizeRule(value);
 312+ });
 313+
 314+ function delegate(event) {
 315+ var validator = $.data(this[0].form, "validator"),
 316+ eventType = "on" + event.type.replace(/^validate/, "");
 317+ validator.settings[eventType] && validator.settings[eventType].call(validator, this[0], event);
 318+ }
 319+ $(this.currentForm)
 320+ .validateDelegate("[type='text'], [type='password'], [type='file'], select, textarea, " +
 321+ "[type='number'], [type='search'] ,[type='tel'], [type='url'], " +
 322+ "[type='email'], [type='datetime'], [type='date'], [type='month'], " +
 323+ "[type='week'], [type='time'], [type='datetime-local'], " +
 324+ "[type='range'], [type='color'] ",
 325+ "focusin focusout keyup", delegate)
 326+ .validateDelegate("[type='radio'], [type='checkbox'], select, option", "click", delegate);
 327+
 328+ if (this.settings.invalidHandler)
 329+ $(this.currentForm).bind("invalid-form.validate", this.settings.invalidHandler);
 330+ },
 331+
 332+ // http://docs.jquery.com/Plugins/Validation/Validator/form
 333+ form: function() {
 334+ this.checkForm();
 335+ $.extend(this.submitted, this.errorMap);
 336+ this.invalid = $.extend({}, this.errorMap);
 337+ if (!this.valid())
 338+ $(this.currentForm).triggerHandler("invalid-form", [this]);
 339+ this.showErrors();
 340+ return this.valid();
 341+ },
 342+
 343+ checkForm: function() {
 344+ this.prepareForm();
 345+ for ( var i = 0, elements = (this.currentElements = this.elements()); elements[i]; i++ ) {
 346+ this.check( elements[i] );
 347+ }
 348+ return this.valid();
 349+ },
 350+
 351+ // http://docs.jquery.com/Plugins/Validation/Validator/element
 352+ element: function( element ) {
 353+ element = this.validationTargetFor( this.clean( element ) );
 354+ this.lastElement = element;
 355+ this.prepareElement( element );
 356+ this.currentElements = $(element);
 357+ var result = this.check( element );
 358+ if ( result ) {
 359+ delete this.invalid[element.name];
 360+ } else {
 361+ this.invalid[element.name] = true;
 362+ }
 363+ if ( !this.numberOfInvalids() ) {
 364+ // Hide error containers on last error
 365+ this.toHide = this.toHide.add( this.containers );
 366+ }
 367+ this.showErrors();
 368+ return result;
 369+ },
 370+
 371+ // http://docs.jquery.com/Plugins/Validation/Validator/showErrors
 372+ showErrors: function(errors) {
 373+ if(errors) {
 374+ // add items to error list and map
 375+ $.extend( this.errorMap, errors );
 376+ this.errorList = [];
 377+ for ( var name in errors ) {
 378+ this.errorList.push({
 379+ message: errors[name],
 380+ element: this.findByName(name)[0]
 381+ });
 382+ }
 383+ // remove items from success list
 384+ this.successList = $.grep( this.successList, function(element) {
 385+ return !(element.name in errors);
 386+ });
 387+ }
 388+ this.settings.showErrors
 389+ ? this.settings.showErrors.call( this, this.errorMap, this.errorList )
 390+ : this.defaultShowErrors();
 391+ },
 392+
 393+ // http://docs.jquery.com/Plugins/Validation/Validator/resetForm
 394+ resetForm: function() {
 395+ if ( $.fn.resetForm )
 396+ $( this.currentForm ).resetForm();
 397+ this.submitted = {};
 398+ this.lastElement = null;
 399+ this.prepareForm();
 400+ this.hideErrors();
 401+ this.elements().removeClass( this.settings.errorClass );
 402+ },
 403+
 404+ numberOfInvalids: function() {
 405+ return this.objectLength(this.invalid);
 406+ },
 407+
 408+ objectLength: function( obj ) {
 409+ var count = 0;
 410+ for ( var i in obj )
 411+ count++;
 412+ return count;
 413+ },
 414+
 415+ hideErrors: function() {
 416+ this.addWrapper( this.toHide ).hide();
 417+ },
 418+
 419+ valid: function() {
 420+ return this.size() == 0;
 421+ },
 422+
 423+ size: function() {
 424+ return this.errorList.length;
 425+ },
 426+
 427+ focusInvalid: function() {
 428+ if( this.settings.focusInvalid ) {
 429+ try {
 430+ $(this.findLastActive() || this.errorList.length && this.errorList[0].element || [])
 431+ .filter(":visible")
 432+ .focus()
 433+ // manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find
 434+ .trigger("focusin");
 435+ } catch(e) {
 436+ // ignore IE throwing errors when focusing hidden elements
 437+ }
 438+ }
 439+ },
 440+
 441+ findLastActive: function() {
 442+ var lastActive = this.lastActive;
 443+ return lastActive && $.grep(this.errorList, function(n) {
 444+ return n.element.name == lastActive.name;
 445+ }).length == 1 && lastActive;
 446+ },
 447+
 448+ elements: function() {
 449+ var validator = this,
 450+ rulesCache = {};
 451+
 452+ // select all valid inputs inside the form (no submit or reset buttons)
 453+ return $(this.currentForm)
 454+ .find("input, select, textarea")
 455+ .not(":submit, :reset, :image, [disabled]")
 456+ .not( this.settings.ignore )
 457+ .filter(function() {
 458+ !this.name && validator.settings.debug && window.console && console.error( "%o has no name assigned", this);
 459+
 460+ // select only the first element for each name, and only those with rules specified
 461+ if ( this.name in rulesCache || !validator.objectLength($(this).rules()) )
 462+ return false;
 463+
 464+ rulesCache[this.name] = true;
 465+ return true;
 466+ });
 467+ },
 468+
 469+ clean: function( selector ) {
 470+ return $( selector )[0];
 471+ },
 472+
 473+ errors: function() {
 474+ return $( this.settings.errorElement + "." + this.settings.errorClass, this.errorContext );
 475+ },
 476+
 477+ reset: function() {
 478+ this.successList = [];
 479+ this.errorList = [];
 480+ this.errorMap = {};
 481+ this.toShow = $([]);
 482+ this.toHide = $([]);
 483+ this.currentElements = $([]);
 484+ },
 485+
 486+ prepareForm: function() {
 487+ this.reset();
 488+ this.toHide = this.errors().add( this.containers );
 489+ },
 490+
 491+ prepareElement: function( element ) {
 492+ this.reset();
 493+ this.toHide = this.errorsFor(element);
 494+ },
 495+
 496+ check: function( element ) {
 497+ element = this.validationTargetFor( this.clean( element ) );
 498+
 499+ var rules = $(element).rules();
 500+ var dependencyMismatch = false;
 501+ for (var method in rules ) {
 502+ var rule = { method: method, parameters: rules[method] };
 503+ try {
 504+ var result = $.validator.methods[method].call( this, element.value.replace(/\r/g, ""), element, rule.parameters );
 505+
 506+ // if a method indicates that the field is optional and therefore valid,
 507+ // don't mark it as valid when there are no other rules
 508+ if ( result == "dependency-mismatch" ) {
 509+ dependencyMismatch = true;
 510+ continue;
 511+ }
 512+ dependencyMismatch = false;
 513+
 514+ if ( result == "pending" ) {
 515+ this.toHide = this.toHide.not( this.errorsFor(element) );
 516+ return;
 517+ }
 518+
 519+ if( !result ) {
 520+ this.formatAndAdd( element, rule );
 521+ return false;
 522+ }
 523+ } catch(e) {
 524+ this.settings.debug && window.console && console.log("exception occured when checking element " + element.id
 525+ + ", check the '" + rule.method + "' method", e);
 526+ throw e;
 527+ }
 528+ }
 529+ if (dependencyMismatch)
 530+ return;
 531+ if ( this.objectLength(rules) )
 532+ this.successList.push(element);
 533+ return true;
 534+ },
 535+
 536+ // return the custom message for the given element and validation method
 537+ // specified in the element's "messages" metadata
 538+ customMetaMessage: function(element, method) {
 539+ if (!$.metadata)
 540+ return;
 541+
 542+ var meta = this.settings.meta
 543+ ? $(element).metadata()[this.settings.meta]
 544+ : $(element).metadata();
 545+
 546+ return meta && meta.messages && meta.messages[method];
 547+ },
 548+
 549+ // return the custom message for the given element name and validation method
 550+ customMessage: function( name, method ) {
 551+ var m = this.settings.messages[name];
 552+ return m && (m.constructor == String
 553+ ? m
 554+ : m[method]);
 555+ },
 556+
 557+ // return the first defined argument, allowing empty strings
 558+ findDefined: function() {
 559+ for(var i = 0; i < arguments.length; i++) {
 560+ if (arguments[i] !== undefined)
 561+ return arguments[i];
 562+ }
 563+ return undefined;
 564+ },
 565+
 566+ defaultMessage: function( element, method) {
 567+ return this.findDefined(
 568+ this.customMessage( element.name, method ),
 569+ this.customMetaMessage( element, method ),
 570+ // title is never undefined, so handle empty string as undefined
 571+ !this.settings.ignoreTitle && element.title || undefined,
 572+ $.validator.messages[method],
 573+ "<strong>Warning: No message defined for " + element.name + "</strong>"
 574+ );
 575+ },
 576+
 577+ formatAndAdd: function( element, rule ) {
 578+ var message = this.defaultMessage( element, rule.method ),
 579+ theregex = /\$?\{(\d+)\}/g;
 580+ if ( typeof message == "function" ) {
 581+ message = message.call(this, rule.parameters, element);
 582+ } else if (theregex.test(message)) {
 583+ message = jQuery.format(message.replace(theregex, '{$1}'), rule.parameters);
 584+ }
 585+ this.errorList.push({
 586+ message: message,
 587+ element: element
 588+ });
 589+
 590+ this.errorMap[element.name] = message;
 591+ this.submitted[element.name] = message;
 592+ },
 593+
 594+ addWrapper: function(toToggle) {
 595+ if ( this.settings.wrapper )
 596+ toToggle = toToggle.add( toToggle.parent( this.settings.wrapper ) );
 597+ return toToggle;
 598+ },
 599+
 600+ defaultShowErrors: function() {
 601+ for ( var i = 0; this.errorList[i]; i++ ) {
 602+ var error = this.errorList[i];
 603+ this.settings.highlight && this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
 604+ this.showLabel( error.element, error.message );
 605+ }
 606+ if( this.errorList.length ) {
 607+ this.toShow = this.toShow.add( this.containers );
 608+ }
 609+ if (this.settings.success) {
 610+ for ( var i = 0; this.successList[i]; i++ ) {
 611+ this.showLabel( this.successList[i] );
 612+ }
 613+ }
 614+ if (this.settings.unhighlight) {
 615+ for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) {
 616+ this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass );
 617+ }
 618+ }
 619+ this.toHide = this.toHide.not( this.toShow );
 620+ this.hideErrors();
 621+ this.addWrapper( this.toShow ).show();
 622+ },
 623+
 624+ validElements: function() {
 625+ return this.currentElements.not(this.invalidElements());
 626+ },
 627+
 628+ invalidElements: function() {
 629+ return $(this.errorList).map(function() {
 630+ return this.element;
 631+ });
 632+ },
 633+
 634+ showLabel: function(element, message) {
 635+ var label = this.errorsFor( element );
 636+ if ( label.length ) {
 637+ // refresh error/success class
 638+ label.removeClass( this.settings.validClass ).addClass( this.settings.errorClass );
 639+
 640+ // check if we have a generated label, replace the message then
 641+ label.attr("generated") && label.html(message);
 642+ } else {
 643+ // create label
 644+ label = $("<" + this.settings.errorElement + "/>")
 645+ .attr({"for": this.idOrName(element), generated: true})
 646+ .addClass(this.settings.errorClass)
 647+ .html(message || "");
 648+ if ( this.settings.wrapper ) {
 649+ // make sure the element is visible, even in IE
 650+ // actually showing the wrapped element is handled elsewhere
 651+ label = label.hide().show().wrap("<" + this.settings.wrapper + "/>").parent();
 652+ }
 653+ if ( !this.labelContainer.append(label).length )
 654+ this.settings.errorPlacement
 655+ ? this.settings.errorPlacement(label, $(element) )
 656+ : label.insertAfter(element);
 657+ }
 658+ if ( !message && this.settings.success ) {
 659+ label.text("");
 660+ typeof this.settings.success == "string"
 661+ ? label.addClass( this.settings.success )
 662+ : this.settings.success( label );
 663+ }
 664+ this.toShow = this.toShow.add(label);
 665+ },
 666+
 667+ errorsFor: function(element) {
 668+ var name = this.idOrName(element);
 669+ return this.errors().filter(function() {
 670+ return $(this).attr('for') == name;
 671+ });
 672+ },
 673+
 674+ idOrName: function(element) {
 675+ return this.groups[element.name] || (this.checkable(element) ? element.name : element.id || element.name);
 676+ },
 677+
 678+ validationTargetFor: function(element) {
 679+ // if radio/checkbox, validate first element in group instead
 680+ if (this.checkable(element)) {
 681+ element = this.findByName( element.name ).not(this.settings.ignore)[0];
 682+ }
 683+ return element;
 684+ },
 685+
 686+ checkable: function( element ) {
 687+ return /radio|checkbox/i.test(element.type);
 688+ },
 689+
 690+ findByName: function( name ) {
 691+ // select by name and filter by form for performance over form.find("[name=...]")
 692+ var form = this.currentForm;
 693+ return $(document.getElementsByName(name)).map(function(index, element) {
 694+ return element.form == form && element.name == name && element || null;
 695+ });
 696+ },
 697+
 698+ getLength: function(value, element) {
 699+ switch( element.nodeName.toLowerCase() ) {
 700+ case 'select':
 701+ return $("option:selected", element).length;
 702+ case 'input':
 703+ if( this.checkable( element) )
 704+ return this.findByName(element.name).filter(':checked').length;
 705+ }
 706+ return value.length;
 707+ },
 708+
 709+ depend: function(param, element) {
 710+ return this.dependTypes[typeof param]
 711+ ? this.dependTypes[typeof param](param, element)
 712+ : true;
 713+ },
 714+
 715+ dependTypes: {
 716+ "boolean": function(param, element) {
 717+ return param;
 718+ },
 719+ "string": function(param, element) {
 720+ return !!$(param, element.form).length;
 721+ },
 722+ "function": function(param, element) {
 723+ return param(element);
 724+ }
 725+ },
 726+
 727+ optional: function(element) {
 728+ return !$.validator.methods.required.call(this, $.trim(element.value), element) && "dependency-mismatch";
 729+ },
 730+
 731+ startRequest: function(element) {
 732+ if (!this.pending[element.name]) {
 733+ this.pendingRequest++;
 734+ this.pending[element.name] = true;
 735+ }
 736+ },
 737+
 738+ stopRequest: function(element, valid) {
 739+ this.pendingRequest--;
 740+ // sometimes synchronization fails, make sure pendingRequest is never < 0
 741+ if (this.pendingRequest < 0)
 742+ this.pendingRequest = 0;
 743+ delete this.pending[element.name];
 744+ if ( valid && this.pendingRequest == 0 && this.formSubmitted && this.form() ) {
 745+ $(this.currentForm).submit();
 746+ this.formSubmitted = false;
 747+ } else if (!valid && this.pendingRequest == 0 && this.formSubmitted) {
 748+ $(this.currentForm).triggerHandler("invalid-form", [this]);
 749+ this.formSubmitted = false;
 750+ }
 751+ },
 752+
 753+ previousValue: function(element) {
 754+ return $.data(element, "previousValue") || $.data(element, "previousValue", {
 755+ old: null,
 756+ valid: true,
 757+ message: this.defaultMessage( element, "remote" )
 758+ });
 759+ }
 760+
 761+ },
 762+
 763+ classRuleSettings: {
 764+ required: {required: true},
 765+ email: {email: true},
 766+ url: {url: true},
 767+ date: {date: true},
 768+ dateISO: {dateISO: true},
 769+ dateDE: {dateDE: true},
 770+ number: {number: true},
 771+ numberDE: {numberDE: true},
 772+ digits: {digits: true},
 773+ creditcard: {creditcard: true}
 774+ },
 775+
 776+ addClassRules: function(className, rules) {
 777+ className.constructor == String ?
 778+ this.classRuleSettings[className] = rules :
 779+ $.extend(this.classRuleSettings, className);
 780+ },
 781+
 782+ classRules: function(element) {
 783+ var rules = {};
 784+ var classes = $(element).attr('class');
 785+ classes && $.each(classes.split(' '), function() {
 786+ if (this in $.validator.classRuleSettings) {
 787+ $.extend(rules, $.validator.classRuleSettings[this]);
 788+ }
 789+ });
 790+ return rules;
 791+ },
 792+
 793+ attributeRules: function(element) {
 794+ var rules = {};
 795+ var $element = $(element);
 796+
 797+ for (var method in $.validator.methods) {
 798+ var value;
 799+ // If .prop exists (jQuery >= 1.6), use it to get true/false for required
 800+ if (method === 'required' && typeof $.fn.prop === 'function') {
 801+ value = $element.prop(method);
 802+ } else {
 803+ value = $element.attr(method);
 804+ }
 805+ if (value) {
 806+ rules[method] = value;
 807+ } else if ($element[0].getAttribute("type") === method) {
 808+ rules[method] = true;
 809+ }
 810+ }
 811+
 812+ // maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
 813+ if (rules.maxlength && /-1|2147483647|524288/.test(rules.maxlength)) {
 814+ delete rules.maxlength;
 815+ }
 816+
 817+ return rules;
 818+ },
 819+
 820+ metadataRules: function(element) {
 821+ if (!$.metadata) return {};
 822+
 823+ var meta = $.data(element.form, 'validator').settings.meta;
 824+ return meta ?
 825+ $(element).metadata()[meta] :
 826+ $(element).metadata();
 827+ },
 828+
 829+ staticRules: function(element) {
 830+ var rules = {};
 831+ var validator = $.data(element.form, 'validator');
 832+ if (validator.settings.rules) {
 833+ rules = $.validator.normalizeRule(validator.settings.rules[element.name]) || {};
 834+ }
 835+ return rules;
 836+ },
 837+
 838+ normalizeRules: function(rules, element) {
 839+ // handle dependency check
 840+ $.each(rules, function(prop, val) {
 841+ // ignore rule when param is explicitly false, eg. required:false
 842+ if (val === false) {
 843+ delete rules[prop];
 844+ return;
 845+ }
 846+ if (val.param || val.depends) {
 847+ var keepRule = true;
 848+ switch (typeof val.depends) {
 849+ case "string":
 850+ keepRule = !!$(val.depends, element.form).length;
 851+ break;
 852+ case "function":
 853+ keepRule = val.depends.call(element, element);
 854+ break;
 855+ }
 856+ if (keepRule) {
 857+ rules[prop] = val.param !== undefined ? val.param : true;
 858+ } else {
 859+ delete rules[prop];
 860+ }
 861+ }
 862+ });
 863+
 864+ // evaluate parameters
 865+ $.each(rules, function(rule, parameter) {
 866+ rules[rule] = $.isFunction(parameter) ? parameter(element) : parameter;
 867+ });
 868+
 869+ // clean number parameters
 870+ $.each(['minlength', 'maxlength', 'min', 'max'], function() {
 871+ if (rules[this]) {
 872+ rules[this] = Number(rules[this]);
 873+ }
 874+ });
 875+ $.each(['rangelength', 'range'], function() {
 876+ if (rules[this]) {
 877+ rules[this] = [Number(rules[this][0]), Number(rules[this][1])];
 878+ }
 879+ });
 880+
 881+ if ($.validator.autoCreateRanges) {
 882+ // auto-create ranges
 883+ if (rules.min && rules.max) {
 884+ rules.range = [rules.min, rules.max];
 885+ delete rules.min;
 886+ delete rules.max;
 887+ }
 888+ if (rules.minlength && rules.maxlength) {
 889+ rules.rangelength = [rules.minlength, rules.maxlength];
 890+ delete rules.minlength;
 891+ delete rules.maxlength;
 892+ }
 893+ }
 894+
 895+ // To support custom messages in metadata ignore rule methods titled "messages"
 896+ if (rules.messages) {
 897+ delete rules.messages;
 898+ }
 899+
 900+ return rules;
 901+ },
 902+
 903+ // Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
 904+ normalizeRule: function(data) {
 905+ if( typeof data == "string" ) {
 906+ var transformed = {};
 907+ $.each(data.split(/\s/), function() {
 908+ transformed[this] = true;
 909+ });
 910+ data = transformed;
 911+ }
 912+ return data;
 913+ },
 914+
 915+ // http://docs.jquery.com/Plugins/Validation/Validator/addMethod
 916+ addMethod: function(name, method, message) {
 917+ $.validator.methods[name] = method;
 918+ $.validator.messages[name] = message != undefined ? message : $.validator.messages[name];
 919+ if (method.length < 3) {
 920+ $.validator.addClassRules(name, $.validator.normalizeRule(name));
 921+ }
 922+ },
 923+
 924+ methods: {
 925+
 926+ // http://docs.jquery.com/Plugins/Validation/Methods/required
 927+ required: function(value, element, param) {
 928+ // check if dependency is met
 929+ if ( !this.depend(param, element) )
 930+ return "dependency-mismatch";
 931+ switch( element.nodeName.toLowerCase() ) {
 932+ case 'select':
 933+ // could be an array for select-multiple or a string, both are fine this way
 934+ var val = $(element).val();
 935+ return val && val.length > 0;
 936+ case 'input':
 937+ if ( this.checkable(element) )
 938+ return this.getLength(value, element) > 0;
 939+ default:
 940+ return $.trim(value).length > 0;
 941+ }
 942+ },
 943+
 944+ // http://docs.jquery.com/Plugins/Validation/Methods/remote
 945+ remote: function(value, element, param) {
 946+ if ( this.optional(element) )
 947+ return "dependency-mismatch";
 948+
 949+ var previous = this.previousValue(element);
 950+ if (!this.settings.messages[element.name] )
 951+ this.settings.messages[element.name] = {};
 952+ previous.originalMessage = this.settings.messages[element.name].remote;
 953+ this.settings.messages[element.name].remote = previous.message;
 954+
 955+ param = typeof param == "string" && {url:param} || param;
 956+
 957+ if ( this.pending[element.name] ) {
 958+ return "pending";
 959+ }
 960+ if ( previous.old === value ) {
 961+ return previous.valid;
 962+ }
 963+
 964+ previous.old = value;
 965+ var validator = this;
 966+ this.startRequest(element);
 967+ var data = {};
 968+ data[element.name] = value;
 969+ $.ajax($.extend(true, {
 970+ url: param,
 971+ mode: "abort",
 972+ port: "validate" + element.name,
 973+ dataType: "json",
 974+ data: data,
 975+ success: function(response) {
 976+ validator.settings.messages[element.name].remote = previous.originalMessage;
 977+ var valid = response === true;
 978+ if ( valid ) {
 979+ var submitted = validator.formSubmitted;
 980+ validator.prepareElement(element);
 981+ validator.formSubmitted = submitted;
 982+ validator.successList.push(element);
 983+ validator.showErrors();
 984+ } else {
 985+ var errors = {};
 986+ var message = response || validator.defaultMessage( element, "remote" );
 987+ errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message;
 988+ validator.showErrors(errors);
 989+ }
 990+ previous.valid = valid;
 991+ validator.stopRequest(element, valid);
 992+ }
 993+ }, param));
 994+ return "pending";
 995+ },
 996+
 997+ // http://docs.jquery.com/Plugins/Validation/Methods/minlength
 998+ minlength: function(value, element, param) {
 999+ return this.optional(element) || this.getLength($.trim(value), element) >= param;
 1000+ },
 1001+
 1002+ // http://docs.jquery.com/Plugins/Validation/Methods/maxlength
 1003+ maxlength: function(value, element, param) {
 1004+ return this.optional(element) || this.getLength($.trim(value), element) <= param;
 1005+ },
 1006+
 1007+ // http://docs.jquery.com/Plugins/Validation/Methods/rangelength
 1008+ rangelength: function(value, element, param) {
 1009+ var length = this.getLength($.trim(value), element);
 1010+ return this.optional(element) || ( length >= param[0] && length <= param[1] );
 1011+ },
 1012+
 1013+ // http://docs.jquery.com/Plugins/Validation/Methods/min
 1014+ min: function( value, element, param ) {
 1015+ return this.optional(element) || value >= param;
 1016+ },
 1017+
 1018+ // http://docs.jquery.com/Plugins/Validation/Methods/max
 1019+ max: function( value, element, param ) {
 1020+ return this.optional(element) || value <= param;
 1021+ },
 1022+
 1023+ // http://docs.jquery.com/Plugins/Validation/Methods/range
 1024+ range: function( value, element, param ) {
 1025+ return this.optional(element) || ( value >= param[0] && value <= param[1] );
 1026+ },
 1027+
 1028+ // http://docs.jquery.com/Plugins/Validation/Methods/email
 1029+ email: function(value, element) {
 1030+ // contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
 1031+ return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i.test(value);
 1032+ },
 1033+
 1034+ // http://docs.jquery.com/Plugins/Validation/Methods/url
 1035+ url: function(value, element) {
 1036+ // contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
 1037+ return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
 1038+ },
 1039+
 1040+ // http://docs.jquery.com/Plugins/Validation/Methods/date
 1041+ date: function(value, element) {
 1042+ return this.optional(element) || !/Invalid|NaN/.test(new Date(value));
 1043+ },
 1044+
 1045+ // http://docs.jquery.com/Plugins/Validation/Methods/dateISO
 1046+ dateISO: function(value, element) {
 1047+ return this.optional(element) || /^\d{4}[\/-]\d{1,2}[\/-]\d{1,2}$/.test(value);
 1048+ },
 1049+
 1050+ // http://docs.jquery.com/Plugins/Validation/Methods/number
 1051+ number: function(value, element) {
 1052+ return this.optional(element) || /^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/.test(value);
 1053+ },
 1054+
 1055+ // http://docs.jquery.com/Plugins/Validation/Methods/digits
 1056+ digits: function(value, element) {
 1057+ return this.optional(element) || /^\d+$/.test(value);
 1058+ },
 1059+
 1060+ // http://docs.jquery.com/Plugins/Validation/Methods/creditcard
 1061+ // based on http://en.wikipedia.org/wiki/Luhn
 1062+ creditcard: function(value, element) {
 1063+ if ( this.optional(element) )
 1064+ return "dependency-mismatch";
 1065+ // accept only spaces, digits and dashes
 1066+ if (/[^0-9 -]+/.test(value))
 1067+ return false;
 1068+ var nCheck = 0,
 1069+ nDigit = 0,
 1070+ bEven = false;
 1071+
 1072+ value = value.replace(/\D/g, "");
 1073+
 1074+ for (var n = value.length - 1; n >= 0; n--) {
 1075+ var cDigit = value.charAt(n);
 1076+ var nDigit = parseInt(cDigit, 10);
 1077+ if (bEven) {
 1078+ if ((nDigit *= 2) > 9)
 1079+ nDigit -= 9;
 1080+ }
 1081+ nCheck += nDigit;
 1082+ bEven = !bEven;
 1083+ }
 1084+
 1085+ return (nCheck % 10) == 0;
 1086+ },
 1087+
 1088+ // http://docs.jquery.com/Plugins/Validation/Methods/accept
 1089+ accept: function(value, element, param) {
 1090+ param = typeof param == "string" ? param.replace(/,/g, '|') : "png|jpe?g|gif";
 1091+ return this.optional(element) || value.match(new RegExp(".(" + param + ")$", "i"));
 1092+ },
 1093+
 1094+ // http://docs.jquery.com/Plugins/Validation/Methods/equalTo
 1095+ equalTo: function(value, element, param) {
 1096+ // bind to the blur event of the target in order to revalidate whenever the target field is updated
 1097+ // TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
 1098+ var target = $(param).unbind(".validate-equalTo").bind("blur.validate-equalTo", function() {
 1099+ $(element).valid();
 1100+ });
 1101+ return value == target.val();
 1102+ }
 1103+
 1104+ }
 1105+
 1106+});
 1107+
 1108+// deprecated, use $.validator.format instead
 1109+$.format = $.validator.format;
 1110+
 1111+})(jQuery);
 1112+
 1113+// ajax mode: abort
 1114+// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
 1115+// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
 1116+;(function($) {
 1117+ var pendingRequests = {};
 1118+ // Use a prefilter if available (1.5+)
 1119+ if ( $.ajaxPrefilter ) {
 1120+ $.ajaxPrefilter(function(settings, _, xhr) {
 1121+ var port = settings.port;
 1122+ if (settings.mode == "abort") {
 1123+ if ( pendingRequests[port] ) {
 1124+ pendingRequests[port].abort();
 1125+ }
 1126+ pendingRequests[port] = xhr;
 1127+ }
 1128+ });
 1129+ } else {
 1130+ // Proxy ajax
 1131+ var ajax = $.ajax;
 1132+ $.ajax = function(settings) {
 1133+ var mode = ( "mode" in settings ? settings : $.ajaxSettings ).mode,
 1134+ port = ( "port" in settings ? settings : $.ajaxSettings ).port;
 1135+ if (mode == "abort") {
 1136+ if ( pendingRequests[port] ) {
 1137+ pendingRequests[port].abort();
 1138+ }
 1139+ return (pendingRequests[port] = ajax.apply(this, arguments));
 1140+ }
 1141+ return ajax.apply(this, arguments);
 1142+ };
 1143+ }
 1144+})(jQuery);
 1145+
 1146+// provides cross-browser focusin and focusout events
 1147+// IE has native support, in other browsers, use event caputuring (neither bubbles)
 1148+
 1149+// provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation
 1150+// handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target
 1151+;(function($) {
 1152+ // only implement if not provided by jQuery core (since 1.4)
 1153+ // TODO verify if jQuery 1.4's implementation is compatible with older jQuery special-event APIs
 1154+ if (!jQuery.event.special.focusin && !jQuery.event.special.focusout && document.addEventListener) {
 1155+ $.each({
 1156+ focus: 'focusin',
 1157+ blur: 'focusout'
 1158+ }, function( original, fix ){
 1159+ $.event.special[fix] = {
 1160+ setup:function() {
 1161+ this.addEventListener( original, handler, true );
 1162+ },
 1163+ teardown:function() {
 1164+ this.removeEventListener( original, handler, true );
 1165+ },
 1166+ handler: function(e) {
 1167+ arguments[0] = $.event.fix(e);
 1168+ arguments[0].type = fix;
 1169+ return $.event.handle.apply(this, arguments);
 1170+ }
 1171+ };
 1172+ function handler(e) {
 1173+ e = $.event.fix(e);
 1174+ e.type = fix;
 1175+ return $.event.handle.call(this, e);
 1176+ }
 1177+ });
 1178+ };
 1179+ $.extend($.fn, {
 1180+ validateDelegate: function(delegate, type, handler) {
 1181+ return this.bind(type, function(event) {
 1182+ var target = $(event.target);
 1183+ if (target.is(delegate)) {
 1184+ return handler.apply(target, arguments);
 1185+ }
 1186+ });
 1187+ }
 1188+ });
 1189+})(jQuery);
Property changes on: trunk/extensions/DonationInterface/globalcollect_gateway/modules/js/jquery.validate.js
___________________________________________________________________
Added: svn:mime-type
11190 + text/plain
Added: svn:keywords
21191 + Author Date HeadURL Header Id Revision
Added: svn:eol-style
31192 + native
Index: trunk/extensions/DonationInterface/globalcollect_gateway/modules/js/validate.js
@@ -0,0 +1,569 @@
 2+/**
 3+ * GlobalCollect Validation
 4+ *
 5+ * Things you need to know:
 6+ * - jquery.validate.js is awesome
 7+ * - Howto change the default messages: @link http://stackoverflow.com/questions/2457032/jquery-validation-change-default-error-message
 8+ *
 9+ * @since r100950
 10+ */
 11+
 12+/*******************************************************************************
 13+
 14+Helpers
 15+
 16+*******************************************************************************/
 17+
 18+/**
 19+ * clearField
 20+ *
 21+ * @param object field
 22+ * @param string field
 23+ */
 24+window.clearField = function( field, defaultValue ) {
 25+ if (field.value == defaultValue) {
 26+ field.value = '';
 27+ field.style.color = 'black';
 28+ }
 29+};
 30+
 31+/**
 32+ * isset
 33+ *
 34+ * @param mixed varname
 35+ */
 36+function isset( varname ){
 37+ if ( typeof( varname ) == "undefined" ) {
 38+ return false;
 39+ }
 40+ else {
 41+ return true;
 42+ }
 43+}
 44+
 45+/**
 46+ * empty
 47+ *
 48+ * @param mixed value
 49+ */
 50+function empty( value ) {
 51+
 52+ var key;
 53+
 54+ if ( value === '' || value === 0 || value === '0' || value === null || value === false || typeof value === 'undefined' ) {
 55+ return true;
 56+ }
 57+ else if ( typeof value == 'object' ) {
 58+ for ( key in value ) {
 59+ return false;
 60+ }
 61+ return true;
 62+ }
 63+
 64+ return false;
 65+}
 66+
 67+/*******************************************************************************
 68+
 69+Validate Elements
 70+
 71+*******************************************************************************/
 72+
 73+/**
 74+ * Validate the element: amount
 75+ *
 76+ */
 77+function validateElementAmount( options ) {
 78+
 79+ $().ready(function() {
 80+
 81+ /**
 82+ * Convert to an integer value because we will not test for:
 83+ * - 1.00
 84+ * - 0.00
 85+ * - 1,00
 86+ */
 87+ jQuery.validator.addMethod("requirefunds", function(value, element, params) {
 88+
 89+ var integerValue = parseInt( value );
 90+
 91+ if ( isset( params.min ) ) {
 92+ params.min = parseInt( params.min );
 93+ }
 94+ else {
 95+ params.min = 0;
 96+ }
 97+ //console.log('value: ' + value);
 98+ //console.log('integerValue: ' + integerValue);
 99+ //console.log(params);
 100+
 101+ return integerValue >= params.min;
 102+ }, mw.msg( 'donate_interface-error-msg-invalid-amount' ) );
 103+
 104+ $("#amount").rules("add",
 105+ {
 106+ required: true,
 107+ requirefunds: {
 108+ min: 1,
 109+ },
 110+ }
 111+ );
 112+ });
 113+}
 114+
 115+/**
 116+ * Validate the element: emailAdd
 117+ *
 118+ */
 119+function validateElementEmail( options ) {
 120+
 121+ $().ready(function() {
 122+
 123+ $("#emailAdd").rules("add",
 124+ {
 125+ required: true,
 126+ email: true,
 127+ messages: {
 128+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-emailAdd' ),
 129+ email: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-emailAdd' ),
 130+ }
 131+ }
 132+ );
 133+ });
 134+}
 135+
 136+/**
 137+ * Validate the element: fname
 138+ *
 139+ */
 140+function validateElementFirstName( options ) {
 141+
 142+ $().ready(function() {
 143+
 144+ $("#fname").rules("add",
 145+ {
 146+ required: true,
 147+ messages: {
 148+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-fname' ),
 149+ }
 150+ }
 151+ );
 152+ });
 153+}
 154+
 155+/**
 156+ * Validate the element: lname
 157+ *
 158+ */
 159+function validateElementLastName( options ) {
 160+
 161+ $().ready(function() {
 162+
 163+ $("#lname").rules("add",
 164+ {
 165+ required: true,
 166+ messages: {
 167+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-lname' ),
 168+ }
 169+ }
 170+ );
 171+ });
 172+}
 173+
 174+/**
 175+ * Validate the element: street
 176+ *
 177+ */
 178+function validateElementStreet( options ) {
 179+
 180+ $().ready(function() {
 181+
 182+ $("#street").rules("add",
 183+ {
 184+ required: true,
 185+ messages: {
 186+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-street' ),
 187+ }
 188+ }
 189+ );
 190+ });
 191+}
 192+
 193+/**
 194+ * Validate the element: city
 195+ *
 196+ */
 197+function validateElementCity( options ) {
 198+
 199+ $().ready(function() {
 200+
 201+ $("#city").rules("add",
 202+ {
 203+ required: true,
 204+ messages: {
 205+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-city' ),
 206+ }
 207+ }
 208+ );
 209+ });
 210+}
 211+
 212+/**
 213+ * Validate the element: state
 214+ *
 215+ * @todo
 216+ * - This should only be required for the US at this point.
 217+ * - It will be required outside the US, but that may be dependent on payment type.
 218+ *
 219+ */
 220+function validateElementState( options ) {
 221+
 222+ $().ready(function() {
 223+
 224+ $("#state").rules("add",
 225+ {
 226+ required: true,
 227+ notEqual: 'YY',
 228+ messages: {
 229+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-state' ),
 230+ notEqual: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-state' ),
 231+ }
 232+ }
 233+ );
 234+ });
 235+}
 236+
 237+/**
 238+ * Validate the element: zip
 239+ *
 240+ */
 241+function validateElementZip( options ) {
 242+
 243+ $().ready(function() {
 244+
 245+ $("#zip").rules("add",
 246+ {
 247+ required: true,
 248+ messages: {
 249+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-zip' ),
 250+ }
 251+ }
 252+ );
 253+ });
 254+}
 255+
 256+/**
 257+ * Validate the element: country
 258+ *
 259+ * @todo
 260+ * - This should handle dropdowns
 261+ *
 262+ */
 263+function validateElementCountry( options ) {
 264+
 265+ $().ready(function() {
 266+
 267+ $("#country").rules("add",
 268+ {
 269+ required: true,
 270+ messages: {
 271+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-country' ),
 272+ }
 273+ }
 274+ );
 275+ });
 276+}
 277+
 278+/**
 279+ * Validate the element: card_num
 280+ *
 281+ * @todo
 282+ * - There are more options we can test. They are commented out.
 283+ *
 284+ */
 285+function validateElementCardNumber( options ) {
 286+
 287+ $().ready(function() {
 288+
 289+ $("#card_num").rules("add",
 290+ {
 291+ required: true,
 292+ //creditcard: true,
 293+ //creditcardtypes: true,
 294+ messages: {
 295+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-card_num' ),
 296+ }
 297+ }
 298+ );
 299+ });
 300+}
 301+
 302+/**
 303+ * Validate the element: cvv
 304+ *
 305+ */
 306+function validateElementCvv( options ) {
 307+
 308+ $().ready(function() {
 309+
 310+ $("#cvv").rules("add",
 311+ {
 312+ required: true,
 313+ messages: {
 314+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-cvv' ),
 315+ }
 316+ }
 317+ );
 318+ });
 319+}
 320+
 321+/**
 322+ * Validate the element: payment_method
 323+ *
 324+ */
 325+function validateElementPaymentMethod( options ) {
 326+
 327+ $().ready(function() {
 328+
 329+ // Hidden elements do not have ids
 330+ $('#' + options.formId + " input[name=payment_method]").rules("add",
 331+ {
 332+ required: true,
 333+ messages: {
 334+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-payment_method' ),
 335+ }
 336+ }
 337+ );
 338+ });
 339+}
 340+
 341+/**
 342+ * Validate the element: payment_submethod
 343+ *
 344+ */
 345+function validateElementPaymentSubmethod( options ) {
 346+
 347+ $().ready(function() {
 348+
 349+ // Hidden elements do not have ids
 350+ $('#' + options.formId + " input[name=payment_submethod]").rules("add",
 351+ {
 352+ required: true,
 353+ messages: {
 354+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-payment_submethod' ),
 355+ }
 356+ }
 357+ );
 358+ });
 359+}
 360+
 361+/**
 362+ * Validate the element: issuer_id
 363+ *
 364+ */
 365+function validateElementIssuerId( options ) {
 366+
 367+ $().ready(function() {
 368+
 369+ $("#issuer_id").rules("add",
 370+ {
 371+ required: true,
 372+ messages: {
 373+ required: mw.msg( 'donate_interface-error-msg-js' ) + ' ' + mw.msg( 'donate_interface-error-msg-issuer_id' ),
 374+ }
 375+ }
 376+ );
 377+ });
 378+}
 379+
 380+/*******************************************************************************
 381+
 382+Validate Element Groups
 383+
 384+*******************************************************************************/
 385+
 386+/**
 387+ * Validate Bank Transfers
 388+ *
 389+ */
 390+
 391+function validateForm( options ) {
 392+/*
 393+ $("#form1").validate({
 394+ errorLabelContainer: $("#form1 div.error")
 395+ });
 396+
 397+ var container = $('div.container');
 398+ // validate the form when it is submitted
 399+ var validator = $("#form2").validate({
 400+ errorContainer: container,
 401+ errorLabelContainer: $("ol", container),
 402+ wrapper: 'li',
 403+ meta: "validate"
 404+ });
 405+
 406+ $(".cancel").click(function() {
 407+ validator.resetForm();
 408+ });
 409+
 410+*/
 411+ $().ready(function() {
 412+
 413+ if ( !isset( options.formId ) ) {
 414+ options.formId = '';
 415+ }
 416+
 417+ if ( empty( options.formId ) ) {
 418+
 419+ // An id must be specified to validate the form.
 420+ return;
 421+ }
 422+
 423+ var validateOptions = {
 424+ ignore: ':hidden',
 425+ }
 426+
 427+ $("#" + options.formId).validate();
 428+
 429+ // Check for payment_method
 430+ if ( !isset( options.payment_method ) ) {
 431+ options.payment_method = '';
 432+ }
 433+
 434+ // Check for payment_submethod
 435+ if ( !isset( options.payment_submethod ) ) {
 436+ options.payment_submethod = '';
 437+ }
 438+
 439+ //console.log( options );
 440+ // Initialize validate options if not set.
 441+ if ( !isset( options.validate ) ) {
 442+ options.validate = {};
 443+ }
 444+ //console.log( options.validate );
 445+
 446+ /*
 447+ * Setup default validations based on payment_method
 448+ */
 449+
 450+ if ( options.payment_method == 'cc' ) {
 451+
 452+ // card_num and cvv are not validated on our site.
 453+ }
 454+ else if ( options.payment_method == 'bt' ) {
 455+
 456+ options.validate.payment = true;
 457+ }
 458+ else if ( options.payment_method == 'rtbt' ) {
 459+
 460+ options.validate.payment = true;
 461+ }
 462+ //console.log( options.validate );
 463+
 464+ /*
 465+ * Setup default validations based on payment_submethod
 466+ */
 467+
 468+ if ( options.payment_submethod == 'rtbt_ideal' ) {
 469+
 470+ // Ideal requires issuer_id
 471+ options.validate.issuerId = true;
 472+ }
 473+ else if ( options.payment_submethod == 'rtbt_eps' ) {
 474+
 475+ // eps requires issuer_id
 476+ options.validate.issuerId = true;
 477+ }
 478+ //console.log( options.validate );
 479+
 480+ /*
 481+ * Standard elements groups to validate
 482+ */
 483+
 484+ // Options: Validate address
 485+ if ( !isset( options.validate.address ) ) {
 486+ options.validate.address = true;
 487+ }
 488+
 489+ // Options: Validate amount
 490+ if ( !isset( options.validate.amount ) ) {
 491+ options.validate.amount = true;
 492+ }
 493+
 494+ // Options: Validate creditCard
 495+ if ( !isset( options.validate.creditCard ) ) {
 496+ options.validate.creditCard = false;
 497+ }
 498+
 499+ // Options: Validate email
 500+ if ( !isset( options.validate.email ) ) {
 501+ options.validate.email = true;
 502+ }
 503+
 504+ // Options: Validate issuerId
 505+ if ( !isset( options.validate.issuerId ) ) {
 506+ options.validate.issuerId = false;
 507+ }
 508+
 509+ // Options: Validate name
 510+ if ( !isset( options.validate.name ) ) {
 511+ options.validate.name = true;
 512+ }
 513+
 514+ // Options: Validate payment
 515+ if ( !isset( options.validate.payment ) ) {
 516+ options.validate.payment = false;
 517+ }
 518+ //console.log( options.validate );
 519+
 520+ /*
 521+ * Standard elements groups to validate if enabled
 522+ */
 523+
 524+ // Validate: address
 525+ if ( options.validate.address ) {
 526+ validateElementStreet( options );
 527+ validateElementCity( options );
 528+ validateElementState( options );
 529+ //validateElementZip( options );
 530+ validateElementCountry( options );
 531+ }
 532+
 533+ // Validate: amount
 534+ if ( options.validate.amount ) {
 535+ validateElementAmount( options );
 536+ }
 537+
 538+ // Validate: creditCard
 539+ if ( options.validate.creditCard ) {
 540+ validateElementCardNumber( options );
 541+ validateElementCvv( options );
 542+ }
 543+
 544+ // Validate: email
 545+ if ( options.validate.email ) {
 546+ validateElementEmail( options );
 547+ }
 548+
 549+ // Validate: name
 550+ if ( options.validate.name ) {
 551+ validateElementFirstName( options );
 552+ validateElementLastName( options );
 553+ }
 554+
 555+ // Validate: payment
 556+ if ( options.validate.payment ) {
 557+ validateElementPaymentMethod( options );
 558+ validateElementPaymentSubmethod( options );
 559+
 560+ // Validate: issuer_id
 561+ if ( options.validate.issuerId ) {
 562+ validateElementIssuerId( options );
 563+ }
 564+ }
 565+
 566+ // The following validators are not ready:
 567+
 568+ });
 569+}
 570+
Property changes on: trunk/extensions/DonationInterface/globalcollect_gateway/modules/js/validate.js
___________________________________________________________________
Added: svn:mime-type
1571 + text/plain
Added: svn:keywords
2572 + Author Date HeadURL Header Id Revision
Added: svn:eol-style
3573 + native
Index: trunk/extensions/DonationInterface/globalcollect_gateway/modules/js/jquery.validate.additional-methods.js
@@ -0,0 +1,306 @@
 2+/**
 3+ * jQuery Validation Plugin 1.9.0
 4+ *
 5+ * http://bassistance.de/jquery-plugins/jquery-plugin-validation/
 6+ * http://docs.jquery.com/Plugins/Validation
 7+ *
 8+ * Copyright (c) 2006 - 2011 Jörn Zaefferer
 9+ *
 10+ * Dual licensed under the MIT and GPL licenses:
 11+ * http://www.opensource.org/licenses/mit-license.php
 12+ * http://www.gnu.org/licenses/gpl.html
 13+ */
 14+
 15+(function() {
 16+
 17+ function stripHtml(value) {
 18+ // remove html tags and space chars
 19+ return value.replace(/<.[^<>]*?>/g, ' ').replace(/&nbsp;|&#160;/gi, ' ')
 20+ // remove numbers and punctuation
 21+ .replace(/[0-9.(),;:!?%#$'"_+=\/-]*/g,'');
 22+ }
 23+ jQuery.validator.addMethod("maxWords", function(value, element, params) {
 24+ return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length < params;
 25+ }, jQuery.validator.format("Please enter {0} words or less."));
 26+
 27+ jQuery.validator.addMethod("minWords", function(value, element, params) {
 28+ return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params;
 29+ }, jQuery.validator.format("Please enter at least {0} words."));
 30+
 31+ jQuery.validator.addMethod("rangeWords", function(value, element, params) {
 32+ return this.optional(element) || stripHtml(value).match(/\b\w+\b/g).length >= params[0] && value.match(/bw+b/g).length < params[1];
 33+ }, jQuery.validator.format("Please enter between {0} and {1} words."));
 34+
 35+})();
 36+
 37+jQuery.validator.addMethod("letterswithbasicpunc", function(value, element) {
 38+ return this.optional(element) || /^[a-z-.,()'\"\s]+$/i.test(value);
 39+}, "Letters or punctuation only please");
 40+
 41+jQuery.validator.addMethod("alphanumeric", function(value, element) {
 42+ return this.optional(element) || /^\w+$/i.test(value);
 43+}, "Letters, numbers, spaces or underscores only please");
 44+
 45+jQuery.validator.addMethod("lettersonly", function(value, element) {
 46+ return this.optional(element) || /^[a-z]+$/i.test(value);
 47+}, "Letters only please");
 48+
 49+jQuery.validator.addMethod("nowhitespace", function(value, element) {
 50+ return this.optional(element) || /^\S+$/i.test(value);
 51+}, "No white space please");
 52+
 53+jQuery.validator.addMethod("ziprange", function(value, element) {
 54+ return this.optional(element) || /^90[2-5]\d\{2}-\d{4}$/.test(value);
 55+}, "Your ZIP-code must be in the range 902xx-xxxx to 905-xx-xxxx");
 56+
 57+jQuery.validator.addMethod("integer", function(value, element) {
 58+ return this.optional(element) || /^-?\d+$/.test(value);
 59+}, "A positive or negative non-decimal number please");
 60+
 61+/**
 62+* Return true, if the value is a valid vehicle identification number (VIN).
 63+*
 64+* Works with all kind of text inputs.
 65+*
 66+* @example <input type="text" size="20" name="VehicleID" class="{required:true,vinUS:true}" />
 67+* @desc Declares a required input element whose value must be a valid vehicle identification number.
 68+*
 69+* @name jQuery.validator.methods.vinUS
 70+* @type Boolean
 71+* @cat Plugins/Validate/Methods
 72+*/
 73+jQuery.validator.addMethod(
 74+ "vinUS",
 75+ function(v){
 76+ if (v.length != 17)
 77+ return false;
 78+ var i, n, d, f, cd, cdv;
 79+ var LL = ["A","B","C","D","E","F","G","H","J","K","L","M","N","P","R","S","T","U","V","W","X","Y","Z"];
 80+ var VL = [1,2,3,4,5,6,7,8,1,2,3,4,5,7,9,2,3,4,5,6,7,8,9];
 81+ var FL = [8,7,6,5,4,3,2,10,0,9,8,7,6,5,4,3,2];
 82+ var rs = 0;
 83+ for(i = 0; i < 17; i++){
 84+ f = FL[i];
 85+ d = v.slice(i,i+1);
 86+ if(i == 8){
 87+ cdv = d;
 88+ }
 89+ if(!isNaN(d)){
 90+ d *= f;
 91+ }
 92+ else{
 93+ for(n = 0; n < LL.length; n++){
 94+ if(d.toUpperCase() === LL[n]){
 95+ d = VL[n];
 96+ d *= f;
 97+ if(isNaN(cdv) && n == 8){
 98+ cdv = LL[n];
 99+ }
 100+ break;
 101+ }
 102+ }
 103+ }
 104+ rs += d;
 105+ }
 106+ cd = rs % 11;
 107+ if(cd == 10){cd = "X";}
 108+ if(cd == cdv){return true;}
 109+ return false;
 110+ },
 111+ "The specified vehicle identification number (VIN) is invalid."
 112+);
 113+
 114+/**
 115+ * Return true, if the value is a valid date, also making this formal check dd/mm/yyyy.
 116+ *
 117+ * @example jQuery.validator.methods.date("01/01/1900")
 118+ * @result true
 119+ *
 120+ * @example jQuery.validator.methods.date("01/13/1990")
 121+ * @result false
 122+ *
 123+ * @example jQuery.validator.methods.date("01.01.1900")
 124+ * @result false
 125+ *
 126+ * @example <input name="pippo" class="{dateITA:true}" />
 127+ * @desc Declares an optional input element whose value must be a valid date.
 128+ *
 129+ * @name jQuery.validator.methods.dateITA
 130+ * @type Boolean
 131+ * @cat Plugins/Validate/Methods
 132+ */
 133+jQuery.validator.addMethod(
 134+ "dateITA",
 135+ function(value, element) {
 136+ var check = false;
 137+ var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
 138+ if( re.test(value)){
 139+ var adata = value.split('/');
 140+ var gg = parseInt(adata[0],10);
 141+ var mm = parseInt(adata[1],10);
 142+ var aaaa = parseInt(adata[2],10);
 143+ var xdata = new Date(aaaa,mm-1,gg);
 144+ if ( ( xdata.getFullYear() == aaaa ) && ( xdata.getMonth () == mm - 1 ) && ( xdata.getDate() == gg ) )
 145+ check = true;
 146+ else
 147+ check = false;
 148+ } else
 149+ check = false;
 150+ return this.optional(element) || check;
 151+ },
 152+ "Please enter a correct date"
 153+);
 154+
 155+jQuery.validator.addMethod("dateNL", function(value, element) {
 156+ return this.optional(element) || /^\d\d?[\.\/-]\d\d?[\.\/-]\d\d\d?\d?$/.test(value);
 157+ }, "Vul hier een geldige datum in."
 158+);
 159+
 160+jQuery.validator.addMethod("time", function(value, element) {
 161+ return this.optional(element) || /^([01]\d|2[0-3])(:[0-5]\d){0,2}$/.test(value);
 162+}, "Please enter a valid time, between 00:00 and 23:59");
 163+jQuery.validator.addMethod("time12h", function(value, element) {
 164+ return this.optional(element) || /^((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))$/i.test(value);
 165+}, "Please enter a valid time, between 00:00 am and 12:00 pm");
 166+
 167+/**
 168+ * matches US phone number format
 169+ *
 170+ * where the area code may not start with 1 and the prefix may not start with 1
 171+ * allows '-' or ' ' as a separator and allows parens around area code
 172+ * some people may want to put a '1' in front of their number
 173+ *
 174+ * 1(212)-999-2345
 175+ * or
 176+ * 212 999 2344
 177+ * or
 178+ * 212-999-0983
 179+ *
 180+ * but not
 181+ * 111-123-5434
 182+ * and not
 183+ * 212 123 4567
 184+ */
 185+jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
 186+ phone_number = phone_number.replace(/\s+/g, "");
 187+ return this.optional(element) || phone_number.length > 9 &&
 188+ phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
 189+}, "Please specify a valid phone number");
 190+
 191+jQuery.validator.addMethod('phoneUK', function(phone_number, element) {
 192+return this.optional(element) || phone_number.length > 9 &&
 193+phone_number.match(/^(\(?(0|\+44)[1-9]{1}\d{1,4}?\)?\s?\d{3,4}\s?\d{3,4})$/);
 194+}, 'Please specify a valid phone number');
 195+
 196+jQuery.validator.addMethod('mobileUK', function(phone_number, element) {
 197+return this.optional(element) || phone_number.length > 9 &&
 198+phone_number.match(/^((0|\+44)7(5|6|7|8|9){1}\d{2}\s?\d{6})$/);
 199+}, 'Please specify a valid mobile number');
 200+
 201+// TODO check if value starts with <, otherwise don't try stripping anything
 202+jQuery.validator.addMethod("strippedminlength", function(value, element, param) {
 203+ return jQuery(value).text().length >= param;
 204+}, jQuery.validator.format("Please enter at least {0} characters"));
 205+
 206+// same as email, but TLD is optional
 207+jQuery.validator.addMethod("email2", function(value, element, param) {
 208+ return this.optional(element) || /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test(value);
 209+}, jQuery.validator.messages.email);
 210+
 211+// same as url, but TLD is optional
 212+jQuery.validator.addMethod("url2", function(value, element, param) {
 213+ return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value);
 214+}, jQuery.validator.messages.url);
 215+
 216+// NOTICE: Modified version of Castle.Components.Validator.CreditCardValidator
 217+// Redistributed under the the Apache License 2.0 at http://www.apache.org/licenses/LICENSE-2.0
 218+// Valid Types: mastercard, visa, amex, dinersclub, enroute, discover, jcb, unknown, all (overrides all other settings)
 219+jQuery.validator.addMethod("creditcardtypes", function(value, element, param) {
 220+
 221+ if (/[^0-9-]+/.test(value))
 222+ return false;
 223+
 224+ value = value.replace(/\D/g, "");
 225+
 226+ var validTypes = 0x0000;
 227+
 228+ if (param.mastercard)
 229+ validTypes |= 0x0001;
 230+ if (param.visa)
 231+ validTypes |= 0x0002;
 232+ if (param.amex)
 233+ validTypes |= 0x0004;
 234+ if (param.dinersclub)
 235+ validTypes |= 0x0008;
 236+ if (param.enroute)
 237+ validTypes |= 0x0010;
 238+ if (param.discover)
 239+ validTypes |= 0x0020;
 240+ if (param.jcb)
 241+ validTypes |= 0x0040;
 242+ if (param.unknown)
 243+ validTypes |= 0x0080;
 244+ if (param.all)
 245+ validTypes = 0x0001 | 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0040 | 0x0080;
 246+
 247+ if (validTypes & 0x0001 && /^(51|52|53|54|55)/.test(value)) { //mastercard
 248+ return value.length == 16;
 249+ }
 250+ if (validTypes & 0x0002 && /^(4)/.test(value)) { //visa
 251+ return value.length == 16;
 252+ }
 253+ if (validTypes & 0x0004 && /^(34|37)/.test(value)) { //amex
 254+ return value.length == 15;
 255+ }
 256+ if (validTypes & 0x0008 && /^(300|301|302|303|304|305|36|38)/.test(value)) { //dinersclub
 257+ return value.length == 14;
 258+ }
 259+ if (validTypes & 0x0010 && /^(2014|2149)/.test(value)) { //enroute
 260+ return value.length == 15;
 261+ }
 262+ if (validTypes & 0x0020 && /^(6011)/.test(value)) { //discover
 263+ return value.length == 16;
 264+ }
 265+ if (validTypes & 0x0040 && /^(3)/.test(value)) { //jcb
 266+ return value.length == 16;
 267+ }
 268+ if (validTypes & 0x0040 && /^(2131|1800)/.test(value)) { //jcb
 269+ return value.length == 15;
 270+ }
 271+ if (validTypes & 0x0080) { //unknown
 272+ return true;
 273+ }
 274+ return false;
 275+}, "Please enter a valid credit card number.");
 276+
 277+jQuery.validator.addMethod("ipv4", function(value, element, param) {
 278+ return this.optional(element) || /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/i.test(value);
 279+}, "Please enter a valid IP v4 address.");
 280+
 281+jQuery.validator.addMethod("ipv6", function(value, element, param) {
 282+ return this.optional(element) || /^((([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){6}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(([0-9A-Fa-f]{1,4}:){0,5}:((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|(::([0-9A-Fa-f]{1,4}:){0,5}((\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b)\.){3}(\b((25[0-5])|(1\d{2})|(2[0-4]\d)|(\d{1,2}))\b))|([0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})|(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})|(([0-9A-Fa-f]{1,4}:){1,7}:))$/i.test(value);
 283+}, "Please enter a valid IP v6 address.");
 284+
 285+/**
 286+ * Return true if the field value matches the given format RegExp
 287+ *
 288+ * @example jQuery.validator.methods.pattern("AR1004",element,/^AR\d{4}$/)
 289+ * @result true
 290+ *
 291+ * @example jQuery.validator.methods.pattern("BR1004",element,/^AR\d{4}$/)
 292+ * @result false
 293+ *
 294+ * @name jQuery.validator.methods.pattern
 295+ * @type Boolean
 296+ * @cat Plugins/Validate/Methods
 297+ */
 298+jQuery.validator.addMethod("pattern", function(value, element, param) {
 299+ return this.optional(element) || param.test(value);
 300+}, "Invalid format.");
 301+
 302+/**
 303+ * notEqual was added to the file.
 304+ */
 305+jQuery.validator.addMethod("notEqual", function(value, element, param) {
 306+ return this.optional(element) || value != param;
 307+}, "Please specify a different value.");
Property changes on: trunk/extensions/DonationInterface/globalcollect_gateway/modules/js/jquery.validate.additional-methods.js
___________________________________________________________________
Added: svn:mime-type
1308 + text/plain
Added: svn:keywords
2309 + Author Date HeadURL Header Id Revision
Added: svn:eol-style
3310 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r102236MFT r90286, r100671, r100837, r100950, r101060, r101063, r101064, r101073, r1......khorn03:06, 7 November 2011
r102237MFT r90286, r100671, r100837, r100950, r101060, r101063, r101064, r101073, r1......khorn03:07, 7 November 2011

Status & tagging log