/*----------------------------- popup -----------------------------*/ (function($){ var defaults = { showTrigger:'.popup_show_trigger', hideTrigger:'.popup_hide_trigger', overlayClassName:'popup_overlay', fadeSpeed:500, callbackFadeInStart:() => {}, callbackFadeInFinish:() => {}, callbackFadeOutStart:() => {}, callbackFadeOutFinish:() => {} }; $.fn.popup = function(options){ var configs = {}, el = this, lenEl = el.length; if(lenEl === 0)return this; if(lenEl > 1){ el.each(function(){$(this).popup(options)}); return this; } var flagExecute = false, cssTopEl = parseInt(el.css('top')); el.funcInit = () => { configs = $.extend({}, defaults, options); el.funcPutHtml(); el.funcAddEventListenerTrigger(); el.funcCustomEvents(); el.funcDestructor(); }, el.funcDestructor = () => { lenEl = el.funcInit = el.funcPutHtml = el.funcAddEventListenerTrigger = el.funcCustomEvents = el.funcDestructor = void 0; }, el.funcPutHtml = () => { el.wrap('
'); }, el.funcAddEventListenerTrigger = () => { var dataPopupShowTrigger = el.data('popup_show_trigger'), dataPopupHideTrigger = el.data('popup_hide_trigger'), eleShowTrigger = $(typeof dataPopupShowTrigger !== 'undefined'?dataPopupShowTrigger:configs.showTrigger), eleHideTrigger = $(typeof dataPopupHideTrigger !== 'undefined'?dataPopupHideTrigger:configs.hideTrigger), eleOverlay = $('.' + configs.overlayClassName); eleShowTrigger.on({ click:function(){ el.funcShowPopup(); } }); eleHideTrigger.on({ click:function(){ el.funcHidePopup(); } }); eleOverlay.on({ click:function(){ el.funcHidePopup(); } }); el.on({ click:function(e){ e.stopPropagation(); } }); }, el.funcAddEventListenerWindow = () => { var eleWindow = $(window); eleWindow.on({ 'resize.popup_window_resize':function(){ el.funcAdjustmentHeight(); } }); }, el.funcRemoveEventListenerWindow = () => { var eleWindow = $(window); eleWindow.off('resize.popup_window_resize'); }, el.funcCustomEvents = () => { el.on({ 'popup.show':(e) => { el.funcShowPopup(); }, 'popup.hide':(e) => { el.funcHidePopup(); }, 'popup.adjustmentHeight':(e) => { el.funcAdjustmentHeight(); } }); }, el.funcAdjustmentHeight = () => { var cssHeightWindow = $(window).height(), cssDisplayEl = el.css('display'), cssPutHeight = cssHeightWindow - cssTopEl * 2; if(cssDisplayEl === 'none'){ el.css({ display:'block', top:cssHeightWindow + 'px' }); } var cssHeightEl = $('> div > div', el).eq(0).outerHeight(true); if(cssDisplayEl === 'none'){ el.css({ display:'none', top:cssTopEl + 'px' }); } if(cssHeightEl > cssPutHeight){ el.css({ height:cssPutHeight + 'px' }); }else{ el.css({ height:cssHeightEl + 'px', top:((cssHeightWindow - cssHeightEl) / 2) + 'px' }); } }, el.funcShowPopup = () => { if(flagExecute) return false; flagExecute = true; configs.callbackFadeInStart(); $('.' + configs.overlayClassName).show(); el.funcAdjustmentHeight(); el.funcAddEventListenerWindow(); el .stop() .fadeIn( configs.fadeSpeed, () => { flagExecute = false; configs.callbackFadeInFinish(); } ); }, el.funcHidePopup = () => { if(flagExecute) return false; flagExecute = true; configs.callbackFadeOutStart(); el .stop() .fadeOut( configs.fadeSpeed, () => { $('.' + configs.overlayClassName).hide(); el.funcRemoveEventListenerWindow(); flagExecute = false; configs.callbackFadeOutFinish(); } ); }; el.funcInit(); return this; }; })(jQuery); /*----------------------------- /popup -----------------------------*/