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.

0 lines
8.6 KiB

10 years ago
  1. !function(a,b,c,d){a.fn.modal=function(e){var f,g=a(this),h=a(b),i=a(c),j=a("body"),k=g.selector||"",l=(new Date).getTime(),m=[],n=arguments[0],o="string"==typeof n,p=[].slice.call(arguments,1),q=b.requestAnimationFrame||b.mozRequestAnimationFrame||b.webkitRequestAnimationFrame||b.msRequestAnimationFrame||function(a){setTimeout(a,0)};return g.each(function(){var g,r,s,t,u,v,w=a.isPlainObject(e)?a.extend(!0,{},a.fn.modal.settings,e):a.extend({},a.fn.modal.settings),x=w.selector,y=w.className,z=w.namespace,A=w.error,B="."+z,C="module-"+z,D=a(this),E=a(w.context),F=D.find(x.close),G=this,H=D.data(C);v={initialize:function(){return v.verbose("Initializing dimmer",E),a.fn.dimmer===d?void v.error(A.dimmer):(t=E.dimmer({closable:!1,useCSS:!0,duration:{show:.9*w.duration,hide:1.1*w.duration}}),w.detachable&&t.dimmer("add content",D),u=t.dimmer("get dimmer"),r=D.siblings(x.modal),g=r.add(D),v.verbose("Attaching close events",F),F.on("click"+B,v.event.close),h.on("resize"+B,v.event.resize),void v.instantiate())},instantiate:function(){v.verbose("Storing instance of modal"),H=v,D.data(C,H)},destroy:function(){v.verbose("Destroying previous modal"),D.removeData(C).off(B),F.off(B),E.dimmer("destroy")},refresh:function(){v.remove.scrolling(),v.cacheSizes(),v.set.screenHeight(),v.set.type(),v.set.position()},attachEvents:function(b,c){var d=a(b);c=a.isFunction(v[c])?v[c]:v.toggle,d.size()>0?(v.debug("Attaching modal events to element",b,c),d.off(B).on("click"+B,c)):v.error(A.notFound)},event:{close:function(){v.verbose("Closing element pressed"),a(this).is(x.approve)?a.proxy(w.onApprove,G)()!==!1?v.hide():v.verbose("Approve callback returned false cancelling hide"):a(this).is(x.deny)?a.proxy(w.onDeny,G)()!==!1?v.hide():v.verbose("Deny callback returned false cancelling hide"):v.hide()},click:function(b){0===a(b.target).closest(x.modal).size()&&(v.debug("Dimmer clicked, hiding all modals"),w.allowMultiple?v.hide():v.hideAll(),b.stopImmediatePropagation())},debounce:function(a,b){clearTimeout(v.timer),v.timer=setTimeout(a,b)},keyboard:function(a){var b=a.which,c=27;b==c&&(w.closable?(v.debug("Escape key pressed hiding modal"),v.hide()):v.debug("Escape key pressed, but closable is set to false"),a.preventDefault())},resize:function(){t.dimmer("is active")&&q(v.refresh)}},toggle:function(){v.is.active()?v.hide():v.show()},show:function(b){b=a.isFunction(b)?b:function(){},v.showDimmer(),v.showModal(b)},showModal:function(b){b=a.isFunction(b)?b:function(){},v.is.active()?v.debug("Modal is already visible"):(v.cacheSizes(),v.set.position(),v.set.screenHeight(),v.set.type(),r.filter(":visible").size()>0&&!w.allowMultiple?(v.debug("Other modals visible, queueing show animation"),v.hideOthers(v.showModal)):(a.proxy(w.onShow,G)(),w.transition&&a.fn.transition!==d&&D.transition("is supported")?(v.debug("Showing modal with css animations"),D.transition(w.transition+" in",w.duration,function(){a.proxy(w.onVisible,G)(),v.set.active(),b()})):(v.debug("Showing modal with javascript"),D.fadeIn(w.duration,w.easing,function(){a.proxy(w.onVisible,G)(),v.set.active(),b()}))))},showDimmer:function(){t.dimmer("is active")?v.debug("Dimmer already visible"):(v.debug("Showing dimmer"),t.dimmer("show"))},hide:function(b){b=a.isFunction(b)?b:function(){},g.filter(":visible").size()<=1&&v.hideDimmer(),v.hideModal(b)},hideDimmer:function(){return v.is.active()?(v.debug("Hiding dimmer"),w.closable&&u.off("click"+B),void t.dimmer("hide",function(){w.transition&&a.fn.transition!==d&&D.transition("is supported")&&(D.transition("reset"),v.remove.screenHeight()),v.remove.active()})):void v.debug("Dimmer is not visible cannot hide")},hideModal:function(b){return b=a.isFunction(b)?b:function(){},v.is.active()?(v.debug("Hiding modal"),v.remove.keyboardShortcuts(),a.proxy(w.onHide,G)(),void(w.transition&&a.fn.transition!==d&&D.transition("is supported")?D.transition(w.transition+" out",w.duration,function(){a.proxy(w.onHidden,G)(),v.remove.active(),v.restore.focus(),b()}):D.fadeOut(w.duration,w.easing,function(){a.proxy(w.onHidden,G)(),v.remove.active(),v.restore.focus(),b()