-
Notifications
You must be signed in to change notification settings - Fork 42
/
jquery.contactable.min.js
executable file
·1 lines (1 loc) · 3.72 KB
/
jquery.contactable.min.js
1
(function(a){a.fn.contactable=function(b){b=a.extend({url:"mail.php",name:"Name",email:"Email",dropdownTitle:"",dropdownOptions:["General","Website bug","Feature request"],message:"Message",subject:"A contactable message",submit:"SEND",recievedMsg:"Thank you for your message",notRecievedMsg:"Sorry but your message could not be sent, try again later",disclaimer:"Please feel free to get in touch, we value your feedback",hideOnSubmit:!0},b);return this.each(function(){function f(){a(".contactable-holder").hide(); a("#contactable-loading").show();a.ajax({type:"POST",url:b.url,data:{subject:b.subject,name:a("#contactable-name").val(),email:a("#contactable-email").val(),issue:a("#contactable-dropdown").val(),message:a("#contactable-message").val()},success:function(e){a("#contactable-loading").css({display:"none"});"success"===e.response?(a("#contactable-callback").show().append(b.recievedMsg),!0===b.hideOnSubmit&&$("#contactable-inner").click()):(a("#contactable-callback").show().append(b.notRecievedMsg),setTimeout(function(){a(".contactable-holder").show(); a("#contactable-callback").hide().html("")},2E3))},error:function(e){a("#contactable-loading").css({display:"none"});a("#contactable-callback").show().append(b.notRecievedMsg)}})}var c="",g=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/,h=b.dropdownOptions.length,d;if(b.dropdownTitle){c+='<p><label for="contactable-dropdown">'+b.dropdownTitle+' </label><br /><select name="dropdown" id="contactable-dropdown" class="contactable-dropdown">';for(d=0;d<h;d++)c+='<option value="'+b.dropdownOptions[d]+ '">'+b.dropdownOptions[d]+"</option>";c+="</select></p>"}a(this).html('<div id="contactable-inner"></div><form id="contactable-contactForm" method="" action=""><div id="contactable-loading"></div><div id="contactable-callback"></div><div class="contactable-holder"><p><label for="contactable-name">'+b.name+'<span class="contactable-green"> * </span></label><br /><input id="contactable-name" class="contactable-contact contactable-validate" name="name" /></p><p><label for="contactable-email">'+b.email+ ' <span class="contactable-green"> * </span></label><br /><input id="contactable-email" class="contactable-contact contactable-validate" name="email" /></p>'+c+'<p><label for="contactable-message">'+b.message+' <span class="contactable-green"> * </span></label><br /><textarea id="contactable-message" name="message" class="contactable-message contactable-validate" rows="4" cols="30" ></textarea></p><p><input class="contactable-submit" type="submit" value="'+b.submit+'"/></p><p class="contactable-disclaimer">'+ b.disclaimer+"</p></div></form>");$.fn.toggleClick=function(){var a=arguments,b=0;return this.click(function(){a[b].apply(this,arguments);b=(b+1)%a.length})};a("#contactable-inner").toggleClick(function(){a("#contactable-overlay").css({display:"block"});a(this).animate({marginLeft:"-=5px"},"2000");a("#contactable-contactForm").animate({marginLeft:"-=0px"},"2000");a(this).animate({marginLeft:"+=387px"},"4000");a("#contactable-contactForm").animate({marginLeft:"+=390px"},"4000")},function(){a("#contactable-contactForm").animate({marginLeft:"-=390px"}, "4000");a(this).animate({marginLeft:"-=387px"},"4000").animate({marginLeft:"+=5px"},"2000");a("#contactable-overlay").css({display:"none"})});a("#contactable-contactForm").submit(function(){var b=!0;a("#contactable-contactForm .contactable-validate").each(function(){a(this).removeClass("contactable-invalid")});a("#contactable-contactForm .contactable-validate").each(function(){2>a(this).val().length&&(a(this).addClass("contactable-invalid"),b=!1);g.test(a("#contactable-contactForm #contactable-email").val())|| (a("#contactable-contactForm #contactable-email").addClass("contactable-invalid"),b=!1)});!0===b&&f();return!1})})}})(jQuery);