forked from lazerwalker/DorianJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.dorian.min.js
5 lines (5 loc) · 1.62 KB
/
jquery.dorian.min.js
1
2
3
4
5
/** Dorian.js
* Michael Lazer-Walker
* https://github.com/lazerwalker/jquery-modal
* Licensed under the MIT License*/
(function(e,t,n){function u(e){var t=Object.prototype.toString.call(e);return t=="[object String]"?(val=+e.replace(/px$/,""),u(val)):t==="[object Number]"?e===e:!1}function a(t){var n=e("#"+t);return n.length||(n=e("<div id='"+t+"'></div>")),n}function f(){s=a(r.shade),o=a(r.wrapper),i=a(r.el),r.classString&&i.addClass(r.classString);var t;typeof r.html=="function"?t=r.html():t=r.html,i.html(t).appendTo(o),o.appendTo("body"),s.appendTo("body");if(r.closeButton){var n=a(r.closeButton).appendTo(i);n.on("click",c)}u(r.width)&&i.width(r.width),u(r.height)&&i.height(r.height),r.respectScroll&&o.css("margin-top",e(document).scrollTop()),r.fade&&(s.fadeIn("fast").show(),i.fadeIn("fast").show());if(r.clickToDismiss){var f="click";r.touch&&(f="touchend"),e(document).on(f,"#"+r.shade+", #"+r.wrapper,function(t){var n=e(t.target);(n.is(s)||n.is(o))&&c()})}r.keyboardDismiss&&e(document).on("keyup",l),typeof r.onCreate=="function"&&r.onCreate()}function l(e){e.keyCode===27&&c()}function c(t){r.keyboardDismiss&&e(document).off("keyup",l),h(i,r.onDestroy,t),h(s)}function h(e,t,n){function i(){e.remove(),typeof t=="function"&&t(n)}r.fade?e.fadeOut("fast",i):i()}var r={},i,s,o;e.modal=function(t){var n={html:"",classString:"",height:"",width:"",onCreate:function(){},onDestroy:function(){},fade:!0,keyboardDismiss:!0,clickToDismiss:!0,respectScroll:!0,touch:!1,shade:"modal-shade",wrapper:"modal-wrapper",el:"modal",closeButton:"modal-cancel"};r=e.extend(n,t||{}),i=e("#"+r.el),i.length?h(i,f):f()},e.modal.close=c})(jQuery,this);