2 lines
37 KiB
JavaScript
2 lines
37 KiB
JavaScript
|
!function(t,i){"function"==typeof define&&define.amd?define(["jquery"],function(s){return t.jBox=i(s)}):"object"==typeof module&&module.exports?module.exports=t.jBox=i(require("jquery")):t.jBox=i(t.jQuery)}(this,function(t){var i=function i(s,o){return this.options={id:null,width:"auto",height:"auto",minWidth:null,minHeight:null,maxWidth:null,maxHeight:null,responsiveWidth:!0,responsiveHeight:!0,responsiveMinWidth:100,responsiveMinHeight:100,attach:null,trigger:"click",preventDefault:!1,content:null,getContent:null,title:null,getTitle:null,footer:null,isolateScroll:!0,ajax:{url:null,data:"",reload:!1,getURL:"data-url",getData:"data-ajax",setContent:!0,spinner:!0,spinnerDelay:300,spinnerReposition:!0},target:null,position:{x:"center",y:"center"},outside:null,offset:0,attributes:{x:"left",y:"top"},fixed:!1,adjustPosition:!0,adjustTracker:!1,adjustDistance:5,reposition:!0,repositionOnOpen:!0,repositionOnContent:!0,pointer:!1,pointTo:"target",fade:180,animation:null,theme:"Default",addClass:null,overlay:!1,zIndex:1e4,delayOpen:0,delayClose:0,closeOnEsc:!1,closeOnClick:!1,closeOnMouseleave:!1,closeButton:!1,appendTo:t("body"),createOnInit:!1,blockScroll:!1,draggable:!1,dragOver:!0,autoClose:!1,preloadAudio:!0,audio:null,volume:100,onInit:null,onAttach:null,onPosition:null,onCreated:null,onOpen:null,onClose:null,onCloseComplete:null},this._pluginOptions={Tooltip:{getContent:"title",trigger:"mouseenter",position:{x:"center",y:"top"},outside:"y",pointer:!0},Mouse:{responsiveWidth:!1,responsiveHeight:!1,adjustPosition:"flip",target:"mouse",trigger:"mouseenter",position:{x:"right",y:"bottom"},outside:"xy",offset:5},Modal:{target:t(window),fixed:!0,blockScroll:!0,closeOnEsc:!0,closeOnClick:"overlay",closeButton:!0,overlay:!0,animation:"zoomIn"}},this.options=t.extend(!0,this.options,this._pluginOptions[s]?this._pluginOptions[s]:i._pluginOptions[s],o),"string"==t.type(s)&&(this.type=s),this._fireEvent=function(t,i){this.options["_"+t]&&this.options["_"+t].bind(this)(i),this.options[t]&&this.options[t].bind(this)(i)},null===this.options.id&&(this.options.id="jBox"+i._getUniqueID()),this.id=this.options.id,("center"==this.options.position.x&&"x"==this.options.outside||"center"==this.options.position.y&&"y"==this.options.outside)&&(this.options.outside=null),"target"==this.options.pointTo&&(!this.options.outside||"xy"==this.options.outside)&&(this.options.pointer=!1),"object"!=t.type(this.options.offset)?this.options.offset={x:this.options.offset,y:this.options.offset}:this.options.offset=t.extend({x:0,y:0},this.options.offset),"object"!=t.type(this.options.adjustDistance)?this.options.adjustDistance={top:this.options.adjustDistance,right:this.options.adjustDistance,bottom:this.options.adjustDistance,left:this.options.adjustDistance}:this.options.adjustDistance=t.extend({top:5,left:5,right:5,bottom:5},this.options.adjustDistance),this.outside=!(!this.options.outside||"xy"==this.options.outside)&&this.options.position[this.options.outside],this.align=this.outside?this.outside:"center"!=this.options.position.y&&"number"!=t.type(this.options.position.y)?this.options.position.x:"center"!=this.options.position.x&&"number"!=t.type(this.options.position.x)?this.options.position.y:this.options.attributes.x,this._getOpp=function(t){return{left:"right",right:"left",top:"bottom",bottom:"top",x:"y",y:"x"}[t]},this._getXY=function(t){return{left:"x",right:"x",top:"y",bottom:"y",center:"x"}[t]},this._getTL=function(t){return{left:"left",right:"left",top:"top",bottom:"top",center:"left",x:"left",y:"top"}[t]},this._getInt=function(i,s){return"auto"==i?"auto":i&&"string"==t.type(i)&&"%"==i.slice(-1)?t(window)["height"==s?"innerHeight":"innerWidth"]()*parseInt(i.replace("%",""))/100:i},this._createSVG=function(i,s){var o=document.createElementNS("http://www.w3.org/2000/svg",i);return t.each(s,function(t,i){o.setAttribute(i[0],i[1]||"")}),o},this._isolateScroll=function(t){t&&t.length&&t.on("DOMMouseScroll.jBoxIsolateScroll mousewheel.jBoxIsolateScroll",function(i){var s=i.wheelDelta||i.originalEvent&&i.originalEvent.wheelDelta||-i.detail,o=this.scrollT
|
||
|
opacity:1},{queue:!1,duration:this.options.fade,start:function(){this.isOpening=!0,this.wrapper.css({display:"block"})}.bind(this),always:function(){this.isOpening=!1,setTimeout(function(){this.positionOnFadeComplete&&this.position()&&(this.positionOnFadeComplete=!1)}.bind(this),10)}.bind(this)}):(this.wrapper.css({display:"block",opacity:1}),this.positionOnFadeComplete&&this.position()&&(this.positionOnFadeComplete=!1)))}.bind(this);return!this.options.delayOpen||this.isOpen||this.isClosing||i.ignoreDelay?s():this.timer=setTimeout(s,this.options.delayOpen),this},i.prototype.close=function(i){if(i||(i={}),this.isDestroyed||this.isClosing)return!1;if(this.timer&&clearTimeout(this.timer),this._blockBodyClick(),this.isDisabled)return this;var s=function(){this._fireEvent("onClose"),this.isOpen&&(this.isOpen=!1,this._detachEvents(),this.options.blockScroll&&t("body").removeClass("jBox-blockScroll-"+this.id),this.options.overlay&&this._hideOverlay(),this.options.animation&&!this.isOpening&&this._animate("close"),this.options.audio&&this.options.audio.close&&this.audio(this.options.audio.close,this.options.volume.close),this.options.fade?this.wrapper.stop().animate({opacity:0},{queue:!1,duration:this.options.fade,start:function(){this.isClosing=!0}.bind(this),complete:function(){this.wrapper.css({display:"none"}),this._fireEvent("onCloseComplete")}.bind(this),always:function(){this.isClosing=!1}.bind(this)}):(this.wrapper.css({display:"none",opacity:0}),this._fireEvent("onCloseComplete")))}.bind(this);return i.ignoreDelay?s():this.timer=setTimeout(s,Math.max(this.options.delayClose,10)),this},i.prototype.toggle=function(t){return this[this.isOpen?"close":"open"](t),this},i.prototype.disable=function(){return this.isDisabled=!0,this},i.prototype.enable=function(){return this.isDisabled=!1,this},i.prototype.hide=function(){return this.disable(),this.wrapper&&this.wrapper.css({display:"none"}),this},i.prototype.show=function(){return this.enable(),this.wrapper&&this.wrapper.css({display:"block"}),this},i.prototype.ajax=function(i,s){i||(i={}),t.each([["getData","data"],["getURL","url"]],function(t,s){this.options.ajax[s[0]]&&!i[s[1]]&&this.source&&void 0!=this.source.attr(this.options.ajax[s[0]])&&(i[s[1]]=this.source.attr(this.options.ajax[s[0]])||"")}.bind(this));var o=t.extend(!0,{},this.options.ajax);this.ajaxRequest&&this.ajaxRequest.abort();var e=i.beforeSend||o.beforeSend||function(){},n=i.complete||o.complete||function(){},a=i.success||o.success||function(){},h=i.error||o.error||function(){},p=t.extend(!0,o,i);return p.beforeSend=function(){this.wrapper.addClass("jBox-loading"),p.spinner&&(this.spinnerDelay=setTimeout(function(){this.wrapper.addClass("jBox-loading-spinner"),p.spinnerReposition&&(s?this.positionOnFadeComplete=!0:this.position()),this.spinner=t(p.spinner!==!0?p.spinner:'<div class="jBox-spinner"></div>').appendTo(this.container),this.titleContainer&&"absolute"==this.spinner.css("position")&&this.spinner.css({transform:"translateY("+.5*this.titleContainer.outerHeight()+"px)"})}.bind(this),""==this.content.html()?0:p.spinnerDelay||0)),e.bind(this)()}.bind(this),p.complete=function(t){this.spinnerDelay&&clearTimeout(this.spinnerDelay),this.wrapper.removeClass("jBox-loading jBox-loading-spinner jBox-loading-spinner-delay"),this.spinner&&this.spinner.length&&this.spinner.remove()&&p.spinnerReposition&&(s?this.positionOnFadeComplete=!0:this.position()),this.ajaxLoaded=!0,n.bind(this)(t)}.bind(this),p.success=function(t){p.setContent&&this.setContent(t,!0)&&(s?this.positionOnFadeComplete=!0:this.position()),p.setContent&&this.source&&this.source.data("jBox-ajax-data",t),a.bind(this)(t)}.bind(this),p.error=function(t){h.bind(this)(t)}.bind(this),this.ajaxRequest=t.ajax(p),this},i.prototype.audio=function(s,o){if(!s)return this;if(!i._audio&&(i._audio={}),!i._audio[s]){var e=t("<audio/>");t("<source/>",{src:s+".mp3"}).appendTo(e),t("<source/>",{src:s+".ogg"}).appendTo(e),i._audio[s]=e[0]}i._audio[s].volume=Math.min((void 0!=o?o:100)/100,1);try{i._audio[s].pause(),i._audio[s].currentTime=0}catch(t){}return i._audio[
|