diff --git a/README.md b/README.md index 51cb75b..1e8db37 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,12 @@ new Donate({ }); ``` -# API +# API - show() - 显示模态框 - hide() - 隐藏模态框 +- destroy() - 销毁 # License -This content is released under the [MIT](http://opensource.org/licenses/MIT) License. \ No newline at end of file +This content is released under the [MIT](http://opensource.org/licenses/MIT) License. diff --git a/dist/vdonate.min.js b/dist/vdonate.min.js index bb0cbbd..cecde98 100644 --- a/dist/vdonate.min.js +++ b/dist/vdonate.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Donate",[],e):"object"==typeof exports?exports.Donate=e():t.Donate=e()}(this,function(){return function(t){function e(o){if(n[o])return n[o].exports;var a=n[o]={i:o,l:!1,exports:{}};return t[o].call(a.exports,a,a.exports,e),a.l=!0,a.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,o){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:o})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="./",e(e.s=5)}([function(t,e,n){function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i=function(){function t(t,e){for(var n=0;n\n \n

\n \n \n \n ',e='\n \n ";this.el&&(this.el.innerHTML=e),this.modal=document.createElement("div"),this.modal.innerHTML=t,this.modal.id="donate-modal-container",d.appendChild(this.modal)}},{key:"bind",value:function(){var t=this,e=this.modal.querySelectorAll(".donate-tab a"),n=this.modal.querySelectorAll(".donate-tab .donate-image");this.modal.addEventListener("click",function(o){if(o.stopPropagation(),o.target.dataset.index)return[].slice.call(e).forEach(function(t){t.classList.toggle("active")}),void[].slice.call(n).forEach(function(t){t.classList.toggle("active")});t.hide()},!1),this.el&&this.el.addEventListener("click",function(e){"donate-btn"===e.target.className&&t.show()},!1)}},{key:"show",value:function(){this.modal.classList.add("active")}},{key:"hide",value:function(){this.modal.classList.remove("active")}}]),t}();t.exports=l},function(t,e){function n(t,e){for(var n=0;n=0&&v.splice(e,1)}function r(t){var e=document.createElement("style");return e.type="text/css",a(t,e),e}function d(t){var e=document.createElement("link");return e.rel="stylesheet",a(t,e),e}function l(t,e){var n,o,a;if(e.singleton){var l=g++;n=b||(b=r(e)),o=s.bind(null,n,l,!1),a=s.bind(null,n,l,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=d(e),o=u.bind(null,n),a=function(){i(n),n.href&&URL.revokeObjectURL(n.href)}):(n=r(e),o=c.bind(null,n),a=function(){i(n)});return o(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;o(t=e)}else a()}}function s(t,e,n,o){var a=n?"":o.css;if(t.styleSheet)t.styleSheet.cssText=y(e,a);else{var i=document.createTextNode(a),r=t.childNodes;r[e]&&t.removeChild(r[e]),r.length?t.insertBefore(i,r[e]):t.appendChild(i)}}function c(t,e){var n=e.css,o=e.media;if(o&&t.setAttribute("media",o),t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}function u(t,e){var n=e.css,o=e.sourceMap;o&&(n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var a=new Blob([n],{type:"text/css"}),i=t.href;t.href=URL.createObjectURL(a),i&&URL.revokeObjectURL(i)}var p={},f=function(t){var e;return function(){return void 0===e&&(e=t.apply(this,arguments)),e}},h=f(function(){return/msie [6-9]\b/.test(self.navigator.userAgent.toLowerCase())}),m=f(function(){return document.head||document.getElementsByTagName("head")[0]}),b=null,g=0,v=[];t.exports=function(t,e){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");e=e||{},void 0===e.singleton&&(e.singleton=h()),void 0===e.insertAt&&(e.insertAt="bottom");var a=o(t);return n(a,e),function(t){for(var i=[],r=0;r\n \n

\n \n \n \n ',e='\n \n ";this.el&&(this.el.innerHTML=e),this.modal=document.createElement("div"),this.modal.innerHTML=t,this.modal.id="donate-modal-container",d.appendChild(this.modal)}},{key:"bind",value:function(){var t=this;this.btns=this.modal.querySelectorAll(".donate-tab a"),this.images=this.modal.querySelectorAll(".donate-tab .donate-image"),this.modal.addEventListener("click",this._modalEvent.bind(t),!1),this.el&&this.el.addEventListener("click",this._donateBtnEvent.bind(t),!1)}},{key:"_modalEvent",value:function(t){if(t.stopPropagation(),t.target.dataset.index)return[].slice.call(this.btns).forEach(function(t){t.classList.toggle("active")}),void[].slice.call(this.images).forEach(function(t){t.classList.toggle("active")});this.hide()}},{key:"_donateBtnEvent",value:function(t){"donate-btn"===t.target.className&&this.show()}},{key:"show",value:function(){this.modal.classList.add("active")}},{key:"hide",value:function(){this.modal.classList.remove("active")}},{key:"destroy",value:function(){var t=this;this.modal.removeEventListener("click",this._modalEvent.bind(t),!1),this.el.removeEventListener("click",this._donateBtnEvent.bind(t),!1)}}]),t}();t.exports=s},function(t,e){function n(t,e){for(var n=0;n=0&&g.splice(e,1)}function r(t){var e=document.createElement("style");return e.type="text/css",a(t,e),e}function d(t){var e=document.createElement("link");return e.rel="stylesheet",a(t,e),e}function s(t,e){var n,o,a;if(e.singleton){var s=v++;n=b||(b=r(e)),o=l.bind(null,n,s,!1),a=l.bind(null,n,s,!0)}else t.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=d(e),o=u.bind(null,n),a=function(){i(n),n.href&&URL.revokeObjectURL(n.href)}):(n=r(e),o=c.bind(null,n),a=function(){i(n)});return o(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;o(t=e)}else a()}}function l(t,e,n,o){var a=n?"":o.css;if(t.styleSheet)t.styleSheet.cssText=y(e,a);else{var i=document.createTextNode(a),r=t.childNodes;r[e]&&t.removeChild(r[e]),r.length?t.insertBefore(i,r[e]):t.appendChild(i)}}function c(t,e){var n=e.css,o=e.media;if(o&&t.setAttribute("media",o),t.styleSheet)t.styleSheet.cssText=n;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(n))}}function u(t,e){var n=e.css,o=e.sourceMap;o&&(n+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(o))))+" */");var a=new Blob([n],{type:"text/css"}),i=t.href;t.href=URL.createObjectURL(a),i&&URL.revokeObjectURL(i)}var p={},f=function(t){var e;return function(){return void 0===e&&(e=t.apply(this,arguments)),e}},h=f(function(){return/msie [6-9]\b/.test(self.navigator.userAgent.toLowerCase())}),m=f(function(){return document.head||document.getElementsByTagName("head")[0]}),b=null,v=0,g=[];t.exports=function(t,e){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");e=e||{},void 0===e.singleton&&(e.singleton=h()),void 0===e.insertAt&&(e.insertAt="bottom");var a=o(t);return n(a,e),function(t){for(var i=[],r=0;r - `; + ` var btnTpl = ` @@ -57,35 +57,39 @@ class Donate { } bind() { - var btns = this.modal.querySelectorAll('.donate-tab a'); - var images = this.modal.querySelectorAll('.donate-tab .donate-image'); - - this.modal.addEventListener('click', (e) => { - e.stopPropagation(); - var index = e.target.dataset.index; - if (index) { - [].slice.call(btns).forEach((btn) => { - btn.classList.toggle('active'); - }); - [].slice.call(images).forEach((image) => { - image.classList.toggle('active'); - }); - return; - } - - this.hide(); - - }, false); + var self = this; + this.btns = this.modal.querySelectorAll('.donate-tab a'); + this.images = this.modal.querySelectorAll('.donate-tab .donate-image'); + + this.modal.addEventListener('click', this._modalEvent.bind(self), false); if (!this.el) { return; } - this.el.addEventListener('click', (e) => { - if (e.target.className === 'donate-btn') { - this.show(); - } - }, false); + this.el.addEventListener('click', this._donateBtnEvent.bind(self), false); + } + + _modalEvent(e) { + e.stopPropagation(); + var index = e.target.dataset.index; + if (index) { + [].slice.call(this.btns).forEach((btn) => { + btn.classList.toggle('active'); + }); + [].slice.call(this.images).forEach((image) => { + image.classList.toggle('active'); + }); + return; + } + + this.hide(); + } + + _donateBtnEvent(e) { + if (e.target.className === 'donate-btn') { + this.show(); + } } show() { @@ -95,6 +99,13 @@ class Donate { hide() { this.modal.classList.remove('active'); } + + destroy() { + var self = this; + this.modal.removeEventListener('click', this._modalEvent.bind(self), false); + this.el.removeEventListener('click', this._donateBtnEvent.bind(self), false); + } + } -module.exports = Donate; \ No newline at end of file +module.exports = Donate;