jqmodal.js 3.3 KB

12
  1. !function(e,o){"use strict";"function"==typeof define&&define.amd?define(["jquery"],function(t){return o(t,e.document)}):"object"==typeof module&&module.exports?module.exports=function(t,e){return t||(t=window),void 0===e&&(e="undefined"!=typeof window?require("jquery"):require("jquery")(t)),o(e,t.document),e}:o(jQuery,e.document)}("undefined"!=typeof window?window:this,function(h,e){"use strict";var m,o=0,l=[],a=function(t){try{h(":input:visible",t.w).first().focus()}catch(t){}},w=function(t){a(t)},n=function(t){var e=m[l[l.length-1]],o=!h(t.target).parents(".jqmID"+e.s)[0],n=h(t.target).offset(),i=void 0!==t.pageX?t.pageX:n.left,s=void 0!==t.pageY?t.pageY:n.top,r=function(){var o=!1;return h(".jqmID"+e.s).each(function(){var t=h(this),e=t.offset();if(e.top<=s&&s<=e.top+t.height()&&e.left<=i&&i<=e.left+t.width())return!(o=!0)}),o};return!("mousedown"===t.type||!r())||("mousedown"===t.type&&o&&(r()&&(o=!1),o&&!h(t.target).is(":input")&&a(e)),!o)},p=function(t){h(e)[t]("keypress keydown mousedown",n)},i=function(t,e,o){return t.each(function(){var t=this._jqm;h(e).each(function(){this[o]||(this[o]=[],h(this).click(function(){var t,e,o,n=["jqmShow","jqmHide"];for(t=0;t<n.length;t++)for(o in this[e=n[t]])this[e].hasOwnProperty(o)&&m[this[e][o]]&&m[this[e][o]].w[e](this);return!1})),this[o].push(t)})})};h.fn.jqm=function(t){var e={overlay:50,closeoverlay:!1,overlayClass:"jqmOverlay",closeClass:"jqmClose",trigger:".jqModal",ajax:!1,ajaxText:"",target:!1,modal:!1,toTop:!1,onShow:!1,onHide:!1,onLoad:!1};return this.each(function(){if(this._jqm)return m[this._jqm].c=h.extend({},m[this._jqm].c,t),m[this._jqm].c;o++,this._jqm=o,m[o]={c:h.extend(e,h.jqm.params,t),a:!1,w:h(this).addClass("jqmID"+o),s:o},e.trigger&&h(this).jqmAddTrigger(e.trigger)})},h.fn.jqmAddClose=function(t){return i(this,t,"jqmHide")},h.fn.jqmAddTrigger=function(t){return i(this,t,"jqmShow")},h.fn.jqmShow=function(t){return this.each(function(){h.jqm.open(this._jqm,t)})},h.fn.jqmHide=function(t){return this.each(function(){h.jqm.close(this._jqm,t)})},h.jqm={hash:{},open:function(t,e){var o,n,i,s,r,a=m[t],d=a.c,u=a.w.parent().offset(),c="."+d.closeClass,f=parseInt(a.w.css("z-index"),10);return f=0<f?f:3e3,o=h("<div></div>").css({height:"100%",width:"100%",position:"fixed",left:0,top:0,"z-index":f-1,opacity:d.overlay/100}),a.a||(a.t=e,a.a=!0,a.w.css("z-index",f),h(a.w[0].ownerDocument).data("ui-dialog-overlays")&&a.w.addClass("ui-dialog"),d.modal?(l[0]||setTimeout(function(){p("bind")},1),l.push(t)):0<d.overlay?d.closeoverlay&&a.w.jqmAddClose(o):o=!1,a.o=!!o&&o.addClass(d.overlayClass).prependTo("body"),d.ajax?(n=d.target||a.w,i=d.ajax,n="string"==typeof n?h(n,a.w):h(n),i="@"===i.substr(0,1)?h(e).attr(i.substring(1)):i,n.html(d.ajaxText).load(i,function(){d.onLoad&&d.onLoad.call(this,a),c&&a.w.jqmAddClose(h(c,a.w)),w(a)})):c&&a.w.jqmAddClose(h(c,a.w)),d.toTop&&a.o&&(u=a.w.parent().offset(),s=parseFloat(a.w.css("left")||0),r=parseFloat(a.w.css("top")||0),a.w.before('<span id="jqmP'+a.w[0]._jqm+'"></span>').insertAfter(a.o),a.w.css({top:u.top+r,left:u.left+s})),d.onShow?d.onShow(a):a.w.show(),w(a)),!1},close:function(t){var e=m[t];return e.a&&(e.a=!1,l[0]&&(l.pop(),l[0]||p("unbind")),e.c.toTop&&e.o&&h("#jqmP"+e.w[0]._jqm).after(e.w).remove(),e.c.onHide?e.c.onHide(e):(e.w.hide(),e.o&&e.o.remove())),!1},params:{}},m=h.jqm.hash});
  2. //# sourceMappingURL=jqmodal.js.map