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

11 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=(new Date).getTime(),k=[],l=arguments[0],m="string"==typeof l,n=[].slice.call(arguments,1);return g.each(function(){var o,p,q,r,s=a.isPlainObject(e)?a.extend(!0,{},a.fn.modal.settings,e):a.extend({},a.fn.modal.settings),t=s.selector,u=s.className,v=s.namespace,w=s.error,x="."+v,y="module-"+v,z=g.selector||"",A=a(this),B=a(s.context),C=g.not(A),D=A.find(t.close),E=this,F=A.data(y);r={initialize:function(){return r.verbose("Initializing dimmer",B),typeof a.fn.dimmer===d?(r.error(w.dimmer),void 0):(p=B.dimmer({closable:!1,show:.95*s.duration,hide:1.05*s.duration}).dimmer("add content",A),q=p.dimmer("get dimmer"),r.verbose("Attaching close events",D),D.on("click"+x,r.event.close),h.on("resize",function(){r.event.debounce(r.refresh,50)}),r.instantiate(),void 0)},instantiate:function(){r.verbose("Storing instance of modal"),F=r,A.data(y,F)},destroy:function(){r.verbose("Destroying previous modal"),A.removeData(y).off(x),D.off(x),B.dimmer("destroy")},refresh:function(){r.remove.scrolling(),r.cacheSizes(),r.set.type(),r.set.position()},attachEvents:function(b,c){var d=a(b);c=a.isFunction(r[c])?r[c]:r.toggle,d.size()>0?(r.debug("Attaching modal events to element",b,c),d.off(x).on("click"+x,c)):r.error(w.notFound)},event:{close:function(){r.verbose("Closing element pressed"),a(this).is(t.approve)?a.proxy(s.onApprove,E)()?r.hide():r.verbose("Approve callback returned false cancelling hide"):a(this).is(t.deny)?a.proxy(s.onDeny,E)()?r.hide():r.verbose("Deny callback returned false cancelling hide"):r.hide()},click:function(a){r.verbose("Determining if event occured on dimmer",a),0===q.find(a.target).size()&&(r.hide(),a.stopImmediatePropagation())},debounce:function(a,b){clearTimeout(r.timer),r.timer=setTimeout(a,b)},keyboard:function(a){var b=a.which,c=27;b==c&&(s.closable?(r.debug("Escape key pressed hiding modal"),r.hide()):r.debug("Escape key pressed, but closable is set to false"),a.preventDefault())},resize:function(){p.dimmer("is active")&&r.refresh()}},toggle:function(){r.is.active()?r.hide():r.show()},show:function(){r.showDimmer(),r.cacheSizes(),r.set.position(),r.hideAll(),s.transition&&a.fn.transition!==d?A.transition(s.transition+" in",s.duration,r.set.active):A.fadeIn(s.duration,s.easing,r.set.active),r.debug("Triggering dimmer"),a.proxy(s.onShow,E)()},showDimmer:function(){r.debug("Showing modal"),p.dimmer("show")},hide:function(){s.closable&&q.off("click"+x),p.dimmer("is active")&&p.dimmer("hide"),r.is.active()?(r.hideModal(),a.proxy(s.onHide,E)()):r.debug("Cannot hide modal, modal is not visible")},hideDimmer:function(){r.debug("Hiding dimmer"),p.dimmer("hide")},hideModal:function(){r.debug("Hiding modal"),r.remove.keyboardShortcuts(),s.transition&&a.fn.transition!==d?A.transition(s.transition+" out",s.duration,function(){r.remove.active(),r.restore.focus()}):A.fadeOut(s.duration,s.easing,function(){r.remove.active(),r.restore.focus()})},hideAll:function(){C.filter(":visible").modal("hide")},add:{keyboardShortcuts:function(){r.verbose("Adding keyboard shortcuts"),i.on("keyup"+x,r.event.keyboard)}},save:{focus:function(){o=a(c.activeElement).blur()}},restore:{focus:function(){o&&o.size()>0&&o.focus()}},remove:{active:function(){A.removeClass(u.active)},keyboardShortcuts:function(){r.verbose("Removing keyboard shortcuts"),i.off("keyup"+x)},scrolling:function(){p.removeClass(u.scrolling),A.removeClass(u.scrolling)}},cacheSizes:function(){r.cache={height:A.outerHeight()+s.offset,contextHeight:"body"==s.context?a(b).height():p.height()},r.debug("Caching modal and container sizes",r.cache)},can:{fit:function(){return r.cache.height<r.cache.contextHeight}},is:{active:function(){return A.hasClass(u.active)}},set:{active:function(){r.add.keyboardShortcuts(),r.save.focus(),r.set.type(),A.addClass(u.active),s.closable&&q.on("click"+x,r.event.click)},scrolling:function(){p.addClass(u.scrolling),A.addClass(u.scrolling)},type:function(){r.can.fit()?(r.verbose("Modal fits on screen"),r.remove.scrolling()):(r.verbose("Modal cannot fit on screen setting to scro