You cannot 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 line
18 KiB
JavaScript

!function(t,e,o,n){"use strict";e=void 0!==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=(new Date).getTime(),d=[],f=arguments[0],g="string"==typeof f,h=[].slice.call(arguments,1);return a.each(function(){var a,m,v,b,w,y,P=t.isPlainObject(i)?t.extend(!0,{},t.fn.popup.settings,i):t.extend({},t.fn.popup.settings),C=P.selector,T=P.className,x=P.error,k=P.metadata,E=P.namespace,S="."+P.namespace,A="module-"+E,F=t(this),O=t(P.context),D=t(P.scrollContext),j=t(P.boundary),H=P.target?t(P.target):F,R=0,N=!1,V=!1,W=this,M=F.data(A);y={initialize:function(){y.debug("Initializing",F),y.createID(),y.bind.events(),!y.exists()&&P.preserve&&y.create(),P.observeChanges&&y.observeChanges(),y.instantiate()},instantiate:function(){y.verbose("Storing instance",y),M=y,F.data(A,M)},observeChanges:function(){"MutationObserver"in e&&((v=new MutationObserver(y.event.documentChanged)).observe(o,{childList:!0,subtree:!0}),y.debug("Setting up mutation observer",v))},refresh:function(){P.popup?a=t(P.popup).eq(0):P.inline&&(a=H.nextAll(C.popup).eq(0),P.popup=a),P.popup?(a.addClass(T.loading),m=y.get.offsetParent(),a.removeClass(T.loading),P.movePopup&&y.has.popup()&&y.get.offsetParent(a)[0]!==m[0]&&(y.debug("Moving popup to the same offset parent as target"),a.detach().appendTo(m))):m=P.inline?y.get.offsetParent(H):y.has.popup()?y.get.offsetParent(a):l,m.is("html")&&m[0]!==l[0]&&(y.debug("Setting page as offset parent"),m=l),y.get.variation()&&y.set.variation()},reposition:function(){y.refresh(),y.set.position()},destroy:function(){y.debug("Destroying previous module"),v&&v.disconnect(),a&&!P.preserve&&y.removePopup(),clearTimeout(y.hideTimer),clearTimeout(y.showTimer),y.unbind.close(),y.unbind.events(),F.removeData(A)},event:{start:function(e){var o=t.isPlainObject(P.delay)?P.delay.show:P.delay;clearTimeout(y.hideTimer),V||(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){V=!0,y.show()},resize:function(){y.is.visible()&&y.set.position()},documentChanged:function(e){[].forEach.call(e,function(e){e.removedNodes&&[].forEach.call(e.removedNodes,function(e){(e==W||t(e).find(W).length>0)&&(y.debug("Element removed from DOM, tearing down events"),y.destroy())})})},hideGracefully:function(e){var n=t(e.target),i=t.contains(o.documentElement,e.target),r=n.closest(C.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(T.popup).data(k.activator,F).html(e),P.inline?(y.verbose("Inserting popup element inline",a),a.insertAfter(F)):(y.verbose("Appending popup element to body",a),a.appendTo(O)),y.refresh(),y.set.variation(),P.hoverable&&y.bind.popup(),P.onCreate.call(a,W)):0!==H.next(C.popup).length?(y.verbose("Pre-existing popup found"),P.inline=!0,P.popup=H.next(C.popup).data(k.activator,F),y.refresh(),P.hoverable&&y.bind.popup()):P.popup?(t(P.popup).data(k.activator,F),y.verbose("Used popup specified in settings"),y.refresh(),P.hoverable&&y.bind.popup()):y.debug("No content specified skipping display",W)},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(),!1===P.onShow.call(a,W))return void y.debug("onShow callback returned false, cancelling popup animation");P.preserve||P.popup||y.refresh(),a&&y.set.position()&&(y.save.cond