syriastreet.com/assets/js/lib/remodal.js
2023-10-11 18:20:29 +00:00

1 line
No EOL
7.1 KiB
JavaScript

!function(n,e){"function"==typeof define&&define.amd?define(["jquery"],function(t){return e(n,t)}):"object"==typeof exports?e(n,require("jquery")):e(n,n.jQuery||n.Zepto)}(this,function(t,s){"use strict";var o,r,d="remodal",i=t.REMODAL_GLOBALS&&t.REMODAL_GLOBALS.NAMESPACE||d,c=s.map(["animationstart","webkitAnimationStart","MSAnimationStart","oAnimationStart"],function(t){return t+"."+i}).join(" "),l=s.map(["animationend","webkitAnimationEnd","MSAnimationEnd","oAnimationEnd"],function(t){return t+"."+i}).join(" "),p=s.extend({hashTracking:!0,closeOnConfirm:!0,closeOnCancel:!0,closeOnEscape:!0,closeOnOutsideClick:!0,modifier:"",appendTo:null},t.REMODAL_GLOBALS&&t.REMODAL_GLOBALS.DEFAULTS),m={CLOSING:"closing",CLOSED:"closed",OPENING:"opening",OPENED:"opened"},u="confirmation",f="cancellation",g=void 0!==(t=document.createElement("div").style).animationName||void 0!==t.WebkitAnimationName||void 0!==t.MozAnimationName||void 0!==t.msAnimationName||void 0!==t.OAnimationName,h=/iPad|iPhone|iPod/.test(navigator.platform);function v(t){if(g&&"none"===t.css("animation-name")&&"none"===t.css("-webkit-animation-name")&&"none"===t.css("-moz-animation-name")&&"none"===t.css("-o-animation-name")&&"none"===t.css("-ms-animation-name"))return 0;for(var n,e=t.css("animation-duration")||t.css("-webkit-animation-duration")||t.css("-moz-animation-duration")||t.css("-o-animation-duration")||t.css("-ms-animation-duration")||"0s",a=t.css("animation-delay")||t.css("-webkit-animation-delay")||t.css("-moz-animation-delay")||t.css("-o-animation-delay")||t.css("-ms-animation-delay")||"0s",i=t.css("animation-iteration-count")||t.css("-webkit-animation-iteration-count")||t.css("-moz-animation-iteration-count")||t.css("-o-animation-iteration-count")||t.css("-ms-animation-iteration-count")||"1",e=e.split(", "),a=a.split(", "),i=i.split(", "),o=0,s=e.length,r=Number.NEGATIVE_INFINITY;o<s;o++)r<(n=parseFloat(e[o])*parseInt(i[o],10)+parseFloat(a[o]))&&(r=n);return r}function $(){var t,n,e;return s(document.body).height()<=s(window).height()?0:(t=document.createElement("div"),e=document.createElement("div"),t.style.visibility="hidden",t.style.width="100px",document.body.appendChild(t),n=t.offsetWidth,t.style.overflow="scroll",e.style.width="100%",t.appendChild(e),e=e.offsetWidth,t.parentNode.removeChild(t),n-e)}function a(){var t,n,e,a;h||(t=s("html"),n=E("is-locked"),t.hasClass(n)&&(a=s(document.body),e=parseInt(a.css("padding-right"),10)-$(),a.css("padding-right",e+"px"),t.removeClass(n)))}function C(t,n,e,a){var i=E("is",n),o=[E("is",m.CLOSING),E("is",m.OPENING),E("is",m.CLOSED),E("is",m.OPENED)].join(" ");t.$bg.removeClass(o).addClass(i),t.$overlay.removeClass(o).addClass(i),t.$wrapper.removeClass(o).addClass(i),t.$modal.removeClass(o).addClass(i),t.state=n,e||t.$modal.trigger({type:n,reason:a},[{reason:a}])}function y(t,n,e){function a(t){t.target===this&&o++}function i(t){t.target===this&&0==--o&&(s.each(["$bg","$overlay","$wrapper","$modal"],function(t,n){e[n].off(c+" "+l)}),n())}var o=0;s.each(["$bg","$overlay","$wrapper","$modal"],function(t,n){e[n].on(c,a).on(l,i)}),t(),0===v(e.$bg)&&0===v(e.$overlay)&&0===v(e.$wrapper)&&0===v(e.$modal)&&(s.each(["$bg","$overlay","$wrapper","$modal"],function(t,n){e[n].off(c+" "+l)}),n())}function O(e){e.state!==m.CLOSED&&(s.each(["$bg","$overlay","$wrapper","$modal"],function(t,n){e[n].off(c+" "+l)}),e.$bg.removeClass(e.settings.modifier),e.$overlay.removeClass(e.settings.modifier).hide(),e.$wrapper.hide(),a(),C(e,m.CLOSED,!0))}function E(){for(var t=i,n=0;n<arguments.length;++n)t+="-"+arguments[n];return t}function n(){var t,n=location.hash.replace("#","");if(n){try{t=s("[data-"+d+'-id="'+n+'"]')}catch(t){}t&&t.length&&(n=s[d].lookup[t.data(d)])&&n.settings.hashTracking&&n.open()}else o&&o.state===m.OPENED&&o.settings.hashTracking&&o.close()}function w(t,n){var e=s(document.body),a=this;a.settings=s.extend({},p,n),a.index=s[d].lookup.push(a)-1,a.state=m.CLOSED,a.$overlay=s("."+E("overlay")),null!==a.settings.appendTo&&a.settings.appendTo.length&&(e=s(a.settings.appendTo)),a.$overlay.length||(a.$overlay=s("<div>").addClass(E("overlay")+" "+E("is",m.CLOSED)).hide(),e.append(a.$overlay)),a.$bg=s("."+E("bg")).addClass(E("is",m.CLOSED)),a.$modal=t.addClass(i+" "+E("is-initialized")+" "+a.settings.modifier+" "+E("is",m.CLOSED)).attr("tabindex","-1"),a.$wrapper=s("<div>").addClass(E("wrapper")+" "+a.settings.modifier+" "+E("is",m.CLOSED)).hide().append(a.$modal),e.append(a.$wrapper),a.$wrapper.on("click."+i,"[data-"+d+'-action="close"]',function(t){t.preventDefault(),a.close()}),a.$wrapper.on("click."+i,"[data-"+d+'-action="cancel"]',function(t){t.preventDefault(),a.$modal.trigger(f),a.settings.closeOnCancel&&a.close(f)}),a.$wrapper.on("click."+i,"[data-"+d+'-action="confirm"]',function(t){t.preventDefault(),a.$modal.trigger(u),a.settings.closeOnConfirm&&a.close(u)}),a.$wrapper.on("click."+i,function(t){s(t.target).hasClass(E("wrapper"))&&a.settings.closeOnOutsideClick&&a.close()})}w.prototype.open=function(){var t,n,e,a,i=this;i.state!==m.OPENING&&i.state!==m.CLOSING&&((a=i.$modal.attr("data-"+d+"-id"))&&i.settings.hashTracking&&(r=s(window).scrollTop(),location.hash=a),o&&o!==i&&O(o),o=i,h||(a=s("html"),t=E("is-locked"),a.hasClass(t))||(e=s(document.body),n=parseInt(e.css("padding-right"),10)+$(),e.css("padding-right",n+"px"),a.addClass(t)),i.$bg.addClass(i.settings.modifier),i.$overlay.addClass(i.settings.modifier).show(),i.$wrapper.show().scrollTop(0),i.$modal.focus(),y(function(){C(i,m.OPENING)},function(){C(i,m.OPENED)},i))},w.prototype.close=function(t){var n=this;n.state!==m.OPENING&&n.state!==m.CLOSING&&(n.settings.hashTracking&&n.$modal.attr("data-"+d+"-id")===location.hash.substr(1)&&(location.hash="",s(window).scrollTop(r)),y(function(){C(n,m.CLOSING,!1,t)},function(){n.$bg.removeClass(n.settings.modifier),n.$overlay.removeClass(n.settings.modifier).hide(),n.$wrapper.hide(),a(),C(n,m.CLOSED,!1,t)},n))},w.prototype.getState=function(){return this.state},w.prototype.destroy=function(){var t=s[d].lookup;O(this),this.$wrapper.remove(),delete t[this.index],0===s.grep(t,function(t){return!!t}).length&&(this.$overlay.remove(),this.$bg.removeClass(E("is",m.CLOSING)+" "+E("is",m.OPENING)+" "+E("is",m.CLOSED)+" "+E("is",m.OPENED)))},s[d]={lookup:[]},s.fn[d]=function(e){var a,i;return this.each(function(t,n){null==(i=s(n)).data(d)?(a=new w(i,e),i.data(d,a.index),a.settings.hashTracking&&i.attr("data-"+d+"-id")===location.hash.substr(1)&&a.open()):a=s[d].lookup[i.data(d)]}),a},s(document).ready(function(){s(document).on("click","[data-"+d+"-target]",function(t){t.preventDefault();t=t.currentTarget.getAttribute("data-"+d+"-target"),t=s("[data-"+d+'-id="'+t+'"]');s[d].lookup[t.data(d)].open()}),s(document).find("."+i).each(function(t,n){var n=s(n),e=n.data(d+"-options");e?("string"==typeof e||e instanceof String)&&(e=function(t){for(var n,e,a={},i=0,o=(n=(t=t.replace(/\s*:\s*/g,":").replace(/\s*,\s*/g,",")).split(",")).length;i<o;i++)n[i]=n[i].split(":"),("string"==typeof(e="string"==typeof(e=n[i][1])||e instanceof String?"true"===e||"false"!==e&&e:e)||e instanceof String)&&(e=isNaN(e)?e:+e),a[n[i][0]]=e;return a}(e)):e={},n[d](e)}),s(document).on("keydown."+i,function(t){o&&o.settings.closeOnEscape&&o.state===m.OPENED&&27===t.keyCode&&o.close()}),s(window).on("hashchange."+i,n)})});