-
Notifications
You must be signed in to change notification settings - Fork 1
/
modag.min.js
4 lines (4 loc) · 6.11 KB
/
modag.min.js
1
2
3
4
/*!
* modag.js :: (c) Dan Jarvis 2013 :: License MIT
*/
!function(e,t,n){"undefined"!=typeof module&&module.exports?module.exports=n():"function"==typeof define&&define.amd?define(n):t[e]=n()}("modag",this,function(){function r(e){setTimeout(e,20)}function i(e,t){var n;e=e||{};for(n in t)"object"==typeof t[n].constructor?e[n]=this._extend(e[n],t[n]):e[n]=t[n];return e}function s(e){var t,n={};for(t in e)"object"==typeof e[t]?n[t]=s(e[t]):n[t]=e[t];return n}function o(e,t){if("undefined"==typeof e)return;if("string"==typeof e)$(t).toggleClass(e);else if(Array===e.constructor)for(var n in e)$(t).toggleClass(e[n])}function u(e,t){if("undefined"!=typeof e)for(var n in e)$(t).attr(n,e[n])}function a(e,t,n){if("undefined"!=typeof e)for(var r in e)$(t).on(r,e[r],n)}function f(t){var n,r,s=t.overlay.selector;return"undefined"!=typeof t._overlayElement?t._overlayElement:("undefined"==typeof s?s=".overlay":s[0]!="#"&&s[0]!="."&&(s="."+s),n=$(s)[0],"undefined"!=typeof n?n:(r="<div ",s[0]=="#"?r+='id="'+s.substring(1)+'"':r+='class="'+s.substring(1)+'"',r+="></div>",$("body").append(r),t.overlay.selector=s,"object"==typeof t.overlay.css&&(t.overlay.css=i(e,t.overlay.css),$(s).css(t.overlay.css)),$(s)[0]))}function l(e){return"undefined"!=typeof e._dialogElement?e._dialogElement:$(e.selector)[0]}function c(e,t,r){if("undefined"==typeof e||e.length===0)return;var i=function(){this.readyState===4&&(/^20\d$/.test(this.status)?($("body").append(this.responseText),"function"==typeof t&&t($("body").children().last())):"function"==typeof r&&r(this))},s=n();s.onreadystatechange=i,s.open("GET",e,!0),s.send("")}function h(e){var n=i(this,e||{});n.animations=i(n.animations,t),n.preload&&"undefined"!=typeof n.url&&n._preload(),n.trigger.selector&&n.trigger.event&&$(n.trigger.selector).on(n.trigger.event,function(e,t){t.show()},n)}function p(e){return new h(e)}var e={"z-index":1,display:"none",height:"100%",width:"100%",margin:0,padding:0,position:"absolute",top:"0px",left:"0px",opacity:"0.8",background:"#000"},t={overlayIn:{css:{display:"block",opacity:"0"},animate:{duration:100,opacity:"0.8"}},overlayOut:{css:{},animate:{opacity:"0",duration:250}},dialogIn:{css:{display:"block","margin-top":"-1000px"},animate:{"margin-top":"-200px",duration:300}},dialogOut:{css:{},animate:{"margin-top":"-1000px",duration:300}}},n=window.XMLHttpRequest?function(){return new XMLHttpRequest}:function(){return new ActiveXObject("Microsoft.XMLHTTP")};return h.prototype={selector:undefined,classes:[],attributes:{},preload:!0,animate:!1,animations:{overlayIn:{},overlayOut:{},dialogIn:{},dialogOut:{}},modal:!0,hideOnOverlayClick:!0,overlay:{},url:undefined,shown:undefined,hidden:undefined,trigger:{},content:{},_loaded:!1,_overlayElement:undefined,_dialogElement:undefined,show:function(){var e=this;e._dialogElement=l(e),"undefined"==typeof e._dialogElement?c(e.url,function(t){e._dialogElement=t,e._fill()},function(e){window.console&&console.log(e)}):e._loaded?e._show():e._fill(!0)},hide:function(){this._hide()},set:function(){var e,t=[],n=[].slice.call(arguments),r=function(e){return"object"==typeof e?e:{text:e}};if(n.length==1&&"object"==typeof n[0]){for(e in n)"undefined"==typeof this.content[e]?this.content[e]=r(n[e]):this.content[e]=i(this.content[e],r(n[e])),t.push(e);this._setContent(t)}else arguments.length==2&&(e=n[0],"undefined"==typeof this.content[e]?this.content[e]=r(n[1]):this.content[e]=i(this.content[e],r(n[1])),this._setContent(e))},destroy:function(){var e,t;this.trigger.selector&&this.trigger.event&&$(this.trigger.selector).off(this.trigger.event);if("object"==typeof this.content)for(e in this.content)if("object"==typeof e.events)for(t in e.events)$(e.selector,this._dialogElement).off(t);this.modal&&this._hideOverlay(this,function(){$(this._overlayElement).off("click")}),$(this._dialogElement).remove()},_setContent:function(){var e,t,n,r=[],i=[].slice.call(arguments);if(i.length>0){Array!==i[0].constructor?r.push(i[0]):r=i[0];for(e in r)t=this.content[r[e]],n=$(r[e],this._dialogElement),t.text&&$(n).text(t.text),t.html&&$(n).html(t.html),o(t.classes,n),u(t.attributes,n),a(t.events,n,this)}},_preload:function(){var e=this;r(function(){e._dialogElement=l(e),"undefined"==typeof e._dialogElement&&c(e.url,function(t){e._loaded=!0,e._dialogElement=t,e._fill()},function(e){window.console&&console.log(e)})})},_fill:function(e){var t;o(this.classes,this._dialogElement);if("object"==typeof this.content)for(t in this.content)this._setContent(t);e&&this._show()},_show:function(){var e=this;this.modal?this._showOverlay(function(){e._showDialog(function(){"function"==typeof e.shown&&e.shown(e)})}):this._showDialog(function(){"function"==typeof e.shown&&e.shown(e)})},_hide:function(){var e=this;this.modal?this._hideDialog(function(){e._hideOverlay(function(){"function"==typeof e.hidden&&e.hidden(e)})}):this._hideDialog(function(){"function"==typeof e.hidden&&e.hidden(e)})},_showOverlay:function(e){var t,n,r=this;"undefined"==typeof this._overlayElement&&(this._overlayElement=f(this)),this.hideOnOverlayClick&&$(this._overlayElement).on("click",function(){r.hide()}),this.animate?(t=s(this.animations.overlayIn.css),n=s(this.animations.overlayIn.animate),n.complete=e,$(this._overlayElement).css(t).animate(n)):($(this._overlayElement).show("block"),"function"==typeof e&&e())},_hideOverlay:function(e){var t=this,n,r,i=function(){$(t._overlayElement).hide(),"function"==typeof e&&e()};this.hideOnOverlayClick&&$(this._overlayElement).on("click",null),this.animate?(n=s(this.animations.overlayOut.css),r=s(this.animations.overlayOut.animate),r.complete=i,$(this._overlayElement).css(n).animate(r)):($(this._overlayElement).hide(),"function"==typeof e&&e())},_showDialog:function(e){var t,n;this.animate?(n=s(this.animations.dialogIn.css),t=s(this.animations.dialogIn.animate),t.complete=e,$(this._dialogElement).css(n).animate(t)):($(this._dialogElement).show("block"),"function"==typeof e&&e())},_hideDialog:function(e){var t=this,n,r,i=function(){$(t._dialogElement).hide(),"function"==typeof e&&e()};this.animate?(n=s(this.animations.dialogOut.css),r=s(this.animations.dialogOut.animate),r.complete=i,$(this._dialogElement).css(n).animate(r)):($(this._dialogElement).hide(),"function"==typeof e&&e())}},p})