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
8.9 KiB

!function(a,b,c,d){a.fn.popup=function(e){var f,g=a(this),h=a(c),i=a("body"),j=g.selector||"",k=(new Date).getTime(),l=[],m=arguments[0],n="string"==typeof m,o=[].slice.call(arguments,1);return g.each(function(){var c,g=a.isPlainObject(e)?a.extend(!0,{},a.fn.popup.settings,e):a.extend({},a.fn.popup.settings),p=g.selector,q=g.className,r=g.error,s=g.metadata,t=g.namespace,u="."+g.namespace,v="module-"+t,w=a(this),x=g.target?a(g.target):w,y=a(b),z=g.inline?x.offsetParent():y,A=g.inline?x.next(g.selector.popup):y.children(g.selector.popup).last(),B=0,C=this,D=w.data(v);c={initialize:function(){c.debug("Initializing module",w),"click"==g.on?w.on("click",c.toggle):w.on(c.get.startEvent()+u,c.event.start).on(c.get.endEvent()+u,c.event.end),g.target&&c.debug("Target set to element",x),y.on("resize"+u,c.event.resize),c.instantiate()},instantiate:function(){c.verbose("Storing instance of module",c),D=c,w.data(v,D)},refresh:function(){g.inline?(A=x.next(p.popup),z=x.offsetParent()):A=y.children(p.popup).last()},destroy:function(){c.debug("Destroying previous module"),y.off(u),A.remove(),w.off(u).removeData(v)},event:{start:function(){c.timer=setTimeout(function(){c.is.hidden()&&c.show()},g.delay)},end:function(){clearTimeout(c.timer),c.is.visible()&&c.hide()},resize:function(){c.is.visible()&&c.set.position()}},create:function(){c.debug("Creating pop-up html");var b=w.data(s.html)||g.html,d=w.data(s.variation)||g.variation,e=w.data(s.title)||g.title,f=w.data(s.content)||w.attr("title")||g.content;b||f||e?(b||(b=g.template({title:e,content:f})),A=a("<div/>").addClass(q.popup).addClass(d).html(b),g.inline?(c.verbose("Inserting popup element inline",A),A.insertAfter(w)):(c.verbose("Appending popup element to body",A),A.appendTo(i)),a.proxy(g.onCreate,A)()):c.error(r.content)},toggle:function(){c.debug("Toggling pop-up"),c.is.hidden()?(c.hideAll(),c.show()):c.hide()},show:function(a){a=a||function(){},c.debug("Showing pop-up",g.transition),g.preserve||c.refresh(),c.exists()||c.create(),c.set.position(),c.animate.show(a)},hide:function(a){a=a||function(){},w.removeClass(q.visible),c.unbind.close(),c.is.visible()&&c.animate.hide(a)},hideAll:function(){a(p.popup).filter(":visible").popup("hide")},hideGracefully:function(b){0===a(b.target).closest(p.popup).size()&&c.hide()},exists:function(){return g.inline?0!==A.size():A.parent(i).size()},remove:function(){c.debug("Removing popup"),A.remove()},animate:{show:function(b){b=b||function(){},w.addClass(q.visible),g.transition&&a.fn.transition!==d&&w.transition("is supported")?A.transition(g.transition+" in",g.duration,function(){c.bind.close(),a.proxy(b,C)()}):A.stop().fadeIn(g.duration,g.easing,function(){c.bind.close(),a.proxy(b,C)()}),a.proxy(g.onShow,C)()},hide:function(b){b=b||function(){},c.debug("Hiding pop-up"),g.transition&&a.fn.transition!==d&&w.transition("is supported")?A.transition(g.transition+" out",g.duration,function(){c.reset(),b()}):A.stop().fadeOut(g.duration,g.easing,function(){c.reset(),b()}),a.proxy(g.onHide,C)()}},get:{startEvent:function(){return"hover"==g.on?"mouseenter":"focus"==g.on?"focus":void 0},endEvent:function(){return"hover"==g.on?"mouseleave":"focus"==g.on?"blur":void 0},offstagePosition:function(){var d={top:a(b).scrollTop(),bottom:a(b).scrollTop()+a(b).height(),left:0,right:a(b).width()},e={width:A.width(),height:A.outerHeight(),position:A.offset()},f={},g=[];return e.position&&(f={top:e.position.top<d.top,bottom:e.position.top+e.height>d.bottom,right:e.position.left+e.width>d.right,left:e.position.left<d.left}),c.verbose("Checking if outside viewable area",e.position),a.each(f,function(a,b){b&&g.push(a)}),g.length>0?g.join(" "):!1},nextPosition:function(a){switch(a){case"top left":a="bottom left";break;case"bottom left":a="top right";break;case"top right":a="bottom right";break;case"bottom right":a="top center";break;case"top center":a="bottom center";break;case"bottom center":a="right center";break;case"right center":a="left center";break;case"left center":a="top center"}return a}},set:{position:function(d,e){var f,h,i=(a(b).width(),a(b).height(),x.outerWidth()),j=x.outerHeight(),k=A.width(),l=A.outerHeight(),m=z.outerWidth(),n=z.outerHeight(),o=g.distanceAway,p=g.inline?x.position():x.offset();switch(d=d||w.data(s.position)||g.position,e=e||w.data(s.offset)||g.offset,g.inline&&("left center"==d||"right center"==d?(e+=parseInt(b.getComputedStyle(C).getPropertyValue("margin-top"),10),o+=-parseInt(b.getComputedStyle(C).getPropertyValue("margin-left"),10)):(e+=parseInt(b.getComputedStyle(C).getPropertyValue("margin-left"),10),o+=parseInt(b.getComputedStyle(C).getPropertyValue("margin-top"),10))),c.debug("Calculating offset for position",d),d){case"top left":f={bottom:n-p.top+o,right:m-p.left-e,top:"auto",left:"auto"};break;case"top center":f={bottom:n-p.top+o,left:p.left+i/2-k/2+e,top:"auto",right:"auto"};break;case"top right":f={top:"auto",bottom:n-p.top+o,left:p.left+i+e,right:"auto"};break;case"left center":f={top:p.top+j/2-l/2+e,right:m-p.left+o,left:"auto",bottom:"auto"};break;case"right center":f={top:p.top+j/2-l/2+e,left:p.left+i+o,bottom:"auto",right:"auto"};break;case"bottom left":f={top:p.top+j+o,right:m-p.left-e,left:"auto",bottom:"auto"};break;case"bottom center":f={top:p.top+j+o,left:p.left+i/2-k/2+e,bottom:"auto",right:"auto"};break;case"bottom right":f={top:p.top+j+o,left:p.left+i+e,bottom:"auto",right:"auto"}}return A.css(f).removeClass(q.position).addClass(d),h=c.get.offstagePosition(),h?(c.debug("Element is outside boundaries",h),B<g.maxSearchDepth?(d=c.get.nextPosition(d),B++,c.debug("Trying new position",d),c.set.position(d)):(c.error(r.recursion),B=0,!1)):(c.debug("Position is on stage",d),B=0,!0)}},bind:{close:function(){"click"==g.on&&g.closable&&(c.verbose("Binding popup close event to document"),h.on("click"+u,c.hideGracefully))}},unbind:{close:function(){"click"==g.on&&g.closable&&(c.verbose("Removing close event from document"),h.off("click"+u))}},is:{visible:function(){return A.is(":visible")},hidden:function(){return!c.is.visible()}},reset:function(){A.attr("style","").removeAttr("style"),g.preserve||c.remove()},setting:function(b,c){if(a.isPlainObject(b))a.extend(!0,g,b);else{if(c===d)return g[b];g[b]=c}},internal:function(b,e){if(a.isPlainObject(b))a.extend(!0,c,b);else{if(e===d)return c[b];c[b]=e}},debug:function(){g.debug&&(g.performance?c.performance.log(arguments):(c.debug=Function.prototype.bind.call(console.info,console,g.name+":"),c.debug.apply(console,arguments)))},verbose:function(){g.verbose&&g.debug&&(g.performance?c.performance.log(arguments):(c.verbose=Function.prototype.bind.call(console.info,console,g.name+":"),c.verbose.apply(console,arguments)))},error:function(){c.error=Function.prototype.bind.call(console.error,console,g.name+":"),c.error.apply(console,arguments)},performance:{log:function(a){var b,d,e;g.performance&&(b=(new Date).getTime(),e=k||b,d=b-e,k=b,l.push({Element:C,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":d})),clearTimeout(c.performance.timer),c.performance.timer=setTimeout(c.performance.display,100)},display:function(){var b=g.name+":",e=0;k=!1,clearTimeout(c.performance.timer),a.each(l,function(a,b){e+=b["Execution Time"]}),b+=" "+e+"ms",j&&(b+=" '"+j+"'"),(console.group!==d||console.table!==d)&&l.length>0&&(console.groupCollapsed(b),console.table?console.table(l):a.each(l,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),l=[]}},invoke:function(b,e,g){var h,i,j;return e=e||o,g=C||g,"string"==typeof b&&D!==d&&(b=b.split(/[\. ]/),h=b.length-1,a.each(b,function(e,f){var g=e!=h?f+b[e+1].charAt(0).toUpperCase()+b[e+1].slice(1):b;if(a.isPlainObject(D[f])&&e!=h)D=D[f];else{if(!a.isPlainObject(D[g])||e==h)return D[f]!==d?(i=D[f],!1):D[g]!==d?(i=D[g],!1):(c.error(r.method,b),!1);D=D[g]}})),a.isFunction(i)?j=i.apply(g,e):i!==d&&(j=i),a.isArray(f)?f.push(j):f!==d?f=[f,j]:j!==d&&(f=j),i}},n?(D===d&&c.initialize(),c.invoke(m)):(D!==d&&c.destroy(),c.initialize())}),f!==d?f:this},a.fn.popup.settings={name:"Popup",debug:!0,verbose:!0,performance:!0,namespace:"popup",onCreate:function(){},onShow:function(){},onHide:function(){},variation:"",content:!1,html:!1,title:!1,on:"hover",target:!1,closable:!0,position:"top center",delay:150,inline:!1,preserve:!1,duration:250,easing:"easeOutQuint",transition:"scale",distanceAway:0,offset:0,maxSearchDepth:10,error:{content:"Your popup has no content specified",method:"The method you called is not defined.",recursion:"Popup attempted to reposition element to fit, but could not find an adequate position."},metadata:{content:"content",html:"html",offset:"offset",position:"position",title:"title",variation:"variation"},className:{loading:"loading",popup:"ui popup",position:"top left center bottom right",visible:"visible"},selector:{popup:".ui.popup"},template:function(a){var b="";return typeof a!==d&&(typeof a.title!==d&&a.title&&(b+='<div class="header">'+a.title+'</div class="header">'),typeof a.content!==d&&a.content&&(b+='<div class="content">'+a.content+"</div>")),b}}}(jQuery,window,document);