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
10 KiB
1 lines
10 KiB
!function(a,b,c,d){a.fn.popup=function(e){var f,g=a(this),h=a(c),i=g.selector||"",j=(new Date).getTime(),k=[],l=arguments[0],m="string"==typeof l,n=[].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),o=g.selector,p=g.className,q=g.error,r=g.metadata,s=g.namespace,t="."+g.namespace,u="module-"+s,v=a(this),w=a(g.context),x=g.target?a(g.target):v,y=a(b),z=g.popup?a(g.popup):g.inline?x.next(g.selector.popup):y.children(g.selector.popup).last(),A=g.popup?z.offsetParent():g.inline?x.offsetParent():y,B=0,C=this,D=v.data(u);c={initialize:function(){c.debug("Initializing module",v),"click"==g.on?v.on("click",c.toggle):c.get.startEvent()&&v.on(c.get.startEvent()+t,c.event.start).on(c.get.endEvent()+t,c.event.end),g.target&&c.debug("Target set to element",x),y.on("resize"+t,c.event.resize),c.exists()?g.hoverable&&c.bind.popup():c.create(),c.instantiate()},instantiate:function(){c.verbose("Storing instance of module",c),D=c,v.data(u,D)},refresh:function(){g.popup?(z=a(g.popup),A=z.offsetParent()):g.inline?(z=x.next(o.popup),A=x.offsetParent()):z=y.children(o.popup).last()},destroy:function(){c.debug("Destroying previous module"),z.remove(),v.off(t).removeData(u)},event:{start:function(){var b=a.isPlainObject(g.delay)?g.delay.show:g.delay;clearTimeout(c.hideTimer),c.showTimer=setTimeout(function(){c.is.hidden()&&c.show()},b)},end:function(){var b=a.isPlainObject(g.delay)?g.delay.hide:g.delay;clearTimeout(c.showTimer),c.hideTimer=setTimeout(function(){c.is.visible()&&c.hide()},b)},resize:function(){c.is.visible()&&c.set.position()}},create:function(){c.debug("Creating pop-up html");var b=v.data(r.html)||g.html,e=v.data(r.variation)||g.variation,f=v.data(r.title)||g.title,h=v.data(r.content)||v.attr("title")||g.content;b||h||f?(b||(b=g.template({title:f,content:h})),z=a("<div/>").addClass(p.popup).addClass(e).html(b),e&&z.addClass(e),g.inline?(c.verbose("Inserting popup element inline",z),z.insertAfter(v)):(c.verbose("Appending popup element to body",z),z.appendTo(w)),g.hoverable&&c.cache===d&&c.bind.popup(),a.proxy(g.onCreate,z)()):c.error(q.content,C)},toggle:function(){c.debug("Toggling pop-up"),c.is.hidden()?(c.debug("Popup is hidden, showing pop-up"),c.unbind.close(),c.hideAll(),c.show()):(c.debug("Popup is visible, hiding pop-up"),c.hide())},show:function(a){a=a||function(){},c.debug("Showing pop-up",g.transition),g.preserve||g.popup||c.refresh(),c.exists()||c.create(),c.set.position()&&(c.save.conditions(),c.animate.show(a))},hide:function(a){a=a||function(){},v.removeClass(p.visible),c.unbind.close(),c.is.visible()&&(c.restore.conditions(),c.animate.hide(a))},hideAll:function(){a(o.popup).filter(":visible").popup("hide")},hideGracefully:function(b){b&&0===a(b.target).closest(o.popup).size()?(c.debug("Click occurred outside popup hiding popup"),c.hide()):c.debug("Click was inside popup, keeping popup open")},exists:function(){return g.inline?0!==z.size():z.parent(w).size()},remove:function(){c.debug("Removing popup"),z.remove()},save:{conditions:function(){c.cache={title:v.attr("title")},c.cache.title&&v.removeAttr("title"),c.verbose("Saving original attributes",c.cache.title)}},restore:{conditions:function(){return c.cache&&c.cache.title&&v.attr("title",c.cache.title),c.verbose("Restoring original attributes",c.cache.title),!0}},animate:{show:function(b){b=b||function(){},v.addClass(p.visible),g.transition&&a.fn.transition!==d&&v.transition("is supported")?z.transition(g.transition+" in",g.duration,function(){c.bind.close(),a.proxy(b,C)()}):z.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&&v.transition("is supported")?z.transition(g.transition+" out",g.duration,function(){c.reset(),b()}):z.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":!1},endEvent:function(){return"hover"==g.on?"mouseleave":"focus"==g.on?"blur":!1},offstagePosition:function(){var d={top:a(b).scrollTop(),bottom:a(b).scrollTop()+a(b).height(),left:0,right:a(b).width()},e={width:z.width(),height:z.outerHeight(),position:z.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(e,f){var h,i,j=(a(b).width(),a(b).height(),x.outerWidth()),k=x.outerHeight(),l=z.width(),m=z.outerHeight(),n=A.outerWidth(),o=A.outerHeight(),s=g.distanceAway,t=g.inline?x.position():x.offset();switch(e=e||v.data(r.position)||g.position,f=f||v.data(r.offset)||g.offset,g.inline&&("left center"==e||"right center"==e?(f+=parseInt(b.getComputedStyle(C).getPropertyValue("margin-top"),10),s+=-parseInt(b.getComputedStyle(C).getPropertyValue("margin-left"),10)):(f+=parseInt(b.getComputedStyle(C).getPropertyValue("margin-left"),10),s+=parseInt(b.getComputedStyle(C).getPropertyValue("margin-top"),10))),c.debug("Calculating offset for position",e),e){case"top left":h={top:"auto",bottom:o-t.top+s,left:t.left+f,right:"auto"};break;case"top center":h={bottom:o-t.top+s,left:t.left+j/2-l/2+f,top:"auto",right:"auto"};break;case"top right":h={bottom:o-t.top+s,right:n-t.left-j-f,top:"auto",left:"auto"};break;case"left center":h={top:t.top+k/2-m/2+f,right:n-t.left+s,left:"auto",bottom:"auto"};break;case"right center":h={top:t.top+k/2-m/2+f,left:t.left+j+s,bottom:"auto",right:"auto"};break;case"bottom left":h={top:t.top+k+s,left:t.left+f,bottom:"auto",right:"auto"};break;case"bottom center":h={top:t.top+k+s,left:t.left+j/2-l/2+f,bottom:"auto",right:"auto"};break;case"bottom right":h={top:t.top+k+s,right:n-t.left-j-f,left:"auto",bottom:"auto"}}return h===d&&c.error(q.invalidPosition),z.css(h).removeClass(p.position).addClass(e).addClass(p.loading),i=c.get.offstagePosition(),i?(c.debug("Element is outside boundaries",i),B<g.maxSearchDepth?(e=c.get.nextPosition(e),B++,c.debug("Trying new position",e),c.set.position(e)):(c.error(q.recursion),B=0,c.reset(),z.removeClass(p.loading),!1)):(c.debug("Position is on stage",e),B=0,z.removeClass(p.loading),!0)}},bind:{popup:function(){g.hoverable&&(c.verbose("Allowing hover events on popup to prevent closing"),z.on("mouseenter",c.event.start).on("mouseleave",c.event.end))},close:function(){"click"==g.on&&g.closable&&(c.verbose("Binding popup close event to document"),h.on("click"+t,function(b){c.verbose("Pop-up clickaway intent detected"),a.proxy(c.hideGracefully,this)(b)}))}},unbind:{close:function(){"click"==g.on&&g.closable&&(c.verbose("Removing close event from document"),h.off("click"+t))}},is:{animating:function(){return z.is(":animated")||z.hasClass(p.animating)},visible:function(){return z.is(":visible")},hidden:function(){return!c.is.visible()}},reset:function(){z.removeClass(p.visible),g.preserve||g.popup?a.fn.transition!==d&&z.transition("remove transition"):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=j||b,d=b-e,j=b,k.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;j=!1,clearTimeout(c.performance.timer),a.each(k,function(a,b){e+=b["Execution Time"]}),b+=" "+e+"ms",i&&(b+=" '"+i+"'"),(console.group!==d||console.table!==d)&&k.length>0&&(console.groupCollapsed(b),console.table?console.table(k):a.each(k,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),k=[]}},invoke:function(b,c,e){var g,h,i,j=D;return c=c||n,e=C||e,"string"==typeof b&&j!==d&&(b=b.split(/[\. ]/),g=b.length-1,a.each(b,function(c,e){var f=c!=g?e+b[c+1].charAt(0).toUpperCase()+b[c+1].slice(1):b;if(a.isPlainObject(j[f])&&c!=g)j=j[f];else{if(j[f]!==d)return h=j[f],!1;if(!a.isPlainObject(j[e])||c==g)return j[e]!==d?(h=j[e],!1):!1;j=j[e]}})),a.isFunction(h)?i=h.apply(e,c):h!==d&&(i=h),a.isArray(f)?f.push(i):f!==d?f=[f,i]:i!==d&&(f=i),h}},m?(D===d&&c.initialize(),c.invoke(l)):(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:!1,content:!1,html:!1,title:!1,on:"hover",closable:!0,context:"body",position:"top center",delay:{show:50,hide:0},target:!1,popup:!1,inline:!1,preserve:!1,hoverable:!1,duration:200,easing:"easeOutQuint",transition:"scale",distanceAway:0,offset:0,maxSearchDepth:10,error:{content:"Your popup has no content specified",invalidPosition:"The position you specified is not a valid position",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:{animating:"animating",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);
|