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

!function(a,b,c,d){"use strict";a.fn.popup=function(e){var f,g=a(this),h=a(c),i=g.selector||"",j=("ontouchstart"in c.documentElement,(new Date).getTime()),k=[],l=arguments[0],m="string"==typeof l,n=[].slice.call(arguments,1);return g.each(function(){var c,g,o,p=a.isPlainObject(e)?a.extend(!0,{},a.fn.popup.settings,e):a.extend({},a.fn.popup.settings),q=p.selector,r=p.className,s=p.error,t=p.metadata,u=p.namespace,v="."+p.namespace,w="module-"+u,x=a(this),y=a(p.context),z=p.target?a(p.target):x,A=a(b),B=a("body"),C=0,D=this,E=x.data(w);o={initialize:function(){o.debug("Initializing module",x),o.refresh(),"click"==p.on?x.on("click"+v,o.toggle):o.get.startEvent()&&x.on(o.get.startEvent()+v,o.event.start).on(o.get.endEvent()+v,o.event.end),p.target&&o.debug("Target set to element",z),A.on("resize"+v,o.event.resize),o.exists()?p.hoverable&&o.bind.popup():o.create(),o.instantiate()},instantiate:function(){o.verbose("Storing instance of module",o),E=o,x.data(w,E)},refresh:function(){c=p.popup?a(p.popup):p.inline?z.next(p.selector.popup):!1,g=p.popup?c.offsetParent():p.inline?z.offsetParent():B},destroy:function(){o.debug("Destroying previous module"),c&&!p.preserve&&o.remove(),x.off(v).removeData(w)},event:{start:function(){var b=a.isPlainObject(p.delay)?p.delay.show:p.delay;clearTimeout(o.hideTimer),o.showTimer=setTimeout(function(){!o.is.hidden()||o.is.active()&&o.is.dropdown()||o.show()},b)},end:function(){var b=a.isPlainObject(p.delay)?p.delay.hide:p.delay;clearTimeout(o.showTimer),o.hideTimer=setTimeout(function(){o.is.visible()&&o.hide()},b)},resize:function(){o.is.visible()&&o.set.position()}},create:function(){var b=x.data(t.html)||p.html,e=x.data(t.variation)||p.variation,f=x.data(t.title)||p.title,g=x.data(t.content)||x.attr("title")||p.content;b||g||f?(o.debug("Creating pop-up html"),b||(b=p.templates.popup({title:f,content:g})),c=a("<div/>").addClass(r.popup).addClass(e).html(b),e&&c.addClass(e),p.inline?(o.verbose("Inserting popup element inline",c),c.insertAfter(x)):(o.verbose("Appending popup element to body",c),c.appendTo(y)),p.hoverable&&o.cache===d&&o.bind.popup(),a.proxy(p.onCreate,c)()):0!==z.next(p.selector.popup).size()?(o.verbose("Pre-existing popup found, reverting to inline"),p.inline=!0,o.refresh()):o.error(s.content,D)},toggle:function(){o.debug("Toggling pop-up"),o.is.hidden()?(o.debug("Popup is hidden, showing pop-up"),o.unbind.close(),o.hideAll(),o.show()):(o.debug("Popup is visible, hiding pop-up"),o.hide())},show:function(a){a=a||function(){},o.debug("Showing pop-up",p.transition),p.preserve||p.popup||o.refresh(),o.exists()||o.create(),c&&o.set.position()&&(o.save.conditions(),o.animate.show(a))},hide:function(a){a=a||function(){},x.removeClass(r.visible),o.unbind.close(),o.is.visible()&&(o.restore.conditions(),o.animate.hide(a))},hideAll:function(){a(q.popup).filter(":visible").popup("hide")},hideGracefully:function(b){b&&0===a(b.target).closest(q.popup).size()?(o.debug("Click occurred outside popup hiding popup"),o.hide()):o.debug("Click was inside popup, keeping popup open")},exists:function(){return c?p.inline||p.popup?0!==c.size():c.closest(y).size():!1},remove:function(){o.debug("Removing popup"),c.remove()},save:{conditions:function(){o.cache={title:x.attr("title")},o.cache.title&&x.removeAttr("title"),o.verbose("Saving original attributes",o.cache.title)}},restore:{conditions:function(){return o.cache&&o.cache.title&&(x.attr("title",o.cache.title),o.verbose("Restoring original attributes",o.cache.title)),!0}},animate:{show:function(b){b=b||function(){},x.addClass(r.visible),p.transition&&a.fn.transition!==d&&x.transition("is supported")?c.transition(p.transition+" in",p.duration,function(){o.bind.close(),a.proxy(b,D)()}):c.stop().fadeIn(p.duration,p.easing,function(){o.bind.close(),a.proxy(b,D)()}),a.proxy(p.onShow,D)()},hide:function(b){b=b||function(){},o.debug("Hiding pop-up"),p.transition&&a.fn.transition!==d&&x.transition("is supported")?c.transition(p.transition+" out",p.duration,function(){o.reset(),b()}):c.stop().fadeOut(p.duration,p.easing,function(){o.reset(),b()}),a.proxy(p.onHide,D)()}},get:{startEvent:function(){return"hover"==p.on?"mouseenter":"focus"==p.on?"focus":!1},endEvent:function(){return"hover"==p.on?"mouseleave":"focus"==p.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:c.width(),height:c.outerHeight(),offset:c.offset()},f={},g=[];return e.offset&&(f={top:e.offset.top<d.top,bottom:e.offset.top+e.height>d.bottom,right:e.offset.left+e.width>d.right,left:e.offset.left<d.left}),o.verbose("Checking if outside viewable area",e.offset),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(),z.outerWidth()),k=z.outerHeight(),l=c.outerWidth(),m=c.outerHeight(),n=g.outerWidth(),q=g.outerHeight(),u=p.distanceAway,v=z[0],w=p.inline?parseInt(b.getComputedStyle(v).getPropertyValue("margin-top"),10):0,y=p.inline?parseInt(b.getComputedStyle(v).getPropertyValue("margin-left"),10):0,A=p.inline||p.popup?z.position():z.offset();switch(e=e||x.data(t.position)||p.position,f=f||x.data(t.offset)||p.offset,p.inline&&(o.debug("Adding targets margin to calculation"),"left center"==e||"right center"==e?(f+=w,u+=-y):"top left"==e||"top center"==e||"top right"==e?(f+=y,u-=w):(f+=y,u+=w)),o.debug("Calculating popup positioning",e),e){case"top left":h={top:"auto",bottom:q-A.top+u,left:A.left+f,right:"auto"};break;case"top center":h={bottom:q-A.top+u,left:A.left+j/2-l/2+f,top:"auto",right:"auto"};break;case"top right":h={bottom:q-A.top+u,right:n-A.left-j-f,top:"auto",left:"auto"};break;case"left center":h={top:A.top+k/2-m/2+f,right:n-A.left+u,left:"auto",bottom:"auto"};break;case"right center":h={top:A.top+k/2-m/2+f,left:A.left+j+u,bottom:"auto",right:"auto"};break;case"bottom left":h={top:A.top+k+u,left:A.left+f,bottom:"auto",right:"auto"};break;case"bottom center":h={top:A.top+k+u,left:A.left+j/2-l/2+f,bottom:"auto",right:"auto"};break;case"bottom right":h={top:A.top+k+u,right:n-A.left-j-f,left:"auto",bottom:"auto"}}return h===d&&o.error(s.invalidPosition),c.css(h).removeClass(r.position).addClass(e).addClass(r.loading),i=o.get.offstagePosition(),i?(o.debug("Element is outside boundaries",i),C<p.maxSearchDepth?(e=o.get.nextPosition(e),C++,o.debug("Trying new position",e),c?o.set.position(e):!1):(o.error(s.recursion),C=0,o.reset(),c.removeClass(r.loading),!1)):(o.debug("Position is on stage",e),C=0,c.removeClass(r.loading),!0)}},bind:{popup:function(){p.hoverable&&(o.verbose("Allowing hover events on popup to prevent closing"),c.on("mouseenter",o.event.start).on("mouseleave",o.event.end))},close:function(){"click"==p.on&&p.closable&&(o.verbose("Binding popup close event to document"),h.on("click"+v,function(b){o.verbose("Pop-up clickaway intent detected"),a.proxy(o.hideGracefully,D)(b)}))}},unbind:{close:function(){"click"==p.on&&p.closable&&(o.verbose("Removing close event from document"),h.off("click"+v))}},is:{active:function(){return x.hasClass(r.active)},animating:function(){return c&&c.is(":animated")||c.hasClass(r.animating)},visible:function(){return c&&c.is(":visible")},dropdown:function(){return x.hasClass(r.dropdown)},hidden:function(){return!o.is.visible()}},reset:function(){c.removeClass(r.visible),p.preserve||p.popup?a.fn.transition!==d&&c.transition("remove transition"):o.remove()},setting:function(b,c){if(a.isPlainObject(b))a.extend(!0,p,b);else{if(c===d)return p[b];p[b]=c}},internal:function(b,c){if(a.isPlainObject(b))a.extend(!0,o,b);else{if(c===d)return o[b];o[b]=c}},debug:function(){p.debug&&(p.performance?o.performance.log(arguments):(o.debug=Function.prototype.bind.call(console.info,console,p.name+":"),o.debug.apply(console,arguments)))},verbose:function(){p.verbose&&p.debug&&(p.performance?o.performance.log(arguments):(o.verbose=Function.prototype.bind.call(console.info,console,p.name+":"),o.verbose.apply(console,arguments)))},error:function(){o.error=Function.prototype.bind.call(console.error,console,p.name+":"),o.error.apply(console,arguments)},performance:{log:function(a){var b,c,d;p.performance&&(b=(new Date).getTime(),d=j||b,c=b-d,j=b,k.push({Element:D,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":c})),clearTimeout(o.performance.timer),o.performance.timer=setTimeout(o.performance.display,100)},display:function(){var b=p.name+":",c=0;j=!1,clearTimeout(o.performance.timer),a.each(k,function(a,b){c+=b["Execution Time"]}),b+=" "+c+"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=E;return c=c||n,e=D||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?(E===d&&o.initialize(),o.invoke(l)):(E!==d&&o.destroy(),o.initialize())}),f!==d?f:this},a.fn.popup.settings={name:"Popup",debug:!1,verbose:!1,performance:!1,namespace:"popup",onCreate:function(){},onRemove:function(){},onShow:function(){},onHide:function(){},variation:"",content:!1,html:!1,title:!1,on:"hover",closable:!0,context:"body",position:"top left",delay:{show:50,hide:0},target:!1,popup:!1,inline:!1,preserve:!0,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:{active:"active",animating:"animating",dropdown:"dropdown",loading:"loading",popup:"ui popup",position:"top left center bottom right",visible:"visible"},selector:{popup:".ui.popup"},templates:{escape:function(a){var b=/[&<>"'`]/g,c=/[&<>"'`]/,d={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},e=function(a){return d[a]};return c.test(a)?a.replace(b,e):a},popup:function(b){var c="",e=a.fn.popup.settings.templates.escape;return typeof b!==d&&(typeof b.title!==d&&b.title&&(b.title=e(b.title),c+='<div class="header">'+b.title+"</div>"),typeof b.content!==d&&b.content&&(b.content=e(b.content),c+='<div class="content">'+b.content+"</div>")),c}}},a.extend(a.easing,{easeOutQuad:function(a,b,c,d,e){return-d*(b/=e)*(b-2)+c}})}(jQuery,window,document);