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

/*!
* # Semantic UI 2.2.0 - Popup
* http://github.com/semantic-org/semantic-ui/
*
*
* Copyright 2015 Contributors
* Released under the MIT license
* http://opensource.org/licenses/MIT
*
*/
!function(t,e,o,n){"use strict";e="undefined"!=typeof e&&e.Math==Math?e:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),t.fn.popup=function(i){var r,a=t(this),s=t(o),p=t(e),l=t("body"),u=a.selector||"",c=!0,d=(new Date).getTime(),f=[],g=arguments[0],h="string"==typeof g,m=[].slice.call(arguments,1);return a.each(function(){var a,v,b,w,y,P=t.isPlainObject(i)?t.extend(!0,{},t.fn.popup.settings,i):t.extend({},t.fn.popup.settings),T=P.selector,C=P.className,x=P.error,k=P.metadata,S=P.namespace,R="."+P.namespace,A="module-"+S,E=t(this),D=t(P.context),O=t(P.scrollContext),j=t(P.boundary),F=P.target?t(P.target):E,H=0,W=!1,G=!1,I=this,N=E.data(A);y={initialize:function(){y.debug("Initializing",E),y.createID(),y.bind.events(),!y.exists()&&P.preserve&&y.create(),y.instantiate()},instantiate:function(){y.verbose("Storing instance",y),N=y,E.data(A,N)},refresh:function(){P.popup?a=t(P.popup).eq(0):P.inline&&(a=F.nextAll(T.popup).eq(0),P.popup=a),P.popup?(a.addClass(C.loading),v=y.get.offsetParent(),a.removeClass(C.loading),P.movePopup&&y.has.popup()&&y.get.offsetParent(a)[0]!==v[0]&&(y.debug("Moving popup to the same offset parent as activating element"),a.detach().appendTo(v))):v=P.inline?y.get.offsetParent(F):y.has.popup()?y.get.offsetParent(a):l,v.is("html")&&v[0]!==l[0]&&(y.debug("Setting page as offset parent"),v=l),y.get.variation()&&y.set.variation()},reposition:function(){y.refresh(),y.set.position()},destroy:function(){y.debug("Destroying previous module"),a&&!P.preserve&&y.removePopup(),clearTimeout(y.hideTimer),clearTimeout(y.showTimer),p.off(b),E.off(R).removeData(A)},event:{start:function(e){var o=t.isPlainObject(P.delay)?P.delay.show:P.delay;clearTimeout(y.hideTimer),G||(y.showTimer=setTimeout(y.show,o))},end:function(){var e=t.isPlainObject(P.delay)?P.delay.hide:P.delay;clearTimeout(y.showTimer),y.hideTimer=setTimeout(y.hide,e)},touchstart:function(t){G=!0,y.show()},resize:function(){y.is.visible()&&y.set.position()},hideGracefully:function(e){var n=t(e.target),i=t.contains(o.documentElement,e.target),r=n.closest(T.popup).length>0;e&&!r&&i?(y.debug("Click occurred outside popup hiding popup"),y.hide()):y.debug("Click was inside popup, keeping popup open")}},create:function(){var e=y.get.html(),o=y.get.title(),n=y.get.content();e||n||o?(y.debug("Creating pop-up html"),e||(e=P.templates.popup({title:o,content:n})),a=t("<div/>").addClass(C.popup).data(k.activator,E).html(e),P.inline?(y.verbose("Inserting popup element inline",a),a.insertAfter(E)):(y.verbose("Appending popup element to body",a),a.appendTo(D)),y.refresh(),y.set.variation(),P.hoverable&&y.bind.popup(),P.onCreate.call(a,I)):0!==F.next(T.popup).length?(y.verbose("Pre-existing popup found"),P.inline=!0,P.popup=F.next(T.popup).data(k.activator,E),y.refresh(),P.hoverable&&y.bind.popup()):P.popup?(t(P.popup).data(k.activator,E),y.verbose("Used popup specified in settings"),y.refresh(),P.hoverable&&y.bind.popup()):y.debug("No content specified skipping display",I)},createID:function(){w=(Math.random().toString(16)+"000000000").substr(2,8),b="."+w,y.verbose("Creating unique id for element",w)},toggle:function(){y.debug("Toggling pop-up"),y.is.hidden()?(y.debug("Popup is hidden, showing pop-up"),y.unbind.close(),y.show()):(y.debug("Popup is visible, hiding pop-up"),y.hide())},show:function(t){if(t=t||function(){},y.debug("Showing pop-up",P.transition),y.is.hidden()&&(!y.is.active()||!y.is.dropdown())){if(y.exists()||y.create(),P.onShow.call(a,I)===!1)return void y.debug("onShow callback returned false, cancelling popup animation");P.preserve||P.popup||y.refresh(),a&&y.set.position()&&(y.save.conditions(),P.exclusive&&y.hideAll(),y.animate.show(t))}},hide:function(t){if(t=t||function(){},y.is.visible()||y.is.animating()){if(P.onHide.call(a,I)===!1)return void y.debug("onHide callback returned false, cancelling popup animation");y.remove.visible(),y.unbind.close(),y.restore.conditions(),y.animate.hide(t)}},hideAll:function(){t(T.popup).filter("."+C.visible).each(function(){t(this).data(k.activator).popup("hide")})},exists:function(){return a?P.inline||P.popup?y.has.popup():a.closest(D).length>=1?!0:!1:!1},removePopup:function(){y.has.popup()&&!P.popup&&(y.debug("Removing popup",a),a.remove(),a=n,P.onRemove.call(a,I))},save:{conditions:function(){y.cache={title:E.attr("title")},y.cache.title&&E.removeAttr("title"),y.verbose("Saving original attributes",y.cache.title)}},restore:{conditions:function(){return y.cache&&y.cache.title&&(E.attr("title",y.cache.title),y.verbose("Restoring original attributes",y.cache.title)),!0}},supports:{svg:function(){return typeof SVGGraphicsElement===n}},animate:{show:function(e){e=t.isFunction(e)?e:function(){},P.transition&&t.fn.transition!==n&&E.transition("is supported")?(y.set.visible(),P.autoRemove&&y.bind.autoRemoval(),a.transition({animation:P.transition+" in",queue:!1,debug:P.debug,verbose:P.verbose,duration:P.duration,onComplete:function(){y.bind.close(),e.call(a,I),P.onVisible.call(a,I)}})):y.error(x.noTransition)},hide:function(e){return e=t.isFunction(e)?e:function(){},y.debug("Hiding pop-up"),P.onHide.call(a,I)===!1?void y.debug("onHide callback returned false, cancelling popup animation"):void(P.transition&&t.fn.transition!==n&&E.transition("is supported")?a.transition({animation:P.transition+" out",queue:!1,duration:P.duration,debug:P.debug,verbose:P.verbose,onComplete:function(){y.reset(),e.call(a,I),P.onHidden.call(a,I),P.autoRemove&&y.unbind.autoRemoval()}}):y.error(x.noTransition))}},change:{content:function(t){a.html(t)}},get:{html:function(){return E.removeData(k.html),E.data(k.html)||P.html},title:function(){return E.removeData(k.title),E.data(k.title)||P.title},content:function(){return E.removeData(k.content),E.data(k.content)||E.attr("title")||P.content},variation:function(){return E.removeData(k.variation),E.data(k.variation)||P.variation},popup:function(){return a},popupOffset:function(){return a.offset()},calculations:function(){var t,o=F[0],n=j[0]==e,i=P.inline||P.popup&&P.movePopup?F.position():F.offset(),r=j.offset()||{top:0,left:0},s={},l=n?{top:p.scrollTop(),left:p.scrollLeft()}:{top:0,left:0};return s={target:{element:F[0],width:F.outerWidth(),height:F.outerHeight(),top:i.top,left:i.left,margin:{}},popup:{width:a.outerWidth(),height:a.outerHeight()},parent:{width:v.outerWidth(),height:v.outerHeight()},screen:{top:r.top,left:r.left,scroll:{top:l.top,left:l.left},width:j.width(),height:j.height()}},P.setFluidWidth&&y.is.fluid()&&(s.container={width:a.parent().outerWidth()},s.popup.width=s.container.width),s.target.margin.top=P.inline?parseInt(e.getComputedStyle(o).getPropertyValue("margin-top"),10):0,s.target.margin.left=P.inline?y.is.rtl()?parseInt(e.getComputedStyle(o).getPropertyValue("margin-right"),10):parseInt(e.getComputedStyle(o).getPropertyValue("margin-left"),10):0,t=s.screen,s.boundary={top:t.top+t.scroll.top,bottom:t.top+t.scroll.top+t.height,left:t.left+t.scroll.left,right:t.left+t.scroll.left+t.width},s},id:function(){return w},startEvent:function(){return"hover"==P.on?"mouseenter":"focus"==P.on?"focus":!1},scrollEvent:function(){return"scroll"},endEvent:function(){return"hover"==P.on?"mouseleave":"focus"==P.on?"blur":!1},distanceFromBoundary:function(t,e){var o,n,i={};return e=e||y.get.calculations(),o=e.popup,n=e.boundary,t&&(i={top:t.top-n.top,left:t.left-n.left,right:n.right-(t.left+o.width),bottom:n.bottom-(t.top+o.height)},y.verbose("Distance from boundaries determined",t,i)),i},offsetParent:function(e){var o=e!==n?e[0]:E[0],i=o.parentNode,r=t(i);if(i)for(var a="none"===r.css("transform"),s="static"===r.css("position"),p=r.is("html");i&&!p&&s&&a;)i=i.parentNode,r=t(i),a="none"===r.css("transform"),s="static"===r.css("position"),p=r.is("html");return r&&r.length>0?r:t()},positions:function(){return{"top left":!1,"top center":!1,"top right":!1,"bottom left":!1,"bottom center":!1,"bottom right":!1,"left center":!1,"right center":!1}},nextPosition:function(t){var e=t.split(" "),o=e[0],n=e[1],i={top:"bottom",bottom:"top",left:"right",right:"left"},r={left:"center",center:"right",right:"left"},a={"top left":"top center","top center":"top right","top right":"right center","right center":"bottom right","bottom right":"bottom center","bottom center":"bottom left","bottom left":"left center","left center":"top left"},s="top"==o||"bottom"==o,p=!1,l=!1,u=!1;return W||(y.verbose("All available positions available"),W=y.get.positions()),y.debug("Recording last position tried",t),W[t]=!0,"opposite"===P.prefer&&(u=[i[o],n],u=u.join(" "),p=W[u]===!0,y.debug("Trying opposite strategy",u)),"adjacent"===P.prefer&&s&&(u=[o,r[n]],u=u.join(" "),l=W[u]===!0,y.debug("Trying adjacent strategy",u)),(l||p)&&(y.debug("Using backup position",u),u=a[t]),u}},set:{position:function(t,e){if(0===F.length||0===a.length)return void y.error(x.notFound);var o,i,r,s,p,l,u,c;if(e=e||y.get.calculations(),t=t||E.data(k.position)||P.position,o=E.data(k.offset)||P.offset,i=P.distanceAway,r=e.target,s=e.popup,p=e.parent,0===r.width&&0===r.height&&!y.is.svg(r.element))return y.debug("Popup target is hidden, no action taken"),!1;switch(P.inline&&(y.debug("Adding margin to calculation",r.margin),"left center"==t||"right center"==t?(o+=r.margin.top,i+=-r.margin.left):"top left"==t||"top center"==t||"top right"==t?(o+=r.margin.left,i-=r.margin.top):(o+=r.margin.left,i+=r.margin.top)),y.debug("Determining popup position from calculations",t,e),y.is.rtl()&&(t=t.replace(/left|right/g,function(t){return"left"==t?"right":"left"}),y.debug("RTL: Popup position updated",t)),H==P.maxSearchDepth&&"string"==typeof P.lastResort&&(t=P.lastResort),t){case"top left":l={top:"auto",bottom:p.height-r.top+i,left:r.left+o,right:"auto"};break;case"top center":l={bottom:p.height-r.top+i,left:r.left+r.width/2-s.width/2+o,top:"auto",right:"auto"};break;case"top right":l={bottom:p.height-r.top+i,right:p.width-r.left-r.width-o,top:"auto",left:"auto"};break;case"left center":l={top:r.top+r.height/2-s.height/2+o,right:p.width-r.left+i,left:"auto",bottom:"auto"};break;case"right center":l={top:r.top+r.height/2-s.height/2+o,left:r.left+r.width+i,bottom:"auto",right:"auto"};break;case"bottom left":l={top:r.top+r.height+i,left:r.left+o,bottom:"auto",right:"auto"};break;case"bottom center":l={top:r.top+r.height+i,left:r.left+r.width/2-s.width/2+o,bottom:"auto",right:"auto"};break;case"bottom right":l={top:r.top+r.height+i,right:p.width-r.left-r.width-o,left:"auto",bottom:"auto"}}if(l===n&&y.error(x.invalidPosition,t),y.debug("Calculated popup positioning values",l),a.css(l).removeClass(C.position).addClass(t).addClass(C.loading),u=y.get.popupOffset(),c=y.get.distanceFromBoundary(u,e),y.is.offstage(c,t)){if(y.debug("Position is outside viewport",t),H<P.maxSearchDepth)return H++,t=y.get.nextPosition(t),y.debug("Trying new position",t),a?y.set.position(t,e):!1;if(!P.lastResort)return y.debug("Popup could not find a position to display",a),y.error(x.cannotPlace,I),y.remove.attempts(),y.remove.loading(),y.reset(),P.onUnplaceable.call(a,I),!1;y.debug("No position found, showing with last position")}return y.debug("Position is on stage",t),y.remove.attempts(),y.remove.loading(),P.setFluidWidth&&y.is.fluid()&&y.set.fluidWidth(e),!0},fluidWidth:function(t){t=t||y.get.calculations(),y.debug("Automatically setting element width to parent width",t.parent.width),a.css("width",t.container.width)},variation:function(t){t=t||y.get.variation(),t&&y.has.popup()&&(y.verbose("Adding variation to popup",t),a.addClass(t))},visible:function(){E.addClass(C.visible)}},remove:{loading:function(){a.removeClass(C.loading)},variation:function(t){t=t||y.get.variation(),t&&(y.verbose("Removing variation",t),a.removeClass(t))},visible:function(){E.removeClass(C.visible)},attempts:function(){y.verbose("Resetting all searched positions"),H=0,W=!1}},bind:{events:function(){y.debug("Binding popup events to module"),"click"==P.on&&E.on("click"+R,y.toggle),"hover"==P.on&&c&&E.on("touchstart"+R,y.event.touchstart),y.get.startEvent()&&E.on(y.get.startEvent()+R,y.event.start).on(y.get.endEvent()+R,y.event.end),P.target&&y.debug("Target set to element",F),p.on("resize"+b,y.event.resize)},popup:function(){y.verbose("Allowing hover events on popup to prevent closing"),a&&y.has.popup()&&a.on("mouseenter"+R,y.event.start).on("mouseleave"+R,y.event.end)},autoRemoval:function(){E.one("remove"+R,function(){y.hide(function(){y.removePopup()})})},close:function(){(P.hideOnScroll===!0||"auto"==P.hideOnScroll&&"click"!=P.on)&&O.one(y.get.scrollEvent()+b,y.event.hideGracefully),"hover"==P.on&&G&&(y.verbose("Binding popup close event to document"),s.on("touchstart"+b,function(t){y.verbose("Touched away from popup"),y.event.hideGracefully.call(I,t)})),"click"==P.on&&P.closable&&(y.verbose("Binding popup close event to document"),s.on("click"+b,function(t){y.verbose("Clicked away from popup"),y.event.hideGracefully.call(I,t)}))}},unbind:{close:function(){(P.hideOnScroll===!0||"auto"==P.hideOnScroll&&"click"!=P.on)&&(s.off("scroll"+b,y.hide),D.off("scroll"+b,y.hide)),"hover"==P.on&&G&&(s.off("touchstart"+b),G=!1),"click"==P.on&&P.closable&&(y.verbose("Removing close event from document"),s.off("click"+b))},autoRemoval:function(){E.off("remove"+b)}},has:{popup:function(){return a&&a.length>0}},is:{offstage:function(e,o){var n=[];return t.each(e,function(t,e){e<-P.jitter&&(y.debug("Position exceeds allowable distance from edge",t,e,o),n.push(t))}),n.length>0?!0:!1},svg:function(t){return y.supports.svg()&&t instanceof SVGGraphicsElement},active:function(){return E.hasClass(C.active)},animating:function(){return a!==n&&a.hasClass(C.animating)},fluid:function(){return a!==n&&a.hasClass(C.fluid)},visible:function(){return a!==n&&a.hasClass(C.visible)},dropdown:function(){return E.hasClass(C.dropdown)},hidden:function(){return!y.is.visible()},rtl:function(){return"rtl"==E.css("direction")}},reset:function(){y.remove.visible(),P.preserve?t.fn.transition!==n&&a.transition("remove transition"):y.removePopup()},setting:function(e,o){if(t.isPlainObject(e))t.extend(!0,P,e);else{if(o===n)return P[e];P[e]=o}},internal:function(e,o){if(t.isPlainObject(e))t.extend(!0,y,e);else{if(o===n)return y[e];y[e]=o}},debug:function(){!P.silent&&P.debug&&(P.performance?y.performance.log(arguments):(y.debug=Function.prototype.bind.call(console.info,console,P.name+":"),y.debug.apply(console,arguments)))},verbose:function(){!P.silent&&P.verbose&&P.debug&&(P.performance?y.performance.log(arguments):(y.verbose=Function.prototype.bind.call(console.info,console,P.name+":"),y.verbose.apply(console,arguments)))},error:function(){P.silent||(y.error=Function.prototype.bind.call(console.error,console,P.name+":"),y.error.apply(console,arguments))},performance:{log:function(t){var e,o,n;P.performance&&(e=(new Date).getTime(),n=d||e,o=e-n,d=e,f.push({Name:t[0],Arguments:[].slice.call(t,1)||"",Element:I,"Execution Time":o})),clearTimeout(y.performance.timer),y.performance.timer=setTimeout(y.performance.display,500)},display:function(){var e=P.name+":",o=0;d=!1,clearTimeout(y.performance.timer),t.each(f,function(t,e){o+=e["Execution Time"]}),e+=" "+o+"ms",u&&(e+=" '"+u+"'"),(console.group!==n||console.table!==n)&&f.length>0&&(console.groupCollapsed(e),console.table?console.table(f):t.each(f,function(t,e){console.log(e.Name+": "+e["Execution Time"]+"ms")}),console.groupEnd()),f=[]}},invoke:function(e,o,i){var a,s,p,l=N;return o=o||m,i=I||i,"string"==typeof e&&l!==n&&(e=e.split(/[\. ]/),a=e.length-1,t.each(e,function(o,i){var r=o!=a?i+e[o+1].charAt(0).toUpperCase()+e[o+1].slice(1):e;if(t.isPlainObject(l[r])&&o!=a)l=l[r];else{if(l[r]!==n)return s=l[r],!1;if(!t.isPlainObject(l[i])||o==a)return l[i]!==n?(s=l[i],!1):!1;l=l[i]}})),t.isFunction(s)?p=s.apply(i,o):s!==n&&(p=s),t.isArray(r)?r.push(p):r!==n?r=[r,p]:p!==n&&(r=p),s}},h?(N===n&&y.initialize(),y.invoke(g)):(N!==n&&N.invoke("destroy"),y.initialize())}),r!==n?r:this},t.fn.popup.settings={name:"Popup",silent:!1,debug:!1,verbose:!1,performance:!0,namespace:"popup",onCreate:function(){},onRemove:function(){},onShow:function(){},onVisible:function(){},onHide:function(){},onUnplaceable:function(){},onHidden:function(){},autoRemove:!0,on:"hover",boundary:e,addTouchEvents:!0,position:"top left",variation:"",movePopup:!0,target:!1,popup:!1,inline:!1,preserve:!1,hoverable:!1,content:!1,html:!1,title:!1,closable:!0,hideOnScroll:"auto",exclusive:!1,context:"body",scrollContext:e,prefer:"opposite",lastResort:!1,delay:{show:50,hide:70},setFluidWidth:!0,duration:200,transition:"scale",distanceAway:0,jitter:2,offset:0,maxSearchDepth:15,error:{invalidPosition:"The position you specified is not a valid position",cannotPlace:"Popup does not fit within the boundaries of the viewport",method:"The method you called is not defined.",noTransition:"This module requires ui transitions <https://github.com/Semantic-Org/UI-Transition>",notFound:"The target or popup you specified does not exist on the page"},metadata:{activator:"activator",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(t){var e=/[&<>"'`]/g,o=/[&<>"'`]/,n={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","`":"&#x60;"},i=function(t){return n[t]};return o.test(t)?t.replace(e,i):t},popup:function(e){var o="",i=t.fn.popup.settings.templates.escape;return typeof e!==n&&(typeof e.title!==n&&e.title&&(e.title=i(e.title),o+='<div class="header">'+e.title+"</div>"),typeof e.content!==n&&e.content&&(e.content=i(e.content),o+='<div class="content">'+e.content+"</div>")),o}}}}(jQuery,window,document);