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.5 KiB

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