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