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