-
Notifications
You must be signed in to change notification settings - Fork 11
/
subbscribe.min.js
5 lines (5 loc) · 4.84 KB
/
subbscribe.min.js
1
2
3
4
5
/**
* Subbscribe.js (http://www.subbscribe.com)
* Copyright (c) 2014 (v2.0) Shlomi Nissan, 1ByteBeta (http://www.1bytebeta.com)
* Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
*/(function(e){e.fn.subbscribe=function(t){function l(e){console.log(e);return r.list=="MailChimp"?e["result"]!="success"?!0:!1:r.list=="CampaignMonitor"?e.Status===400?!0:!1:!0}function c(){e("#subbscribe input").each(function(){e(this).val("")})}function h(e){var t=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;return t.test(e)}function p(){var t=!0,n=e("#subb-NAME"),i=e("#subb-EMAIL");if(!r.emailonly)if(n.val().length<2){t=!1;n.addClass("error")}else n.removeClass("error");if(!h(i.val())){t=!1;i.addClass("error")}else i.removeClass("error");return t}function d(e,t,n){var r=new Date;r.setTime(r.getTime()+n*24*60*60*1e3);var i="expires="+r.toUTCString();document.cookie=e+"="+t+"; "+i+"; path=/"}function v(e){var t=e+"=",n=document.cookie.split(";");for(var r=0;r<n.length;r++){var i=n[r];while(i.charAt(0)==" ")i=i.substring(1);if(i.indexOf(t)==0)return i.substring(t.length,i.length)}return""}var n=this,r=e.extend({list:"MailChimp",url:"",title:"Never miss a post!",text:"Get our latest posts and announcements in your inbox. You won't regret it!",name:"Subbscribe",color:"#ee6262",thumbnail:"https://s3-ap-southeast-2.amazonaws.com/subbscribe/img/avatar.png",emailonly:!1,cm_mail_field:"",delay:0},t);if(r.url==""){console.log("Subbscribe Error: You must provide a valid MailChimp form URL.");return}if(r.list==="CampaignMonitor"&&!r.cm_mail_field.length){console.log("You must provide the mail input name. Found in the form code from Campaign Monitor");return}var i="",s="",o="";if(r.list=="MailChimp"){i="NAME";s="EMAIL";_action=r.url.replace("/post?","/post-json?").concat("&c=?")}else{if(r.list!="CampaignMonitor"){console.log("Subbscribe Error: list value must be set to MailChimp or CampaignMonitor");return}i="cm-name";s=r.cm_mail_field;_action=r.url+"?callback=?"}var u="",a='<input type="email" name="'+s+'" id="subb-EMAIL" placeholder="Email Address" />';r.emailonly||(u=' <input type="text" name="'+i+'" id="subb-NAME" placeholder="Name" />');var f='<div id="subbscribe" style="display: none"><div class="subb-title">'+r.title+' <img class="close-x" src="https://s3-ap-southeast-2.amazonaws.com/subbscribe/img/close.svg" /> </div> <div class="subb-body"> <div class="subb-hidden"> <div class="subb-thumbnail"> <img style="width: 40px; height: 40px;" src="'+r.thumbnail+'" /> </div> <div class="subb-hidden"> <div class="subb-site"> '+r.name+' </div> <button class="subb-button show-form">Subscribe</button> </div> </div> <div class="subb-form" style="display: none"> <p>'+r.text+'</p> <form id="mc-embedded-subbscribe-form" method="post" action="'+r.url+'"> <div class="subbscribe-alert subbscribe-error" style="display: none">Oops! Check your details and try again.</div> <div class="subbscribe-alert subbscribe-success" style="display: none">Thanks! Check your email for confirmation.</div> <div class="text-input"> '+u+' </div> <div class="text-input"> '+a+' </div> <button class="subb-button submit-form" type="submit" style="width: 100%; margin-bottom: 10px;">Subscribe</button></form> <div class="footer">Powered by <a href="http://www.subbscribe.com" target="_blank">Subbscribe.com</a></div> </div> </div> </div>';if(v("subbscribe-hidden")!=1){this.append(f);setTimeout(function(){e("#subbscribe").css("display","block");e("#subbscribe").css("width",e(".subb-site").width()+200);e("#subbscribe").addClass("animated slideInRight")},r.delay*1e3)}e("#subbscribe .subb-button").css("background-color",r.color);e("#subbscribe .close-x").click(function(){e("#subbscribe").toggleClass("slideInRight fadeOut");e("#subbscribe").one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend",function(){e("#subbscribe").remove();d("subbscribe-hidden",1,1)});r.onClose.call()});e("#subbscribe .show-form").click(function(){e("#subbscribe .subb-hidden").hide();e("#subbscribe .subb-form").show()});e("#mc-embedded-subbscribe-form").submit(function(t){t.preventDefault();if(p()){e("#subbscribe .subbscribe-error").slideUp();e("#subbscribe .submit-form").attr("disabled","disabled");e.ajax({url:_action,type:"post",data:e(this).serialize(),dataType:"json",contentType:"application/json; charset=utf-8",success:function(t){if(l(t))console.log("Subbscribe Error: submission failed.");else{c();e(".subbscribe-success").slideDown();setTimeout(function(){e("#subbscribe").addClass("animated fadeOut")},2e3);e("#subbscribe").one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend",function(){e("#subbscribe").remove();d("subbscribe-hidden",1,365);typeof r.onSubbscribe=="function"&&r.onSubbscribe.call()})}}})}else e("#subbscribe .subbscribe-error").slideDown()})}})(jQuery);