/public/assets/js/libs/jquery-validation/demo/marketo/mktSignup.js

https://gitlab.com/dima-antonenko/projectX · JavaScript · 133 lines · 119 code · 12 blank · 2 comment · 16 complexity · 12697360608e3d8a612098c437b4b631 MD5 · raw file

  1. $(document).ready(function(){
  2. $.mockjax({
  3. url: "emails.action",
  4. response: function(settings) {
  5. var email = settings.data.email,
  6. emails = ["glen@marketo.com", "george@bush.gov", "me@god.com", "aboutface@cooper.com", "steam@valve.com", "bill@gates.com"];
  7. this.responseText = "true";
  8. if ( $.inArray( email, emails ) !== -1 ) {
  9. this.responseText = "false";
  10. }
  11. },
  12. responseTime: 500
  13. });
  14. jQuery.validator.addMethod("password", function( value, element ) {
  15. var result = this.optional(element) || value.length >= 6 && /\d/.test(value) && /[a-z]/i.test(value);
  16. if (!result) {
  17. element.value = "";
  18. var validator = this;
  19. setTimeout(function() {
  20. validator.blockFocusCleanup = true;
  21. element.focus();
  22. validator.blockFocusCleanup = false;
  23. }, 1);
  24. }
  25. return result;
  26. }, "Your password must be at least 6 characters long and contain at least one number and one character.");
  27. // a custom method making the default value for companyurl ("http://") invalid, without displaying the "invalid url" message
  28. jQuery.validator.addMethod("defaultInvalid", function(value, element) {
  29. return value != element.defaultValue;
  30. }, "");
  31. jQuery.validator.addMethod("billingRequired", function(value, element) {
  32. if ($("#bill_to_co").is(":checked"))
  33. return $(element).parents(".subTable").length;
  34. return !this.optional(element);
  35. }, "");
  36. jQuery.validator.messages.required = "";
  37. $("form").validate({
  38. invalidHandler: function(e, validator) {
  39. var errors = validator.numberOfInvalids();
  40. if (errors) {
  41. var message = errors == 1
  42. ? 'You missed 1 field. It has been highlighted below'
  43. : 'You missed ' + errors + ' fields. They have been highlighted below';
  44. $("div.error span").html(message);
  45. $("div.error").show();
  46. } else {
  47. $("div.error").hide();
  48. }
  49. },
  50. onkeyup: false,
  51. submitHandler: function() {
  52. $("div.error").hide();
  53. alert("submit! use link below to go to the other step");
  54. },
  55. messages: {
  56. password2: {
  57. required: " ",
  58. equalTo: "Please enter the same password as above"
  59. },
  60. email: {
  61. required: " ",
  62. email: "Please enter a valid email address, example: you@yourdomain.com",
  63. remote: jQuery.validator.format("{0} is already taken, please enter a different address.")
  64. }
  65. },
  66. debug:true
  67. });
  68. $(".resize").vjustify();
  69. $("div.buttonSubmit").hoverClass("buttonSubmitHover");
  70. $("input.phone").mask("(999) 999-9999");
  71. $("input.zipcode").mask("99999");
  72. var creditcard = $("#creditcard").mask("9999 9999 9999 9999");
  73. $("#cc_type").change(
  74. function() {
  75. switch ($(this).val()){
  76. case 'amex':
  77. creditcard.unmask().mask("9999 999999 99999");
  78. break;
  79. default:
  80. creditcard.unmask().mask("9999 9999 9999 9999");
  81. break;
  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. $.fn.vjustify = function() {
  101. var maxHeight=0;
  102. $(".resize").css("height","auto");
  103. this.each(function(){
  104. if (this.offsetHeight > maxHeight) {
  105. maxHeight = this.offsetHeight;
  106. }
  107. });
  108. this.each(function(){
  109. $(this).height(maxHeight);
  110. if (this.offsetHeight > maxHeight) {
  111. $(this).height((maxHeight-(this.offsetHeight-maxHeight)));
  112. }
  113. });
  114. };
  115. $.fn.hoverClass = function(classname) {
  116. return this.hover(function() {
  117. $(this).addClass(classname);
  118. }, function() {
  119. $(this).removeClass(classname);
  120. });
  121. };