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

(function(e,t,n,o){e.fn.popup=function(i){var a,r=e(this),s=e.isPlainObject(i)?e.extend(!0,{},e.fn.popup.settings,i):e.fn.popup.settings,c=("."+s.namespace,"module-"+s.namespace,r.selector||""),l=(r.size(),(new Date).getTime()),u=[],d=s.selector,m=s.className,f=s.error,p=s.metadata,g=s.namespace,h=arguments[0],v="string"==typeof h,b=[].slice.call(arguments,1);return r.each(function(){var i,r=e(this),y=e(t),x=r.offsetParent(),w=s.inline?r.next(d.popup):y.children(d.popup).last(),C=0,k=this,T=r.data("module-"+s.namespace);i={initialize:function(){i.debug("Initializing module",r),"hover"==s.on?r.on("mouseenter."+g,i.event.mouseenter).on("mouseleave."+g,i.event.mouseleave):r.on(s.on+"."+g,i.event[s.on]),y.on("resize."+g,i.event.resize),i.instantiate()},instantiate:function(){i.verbose("Storing instance of module"),T=i,r.data("module-"+g,T)},refresh:function(){w=s.inline?r.next(d.popup):y.children(d.popup).last(),x=r.offsetParent()},destroy:function(){i.debug("Destroying existing popups"),r.off("."+g),w.remove()},event:{mouseenter:function(t){var n=this;i.timer=setTimeout(function(){e.proxy(i.toggle,n)(),e(n).hasClass(m.visible)&&t.stopPropagation()},s.delay)},mouseleave:function(){clearTimeout(i.timer),r.is(":visible")&&i.hide()},click:function(t){e.proxy(i.toggle,this)(),e(this).hasClass(m.visible)&&t.stopPropagation()},resize:function(){w.is(":visible")&&i.position()}},create:function(){i.debug("Creating pop-up content");var t=r.data(p.html)||s.html,n=r.data(p.title)||s.title,o=r.data(p.content)||r.attr("title")||s.content;t||o||n?(t||(t=s.template({title:n,content:o})),w=e("<div/>").addClass(m.popup).html(t),s.inline?w.insertAfter(r):w.appendTo(e("body"))):i.error(f.content)},remove:function(){w.remove()},get:{offstagePosition:function(){var n={top:e(t).scrollTop(),bottom:e(t).scrollTop()+e(t).height(),left:0,right:e(t).width()},o={width:w.outerWidth(),height:w.outerHeight(),position:w.offset()},i={},a=[];return o.position&&(i={top:o.position.top<n.top,bottom:o.position.top+o.height>n.bottom,right:o.position.left+o.width>n.right,left:o.position.left<n.left}),e.each(i,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}},toggle:function(){r=e(this),i.debug("Toggling pop-up"),i.refresh(),0===w.size()&&i.create(),r.hasClass(m.visible)?i.hide():i.position()&&i.show()},position:function(n,o){var a,c,l=(e(t).width(),e(t).height(),r.outerWidth()),u=r.outerHeight(),d=w.outerWidth(),g=w.outerHeight(),h=s.inline?r.position():r.offset(),v=s.inline?x.outerWidth():y.outerWidth(),b=s.inline?x.outerHeight():y.outerHeight();switch(n=n||r.data(p.position)||s.position,o=o||r.data(p.arrowOffset)||s.arrowOffset,i.debug("Calculating offset for position",n),n){case"top left":a={top:"auto",bottom:b-h.top+s.distanceAway,left:h.left+o};break;case"top center":a={bottom:b-h.top+s.distanceAway,left:h.left+l/2-d/2+o,top:"auto",right:"auto"};break;case"top right":a={bottom:b-h.top+s.distanceAway,right:v-h.left-l-o,top:"auto",left:"auto"};break;case"left center":a={top:h.top+u/2-g/2,right:v-h.left+s.distanceAway-o,left:"auto",bottom:"auto"};break;case"right center":a={top:h.top+u/2-g/2,left:h.left+l+s.distanceAway+o,bottom:"auto",right:"auto"};break;case"bottom left":a={top:h.top+u+s.distanceAway,left:h.left+o,bottom:"auto",right:"auto"};break;case"bottom center":a={top:h.top+u+s.distanceAway,left:h.left+l/2-d/2+o,bottom:"auto",right:"auto"};break;case"bottom right":a={top:h.top+u+s.distanceAway,right:v-h.left-l-o,left:"auto",bottom:"auto"}}return e.extend(a,{width:w.width()+1}),w.removeAttr("style").removeClass("top right bottom left center").css(a).addClass(n).addClass(m.loading),c=i.get.offstagePosition(),c?(i.debug("Element is outside boundaries ",c),s.maxSearchDepth>C?(n=i.get.nextPosition(n),C++,i.debug("Trying new position: ",n),i.position(n)):(i.error(f.recursion),C=0,!1)):(i.debug("Position is on stage",n),C=0,!0)},show:function(){i.debug("Showing pop-up"),e(d.popup).filter(":visible").stop().fadeOut(200).prev(r).removeClass(m.visible),r.addClass(m.visible),w.removeClass(m.loading),"pop"==s.animation&&e.fn.popIn!==o?w.stop().popIn(s.duration,s.easing):w.stop().fadeIn(s.duration,s.easing),"click"==s.on&&s.clicktoClose&&(i.debug("Binding popup close event"),e(n).on("click."+g,i.gracefully.hide)),e.proxy(s.onShow,w)()},hide:function(){r.removeClass(m.visible),w.is(":visible")&&(i.debug("Hiding pop-up"),"pop"==s.animation&&e.fn.popOut!==o?w.stop().popOut(s.duration,s.easing,function(){w.hide()}):w.stop().fadeOut(s.duration,s.easing)),"click"==s.on&&s.clicktoClose&&e(n).off("click."+g),e.proxy(s.onHide,w)(),s.inline||i.remove()},gracefully:{hide:function(t){0===e(t.target).closest(d.popup).size()&&i.hide()}},setting:function(t,n){return n===o?s[t]:(e.isPlainObject(t)?e.extend(!0,s,t):s[t]=n,o)},internal:function(t,n){return n===o?i[t]:(e.isPlainObject(t)?e.extend(!0,i,t):i[t]=n,o)},debug:function(){s.debug&&(s.performance?i.performance.log(arguments):i.debug=Function.prototype.bind.call(console.info,console,s.moduleName+":"))},verbose:function(){s.verbose&&s.debug&&(s.performance?i.performance.log(arguments):i.verbose=Function.prototype.bind.call(console.info,console,s.moduleName+":"))},error:function(){i.error=Function.prototype.bind.call(console.log,console,s.moduleName+":")},performance:{log:function(e){var t,n,o;s.performance&&(t=(new Date).getTime(),o=l||t,n=t-o,l=t,u.push({Element:k,Name:e[0],Arguments:e[1]||"","Execution Time":n})),clearTimeout(i.performance.timer),i.performance.timer=setTimeout(i.performance.display,100)},display:function(){var t=s.moduleName+":",n=0;l=!1,e.each(u,function(e,t){n+=t["Execution Time"]}),t+=" "+n+"ms",c&&(t+=" '"+c+"'"),(console.group!==o||console.table!==o)&&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,n,a){var r,s;return n=n||b,a=k||a,"string"==typeof t&&T!==o&&(t=t.split("."),r=t.length-1,e.each(t,function(t,n){e.isPlainObject(T[n])&&t!=r?T=T[n]:T[n]!==o?s=T[n]:i.error(f.method)})),e.isFunction(s)?(T.verbose("Executing invoked function",s),s.apply(a,n)):s||!1}},v?(T===o&&i.initialize(),a=i.invoke(h)):(T===o&&i.destroy(),i.initialize())}),a?a:this},e.fn.popup.settings={moduleName:"Popup",debug:!0,verbose:!0,performance:!0,namespace:"popup",onShow:function(){},onHide:function(){},content:!1,html:!1,title:!1,on:"hover",clicktoClose:!0,position:"top center",delay:0,inline:!0,duration:250,easing:"easeOutQuint",animation:"pop",distanceAway:2,arrowOffset:0,maxSearchDepth:10,error:{content:"Warning: Your popup has no content specified",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",title:"title",position:"position",arrowOffset:"arrowOffset"},className:{popup:"ui popup",visible:"visible",loading:"loading"},selector:{popup:".ui.popup"},template:function(e){var t="";return typeof e!==o&&(typeof e.title!==o&&e.title&&(t+="<h2>"+e.title+"</h2>"),typeof e.content!==o&&e.content&&(t+='<div class="content">'+e.content+"</div>")),t}}})(jQuery,window,document);