PageRenderTime 21ms CodeModel.GetById 10ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/jquery-validate/demo/marketo/mktSignup.js

#
JavaScript | 125 lines | 110 code | 13 blank | 2 comment | 16 complexity | d777b466de5350a27f1cbf2884d25e59 MD5 | raw file
  1 $(document).ready(function(){
  2 	
  3	jQuery.validator.addMethod("password", function( value, element ) {
  4		var result = this.optional(element) || value.length >= 6 && /\d/.test(value) && /[a-z]/i.test(value);
  5		if (!result) {
  6			element.value = "";
  7			var validator = this;
  8			setTimeout(function() {
  9				validator.blockFocusCleanup = true;
 10				element.focus();
 11				validator.blockFocusCleanup = false;
 12			}, 1);
 13		}
 14		return result;
 15	}, "Your password must be at least 6 characters long and contain at least one number and one character.");
 16	
 17	// a custom method making the default value for companyurl ("http://") invalid, without displaying the "invalid url" message
 18	jQuery.validator.addMethod("defaultInvalid", function(value, element) {
 19		return value != element.defaultValue;
 20	}, "");
 21	
 22	jQuery.validator.addMethod("billingRequired", function(value, element) {
 23		if ($("#bill_to_co").is(":checked"))
 24			return $(element).parents(".subTable").length;
 25		return !this.optional(element);
 26	}, "");
 27	
 28	jQuery.validator.messages.required = "";
 29	$("form").validate({
 30		invalidHandler: function(e, validator) {
 31			var errors = validator.numberOfInvalids();
 32			if (errors) {
 33				var message = errors == 1
 34					? 'You missed 1 field. It has been highlighted below'
 35					: 'You missed ' + errors + ' fields.  They have been highlighted below';
 36				$("div.error span").html(message);
 37				$("div.error").show();
 38			} else {
 39				$("div.error").hide();
 40			}
 41		},
 42		onkeyup: false,
 43		submitHandler: function() {
 44			$("div.error").hide();
 45			alert("submit! use link below to go to the other step");
 46		},
 47		messages: {
 48			password2: {
 49				required: " ",
 50				equalTo: "Please enter the same password as above"	
 51			},
 52			email: {
 53				required: " ",
 54				email: "Please enter a valid email address, example: you@yourdomain.com",
 55				remote: jQuery.validator.format("{0} is already taken, please enter a different address.")	
 56			}
 57		},
 58		debug:true
 59	});
 60	
 61  $(".resize").vjustify();
 62  $("div.buttonSubmit").hoverClass("buttonSubmitHover");
 63
 64  if ($.browser.safari) {
 65    $("body").addClass("safari");
 66  }
 67  
 68  $("input.phone").mask("(999) 999-9999");
 69  $("input.zipcode").mask("99999");
 70  var creditcard = $("#creditcard").mask("9999 9999 9999 9999");
 71
 72  $("#cc_type").change(
 73    function() {
 74      switch ($(this).val()){
 75        case 'amex':
 76          creditcard.unmask().mask("9999 999999 99999");
 77          break;
 78        default:
 79          creditcard.unmask().mask("9999 9999 9999 9999");
 80          break;
 81      }
 82    }
 83  );
 84
 85  // toggle optional billing address
 86  var subTableDiv = $("div.subTableDiv");
 87  var toggleCheck = $("input.toggleCheck");
 88  toggleCheck.is(":checked")
 89  	? subTableDiv.hide()
 90	: subTableDiv.show();
 91  $("input.toggleCheck").click(function() {
 92      if (this.checked == true) {
 93        subTableDiv.slideUp("medium");
 94        $("form").valid();
 95      } else {
 96        subTableDiv.slideDown("medium");
 97      }
 98  });
 99
100
101});
102
103$.fn.vjustify = function() {
104    var maxHeight=0;
105    $(".resize").css("height","auto");
106    this.each(function(){
107        if (this.offsetHeight > maxHeight) {
108          maxHeight = this.offsetHeight;
109        }
110    });
111    this.each(function(){
112        $(this).height(maxHeight);
113        if (this.offsetHeight > maxHeight) {
114            $(this).height((maxHeight-(this.offsetHeight-maxHeight)));
115        }
116    });
117};
118
119$.fn.hoverClass = function(classname) {
120	return this.hover(function() {
121		$(this).addClass(classname);
122	}, function() {
123		$(this).removeClass(classname);
124	});
125};