-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.popup.min.js
16 lines (16 loc) · 5.3 KB
/
jquery.popup.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
"use strict";function _instanceof(left,right){if(right!=null&&typeof Symbol!=="undefined"&&right[Symbol.hasInstance]){return!!right[Symbol.hasInstance](left)}else{return left instanceof right}}
function _typeof(obj){if(typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"){_typeof=function _typeof(obj){return typeof obj}}else{_typeof=function _typeof(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj}}
return _typeof(obj)}
function _classCallCheck(instance,Constructor){if(!_instanceof(instance,Constructor)){throw new TypeError("Cannot call a class as a function")}}
function _defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1;descriptor.configurable=!0;if("value" in descriptor)descriptor.writable=!0;Object.defineProperty(target,descriptor.key,descriptor)}}
function _createClass(Constructor,protoProps,staticProps){if(protoProps)_defineProperties(Constructor.prototype,protoProps);if(staticProps)_defineProperties(Constructor,staticProps);return Constructor}(function($,window){var Popup=(function(){function Popup(self,options){_classCallCheck(this,Popup);this.self=self;this._thisHeight=self.outerHeight();this._window=$(window);this._thisTransformHideDefault="scale(0)";this._thisTransformShowDefault="scale(1)";this._opened=!1;this.popupBg=$("#popup-bg");this.options=$.extend({background:"#000",position:"absolute",opacity:0.5,zIndex:123456788,classAnimateShow:"",classAnimateHide:"",time:400,onPopupClose:function onPopupClose(){},onPopupInit:function onPopupInit(){}},options,!0);if(_typeof(options)==="object"||!options){if(self.length){this.init().events()}}else{this[options]()}
return this}
_createClass(Popup,[{key:"init",value:function init(){var _this=this;this._opened=!0;this.lock("-lock","-popup-opened",!0);if(this.options.classAnimateShow!==""){this.self.removeClass(this.options.classAnimateHide);this.self.css({position:this.options.position,WebkitAnimationDuration:this.options.time/1e3+"s",animationDuration:this.options.time/1e3+"s",zIndex:this.options.zIndex+1}).show().addClass("animated "+this.options.classAnimateShow)}else{this.self.css({position:this.options.position,zIndex:this.options.zIndex+1,transform:this._thisTransformHideDefault,transition:"transform "+this.options.time/1e3+"s ease-out"}).fadeIn(this.options.time).css({transform:this._thisTransformShowDefault})}
if(this.options.position==="fixed"){this.popupPosition();this._window.on("resize",function(){_this.self.css({transition:"left "+_this.options.time/1e3+"s ease-out, top "+_this.options.time/1e3+"s ease-out"});_this.popupPosition()})}else if(this.options.position==="absolute"){this.popupPositionRezise();this._window.on("resize",function(){_this.self.css({transition:"left "+_this.options.time/1e3+"s ease-out, top "+_this.options.time/1e3+"s ease-out"});_this.popupPositionRezise()})}
this.options.onPopupInit();this.overlay();return this}},{key:"lock",value:function lock(classLock,classMod,open){var html=$("html");if(open){html.addClass(classMod+" "+classLock)}else{html.removeClass(classMod);setTimeout(function(){html.removeClass(classLock)},this.options.time)}}},{key:"overlay",value:function overlay(){if(document.getElementById("popup-bg")===null){$("<div/>",{id:"popup-bg",css:{position:"fixed",top:0,height:"100%",width:"100%",left:0,display:"none",background:this.options.background,opacity:this.options.opacity,zIndex:this.options.zIndex,cursor:"pointer"}}).appendTo("body")}
this.popupBg=$("#popup-bg");this.popupBg.show();return this}},{key:"close",value:function close(flag){var _this2=this;this._opened=!1;if(this.options.classAnimateHide!==""){this.self.removeClass(this.options.classAnimateShow);this.self.addClass("animated "+this.options.classAnimateHide);setTimeout(function(){_this2.self.hide()},this.options.time)}else{this.self.fadeOut(this.options.time).css({transform:this._thisTransformHideDefault});this.self.removeClass("animated "+this.options.classAnimateShow)}
if(!flag){this.popupBg.fadeOut(this.options.time)}
this.lock("-lock","-popup-opened");this.options.onPopupClose();return this}},{key:"popupPosition",value:function popupPosition(){this.self.css({top:this._window.height()/2-this.self.outerHeight()/2,left:this._window.width()/2-this.self.outerWidth()/2});return this}},{key:"popupPositionRezise",value:function popupPositionRezise(){var $=this.self.offsetParent();if(this._thisHeight>this._window.height()){this.self.css({top:-$.offset().top+this._window.scrollTop()+5})}else{this.self.css({top:-$.offset().top+this._window.scrollTop()+this._window.height()/2-this.self.outerHeight()/2})}
if(this.self.outerWidth()>this._window.width()){this.self.css({left:-$.offset().left+this._window.scrollLeft()+5})}else{this.self.css({left:-$.offset().left+this._window.scrollLeft()+this._window.width()/2-this.self.outerWidth()/2})}
return this}},{key:"events",value:function events(){var _this3=this;this.popupBg.on({click:function click(){_this3._opened&&_this3.close()}});$(".js-popup-close",this.self).on({click:function click(){_this3.close()}});$(document).on({keydown:function keydown(e){if(e.code==="Escape"){_this3._opened&&_this3.close()}}})}}]);return Popup})();$.fn.popup=function(options){if(!this.data("popup")){this.data("popup",new Popup(this,options))}else{this.data("popup").init()}
return this}})(jQuery,window)