-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopbox.min.js
1 lines (1 loc) · 3.8 KB
/
popbox.min.js
1
!function(o){"use strict";var t={autoShow:15e3,autoClose:6e4,autoShowDisabled:!1,showOnScrollStart:48,showOnScrollEnd:52,showOnExitIntent:!0,exitIntentTimeout:8e3,closeOnDimmer:!0,closeOnEsc:!0,noPropagateClicks:!1,onShow:!1,onHide:!1,classes:{popbox:"popbox",workarea:"workarea",fixed:"popbox-fixed",noOverflow:"popbox-no-overflow",closeButton:"popbox-close",closeCountdownMsg:"popbox-close-msg",closeCountdownDigits:"popbox-close-countdown"},timerShow:!1,timerClose:!1,scrollHook:!1,autoShowUsed:!1,showCnt:0,scrollPosition:{y:0,top:"",class:"",save:function(t){this.y=$(o).scrollTop(),this.top=o.getComputedStyle(document.body).top,document.body.style.top=-this.y+"px",$("body").addClass(this.class=t)},restore:function(t){$("body").removeClass(t||this.class),document.body.style.top=this.top,o.scrollTo(0,this.y)}},init:function(o){var t=this;o&&$.extend(this,o),doInit(function(){if("undefined"==typeof $)return 1;if(t.noPropagateClicks&&$("."+t.classes.popbox+" ."+t.classes.workarea).click(function(o){o.stopPropagation()}),t.closeOnDimmer&&$("."+t.classes.popbox).click(function(o){o.stopPropagation(),t.hide()}),$("."+t.classes.closeButton).click(function(o){o.stopPropagation(),o.preventDefault(),t.hide()}),t.autoClose>0&&$("."+t.classes.popbox).find("input, textarea, select").keydown(function(o){t.stopTimerHide(),$(this).off("keydown")}),t.autoShowDisabled&&"scroll"!=t.autoShowDisabled||doInit(function(){t.startAutoShow("scroll"==t.autoShowDisabled)},2),t.showOnExitIntent){var o=function(){$(document).on("mouseout",function(o){if(null===o.toElement&&null===o.relatedTarget&&o.clientY<0){if(t.onBeforeExitIntent&&!t.onBeforeExitIntent())return!1;0==t.showCnt?t.show():t.disableAutoShow()}})};t.exitIntentTimeout>0?setTimeout(o,t.exitIntentTimeout):o()}})},isVisible:function(){return $("."+this.classes.popbox).is(":visible")},show:function(o){var t=this;if(!t.isVisible()){if(0==t.showCnt&&t.disableAutoShow(),++t.showCnt,o){$("."+this.classes.closeCountdownMsg).show(),$("."+t.classes.closeCountdownDigits).show();var e=o/1e3;$("."+t.classes.closeCountdownDigits).html(e),t.timerClose=setInterval(function(){--e,$("."+t.classes.closeCountdownDigits).html(e),e<=0&&t.hide()},1e3)}else $("."+t.classes.closeCountdownMsg).hide();t.scrollPosition.save(t.classes.fixed+" "+t.classes.noOverflow),$("."+t.classes.popbox).show(),t.closeOnEsc&&$(document).keydown(function(o){27==o.keyCode&&t.isVisible()&&(o.stopPropagation(),t.hide(),$(document).off("keydown"))}),t.onShow&&t.onShow()}},hide:function(){var o=this;o.stopTimerHide(),$("."+o.classes.popbox).hide(),o.scrollPosition.restore(),o.onHide&&o.onHide()},stopTimerHide:function(){this.timerClose&&(clearInterval(this.timerClose),this.timerClose=!1,$("."+this.classes.closeCountdownMsg).hide())},startAutoShow:function(t){var e=this,s=function(){0==e.showCnt?e.show(e.autoClose):e.disableAutoShow()},n=function(){e.autoShow&&!e.timerShow&&(e.timerShow=setTimeout(function(){s()},e.autoShow))};e.autoShowUsed||(e.autoShowUsed=1,t||n(),(t||e.showOnScrollEnd>e.showOnScrollStart)&&$(o).scroll(e.scrollHook=function(i){if(t&&n(),e.showOnScrollEnd>e.showOnScrollStart){var l=document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop,c=document.documentElement&&document.documentElement.scrollHeight||document.body.scrollHeight;l+(o.innerHeight||document.documentElement&&document.documentElement.clientHeight||document.body.clientHeight)>c/100*e.showOnScrollStart&&l<c/100*e.showOnScrollEnd&&s()}}))},disableAutoShow:function(){var t=this;t.autoShowUsed&&(t.timerShow&&clearInterval(t.timerShow),t.scrollHook&&$(o).off("scroll"),t.showOnExitIntent&&$(document).off("mouseout"))},onBeforeExitIntent:function(){return"undefined"==typeof alertify||!(alertify.alert().isOpen()||alertify.confirm().isOpen()||alertify.prompt().isOpen())}};o.PopBox||(o.PopBox=t)}("undefined"!=typeof window?window:this);