1
|
function WMP_WAITLIST(){var t=this;this.type="wmp_waitlist",this.container,this.form,this.actionBox,this.DOMDoc,this.send_btn,this.display_btn,this.submitURL,this.listType,this.init=function(){WMPJSInterface=window.parent.WMPJSInterface,this.send_btn=jQuery("#"+this.type+"_send_btn",this.container).get(0),this.display_btn=jQuery("#"+this.type+"_display_btn",this.container).get(0),this.actionBox=jQuery("#"+this.type+"_action",this.container).get(0),this.form=jQuery("#"+this.type+"_form",this.container).get(0),this.addButtonsActions(),null!=this.form&&this.initValidation()},this.initValidation=function(){this.validator=jQuery("#"+this.form.id,this.container).validate({rules:{wmp_waitlist_emailaddress:{required:!0,email:!0}},messages:{wmp_waitlist_emailaddress:{email:"Invalid e-mail address"}},errorPlacement:function(e,i){var n=i[0].id.split("_"),s=n.length>1?n[n.length-1]:n[0],a=jQuery("#error_"+s+"_container",t.DOMDoc);e.appendTo(a)},errorElement:"span"});var e=jQuery("#"+this.type+"_email",this.container);e.data("holder",e.attr("placeholder")),e.focusin(function(){jQuery(this).attr("placeholder","")}).focusout(function(){jQuery(this).attr("placeholder",jQuery(this).data("holder"))})},this.addButtonsActions=function(){jQuery(this.send_btn).unbind("click"),jQuery(this.send_btn).bind("click",function(){t.disableButton(this),t.validate()}),t.enableButton(this.send_btn),jQuery(this.display_btn).unbind("click"),jQuery(this.display_btn).bind("click",function(){t.disableButton(this),jQuery(t.form).show(),jQuery(t.actionBox).hide()}),t.enableButton(this.display_btn),jQuery("#"+t.form.id,t.DOMDoc).bind("keypress",function(t){if(13==t.keyCode)return!1})},this.enableButton=function(t){jQuery(t).css("cursor","pointer"),jQuery(t).animate({opacity:1},100)},this.disableButton=function(t){jQuery(t).unbind("click"),jQuery(t).animate({opacity:.4},100),jQuery(t).css("cursor","default")},this.validate=function(){jQuery(this.form).validate().form();var e=[];for(var i in this.validator.invalid){var n=jQuery(this.form[i]);e.push(n.offset().top)}0==e.length?t.sendData():t.addButtonsActions()},this.sendData=function(){WMPJSInterface.Preloader.start(),jQuery.post(ajaxurl,{action:"wmp_join_waitlist",email:jQuery("#"+t.type+"_emailaddress",t.container).val(),joined_waitlist:t.listType},function(e){if(WMPJSInterface.Preloader.remove(100),0==parseInt(e)){WMPJSInterface.Loader.display({message:"There was an error. Please reload the page and try again in few seconds or contact the plugin administrator if the problem persists."}),t.form.reset(),setTimeout(function(){var e=t.form.elements;for(nElems=e.length,j=0;j<nElems;j++)e[j].disabled=!1},300),t.addButtonsActions()}else WMPJSInterface.Loader.display({message:"Email successfully subscribed"}),jQuery(t.form).hide(),jQuery("#"+t.type+"_added",t.container).show()})}}
|