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

!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.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(){r.verbose("Initializing dimmer",B),p=B.dimmer("add content",A),q=B.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()},instantiate:function(){r.verbose("Storing instance of modal"),F=r,A.data(y,F)},destroy:function(){r.verbose("Destroying previous modal"),A.off(x)},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("Close button pressed"),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&&(r.debug("Escape key pressed hiding modal"),r.hide(),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"),r.set.dimmerSettings(),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.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.save.focus(),r.set.type(),A.addClass(u.active),s.closable&&q.on("click"+x,r.event.click)},dimmerSettings:function(){r.debug("Setting dimmer settings",p),p.dimmer("setting","closable",!1).dimmer("setting","duration",{show:.95*s.duration,hide:1.05*s.duration}).dimmer("setting","onShow",r.add.keyboardShortcuts).dimmer("destroy").dimmer("initialize")},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 scrolling"),r.set.scrolling())},position:function(){r.verbose("Centering modal on page",r.cache,r.cache.height/2),r.can.fit()?A.css({top:"",marginTop:-(r.cache.height/2)}):A.css({marginTop:"1em",top:i.scrollTop()})}},setting:function(b,c){return c===d?s[b]:(a.isPlainObject(b)?a.extend(!0,s,b):s[b]=c,void 0)},internal:function(b,c){return c===d?r[b]:(a.isPlainObject(b)?a.extend(!0,r,b):r[b]=c,void 0)},debug:function(){s.debug&&(s.performance?r.performance.log(arguments):(r.debug=Function.prototype.bind.call(console.info,console,s.name+":"),r.debug.apply(console,arguments)))},verbose:function(){s.verbose&&s.debug&&(s.performance?r.performance.log(arguments):(r.verbose=Function.prototype.bind.call(console.info,console,s.name+":"),r.verbose.apply(console,arguments)))},error:function(){r.error=Function.prototype.bind.call(console.error,console,s.name+":"),r.error.apply(console,arguments)},performance:{log:function(a){var b,c,d;s.performance&&(b=(new Date).getTime(),d=j||b,c=b-d,j=b,k.push({Element:E,Name:a[0],Arguments:[].slice.call(a,1)||"","Execution Time":c})),clearTimeout(r.performance.timer),r.performance.timer=setTimeout(r.performance.display,100)},display:function(){var b=s.name+":",c=0;j=!1,clearTimeout(r.performance.timer),a.each(k,function(a,b){c+=b["Execution Time"]}),b+=" "+c+"ms",z&&(b+=" '"+z+"'"),(console.group!==d||console.table!==d)&&k.length>0&&(console.groupCollapsed(b),console.table?console.table(k):a.each(k,function(a,b){console.log(b.Name+": "+b["Execution Time"]+"ms")}),console.groupEnd()),k=[]}},invoke:function(b,c,e){var g,h,i;return c=c||n,e=E||e,"string"==typeof b&&F!==d&&(b=b.split(/[\. ]/),g=b.length-1,a.each(b,function(c,e){var f=c!=g?e+b[c+1].charAt(0).toUpperCase()+b[c+1].slice(1):b;if(a.isPlainObject(F[e])&&c!=g)F=F[e];else{if(!a.isPlainObject(F[f])||c==g)return F[e]!==d?(h=F[e],!1):F[f]!==d?(h=F[f],!1):(r.error(w.method),!1);F=F[f]}})),a.isFunction(h)?i=h.apply(e,c):h!==d&&(i=h),a.isArray(f)?f.push(i):"string"==typeof f?f=[f,i]:i!==d&&(f=i),h}},m?(F===d&&r.initialize(),r.invoke(l)):(F!==d&&r.destroy(),r.initialize())}),f!==d?f:this},a.fn.modal.settings={name:"Modal",namespace:"modal",verbose:!0,debug:!0,performance:!0,closable:!0,context:"body",duration:500,easing:"easeOutExpo",offset:0,transition:"scale",onShow:function(){},onHide:function(){},selector:{close:".close, .actions .button"},error:{method:"The method you called is not defined."},className:{active:"active",scrolling:"scrolling"}}}(jQuery,window,document);