-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpicomodal.js
More file actions
3 lines (3 loc) · 3.33 KB
/
picomodal.js
File metadata and controls
3 lines (3 loc) · 3.33 KB
1
2
3
// PicoModal 2.0.1 (https://github.com/Nycto/PicoModal)
// License: MIT
!function(a,b){"use strict";function c(a){return"object"==typeof Node?a instanceof Node:a&&"object"==typeof a&&"number"==typeof a.nodeType}function d(a){return"string"==typeof a}function e(){var a=[];return{watch:a.push.bind(a),trigger:function(b){for(var c=!0,d={preventDefault:function(){c=!1}},e=0;e<a.length;e++)a[e](b,d);return c}}}function f(a){this.elem=a}function g(a,b){return f.div().clazz("pico-overlay").clazz(a("overlayClass","")).stylize({display:"block",position:"fixed",top:"0px",left:"0px",height:"100%",width:"100%",zIndex:1e4}).stylize(a("overlayStyles",{opacity:.5,background:"#000"})).onClick(function(){a("overlayClose",!0)&&b()})}function h(a,b){var c=f.div().clazz("pico-content").clazz(a("modalClass","")).stylize({display:"block",position:"fixed",zIndex:10001,left:"50%",top:"50px"}).html(a("content")).onClick(function(a){var c=new f(a.target).anyAncestor(function(a){return/\bpico-close\b/.test(a.elem.className)});c&&b()}),d=a("width",c.getWidth());return c.stylize({width:d+"px",margin:"0 0 0 "+(-(d/2)+"px")}).stylize(a("modalStyles",{backgroundColor:"white",padding:"20px",borderRadius:"5px"})),c}function i(a,b){return b("closeButton",!0)?a.child().html(b("closeHtml","×")).clazz("pico-close").clazz(b("closeClass")).stylize(b("closeStyles",{borderRadius:"2px",cursor:"pointer",height:"15px",width:"15px",position:"absolute",top:"5px",right:"5px",fontSize:"16px",textAlign:"center",lineHeight:"15px",background:"#CCC"})):void 0}function j(a){return function(){return a().elem}}function k(b){function f(a,c){var d=b[a];return"function"==typeof d&&(d=d(c)),void 0===d?c:d}function k(){v().hide(),u().hide(),t.trigger(x)}function l(){s.trigger(x)&&k()}function m(a){return function(){return a.apply(this,arguments),x}}function n(a){if(!o){var b=h(f,l);o={modal:b,overlay:g(f,l),close:i(b,f)},p.trigger(x)}return o[a]}(d(b)||c(b))&&(b={content:b});var o,p=e(),q=e(),r=e(),s=e(),t=e(),u=n.bind(a,"modal"),v=n.bind(a,"overlay"),w=n.bind(a,"close"),x={modalElem:j(u),closeElem:j(w),overlayElem:j(v),show:function(){return q.trigger(x)&&(v().show(),w(),u().show(),r.trigger(x)),this},close:m(l),forceClose:m(k),destroy:function(){u=u().destroy(),v=v().destroy(),w=void 0},options:function(a){b=a},afterCreate:m(p.watch),beforeShow:m(q.watch),afterShow:m(r.watch),beforeClose:m(s.watch),afterClose:m(t.watch)};return x}f.div=function(a){var c=b.createElement("div");return(a||b.body).appendChild(c),new f(c)},f.prototype={child:function(){return f.div(this.elem)},stylize:function(a){a=a||{},"undefined"!=typeof a.opacity&&(a.filter="alpha(opacity="+100*a.opacity+")");for(var b in a)a.hasOwnProperty(b)&&(this.elem.style[b]=a[b]);return this},clazz:function(a){return this.elem.className+=" "+a,this},html:function(a){return c(a)?this.elem.appendChild(a):this.elem.innerHTML=a,this},getWidth:function(){return this.elem.clientWidth},onClick:function(a){return this.elem.attachEvent?this.elem.attachEvent("onclick",a):this.elem.addEventListener("click",a),this},destroy:function(){b.body.removeChild(this.elem)},hide:function(){this.elem.style.display="none"},show:function(){this.elem.style.display="block"},anyAncestor:function(a){for(var b=this.elem;b;){if(a(new f(b)))return!0;b=b.parentNode}return!1}},"function"==typeof a.define&&a.define.amd?a.define(function(){return k}):a.picoModal=k}(window,document);