You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 lines
28 KiB
1 lines
28 KiB
function jBox(e,t){this.options={id:null,width:"auto",height:"auto",attach:null,trigger:"click",preventDefault:false,title:null,content:null,getTitle:null,getContent:null,ajax:null,data:"",reload:false,target:null,position:{x:"center",y:"center"},outside:null,offset:0,attributes:{x:"left",y:"top"},adjustPosition:false,adjustTracker:false,adjustDistance:5,fixed:false,reposition:false,pointer:false,fade:180,animation:null,theme:"Default",addClass:"",overlay:false,zIndex:1e4,delayOpen:0,delayClose:0,closeOnEsc:false,closeOnClick:false,closeOnMouseleave:false,closeButton:false,constructOnInit:false,blockScroll:false,appendTo:jQuery("body"),draggable:null,onInit:function(){},onCreated:function(){},onOpen:function(){},onClose:function(){},onAjax:function(){},onAjaxComplete:function(){},autoClose:7e3,color:null,stack:true,audio:false,volume:100};this.defaultOptions={Tooltip:{getContent:"title",trigger:"mouseenter",position:{x:"center",y:"top"},outside:"y",pointer:true,adjustPosition:true,reposition:true},Mouse:{target:"mouse",position:{x:"right",y:"bottom"},offset:15,trigger:"mouseenter",adjustPosition:"flip"},Modal:{target:jQuery(window),fixed:true,blockScroll:true,closeOnEsc:true,closeOnClick:"body",closeButton:"title",overlay:true,animation:"zoomOut"},Notice:{target:jQuery(window),fixed:true,position:{x:20,y:20},attributes:{x:"right",y:"top"},animation:"zoomIn",closeOnClick:"box",_onInit:function(){this.open();this.options.delayClose=this.options.autoClose;this.options.delayClose&&this.close()}.bind(this),_onCreated:function(){this.options.color&&this.wrapper.addClass("jBox-Notice-color jBox-Notice-"+this.options.color)},_onOpen:function(){jQuery.each(jQuery(".jBox-Notice"),function(e,t){t=jQuery(t);if(t.attr("id")==this.id||t.css(this.options.attributes.y)=="auto"||t.css(this.options.attributes.x)=="auto")return;if(!this.options.stack){t.data("jBox").close({ignoreDelay:true});return}t.css("margin-"+this.options.attributes.y,parseInt(t.css("margin-"+this.options.attributes.y))+this.dimensions.y+10)}.bind(this));if(this.options.audio&&!this.IE8){this.audio=jQuery("<audio/>");jQuery("<source/>",{src:this.options.audio+".mp3"}).appendTo(this.audio);jQuery("<source/>",{src:this.options.audio+".ogg"}).appendTo(this.audio);this.audio[0].volume=Math.min(this.options.volume/100,1);this.audio[0].play()}}.bind(this),_onCloseComplete:function(){this.destroy()}.bind(this)}};if(jQuery.type(e)=="string"){this.type=e;e=this.defaultOptions[e]}this.options=jQuery.extend(this.options,e,t);if(this.options.id===null){var n=1;while(jQuery("#jBox"+n).length!=0)n++;this.options.id="jBox"+n}this.id=this.options.id;(this.options.position.x=="center"&&this.options.outside=="x"||this.options.position.y=="center"&&this.options.outside=="y")&&(this.options.outside=false);(!this.options.outside||this.options.outside=="xy")&&(this.options.pointer=false);jQuery.type(this.options.offset)!="object"&&(this.options.offset={x:this.options.offset,y:this.options.offset});this.options.offset.x||(this.options.offset.x=0);this.options.offset.y||(this.options.offset.y=0);jQuery.type(this.options.adjustDistance)!="object"&&(this.options.adjustDistance={top:this.options.adjustDistance,right:this.options.adjustDistance,bottom:this.options.adjustDistance,left:this.options.adjustDistance});this.align=this.options.outside&&this.options.outside!="xy"?this.options.position[this.options.outside]:this.options.position.y!="center"&&jQuery.type(this.options.position.y)!="number"?this.options.position.x:this.options.position.x!="center"&&jQuery.type(this.options.position.x)!="number"?this.options.position.y:this.options.attributes.x;this.options.outside&&this.options.outside!="xy"&&(this.outside=this.options.position[this.options.outside]);var r=navigator.userAgent.toLowerCase();this.IE8=r.indexOf("msie")!=-1&&parseInt(r.split("msie")[1])==8;this.prefix=r.indexOf("webkit")!=-1?"-webkit-":"";this._getOpp=function(e){return{left:"right",right:"left",top:"bottom",bottom:"top",x:"y",y:"x"}[e]};this._getXY=function(e){return{left:"x",right:"x",top:"y",bottom:"y",center:"x"}[e]};this._getTL=function(e){return{left:"left",right:"left",top:"top",bottom:"top",center:"left",x:"left",y:"top"}[e]};this._create=function(){if(this.wrapper)return;this.wrapper=jQuery("<div/>",{id:this.id,"class":"jBox-wrapper"+(this.type?" jBox-"+this.type:"")+(this.options.theme?" jBox-"+this.options.theme:"")+(this.options.addClass?" "+this.options.addClass:"")+(this.IE8?" jBox-IE8":"")}).css({position:this.options.fixed?"fixed":"absolute",display:"none",opacity:0,zIndex:this.options.zIndex}).data("jBox",this);this.options.closeOnMouseleave&&this.wrapper.mouseenter(function(){this.open()}.bind(this)).mouseleave(function(){this.close()}.bind(this));this.container=jQuery("<div/>",{"class":"jBox-container"}).css({width:this.options.width,height:this.options.height}).appendTo(this.wrapper);this.content=jQuery("<div/>",{"class":"jBox-content"}).appendTo(this.container);if(this.options.closeButton){this.closeButton=jQuery("<div/>",{"class":"jBox-closeButton jBox-noDrag"}).click(function(){this.close()}.bind(this));if(this.options.closeButton!="title"){this.wrapper.addClass("jBox-closeButton-box");this.closeButton.appendTo(this.container)}}this.wrapper.appendTo(this.options.appendTo);if(this.options.pointer){this.pointer={position:this._getOpp(this.outside),xy:this._getXY(this.outside),align:"center",offset:0};this.pointer.element=jQuery("<div/>",{"class":"jBox-pointer jBox-pointer-"+this.pointer.position}).appendTo(this.wrapper);this.pointer.dimensions={x:this.pointer.element.outerWidth(),y:this.pointer.element.outerHeight()};if(jQuery.type(this.options.pointer)=="string"){var e=this.options.pointer.split(":");e[0]&&(this.pointer.align=e[0]);e[1]&&(this.pointer.offset=parseInt(e[1]))}this.pointer.alignAttribute=this.pointer.xy=="x"?this.pointer.align=="bottom"?"bottom":"top":this.pointer.align=="right"?"right":"left";this.wrapper.css("padding-"+this.pointer.position,this.pointer.dimensions[this.pointer.xy]);this.pointer.element.css(this.pointer.alignAttribute,this.pointer.align=="center"?"50%":0).css("margin-"+this.pointer.alignAttribute,this.pointer.offset);this.pointer.margin={margin:this.pointer.element.css("margin")};this.pointer.align=="center"&&this.pointer.element.css(this.prefix+"transform","translate("+(this.pointer.xy=="y"?this.pointer.dimensions.x*-.5+"px":0)+", "+(this.pointer.xy=="x"?this.pointer.dimensions.y*-.5+"px":0)+")");this.pointer.element.css(this.pointer.xy=="x"?"width":"height",parseInt(this.pointer.dimensions[this.pointer.xy])+parseInt(this.container.css("border-"+this.pointer.alignAttribute+"-width")));this.wrapper.addClass("jBox-pointerPosition-"+this.pointer.position)}this.setContent(this.options.content);this.setTitle(this.options.title);if(this.options.draggable){var t=this.options.draggable=="title"?this.titleContainer:this.options.draggable.length>0?this.options.draggable:this.wrapper;t.addClass("jBox-draggable").on("mousedown",function(e){if(e.button==2||jQuery(e.target).hasClass("jBox-noDrag")||jQuery(e.target).parents(".jBox-noDrag").length)return;var t=this.wrapper.outerHeight(),n=this.wrapper.outerWidth(),r=this.wrapper.offset().top+t-e.pageY,i=this.wrapper.offset().left+n-e.pageX;jQuery(document).on("mousemove.jBox-draggable-"+this.id,function(e){this.wrapper.offset({top:e.pageY+r-t,left:e.pageX+i-n})}.bind(this));e.preventDefault()}.bind(this)).on("mouseup",function(){jQuery(document).off("mousemove.jBox-draggable-"+this.id)}.bind(this))}this.options.onCreated.bind(this)();this.options._onCreated&&this.options._onCreated.bind(this)()};this.options.constructOnInit&&this._create();this.options.attach&&this.attach();this._positionMouse=function(e){this.pos={left:e.pageX,top:e.pageY};var t=function(e,t){if(this.options.position[t]=="center"){this.pos[e]-=Math.ceil(this.dimensions[t]/2);return}this.pos[e]+=e==this.options.position[t]?this.dimensions[t]*-1-this.options.offset[t]:this.options.offset[t];return this.pos[e]}.bind(this);this.wrapper.css({left:t("left","x"),top:t("top","y")});this.targetDimensions={x:0,y:0,left:e.pageX,top:e.pageY};this._adjustPosition()};this._attachEvents=function(){this.options.closeOnEsc&&jQuery(document).on("keyup.jBox-"+this.id,function(e){if(e.keyCode==27){this.close({ignoreDelay:true})}}.bind(this));this.options.closeOnClick&&jQuery(document).on("click.jBox-"+this.id,function(e){if(this.blockBodyClick||this.options.closeOnClick=="box"&&e.target!=this.wrapper[0]&&!this.wrapper.has(e.target).length||this.options.closeOnClick=="body"&&(e.target==this.wrapper[0]||this.wrapper.has(e.target).length))return;this.close({ignoreDelay:true})}.bind(this));if((this.options.adjustPosition&&this.options.adjustTracker||this.options.reposition)&&!this.fixed&&this.outside){var e,t=0,n=150;var r=function(){var r=(new Date).getTime();if(!e){if(r-t>n){this.options.reposition&&this.position();this.options.adjustTracker&&this._adjustPosition();t=r}e=setTimeout(function(){e=null;t=(new Date).getTime();this.options.reposition&&this.position();this.options.adjustTracker&&this._adjustPosition()}.bind(this),n)}}.bind(this);this.options.adjustTracker&&this.options.adjustTracker!="resize"&&jQuery(window).on("scroll.jBox-"+this.id,function(e){r()}.bind(this));(this.options.adjustTracker&&this.options.adjustTracker!="scroll"||this.options.reposition)&&jQuery(window).on("resize.jBox-"+this.id,function(e){r()}.bind(this))}this.options.target=="mouse"&&jQuery("body").on("mousemove.jBox-"+this.id,function(e){this._positionMouse(e)}.bind(this))};this._detachEvents=function(){this.options.closeOnEsc&&jQuery(document).off("keyup.jBox-"+this.id);this.options.closeOnClick&&jQuery(document).off("click.jBox-"+this.id);if(this.options.adjustPosition&&this.options.adjustTracker||this.options.reposition){jQuery(window).off("scroll.jBox-"+this.id);jQuery(window).off("resize.jBox-"+this.id)}this.options.target=="mouse"&&jQuery("body").off("mousemove.jBox-"+this.id)};this._addOverlay=function(){!this.overlay&&(this.overlay=jQuery("#jBox-overlay").length?jQuery("#jBox-overlay").css({zIndex:Math.min(jQuery("#jBox-overlay").css("z-index"),this.options.zIndex-1)}):jQuery("<div/>",{id:"jBox-overlay"}).css({display:"none",opacity:0,zIndex:this.options.zIndex-1}).appendTo(jQuery("body")));var e=this.overlay.data("jBox")||{};e["jBox-"+this.id]=true;this.overlay.data("jBox",e);if(this.overlay.css("display")=="block")return;this.options.fade?this.overlay.stop()&&this.overlay.animate({opacity:1},{queue:false,duration:this.options.fade,start:function(){this.overlay.css({display:"block"})}.bind(this)}):this.overlay.css({display:"block",opacity:1})};this._removeOverlay=function(){if(!this.overlay)return;var e=this.overlay.data("jBox");delete e["jBox-"+this.id];this.overlay.data("jBox",e);if(jQuery.isEmptyObject(e)){this.options.fade?this.overlay.stop()&&this.overlay.animate({opacity:0},{queue:false,duration:this.options.fade,complete:function(){this.overlay.css({display:"none"})}.bind(this)}):this.overlay.css({display:"none",opacity:0})}};this._generateCSS=function(){if(this.IE8)return;jQuery.type(this.options.animation)!="object"&&(this.options.animation={pulse:{open:"pulse",close:"zoomOut"},zoomIn:{open:"zoomIn",close:"zoomIn"},zoomOut:{open:"zoomOut",close:"zoomOut"},move:{open:"move",close:"move"},slide:{open:"slide",close:"slide"},flip:{open:"flip",close:"flip"},tada:{open:"tada",close:"zoomOut"}}[this.options.animation]);this.options.animation.open&&(this.options.animation.open=this.options.animation.open.split(":"));this.options.animation.close&&(this.options.animation.close=this.options.animation.close.split(":"));this.options.animation.openDirection=this.options.animation.open?this.options.animation.open[1]:null;this.options.animation.closeDirection=this.options.animation.close?this.options.animation.close[1]:null;this.options.animation.open&&(this.options.animation.open=this.options.animation.open[0]);this.options.animation.close&&(this.options.animation.close=this.options.animation.close[0]);this.options.animation.open&&(this.options.animation.open+="Open");this.options.animation.close&&(this.options.animation.close+="Close");var e={pulse:{duration:350,css:[["0%","scale(1)"],["50%","scale(1.1)"],["100%","scale(1)"]]},zoomInOpen:{duration:this.options.fade||180,css:[["0%","scale(0.9)"],["100%","scale(1)"]]},zoomInClose:{duration:this.options.fade||180,css:[["0%","scale(1)"],["100%","scale(0.9)"]]},zoomOutOpen:{duration:this.options.fade||180,css:[["0%","scale(1.1)"],["100%","scale(1)"]]},zoomOutClose:{duration:this.options.fade||180,css:[["0%","scale(1)"],["100%","scale(1.1)"]]},moveOpen:{duration:this.options.fade||180,positions:{top:{"0%":-12},right:{"0%":12},bottom:{"0%":12},left:{"0%":-12}},css:[["0%","translate%XY(%Vpx)"],["100%","translate%XY(0px)"]]},moveClose:{duration:this.options.fade||180,timing:"ease-in",positions:{top:{"100%":-12},right:{"100%":12},bottom:{"100%":12},left:{"100%":-12}},css:[["0%","translate%XY(0px)"],["100%","translate%XY(%Vpx)"]]},slideOpen:{duration:400,positions:{top:{"0%":-400},right:{"0%":400},bottom:{"0%":400},left:{"0%":-400}},css:[["0%","translate%XY(%Vpx)"],["100%","translate%XY(0px)"]]},slideClose:{duration:400,timing:"ease-in",positions:{top:{"100%":-400},right:{"100%":400},bottom:{"100%":400},left:{"100%":-400}},css:[["0%","translate%XY(0px)"],["100%","translate%XY(%Vpx)"]]},flipOpen:{duration:600,css:[["0%","perspective(400px) rotateX(90deg)"],["40%","perspective(400px) rotateX(-15deg)"],["70%","perspective(400px) rotateX(15deg)"],["100%","perspective(400px) rotateX(0deg)"]]},flipClose:{duration:this.options.fade||300,css:[["0%","perspective(400px) rotateX(0deg)"],["100%","perspective(400px) rotateX(90deg)"]]},tada:{duration:800,css:[["0%","scale(1)"],["10%, 20%","scale(0.9) rotate(-3deg)"],["30%, 50%, 70%, 90%","scale(1.1) rotate(3deg)"],["40%, 60%, 80%","scale(1.1) rotate(-3deg)"],["100%","scale(1) rotate(0)"]]}};jQuery.each(["pulse","tada"],function(t,n){e[n+"Open"]=e[n+"Close"]=e[n]});var t=function(t,n){keyframe_css="@"+this.prefix+"keyframes jBox-animation-"+this.options.animation[t]+"-"+t+(n?"-"+n:"")+" {";jQuery.each(e[this.options.animation[t]].css,function(r,i){var s=n?i[1].replace("%XY",this._getXY(n).toUpperCase()):i[1];e[this.options.animation[t]].positions&&(s=s.replace("%V",e[this.options.animation[t]].positions[n][i[0]]));keyframe_css+=i[0]+" {"+this.prefix+"transform:"+s+";}"}.bind(this));keyframe_css+="}";keyframe_css+=".jBox-animation-"+this.options.animation[t]+"-"+t+(n?"-"+n:"")+" {";keyframe_css+=this.prefix+"animation-duration: "+e[this.options.animation[t]].duration+"ms;";keyframe_css+=this.prefix+"animation-name: jBox-animation-"+this.options.animation[t]+"-"+t+(n?"-"+n:"")+";";keyframe_css+=e[this.options.animation[t]].timing?this.prefix+"animation-timing-function: "+e[this.options.animation[t]].timing+";":"";keyframe_css+="}";return keyframe_css}.bind(this);var n="";jQuery.each(["open","close"],function(r,i){if(!this.options.animation[i]||!e[this.options.animation[i]]||i=="close"&&!this.options.fade)return"";e[this.options.animation[i]].positions?jQuery.each(["top","right","bottom","left"],function(e,r){n+=t(i,r)}):n+=t(i)}.bind(this));jQuery("<style/>").append(n).appendTo(jQuery("head"))};this._blockBodyClick=function(){this.blockBodyClick=true;setTimeout(function(){this.blockBodyClick=false}.bind(this),10)};this.options.animation&&this._generateCSS();this._animate=function(e){if(this.IE8)return;e||(e=this.isOpen?"open":"close");if(!this.options.fade&&e=="close")return null;var t=this.options.animation[e+"Direction"]||(this.align!="center"?this.align:this.options.attributes.x);this.flipped&&this._getXY(t)==this._getXY(this.align)&&(t=this._getOpp(t));var n="jBox-animation-"+this.options.animation[e]+"-"+e+" jBox-animation-"+this.options.animation[e]+"-"+e+"-"+t;this.wrapper.addClass(n);var r=parseFloat(this.wrapper.css(this.prefix+"animation-duration"))*1e3;e=="close"&&(r=Math.min(r,this.options.fade));setTimeout(function(){this.wrapper.removeClass(n)}.bind(this),r)};this._abortAnimation=function(){if(this.IE8)return;var e="jBox-animation";var t=this.wrapper.attr("class").split(" ").filter(function(t){return t.lastIndexOf(e,0)!==0});this.wrapper.attr("class",t.join(" "))};this._adjustPosition=function(){if(!this.options.adjustPosition)return null;if(this.positionAdjusted){this.wrapper.css(this.pos);this.pointer&&this.wrapper.css("padding",0).css("padding-"+this._getOpp(this.outside),this.pointer.dimensions[this._getXY(this.outside)]).removeClass("jBox-pointerPosition-"+this._getOpp(this.pointer.position)).addClass("jBox-pointerPosition-"+this.pointer.position);this.pointer&&this.pointer.element.attr("class","jBox-pointer jBox-pointer-"+this._getOpp(this.outside)).css(this.pointer.margin);this.positionAdjusted=false;this.flipped=false}var e=jQuery(window);var t={x:e.width(),y:e.height(),top:e.scrollTop(),left:e.scrollLeft()};t.bottom=t.top+t.y;t.right=t.left+t.x;var n=t.top>this.pos.top-(this.options.adjustDistance.top||0),r=t.right<this.pos.left+this.dimensions.x+(this.options.adjustDistance.right||0),i=t.bottom<this.pos.top+this.dimensions.y+(this.options.adjustDistance.bottom||0),s=t.left>this.pos.left-(this.options.adjustDistance.left||0),o=s?"left":r?"right":null,u=n?"top":i?"bottom":null,a=o||u;if(!a)return;if(this.options.adjustPosition!="move"&&(o==this.outside||u==this.outside)){this.target=="mouse"&&(this.outside="right");if((this.outside=="top"||this.outside=="left"?t[this._getXY(this.outside)]-(this.targetDimensions[this._getTL(this.outside)]-t[this._getTL(this.outside)])-this.targetDimensions[this._getXY(this.outside)]:this.targetDimensions[this._getTL(this.outside)]-t[this._getTL(this.outside)])>this.dimensions[this._getXY(this.outside)]+this.options.adjustDistance[this._getOpp(this.outside)]){this.wrapper.css(this._getTL(this.outside),this.pos[this._getTL(this.outside)]+(this.dimensions[this._getXY(this.outside)]+this.options.offset[this._getXY(this.outside)]+this.targetDimensions[this._getXY(this.outside)])*(this.outside=="top"||this.outside=="left"?1:-1)).removeClass("jBox-pointerPosition-"+this.pointer.position).addClass("jBox-pointerPosition-"+this._getOpp(this.pointer.position));this.pointer&&this.wrapper.css("padding",0).css("padding-"+this.outside,this.pointer.dimensions[this._getXY(this.outside)]);this.pointer&&this.pointer.element.attr("class","jBox-pointer jBox-pointer-"+this.outside);this.positionAdjusted=true;this.flipped=true}}var f=this._getXY(this.outside)=="x"?u:o;if(this.pointer&&this.options.adjustPosition!="flip"&&this._getXY(f)==this._getOpp(this._getXY(this.outside))){if(this.pointer.align=="center"){var l=this.dimensions[this._getXY(f)]/2-this.pointer.dimensions[this._getOpp(this.pointer.xy)]/2-parseInt(this.pointer.element.css("margin-"+this.pointer.alignAttribute))*(f!=this._getTL(f)?-1:1)}else{var l=f==this.pointer.alignAttribute?parseInt(this.pointer.element.css("margin-"+this.pointer.alignAttribute)):this.dimensions[this._getXY(f)]-parseInt(this.pointer.element.css("margin-"+this.pointer.alignAttribute))-this.pointer.dimensions[this._getXY(f)]}spaceDiff=f==this._getTL(f)?t[this._getTL(f)]-this.pos[this._getTL(f)]+this.options.adjustDistance[f]:(t[this._getOpp(this._getTL(f))]-this.pos[this._getTL(f)]-this.options.adjustDistance[f]-this.dimensions[this._getXY(f)])*-1;if(f==this._getOpp(this._getTL(f))&&this.pos[this._getTL(f)]-spaceDiff<t[this._getTL(f)]+this.options.adjustDistance[this._getTL(f)]){spaceDiff-=t[this._getTL(f)]+this.options.adjustDistance[this._getTL(f)]-(this.pos[this._getTL(f)]-spaceDiff)}spaceDiff=Math.min(spaceDiff,l);if(spaceDiff<=l&&spaceDiff>0){this.pointer.element.css("margin-"+this.pointer.alignAttribute,parseInt(this.pointer.element.css("margin-"+this.pointer.alignAttribute))-spaceDiff*(f!=this.pointer.alignAttribute?-1:1));this.wrapper.css(this._getTL(f),this.pos[this._getTL(f)]+spaceDiff*(f!=this._getTL(f)?-1:1));this.positionAdjusted=true}}};this.options.onInit.bind(this)();this.options._onInit&&this.options._onInit.bind(this)();return this}jBox.prototype.attach=function(e,t){e||(e=this.options.attach);t||(t=this.options.trigger);e&&e.length&&jQuery.each(e,function(e,n){n=jQuery(n);if(!n.data("jBox-attached-"+this.id)){this.options.getContent=="title"&&n.attr("title")!=undefined&&n.data("jBox-getContent",n.attr("title")).removeAttr("title");this.attachedElements||(this.attachedElements=[]);this.attachedElements.push(n[0]);n.on(t+".jBox-attach-"+this.id,function(e){if(this.isOpen&&this.source[0]!=n[0])var r=true;this.source=n;!this.options.target&&(this.target=n);t=="click"&&this.options.preventDefault&&e.preventDefault();this[t=="click"&&!r?"toggle":"open"]()}.bind(this));this.options.trigger=="mouseenter"&&n.on("mouseleave",function(){this.close()}.bind(this));n.data("jBox-attached-"+this.id,t)}}.bind(this));return this};jBox.prototype.detach=function(e){e||(e=this.attachedElements||[]);e&&e.length&&jQuery.each(e,function(e,t){t=jQuery(t);if(t.data("jBox-attached-"+this.id)){t.off(t.data("jBox-attached-"+this.id+".jBox-attach-"+this.id));t.data("jBox-attached-"+this.id,null)}});return this};jBox.prototype.setTitle=function(e){if(e==null||e==undefined)return this;!this.wrapper&&this._create();if(!this.title){this.titleContainer=jQuery("<div/>",{"class":"jBox-title"});this.title=jQuery("<div/>").appendTo(this.titleContainer);this.wrapper.addClass("jBox-hasTitle");if(this.options.closeButton=="title"){this.wrapper.addClass("jBox-closeButton-title");this.closeButton.appendTo(this.titleContainer)}this.titleContainer.insertBefore(this.content)}this.title.html(e);this.position();return this};jBox.prototype.setContent=function(e){if(e==null)return this;!this.wrapper&&this._create();switch(jQuery.type(e)){case"string":this.content.html(e);break;case"object":this.content.children().css({display:"none"});this.options.content.appendTo(this.content).css({display:"block"});break}this.position();return this};jBox.prototype.position=function(e){e||(e={});this.target=e.target||this.target||this.options.target||jQuery(window);this.dimensions={x:this.wrapper.outerWidth(),y:this.wrapper.outerHeight()};if(this.target=="mouse")return;if(this.options.position.x=="center"&&this.options.position.y=="center"){this.wrapper.css({left:"50%",top:"50%",marginLeft:this.dimensions.x*-.5+this.options.offset.x,marginTop:this.dimensions.y*-.5+this.options.offset.y});return this}var t=this.target.offset();this.targetDimensions={x:this.target.outerWidth(),y:this.target.outerHeight(),top:t?t.top:0,left:t?t.left:0};this.pos={};var n=function(e){if(jQuery.inArray(this.options.position[e],["top","right","bottom","left","center"])==-1){this.pos[this.options.attributes[e]]=this.options.position[e];return}var t=this.options.attributes[e]=e=="x"?"left":"top";this.pos[t]=this.targetDimensions[t];if(this.options.position[e]=="center"){this.pos[t]+=Math.ceil((this.targetDimensions[e]-this.dimensions[e])/2);return}t!=this.options.position[e]&&(this.pos[t]+=this.targetDimensions[e]-this.dimensions[e]);(this.options.outside==e||this.options.outside=="xy")&&(this.pos[t]+=this.dimensions[e]*(t!=this.options.position[e]?1:-1))}.bind(this);n("x");n("y");if(this.options.pointer){var r=0;switch(this.pointer.align){case"center":if(this.options.position[this._getOpp(this.options.outside)]!="center"){r+=this.dimensions[this._getOpp(this.options.outside)]/2}break;default:switch(this.options.position[this._getOpp(this.options.outside)]){case"center":r+=(this.dimensions[this._getOpp(this.options.outside)]/2-this.pointer.dimensions[this._getOpp(this.options.outside)]/2)*(this.pointer.align==this._getTL(this.pointer.align)?1:-1);break;default:r+=this.pointer.align!=this.options.position[this._getOpp(this.options.outside)]?this.dimensions[this._getOpp(this.options.outside)]-this.pointer.dimensions[this._getOpp(this.options.outside)]/2:this.pointer.dimensions[this._getOpp(this.options.outside)]/2;break}break}r*=this.options.position[this._getOpp(this.options.outside)]==this.pointer.alignAttribute?-1:1;r+=this.pointer.offset*(this.pointer.align==this._getOpp(this._getTL(this.pointer.align))?1:-1);this.pos[this._getTL(this._getOpp(this.pointer.xy))]+=r}this.pos[this.options.attributes.x]+=this.options.offset.x;this.pos[this.options.attributes.y]+=this.options.offset.y;this.wrapper.css(this.pos);this._adjustPosition();return this};jBox.prototype.open=function(e){e||(e={});!this.wrapper&&this._create();this.timer&&clearTimeout(this.timer);this._blockBodyClick();if(this.isDisabled)return this;var t=function(){this.source&&this.options.getTitle&&this.source.attr(this.options.getTitle)!=undefined&&this.setTitle(this.source.attr(this.options.getTitle));this.source&&this.options.getContent&&(this.source.data("jBox-getContent")!=undefined?this.setContent(this.source.data("jBox-getContent")):this.source.attr(this.options.getContent)!=undefined?this.setContent(this.source.attr(this.options.getContent)):null);this.position({target:e.target});this.options.onOpen.bind(this)();this.options._onOpen&&this.options._onOpen.bind(this)();this.options.ajax&&(!this.ajaxLoaded||this.options.reload)&&this.ajax();this.isClosing&&this._abortAnimation();if(!this.isOpen){this.isOpen=true;this._attachEvents();this.options.blockScroll&&jQuery("body").addClass("jBox-blockScroll-"+this.id);this.options.overlay&&this._addOverlay();this.options.animation&&!this.isClosing&&this._animate("open");if(this.options.fade){this.wrapper.stop().animate({opacity:1},{queue:false,duration:this.options.fade,start:function(){this.isOpening=true;this.wrapper.css({display:"block"})}.bind(this),always:function(){this.isOpening=false}.bind(this)})}else{this.wrapper.css({display:"block",opacity:1})}}}.bind(this);this.options.delayOpen&&!this.isOpen&&!this.isClosing&&!e.ignoreDelay?this.timer=setTimeout(t,this.options.delayOpen):t();return this};jBox.prototype.close=function(e){e||(e={});this.timer&&clearTimeout(this.timer);this._blockBodyClick();if(this.isDisabled)return this;var t=function(){this.options.onClose.bind(this)();if(this.isOpen){this.isOpen=false;this._detachEvents();this.options.blockScroll&&jQuery("body").removeClass("jBox-blockScroll-"+this.id);this.options.overlay&&this._removeOverlay();this.options.animation&&!this.isOpening&&this._animate("close");this.source=null;if(this.options.fade){this.wrapper.stop().animate({opacity:0},{queue:false,duration:this.options.fade,start:function(){this.isClosing=true}.bind(this),complete:function(){this.wrapper.css({display:"none"});this.options._onCloseComplete&&this.options._onCloseComplete.bind(this)()}.bind(this),always:function(){this.isClosing=false}.bind(this)})}else{this.wrapper.css({display:"none",opacity:0});this.options._onCloseComplete&&this.options._onCloseComplete.bind(this)()}}}.bind(this);e.ignoreDelay?t():this.timer=setTimeout(t,Math.max(this.options.delayClose,10));return this};jBox.prototype.toggle=function(e){this[this.isOpen?"close":"open"](e);return this};jBox.prototype.disable=function(){this.isDisabled=true;return this};jBox.prototype.enable=function(){this.isDisabled=false;return this};jBox.prototype.ajax=function(e){e||(e={});this.ajaxRequest&&this.ajaxRequest.abort();this.ajaxRequest=jQuery.ajax({url:e.url||this.options.ajax,data:e.data||this.options.data,beforeSend:function(){this.content.html("");this.wrapper.addClass("jBox-loading");this.position();this.options.onAjax.bind(this)()}.bind(this),complete:function(e){this.wrapper.removeClass("jBox-loading");this.content.html(e.responseText);this.position();this.ajaxLoaded=true;this.options.onAjaxComplete.bind(this)()}.bind(this)});return this};jBox.prototype.destroy=function(){this.close({ignoreDelay:true});this.wrapper.remove();return this};jQuery.fn.jBox=function(e,t){e||(e={});t||(t={});return new jBox(e,jQuery.extend(t,{attach:this}))};if(!Function.prototype.bind){Function.prototype.bind=function(e){var t=Array.prototype.slice.call(arguments,1),n=this,r=function(){},i=function(){return n.apply(this instanceof r&&e?this:e,t.concat(Array.prototype.slice.call(arguments)))};r.prototype=this.prototype;i.prototype=new r;return i}}
|