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

/*
* # Semantic UI
* git://github.com/Semantic-Org/Semantic-UI.git#1.0
*
*
* 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 r,s=e(this),a=e(o),p=s.selector||"",u=("ontouchstart"in o.documentElement,(new Date).getTime()),c=[],l=arguments[0],d="string"==typeof l,f=[].slice.call(arguments,1);return s.each(function(){var o,s,g,m=e.isPlainObject(i)?e.extend(!0,{},e.fn.popup.settings,i):e.extend({},e.fn.popup.settings),h=m.selector,b=m.className,v=m.error,y=m.metadata,w=m.namespace,k="."+m.namespace,x="module-"+w,C=e(this),P=e(m.context),T=m.target?e(m.target):C,A=e(t),E=e("body"),z=0,O=this,j=C.data(x);g={initialize:function(){g.debug("Initializing module",C),g.refresh(),"click"==m.on?C.on("click"+k,g.toggle):g.get.startEvent()&&C.on(g.get.startEvent()+k,g.event.start).on(g.get.endEvent()+k,g.event.end),m.target&&g.debug("Target set to element",T),A.on("resize"+k,g.event.resize),g.exists()?m.hoverable&&g.bind.popup():g.create(),g.instantiate()},instantiate:function(){g.verbose("Storing instance of module",g),j=g,C.data(x,j)},refresh:function(){o=m.popup?e(m.popup):m.inline?T.next(m.selector.popup):!1,s=m.popup?o.offsetParent():m.inline?T.offsetParent():E},destroy:function(){g.debug("Destroying previous module"),o&&!m.preserve&&g.remove(),C.off(k).removeData(x)},event:{start:function(){var t=e.isPlainObject(m.delay)?m.delay.show:m.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(m.delay)?m.delay.hide:m.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)||m.html,n=C.data(y.variation)||m.variation,i=C.data(y.title)||m.title,r=C.data(y.content)||C.attr("title")||m.content;t||r||i?(g.debug("Creating pop-up html"),t||(t=m.templates.popup({title:i,content:r})),o=e("<div/>").addClass(b.popup).addClass(n).html(t),n&&o.addClass(n),m.inline?(g.verbose("Inserting popup element inline",o),o.insertAfter(C)):(g.verbose("Appending popup element to body",o),o.appendTo(P)),m.hoverable&&g.bind.popup(),e.proxy(m.onCreate,o)()):0!==T.next(m.selector.popup).size()?(g.verbose("Pre-existing popup found, reverting to inline"),m.inline=!0,g.refresh(),m.hoverable&&g.bind.popup()):g.debug("No content specified skipping display",O)},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(e){e=e||function(){},g.debug("Showing pop-up",m.transition),m.preserve||m.popup||g.refresh(),g.exists()||g.create(),o&&g.set.position()&&(g.save.conditions(),g.animate.show(e))},hide:function(e){e=e||function(){},C.removeClass(b.visible),g.unbind.close(),g.is.visible()&&(g.restore.conditions(),g.animate.hide(e))},hideAll:function(){e(h.popup).filter(":visible").popup("hide")},hideGracefully:function(t){t&&0===e(t.target).closest(h.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?m.inline||m.popup?0!==o.size():o.closest(P).size():!1},remove:function(){g.debug("Removing popup"),o.remove()},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 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=t||function(){},m.transition&&e.fn.transition!==n&&C.transition("is supported")?o.transition({animation:m.transition+" in",queue:!1,duration:m.duration,start:function(){C.addClass(b.visible)},complete:function(){g.bind.close(),e.proxy(t,O)()}}):(C.addClass(b.visible),o.stop().fadeIn(m.duration,m.easing,function(){g.bind.close(),e.proxy(t,O)()})),e.proxy(m.onShow,O)()},hide:function(t){t=t||function(){},g.debug("Hiding pop-up"),m.transition&&e.fn.transition!==n&&C.transition("is supported")?o.transition({animation:m.transition+" out",queue:!1,duration:m.duration,complete:function(){g.reset(),t()}}):o.stop().fadeOut(m.duration,m.easing,function(){g.reset(),t()}),e.proxy(m.onHide,O)()}},get:{startEvent:function(){return"hover"==m.on?"mouseenter":"focus"==m.on?"focus":!1},endEvent:function(){return"hover"==m.on?"mouseleave":"focus"==m.on?"blur":!1},offstagePosition:function(){var n={top:e(t).scrollTop(),bottom:e(t).scrollTop()+e(t).height(),left:0,right:e(t).width()},i={width:o.width(),height:o.outerHeight(),offset:o.offset()},r={},s=[];return i.offset&&(r={top:i.offset.top<n.top,bottom:i.offset.top+i.height>n.bottom,right:i.offset.left+i.width>n.right,left:i.offset.left<n.left}),g.verbose("Checking if outside viewable area",i.offset),e.each(r,function(e,t){t&&s.push(e)}),s.length>0?s.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,r){var a,p,u=(e(t).width(),e(t).height(),T.outerWidth()),c=T.outerHeight(),l=o.outerWidth(),d=o.outerHeight(),f=s.outerWidth(),h=s.outerHeight(),w=m.distanceAway,k=T[0],x=m.inline?parseInt(t.getComputedStyle(k).getPropertyValue("margin-top"),10):0,P=m.inline?parseInt(t.getComputedStyle(k).getPropertyValue("margin-left"),10):0,A=m.inline||m.popup?T.position():T.offset();switch(i=i||C.data(y.position)||m.position,r=r||C.data(y.offset)||m.offset,m.inline&&(g.debug("Adding targets margin to calculation"),"left center"==i||"right center"==i?(r+=x,w+=-P):"top left"==i||"top center"==i||"top right"==i?(r+=P,w-=x):(r+=P,w+=x)),g.debug("Calculating popup positioning",i),i){case"top left":a={top:"auto",bottom:h-A.top+w,left:A.left+r,right:"auto"};break;case"top center":a={bottom:h-A.top+w,left:A.left+u/2-l/2+r,top:"auto",right:"auto"};break;case"top right":a={bottom:h-A.top+w,right:f-A.left-u-r,top:"auto",left:"auto"};break;case"left center":a={top:A.top+c/2-d/2+r,right:f-A.left+w,left:"auto",bottom:"auto"};break;case"right center":a={top:A.top+c/2-d/2+r,left:A.left+u+w,bottom:"auto",right:"auto"};break;case"bottom left":a={top:A.top+c+w,left:A.left+r,bottom:"auto",right:"auto"};break;case"bottom center":a={top:A.top+c+w,left:A.left+u/2-l/2+r,bottom:"auto",right:"auto"};break;case"bottom right":a={top:A.top+c+w,right:f-A.left-u-r,left:"auto",bottom:"auto"}}return a===n&&g.error(v.invalidPosition),o.css(a).removeClass(b.position).addClass(i).addClass(b.loading),p=g.get.offstagePosition(),p?(g.debug("Element is outside boundaries",p),z<m.maxSearchDepth?(i=g.get.nextPosition(i),z++,g.debug("Trying new position",i),o?g.set.position(i):!1):(g.error(v.recursion),z=0,g.reset(),o.removeClass(b.loading),!1)):(g.debug("Position is on stage",i),z=0,o.removeClass(b.loading),!0)}},bind:{popup:function(){g.verbose("Allowing hover events on popup to prevent closing"),o.on("mouseenter",g.event.start).on("mouseleave",g.event.end)},close:function(){"click"==m.on&&m.closable&&(g.verbose("Binding popup close event to document"),a.on("click"+k,function(t){g.verbose("Pop-up clickaway intent detected"),e.proxy(g.hideGracefully,O)(t)}))}},unbind:{close:function(){"click"==m.on&&m.closable&&(g.verbose("Removing close event from document"),a.off("click"+k))}},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(){o.removeClass(b.visible),m.preserve||m.popup?e.fn.transition!==n&&o.transition("remove transition"):g.remove()},setting:function(t,o){if(e.isPlainObject(t))e.extend(!0,m,t);else{if(o===n)return m[t];m[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(){m.debug&&(m.performance?g.performance.log(arguments):(g.debug=Function.prototype.bind.call(console.info,console,m.name+":"),g.debug.apply(console,arguments)))},verbose:function(){m.verbose&&m.debug&&(m.performance?g.performance.log(arguments):(g.verbose=Function.prototype.bind.call(console.info,console,m.name+":"),g.verbose.apply(console,arguments)))},error:function(){g.error=Function.prototype.bind.call(console.error,console,m.name+":"),g.error.apply(console,arguments)},performance:{log:function(e){var t,o,n;m.performance&&(t=(new Date).getTime(),n=u||t,o=t-n,u=t,c.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:O,"Execution Time":o})),clearTimeout(g.performance.timer),g.performance.timer=setTimeout(g.performance.display,100)},display:function(){var t=m.name+":",o=0;u=!1,clearTimeout(g.performance.timer),e.each(c,function(e,t){o+=t["Execution Time"]}),t+=" "+o+"ms",p&&(t+=" '"+p+"'"),(console.group!==n||console.table!==n)&&c.length>0&&(console.groupCollapsed(t),console.table?console.table(c):e.each(c,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),c=[]}},invoke:function(t,o,i){var s,a,p,u=j;return o=o||f,i=O||i,"string"==typeof t&&u!==n&&(t=t.split(/[\. ]/),s=t.length-1,e.each(t,function(o,i){var r=o!=s?i+t[o+1].charAt(0).toUpperCase()+t[o+1].slice(1):t;if(e.isPlainObject(u[r])&&o!=s)u=u[r];else{if(u[r]!==n)return a=u[r],!1;if(!e.isPlainObject(u[i])||o==s)return u[i]!==n?(a=u[i],!1):!1;u=u[i]}})),e.isFunction(a)?p=a.apply(i,o):a!==n&&(p=a),e.isArray(r)?r.push(p):r!==n?r=[r,p]:p!==n&&(r=p),a}},d?(j===n&&g.initialize(),g.invoke(l)):(j!==n&&g.destroy(),g.initialize())}),r!==n?r:this},e.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:30,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:{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(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);