vue-promise-btn
Advanced tools
Comparing version 1.1.0 to 1.2.0
# Changelog | ||
## 1.2.0 | ||
- Add support for vue@2.6+ | ||
@@ -3,0 +5,0 @@ ## 1.1.0 |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var Vue=_interopDefault(require("vue")),Spinner={render:function(){var e=this.$createElement;return(this._self._c||e)("span",{staticClass:"spinner",style:this.style})},staticRenderFns:[],_scopeId:"data-v-39432f99",name:"Spinner",props:{color:{type:String,default:"#3498db"},size:{type:Number,default:18},width:{type:Number,default:4},duration:{type:String,default:"1s"}},computed:{style:function(){return{borderTopColor:this.color,width:this.size+"px",height:this.size+"px",borderWidth:this.width+"px",animationDuration:this.duration}}}},isPromise=function(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then},isString=function(e){return"string"==typeof e},isObject=function(e){return e===Object(e)},pluginElPropName="$promiseBtnId",elementId=0,stringHTMLRenderer=function(e){return'\n <span class="promise-btn__spinner-wrapper" \n :class="{[options.spinnerHiddenClass]: !show || false}"\n v-show="options.autoHideSpinnerWrapper ? show : true"\n >\n '+e.loader+"\n </span>"},componentRenderer=function(e){return function(n){var t;return n("span",{class:(t={"promise-btn__spinner-wrapper":!0},t[e.spinnerHiddenClass]=!!e.spinnerHiddenClass&&!this.show,t),directives:[{name:"show",value:!e.autoHideSpinnerWrapper||this.show}]},[n(e.loader)])}},initSpinner=function(e,n,t,i){var r=document.createElement("SPAN");e.appendChild(r);var s={el:r,data:{show:!1},props:{parent:{type:Object,default:function(){return t.context}}},render:n.componentRenderer(n)};if(i){var o=n.stringHTMLRenderer(n),a=Vue.compile(o);s=Object.assign({},s,{data:Object.assign({},s.data,{options:n}),render:a.render,staticRenderFns:a.staticRenderFns})}return s},enableBtn=function(e,n){e.getAttribute("disabled")&&n.disableBtn&&e.removeAttribute("disabled"),e.classList.remove(n.btnLoadingClass)},disableBtn=function(e,n){n.disableBtn&&e.setAttribute("disabled","disabled"),e.classList.add(n.btnLoadingClass)},setupVuePromiseBtn=function(e){var n={listeners:{},init:function(t,i,r){var s=isObject(i.value),o=t[pluginElPropName]=elementId++,a=s?i.value:{},d=Object.assign({},e,a),p=r.data.on&&r.data.on[d.action]&&r.data.on[d.action]._withTask,u=isString(d.loader),l=t,c=null,f=!1,m=!1,b=function(){f&&m&&(c.show=!1,f=!1,m=!1,enableBtn(l,d))},h=function(){w=!1,d.showSpinner&&(m=!0,b())};if(n.listeners[o]={el:t,eventType:d.action,handler:p},t.removeEventListener(d.action,p),!p)throw new Error("Please, provide proper handler/action for promise-btn");if("submit"===d.action&&!(l=t.querySelector('[type="submit"]')))throw new Error("No submit button found");if(d.showSpinner){var v=initSpinner(l,d,r,u);c=new Vue(v)}var w=!1;n.listener=function(e){if(!d.disableBtn||!w){var n=p(e);isPromise(n)&&(w=!0,disableBtn(l,d),d.showSpinner&&(c.show=!0,setTimeout(function(){f=!0,b()},d.minTimeout)),n.then(h).catch(function(e){throw h(),e}))}}},bind:function(e,t,i){var r;(r=t.def).init.apply(r,arguments);var s=e[pluginElPropName],o=n.listeners[s].eventType;e.addEventListener(o,n.listener)},unbind:function(e,t){var i=e[pluginElPropName],r=n.listeners[i].eventType;e.removeEventListener(r,n.listener),delete n.listeners[i],delete e[pluginElPropName]}};return n},defaultOptions={btnLoadingClass:"loading",showSpinner:!0,action:"click",disableBtn:!0,stringHTMLRenderer:stringHTMLRenderer,componentRenderer:componentRenderer,minTimeout:400,spinnerHiddenClass:"hidden",autoHideSpinnerWrapper:!1,loader:Spinner};function install(e,n){var t=Object.assign({},defaultOptions,n);e.directive("promise-btn",setupVuePromiseBtn(t))}var main={install:install,Spinner:Spinner,setupVuePromiseBtn:setupVuePromiseBtn};module.exports=main; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var Vue=_interopDefault(require("vue")),Spinner={render:function(){var e=this.$createElement;return(this._self._c||e)("span",{staticClass:"spinner",style:this.style})},staticRenderFns:[],_scopeId:"data-v-39432f99",name:"Spinner",props:{color:{type:String,default:"#3498db"},size:{type:Number,default:18},width:{type:Number,default:4},duration:{type:String,default:"1s"}},computed:{style:function(){return{borderTopColor:this.color,width:this.size+"px",height:this.size+"px",borderWidth:this.width+"px",animationDuration:this.duration}}}},isPromise=function(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then},isString=function(e){return"string"==typeof e},isObject=function(e){return e===Object(e)},pluginElPropName="$promiseBtnId",elementId=0,stringHTMLRenderer=function(e){return'\n <span class="promise-btn__spinner-wrapper" \n :class="{[options.spinnerHiddenClass]: !show || false}"\n v-show="options.autoHideSpinnerWrapper ? show : true"\n >\n '+e.loader+"\n </span>"},componentRenderer=function(e){return function(n){var t;return n("span",{class:(t={"promise-btn__spinner-wrapper":!0},t[e.spinnerHiddenClass]=!!e.spinnerHiddenClass&&!this.show,t),directives:[{name:"show",value:!e.autoHideSpinnerWrapper||this.show}]},[n(e.loader)])}},initSpinner=function(e,n,t,i){var r=document.createElement("SPAN");e.appendChild(r);var s={el:r,data:{show:!1},props:{parent:{type:Object,default:function(){return t.context}}},render:n.componentRenderer(n)};if(i){var o=n.stringHTMLRenderer(n),a=Vue.compile(o);s=Object.assign({},s,{data:Object.assign({},s.data,{options:n}),render:a.render,staticRenderFns:a.staticRenderFns})}return s},enableBtn=function(e,n){e.getAttribute("disabled")&&n.disableBtn&&e.removeAttribute("disabled"),e.classList.remove(n.btnLoadingClass)},disableBtn=function(e,n){n.disableBtn&&e.setAttribute("disabled","disabled"),e.classList.add(n.btnLoadingClass)},setupVuePromiseBtn=function(e){var n={listeners:{},init:function(t,i,r){var s=isObject(i.value),o=t[pluginElPropName]=elementId++,a=s?i.value:{},p=Object.assign({},e,a),d=r.data.on&&r.data.on[p.action]&&(r.data.on[p.action]._withTask||r.data.on[p.action]._wrapper),u=isString(p.loader),l=t,c=null,f=!1,m=!1,b=function(){f&&m&&(c.show=!1,f=!1,m=!1,enableBtn(l,p))},h=function(){w=!1,p.showSpinner&&(m=!0,b())};if(n.listeners[o]={el:t,eventType:p.action,handler:d},t.removeEventListener(p.action,d),!d)throw new Error("Please, provide proper handler/action for promise-btn");if("submit"===p.action&&!(l=t.querySelector('[type="submit"]')))throw new Error("No submit button found");if(p.showSpinner){var v=initSpinner(l,p,r,u);c=new Vue(v)}var w=!1;n.listener=function(e){if(!p.disableBtn||!w){var n=d(e),t="function"==typeof n?function(e){for(var n=e;"function"==typeof n;)n=n();return n}(n):n;isPromise(t)&&(w=!0,disableBtn(l,p),p.showSpinner&&(c.show=!0,setTimeout(function(){f=!0,b()},p.minTimeout)),t.then(h).catch(function(e){throw h(),e}))}}},bind:function(e,t,i){var r;(r=t.def).init.apply(r,arguments);var s=e[pluginElPropName],o=n.listeners[s].eventType;e.addEventListener(o,n.listener)},unbind:function(e,t){var i=e[pluginElPropName],r=n.listeners[i].eventType;e.removeEventListener(r,n.listener),delete n.listeners[i],delete e[pluginElPropName]}};return n},defaultOptions={btnLoadingClass:"loading",showSpinner:!0,action:"click",disableBtn:!0,stringHTMLRenderer:stringHTMLRenderer,componentRenderer:componentRenderer,minTimeout:400,spinnerHiddenClass:"hidden",autoHideSpinnerWrapper:!1,loader:Spinner};function install(e,n){var t=Object.assign({},defaultOptions,n);e.directive("promise-btn",setupVuePromiseBtn(t))}var main={install:install,Spinner:Spinner,setupVuePromiseBtn:setupVuePromiseBtn};module.exports=main; |
@@ -1,1 +0,1 @@ | ||
import Vue from"vue";var Spinner={render:function(){var e=this.$createElement;return(this._self._c||e)("span",{staticClass:"spinner",style:this.style})},staticRenderFns:[],_scopeId:"data-v-39432f99",name:"Spinner",props:{color:{type:String,default:"#3498db"},size:{type:Number,default:18},width:{type:Number,default:4},duration:{type:String,default:"1s"}},computed:{style:function(){return{borderTopColor:this.color,width:this.size+"px",height:this.size+"px",borderWidth:this.width+"px",animationDuration:this.duration}}}},isPromise=function(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then},isString=function(e){return"string"==typeof e},isObject=function(e){return e===Object(e)},pluginElPropName="$promiseBtnId",elementId=0,stringHTMLRenderer=function(e){return'\n <span class="promise-btn__spinner-wrapper" \n :class="{[options.spinnerHiddenClass]: !show || false}"\n v-show="options.autoHideSpinnerWrapper ? show : true"\n >\n '+e.loader+"\n </span>"},componentRenderer=function(e){return function(n){var t;return n("span",{class:(t={"promise-btn__spinner-wrapper":!0},t[e.spinnerHiddenClass]=!!e.spinnerHiddenClass&&!this.show,t),directives:[{name:"show",value:!e.autoHideSpinnerWrapper||this.show}]},[n(e.loader)])}},initSpinner=function(e,n,t,i){var r=document.createElement("SPAN");e.appendChild(r);var s={el:r,data:{show:!1},props:{parent:{type:Object,default:function(){return t.context}}},render:n.componentRenderer(n)};if(i){var o=n.stringHTMLRenderer(n),a=Vue.compile(o);s=Object.assign({},s,{data:Object.assign({},s.data,{options:n}),render:a.render,staticRenderFns:a.staticRenderFns})}return s},enableBtn=function(e,n){e.getAttribute("disabled")&&n.disableBtn&&e.removeAttribute("disabled"),e.classList.remove(n.btnLoadingClass)},disableBtn=function(e,n){n.disableBtn&&e.setAttribute("disabled","disabled"),e.classList.add(n.btnLoadingClass)},setupVuePromiseBtn=function(e){var n={listeners:{},init:function(t,i,r){var s=isObject(i.value),o=t[pluginElPropName]=elementId++,a=s?i.value:{},d=Object.assign({},e,a),p=r.data.on&&r.data.on[d.action]&&r.data.on[d.action]._withTask,l=isString(d.loader),u=t,c=null,f=!1,m=!1,b=function(){f&&m&&(c.show=!1,f=!1,m=!1,enableBtn(u,d))},h=function(){w=!1,d.showSpinner&&(m=!0,b())};if(n.listeners[o]={el:t,eventType:d.action,handler:p},t.removeEventListener(d.action,p),!p)throw new Error("Please, provide proper handler/action for promise-btn");if("submit"===d.action&&!(u=t.querySelector('[type="submit"]')))throw new Error("No submit button found");if(d.showSpinner){var v=initSpinner(u,d,r,l);c=new Vue(v)}var w=!1;n.listener=function(e){if(!d.disableBtn||!w){var n=p(e);isPromise(n)&&(w=!0,disableBtn(u,d),d.showSpinner&&(c.show=!0,setTimeout(function(){f=!0,b()},d.minTimeout)),n.then(h).catch(function(e){throw h(),e}))}}},bind:function(e,t,i){var r;(r=t.def).init.apply(r,arguments);var s=e[pluginElPropName],o=n.listeners[s].eventType;e.addEventListener(o,n.listener)},unbind:function(e,t){var i=e[pluginElPropName],r=n.listeners[i].eventType;e.removeEventListener(r,n.listener),delete n.listeners[i],delete e[pluginElPropName]}};return n},defaultOptions={btnLoadingClass:"loading",showSpinner:!0,action:"click",disableBtn:!0,stringHTMLRenderer:stringHTMLRenderer,componentRenderer:componentRenderer,minTimeout:400,spinnerHiddenClass:"hidden",autoHideSpinnerWrapper:!1,loader:Spinner};function install(e,n){var t=Object.assign({},defaultOptions,n);e.directive("promise-btn",setupVuePromiseBtn(t))}var main={install:install,Spinner:Spinner,setupVuePromiseBtn:setupVuePromiseBtn};export default main; | ||
import Vue from"vue";var Spinner={render:function(){var e=this.$createElement;return(this._self._c||e)("span",{staticClass:"spinner",style:this.style})},staticRenderFns:[],_scopeId:"data-v-39432f99",name:"Spinner",props:{color:{type:String,default:"#3498db"},size:{type:Number,default:18},width:{type:Number,default:4},duration:{type:String,default:"1s"}},computed:{style:function(){return{borderTopColor:this.color,width:this.size+"px",height:this.size+"px",borderWidth:this.width+"px",animationDuration:this.duration}}}},isPromise=function(e){return!!e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof e.then},isString=function(e){return"string"==typeof e},isObject=function(e){return e===Object(e)},pluginElPropName="$promiseBtnId",elementId=0,stringHTMLRenderer=function(e){return'\n <span class="promise-btn__spinner-wrapper" \n :class="{[options.spinnerHiddenClass]: !show || false}"\n v-show="options.autoHideSpinnerWrapper ? show : true"\n >\n '+e.loader+"\n </span>"},componentRenderer=function(e){return function(n){var t;return n("span",{class:(t={"promise-btn__spinner-wrapper":!0},t[e.spinnerHiddenClass]=!!e.spinnerHiddenClass&&!this.show,t),directives:[{name:"show",value:!e.autoHideSpinnerWrapper||this.show}]},[n(e.loader)])}},initSpinner=function(e,n,t,i){var r=document.createElement("SPAN");e.appendChild(r);var s={el:r,data:{show:!1},props:{parent:{type:Object,default:function(){return t.context}}},render:n.componentRenderer(n)};if(i){var o=n.stringHTMLRenderer(n),a=Vue.compile(o);s=Object.assign({},s,{data:Object.assign({},s.data,{options:n}),render:a.render,staticRenderFns:a.staticRenderFns})}return s},enableBtn=function(e,n){e.getAttribute("disabled")&&n.disableBtn&&e.removeAttribute("disabled"),e.classList.remove(n.btnLoadingClass)},disableBtn=function(e,n){n.disableBtn&&e.setAttribute("disabled","disabled"),e.classList.add(n.btnLoadingClass)},setupVuePromiseBtn=function(e){var n={listeners:{},init:function(t,i,r){var s=isObject(i.value),o=t[pluginElPropName]=elementId++,a=s?i.value:{},p=Object.assign({},e,a),d=r.data.on&&r.data.on[p.action]&&(r.data.on[p.action]._withTask||r.data.on[p.action]._wrapper),u=isString(p.loader),l=t,c=null,f=!1,m=!1,b=function(){f&&m&&(c.show=!1,f=!1,m=!1,enableBtn(l,p))},h=function(){w=!1,p.showSpinner&&(m=!0,b())};if(n.listeners[o]={el:t,eventType:p.action,handler:d},t.removeEventListener(p.action,d),!d)throw new Error("Please, provide proper handler/action for promise-btn");if("submit"===p.action&&!(l=t.querySelector('[type="submit"]')))throw new Error("No submit button found");if(p.showSpinner){var v=initSpinner(l,p,r,u);c=new Vue(v)}var w=!1;n.listener=function(e){if(!p.disableBtn||!w){var n=d(e),t="function"==typeof n?function(e){for(var n=e;"function"==typeof n;)n=n();return n}(n):n;isPromise(t)&&(w=!0,disableBtn(l,p),p.showSpinner&&(c.show=!0,setTimeout(function(){f=!0,b()},p.minTimeout)),t.then(h).catch(function(e){throw h(),e}))}}},bind:function(e,t,i){var r;(r=t.def).init.apply(r,arguments);var s=e[pluginElPropName],o=n.listeners[s].eventType;e.addEventListener(o,n.listener)},unbind:function(e,t){var i=e[pluginElPropName],r=n.listeners[i].eventType;e.removeEventListener(r,n.listener),delete n.listeners[i],delete e[pluginElPropName]}};return n},defaultOptions={btnLoadingClass:"loading",showSpinner:!0,action:"click",disableBtn:!0,stringHTMLRenderer:stringHTMLRenderer,componentRenderer:componentRenderer,minTimeout:400,spinnerHiddenClass:"hidden",autoHideSpinnerWrapper:!1,loader:Spinner};function install(e,n){var t=Object.assign({},defaultOptions,n);e.directive("promise-btn",setupVuePromiseBtn(t))}var main={install:install,Spinner:Spinner,setupVuePromiseBtn:setupVuePromiseBtn};export default main; |
@@ -1,1 +0,1 @@ | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("vue")):"function"==typeof define&&define.amd?define(["vue"],n):e.VuePromiseBtn=n(e.Vue)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var n={render:function(){var e=this.$createElement;return(this._self._c||e)("span",{staticClass:"spinner",style:this.style})},staticRenderFns:[],_scopeId:"data-v-39432f99",name:"Spinner",props:{color:{type:String,default:"#3498db"},size:{type:Number,default:18},width:{type:Number,default:4},duration:{type:String,default:"1s"}},computed:{style:function(){return{borderTopColor:this.color,width:this.size+"px",height:this.size+"px",borderWidth:this.width+"px",animationDuration:this.duration}}}},t=0,i=function(n){var i={listeners:{},init:function(r,s,o){var a,d=(a=s.value)===Object(a),p=r.$promiseBtnId=t++,u=d?s.value:{},l=Object.assign({},n,u),c=o.data.on&&o.data.on[l.action]&&o.data.on[l.action]._withTask,f=function(e){return"string"==typeof e}(l.loader),h=r,b=null,m=!1,v=!1,w=function(){m&&v&&(b.show=!1,m=!1,v=!1,function(e,n){e.getAttribute("disabled")&&n.disableBtn&&e.removeAttribute("disabled"),e.classList.remove(n.btnLoadingClass)}(h,l))},y=function(){S=!1,l.showSpinner&&(v=!0,w())};if(i.listeners[p]={el:r,eventType:l.action,handler:c},r.removeEventListener(l.action,c),!c)throw new Error("Please, provide proper handler/action for promise-btn");if("submit"===l.action&&!(h=r.querySelector('[type="submit"]')))throw new Error("No submit button found");if(l.showSpinner){var g=function(n,t,i,r){var s=document.createElement("SPAN");n.appendChild(s);var o={el:s,data:{show:!1},props:{parent:{type:Object,default:function(){return i.context}}},render:t.componentRenderer(t)};if(r){var a=t.stringHTMLRenderer(t),d=e.compile(a);o=Object.assign({},o,{data:Object.assign({},o.data,{options:t}),render:d.render,staticRenderFns:d.staticRenderFns})}return o}(h,l,o,f);b=new e(g)}var S=!1;i.listener=function(e){if(!l.disableBtn||!S){var n,t=c(e);!(n=t)||"object"!=typeof n&&"function"!=typeof n||"function"!=typeof n.then||(S=!0,function(e,n){n.disableBtn&&e.setAttribute("disabled","disabled"),e.classList.add(n.btnLoadingClass)}(h,l),l.showSpinner&&(b.show=!0,setTimeout(function(){m=!0,w()},l.minTimeout)),t.then(y).catch(function(e){throw y(),e}))}}},bind:function(e,n,t){var r;(r=n.def).init.apply(r,arguments);var s=e.$promiseBtnId,o=i.listeners[s].eventType;e.addEventListener(o,i.listener)},unbind:function(e,n){var t=e.$promiseBtnId,r=i.listeners[t].eventType;e.removeEventListener(r,i.listener),delete i.listeners[t],delete e.$promiseBtnId}};return i},r={btnLoadingClass:"loading",showSpinner:!0,action:"click",disableBtn:!0,stringHTMLRenderer:function(e){return'\n <span class="promise-btn__spinner-wrapper" \n :class="{[options.spinnerHiddenClass]: !show || false}"\n v-show="options.autoHideSpinnerWrapper ? show : true"\n >\n '+e.loader+"\n </span>"},componentRenderer:function(e){return function(n){var t;return n("span",{class:(t={"promise-btn__spinner-wrapper":!0},t[e.spinnerHiddenClass]=!!e.spinnerHiddenClass&&!this.show,t),directives:[{name:"show",value:!e.autoHideSpinnerWrapper||this.show}]},[n(e.loader)])}},minTimeout:400,spinnerHiddenClass:"hidden",autoHideSpinnerWrapper:!1,loader:n};return{install:function(e,n){var t=Object.assign({},r,n);e.directive("promise-btn",i(t))},Spinner:n,setupVuePromiseBtn:i}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("vue")):"function"==typeof define&&define.amd?define(["vue"],n):e.VuePromiseBtn=n(e.Vue)}(this,function(e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var n={render:function(){var e=this.$createElement;return(this._self._c||e)("span",{staticClass:"spinner",style:this.style})},staticRenderFns:[],_scopeId:"data-v-39432f99",name:"Spinner",props:{color:{type:String,default:"#3498db"},size:{type:Number,default:18},width:{type:Number,default:4},duration:{type:String,default:"1s"}},computed:{style:function(){return{borderTopColor:this.color,width:this.size+"px",height:this.size+"px",borderWidth:this.width+"px",animationDuration:this.duration}}}},t=0,i=function(n){var i={listeners:{},init:function(r,s,o){var a,d=(a=s.value)===Object(a),p=r.$promiseBtnId=t++,u=d?s.value:{},c=Object.assign({},n,u),l=o.data.on&&o.data.on[c.action]&&(o.data.on[c.action]._withTask||o.data.on[c.action]._wrapper),f=function(e){return"string"==typeof e}(c.loader),h=r,b=null,m=!1,v=!1,w=function(){m&&v&&(b.show=!1,m=!1,v=!1,function(e,n){e.getAttribute("disabled")&&n.disableBtn&&e.removeAttribute("disabled"),e.classList.remove(n.btnLoadingClass)}(h,c))},y=function(){S=!1,c.showSpinner&&(v=!0,w())};if(i.listeners[p]={el:r,eventType:c.action,handler:l},r.removeEventListener(c.action,l),!l)throw new Error("Please, provide proper handler/action for promise-btn");if("submit"===c.action&&!(h=r.querySelector('[type="submit"]')))throw new Error("No submit button found");if(c.showSpinner){var g=function(n,t,i,r){var s=document.createElement("SPAN");n.appendChild(s);var o={el:s,data:{show:!1},props:{parent:{type:Object,default:function(){return i.context}}},render:t.componentRenderer(t)};if(r){var a=t.stringHTMLRenderer(t),d=e.compile(a);o=Object.assign({},o,{data:Object.assign({},o.data,{options:t}),render:d.render,staticRenderFns:d.staticRenderFns})}return o}(h,c,o,f);b=new e(g)}var S=!1;i.listener=function(e){if(!c.disableBtn||!S){var n,t=l(e),i="function"==typeof t?function(e){for(var n=e;"function"==typeof n;)n=n();return n}(t):t;!(n=i)||"object"!=typeof n&&"function"!=typeof n||"function"!=typeof n.then||(S=!0,function(e,n){n.disableBtn&&e.setAttribute("disabled","disabled"),e.classList.add(n.btnLoadingClass)}(h,c),c.showSpinner&&(b.show=!0,setTimeout(function(){m=!0,w()},c.minTimeout)),i.then(y).catch(function(e){throw y(),e}))}}},bind:function(e,n,t){var r;(r=n.def).init.apply(r,arguments);var s=e.$promiseBtnId,o=i.listeners[s].eventType;e.addEventListener(o,i.listener)},unbind:function(e,n){var t=e.$promiseBtnId,r=i.listeners[t].eventType;e.removeEventListener(r,i.listener),delete i.listeners[t],delete e.$promiseBtnId}};return i},r={btnLoadingClass:"loading",showSpinner:!0,action:"click",disableBtn:!0,stringHTMLRenderer:function(e){return'\n <span class="promise-btn__spinner-wrapper" \n :class="{[options.spinnerHiddenClass]: !show || false}"\n v-show="options.autoHideSpinnerWrapper ? show : true"\n >\n '+e.loader+"\n </span>"},componentRenderer:function(e){return function(n){var t;return n("span",{class:(t={"promise-btn__spinner-wrapper":!0},t[e.spinnerHiddenClass]=!!e.spinnerHiddenClass&&!this.show,t),directives:[{name:"show",value:!e.autoHideSpinnerWrapper||this.show}]},[n(e.loader)])}},minTimeout:400,spinnerHiddenClass:"hidden",autoHideSpinnerWrapper:!1,loader:n};return{install:function(e,n){var t=Object.assign({},r,n);e.directive("promise-btn",i(t))},Spinner:n,setupVuePromiseBtn:i}}); |
{ | ||
"name": "vue-promise-btn", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Vue.js plugin that handles buttons asynchronous lock and show loading state indicator", | ||
@@ -44,22 +44,22 @@ "scripts": { | ||
"devDependencies": { | ||
"cross-env": "^5.1.4", | ||
"cross-env": "^5.2.0", | ||
"eslint-config-standard": "^11.0.0", | ||
"eslint-plugin-html": "^4.0.2", | ||
"eslint-plugin-import": "^2.9.0", | ||
"eslint-plugin-html": "^4.0.6", | ||
"eslint-plugin-import": "^2.16.0", | ||
"eslint-plugin-node": "^6.0.1", | ||
"eslint-plugin-promise": "^3.7.0", | ||
"eslint-plugin-standard": "^3.0.1", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.57.0", | ||
"rollup-plugin-buble": "^0.19.2", | ||
"rollup-plugin-commonjs": "^9.1.0", | ||
"eslint-plugin-promise": "^3.8.0", | ||
"eslint-plugin-standard": "^3.1.0", | ||
"rimraf": "^2.6.3", | ||
"rollup": "^0.57.1", | ||
"rollup-plugin-buble": "^0.19.6", | ||
"rollup-plugin-commonjs": "^9.2.0", | ||
"rollup-plugin-eslint": "^4.0.0", | ||
"rollup-plugin-livereload": "^0.6.0", | ||
"rollup-plugin-node-resolve": "^3.2.0", | ||
"rollup-plugin-node-resolve": "^3.4.0", | ||
"rollup-plugin-serve": "^0.4.2", | ||
"rollup-plugin-uglify": "^3.0.0", | ||
"rollup-plugin-vue": "^3.0.0", | ||
"vue": "^2.5.16", | ||
"vue-template-compiler": "^2.5.16" | ||
"vue": "^2.6.3", | ||
"vue-template-compiler": "^2.6.3" | ||
} | ||
} |
@@ -88,3 +88,3 @@ import Vue from 'vue' | ||
} | ||
const handler = vnode.data.on && vnode.data.on[options.action] && vnode.data.on[options.action]._withTask | ||
const handler = vnode.data.on && vnode.data.on[options.action] && (vnode.data.on[options.action]._withTask || vnode.data.on[options.action]._wrapper) | ||
const isLoaderString = isString(options.loader) | ||
@@ -125,2 +125,10 @@ let btnEl = el | ||
const getFiniteHandler = function (expression) { | ||
let result = expression | ||
while (typeof result === 'function') { | ||
result = result() | ||
} | ||
return result | ||
} | ||
// Register info in listeners object | ||
@@ -152,6 +160,7 @@ directive.listeners[id] = { | ||
if (options.disableBtn && scheduled) return | ||
const response = handler(e) | ||
if (isPromise(response)) { | ||
const expression = handler(e) | ||
const responseHandler = typeof expression === 'function' ? getFiniteHandler(expression) : expression | ||
if (isPromise(responseHandler)) { | ||
beforeResponseHandler() | ||
response | ||
responseHandler | ||
.then(resolveHandler) | ||
@@ -158,0 +167,0 @@ .catch(e => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24404
270