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.
 
 
 

11 lines
12 KiB

/*
* # Semantic UI
* https://github.com/Semantic-Org/Semantic-UI
* http://www.semantic-ui.com/
*
* Copyright 2014 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!function(e,t,o,n){"use strict";e.fn.popup=function(i){var s,r=e(this),a=e(o),l=r.selector||"",p=("ontouchstart"in o.documentElement,(new Date).getTime()),u=[],c=arguments[0],d="string"==typeof c,f=[].slice.call(arguments,1);return r.each(function(){var o,r,g,h=e.isPlainObject(i)?e.extend(!0,{},e.fn.popup.settings,i):e.extend({},e.fn.popup.settings),m=h.selector,b=h.className,v=h.error,y=h.metadata,w=h.namespace,x="."+h.namespace,k="module-"+w,C=e(this),P=e(h.context),T=h.target?e(h.target):C,O=e(t),S=e("body"),z=0,A=this,E=C.data(k);g={initialize:function(){g.debug("Initializing module",C),g.refresh(),"click"==h.on?C.on("click"+x,g.toggle):g.get.startEvent()&&C.on(g.get.startEvent()+x,g.event.start).on(g.get.endEvent()+x,g.event.end),h.target&&g.debug("Target set to element",T),O.on("resize"+x,g.event.resize),g.exists()?h.hoverable&&g.bind.popup():g.create(),g.instantiate()},instantiate:function(){g.verbose("Storing instance of module",g),E=g,C.data(k,E)},refresh:function(){h.popup?o=e(h.popup):h.inline&&(o=T.next(h.selector.popup)),h.popup?(o.addClass(b.loading),r=o.offsetParent(),o.removeClass(b.loading)):r=h.inline?T.offsetParent():S,r.is("html")&&(g.debug("Page is popups offset parent"),r=S)},reposition:function(){g.refresh(),g.set.position()},destroy:function(){g.debug("Destroying previous module"),o&&!h.preserve&&g.removePopup(),C.off(x).removeData(k)},event:{start:function(){var t=e.isPlainObject(h.delay)?h.delay.show:h.delay;clearTimeout(g.hideTimer),g.showTimer=setTimeout(function(){!g.is.hidden()||g.is.active()&&g.is.dropdown()||g.show()},t)},end:function(){var t=e.isPlainObject(h.delay)?h.delay.hide:h.delay;clearTimeout(g.showTimer),g.hideTimer=setTimeout(function(){g.is.visible()&&g.hide()},t)},resize:function(){g.is.visible()&&g.set.position()}},create:function(){var t=C.data(y.html)||h.html,n=C.data(y.variation)||h.variation,i=C.data(y.title)||h.title,s=C.data(y.content)||C.attr("title")||h.content;t||s||i?(g.debug("Creating pop-up html"),t||(t=h.templates.popup({title:i,content:s})),o=e("<div/>").addClass(b.popup).addClass(n).html(t),n&&o.addClass(n),h.inline?(g.verbose("Inserting popup element inline",o),o.insertAfter(C)):(g.verbose("Appending popup element to body",o),o.appendTo(P)),h.hoverable&&g.bind.popup(),e.proxy(h.onCreate,o)(A)):0!==T.next(h.selector.popup).size()?(g.verbose("Pre-existing popup found, reverting to inline"),h.inline=!0,g.refresh(),h.hoverable&&g.bind.popup()):g.debug("No content specified skipping display",A)},toggle:function(){g.debug("Toggling pop-up"),g.is.hidden()?(g.debug("Popup is hidden, showing pop-up"),g.unbind.close(),g.hideAll(),g.show()):(g.debug("Popup is visible, hiding pop-up"),g.hide())},show:function(t){t=e.isFunction(t)?t:function(){},g.debug("Showing pop-up",h.transition),h.preserve||h.popup||g.refresh(),g.exists()||g.create(),o&&g.set.position()&&(g.save.conditions(),g.animate.show(t))},hide:function(t){t=e.isFunction(t)?t:function(){},g.remove.visible(),g.unbind.close(),g.is.visible()&&(g.restore.conditions(),g.animate.hide(t))},hideAll:function(){e(m.popup).filter(":visible").popup("hide")},hideGracefully:function(t){t&&0===e(t.target).closest(m.popup).size()?(g.debug("Click occurred outside popup hiding popup"),g.hide()):g.debug("Click was inside popup, keeping popup open")},exists:function(){return o?h.inline||h.popup?0!==o.size():o.closest(P).size():!1},removePopup:function(){g.debug("Removing popup"),e.proxy(h.onRemove,o)(A),o.removePopup()},save:{conditions:function(){g.cache={title:C.attr("title")},g.cache.title&&C.removeAttr("title"),g.verbose("Saving original attributes",g.cache.title)}},restore:{conditions:function(){return A.blur(),g.cache&&g.cache.title&&(C.attr("title",g.cache.title),g.verbose("Restoring original attributes",g.cache.title)),!0}},animate:{show:function(t){t=e.isFunction(t)?t:function(){},h.transition&&e.fn.transition!==n&&C.transition("is supported")?(g.set.visible(),o.transition({animation:h.transition+" in",queue:!1,debug:h.debug,verbose:h.verbose,duration:h.duration,onComplete:function(){g.bind.close(),e.proxy(t,o)(A),e.proxy(h.onVisible,o)(A)}})):(g.set.visible(),o.stop().fadeIn(h.duration,h.easing,function(){g.bind.close(),e.proxy(t,A)()})),e.proxy(h.onShow,o)(A)},hide:function(t){t=e.isFunction(t)?t:function(){},g.debug("Hiding pop-up"),h.transition&&e.fn.transition!==n&&C.transition("is supported")?o.transition({animation:h.transition+" out",queue:!1,duration:h.duration,debug:h.debug,verbose:h.verbose,onComplete:function(){g.reset(),e.proxy(t,o)(A),e.proxy(h.onHidden,o)(A)}}):o.stop().fadeOut(h.duration,h.easing,function(){g.reset(),t()}),e.proxy(h.onHide,o)(A)}},get:{startEvent:function(){return"hover"==h.on?"mouseenter":"focus"==h.on?"focus":!1},endEvent:function(){return"hover"==h.on?"mouseleave":"focus"==h.on?"blur":!1},offstagePosition:function(n){var n=n||!1,i={top:e(t).scrollTop(),bottom:e(t).scrollTop()+e(t).height(),left:0,right:e(t).width()},s={width:o.width(),height:o.height(),offset:o.offset()},r={},a=[];return s.offset&&n&&(g.verbose("Checking if outside viewable area",s.offset),r={top:s.offset.top<i.top,bottom:s.offset.top+s.height>i.bottom,right:s.offset.left+s.width>i.right,left:!1}),e.each(r,function(e,t){t&&a.push(e)}),a.length>0?a.join(" "):!1},nextPosition:function(e){switch(e){case"top left":e="bottom left";break;case"bottom left":e="top right";break;case"top right":e="bottom right";break;case"bottom right":e="top center";break;case"top center":e="bottom center";break;case"bottom center":e="right center";break;case"right center":e="left center";break;case"left center":e="top center"}return e}},set:{position:function(i,s){var a,l,p=(e(t).width(),e(t).height(),T.outerWidth()),u=T.outerHeight(),c=o.outerWidth(),d=o.outerHeight(),f=r.outerWidth(),m=r.outerHeight(),w=h.distanceAway,x=T[0],k=h.inline?parseInt(t.getComputedStyle(x).getPropertyValue("margin-top"),10):0,P=h.inline?parseInt(t.getComputedStyle(x).getPropertyValue("margin-left"),10):0,O=h.inline||h.popup?T.position():T.offset();switch(i=i||C.data(y.position)||h.position,s=s||C.data(y.offset)||h.offset,h.inline&&(g.debug("Adding targets margin to calculation"),"left center"==i||"right center"==i?(s+=k,w+=-P):"top left"==i||"top center"==i||"top right"==i?(s+=P,w-=k):(s+=P,w+=k)),g.debug("Calculating popup positioning",i),i){case"top left":a={top:"auto",bottom:m-O.top+w,left:O.left+s,right:"auto"};break;case"top center":a={bottom:m-O.top+w,left:O.left+p/2-c/2+s,top:"auto",right:"auto"};break;case"top right":a={bottom:m-O.top+w,right:f-O.left-p-s,top:"auto",left:"auto"};break;case"left center":a={top:O.top+u/2-d/2+s,right:f-O.left+w,left:"auto",bottom:"auto"};break;case"right center":a={top:O.top+u/2-d/2+s,left:O.left+p+w,bottom:"auto",right:"auto"};break;case"bottom left":a={top:O.top+u+w,left:O.left+s,bottom:"auto",right:"auto"};break;case"bottom center":a={top:O.top+u+w,left:O.left+p/2-c/2+s,bottom:"auto",right:"auto"};break;case"bottom right":a={top:O.top+u+w,right:f-O.left-p-s,left:"auto",bottom:"auto"}}return a===n&&g.error(v.invalidPosition),o.css(a).removeClass(b.position).addClass(i).addClass(b.loading),l=g.get.offstagePosition(i),l?(g.debug("Element is outside boundaries",l),z<h.maxSearchDepth?(i=g.get.nextPosition(i),z++,g.debug("Trying new position",i),o?g.set.position(i):!1):(g.debug("Popup could not find a position onstage",o),z=0,g.reset(),o.removeClass(b.loading),!1)):(g.debug("Position is on stage",i),z=0,h.setFluidWidth&&o.hasClass(b.fluid)&&o.css("width",r.width()),o.removeClass(b.loading),!0)},visible:function(){C.addClass(b.visible)}},remove:{visible:function(){C.removeClass(b.visible)}},bind:{popup:function(){g.verbose("Allowing hover events on popup to prevent closing"),o&&o.size()>0&&o.on("mouseenter"+x,g.event.start).on("mouseleave"+x,g.event.end)},close:function(){(h.hideOnScroll===!0||"auto"==h.hideOnScroll&&"click"!=h.on)&&(a.one("touchmove"+x,g.hideGracefully).one("scroll"+x,g.hideGracefully),P.one("touchmove"+x,g.hideGracefully).one("scroll"+x,g.hideGracefully)),"click"==h.on&&h.closable&&(g.verbose("Binding popup close event to document"),a.on("click"+x,function(t){g.verbose("Pop-up clickaway intent detected"),e.proxy(g.hideGracefully,A)(t)}))}},unbind:{close:function(){(h.hideOnScroll===!0||"auto"==h.hideOnScroll&&"click"!=h.on)&&(a.off("scroll"+x,g.hide),P.off("scroll"+x,g.hide)),"click"==h.on&&h.closable&&(g.verbose("Removing close event from document"),a.off("click"+x))}},is:{active:function(){return C.hasClass(b.active)},animating:function(){return o&&o.is(":animated")||o.hasClass(b.animating)},visible:function(){return o&&o.is(":visible")},dropdown:function(){return C.hasClass(b.dropdown)},hidden:function(){return!g.is.visible()}},reset:function(){g.remove.visible(),h.preserve||h.popup?e.fn.transition!==n&&o.transition("remove transition"):g.removePopup()},setting:function(t,o){if(e.isPlainObject(t))e.extend(!0,h,t);else{if(o===n)return h[t];h[t]=o}},internal:function(t,o){if(e.isPlainObject(t))e.extend(!0,g,t);else{if(o===n)return g[t];g[t]=o}},debug:function(){h.debug&&(h.performance?g.performance.log(arguments):(g.debug=Function.prototype.bind.call(console.info,console,h.name+":"),g.debug.apply(console,arguments)))},verbose:function(){h.verbose&&h.debug&&(h.performance?g.performance.log(arguments):(g.verbose=Function.prototype.bind.call(console.info,console,h.name+":"),g.verbose.apply(console,arguments)))},error:function(){g.error=Function.prototype.bind.call(console.error,console,h.name+":"),g.error.apply(console,arguments)},performance:{log:function(e){var t,o,n;h.performance&&(t=(new Date).getTime(),n=p||t,o=t-n,p=t,u.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:A,"Execution Time":o})),clearTimeout(g.performance.timer),g.performance.timer=setTimeout(g.performance.display,100)},display:function(){var t=h.name+":",o=0;p=!1,clearTimeout(g.performance.timer),e.each(u,function(e,t){o+=t["Execution Time"]}),t+=" "+o+"ms",l&&(t+=" '"+l+"'"),(console.group!==n||console.table!==n)&&u.length>0&&(console.groupCollapsed(t),console.table?console.table(u):e.each(u,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),u=[]}},invoke:function(t,o,i){var r,a,l,p=E;return o=o||f,i=A||i,"string"==typeof t&&p!==n&&(t=t.split(/[\. ]/),r=t.length-1,e.each(t,function(o,i){var s=o!=r?i+t[o+1].charAt(0).toUpperCase()+t[o+1].slice(1):t;if(e.isPlainObject(p[s])&&o!=r)p=p[s];else{if(p[s]!==n)return a=p[s],!1;if(!e.isPlainObject(p[i])||o==r)return p[i]!==n?(a=p[i],!1):!1;p=p[i]}})),e.isFunction(a)?l=a.apply(i,o):a!==n&&(l=a),e.isArray(s)?s.push(l):s!==n?s=[s,l]:l!==n&&(s=l),a}},d?(E===n&&g.initialize(),g.invoke(c)):(E!==n&&g.destroy(),g.initialize())}),s!==n?s:this},e.fn.popup.settings={name:"Popup",debug:!1,verbose:!0,performance:!0,namespace:"popup",onCreate:function(){},onRemove:function(){},onShow:function(){},onVisible:function(){},onHide:function(){},onHidden:function(){},variation:"",content:!1,html:!1,title:!1,on:"hover",closable:!0,hideOnScroll:"auto",context:"body",position:"top left",delay:{show:30,hide:0},setFluidWidth:!0,target:!1,popup:!1,inline:!1,preserve:!0,hoverable:!1,duration:200,easing:"easeOutQuint",transition:"scale",distanceAway:0,offset:0,maxSearchDepth:10,error:{invalidPosition:"The position you specified is not a valid position",method:"The method you called is not defined."},metadata:{content:"content",html:"html",offset:"offset",position:"position",title:"title",variation:"variation"},className:{active:"active",animating:"animating",dropdown:"dropdown",fluid:"fluid",loading:"loading",popup:"ui popup",position:"top left center bottom right",visible:"visible"},selector:{popup:".ui.popup"},templates:{escape:function(e){var t=/[&<>"'`]/g,o=/[&<>"'`]/,n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},i=function(e){return n[e]};return o.test(e)?e.replace(t,i):e},popup:function(t){var o="",i=e.fn.popup.settings.templates.escape;return typeof t!==n&&(typeof t.title!==n&&t.title&&(t.title=i(t.title),o+='<div class="header">'+t.title+"</div>"),typeof t.content!==n&&t.content&&(t.content=i(t.content),o+='<div class="content">'+t.content+"</div>")),o}}},e.extend(e.easing,{easeOutQuad:function(e,t,o,n,i){return-n*(t/=i)*(t-2)+o}})}(jQuery,window,document);