From 33a0f0b1836999938092e67f0aadb74d8ae82300 Mon Sep 17 00:00:00 2001 From: Jamie Davidson Date: Sun, 7 Dec 2014 19:17:37 -0500 Subject: [PATCH] Add method to update options in bulk --- build/please-wait.js | 13 +++++++++++++ build/please-wait.min.js | 2 +- src/please-wait.coffee | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/build/please-wait.js b/build/please-wait.js index 5ce40bc..1163444 100644 --- a/build/please-wait.js +++ b/build/please-wait.js @@ -151,6 +151,19 @@ } }; + PleaseWait.prototype.updateOptions = function(options) { + var k, v, _results; + if (options == null) { + options = {}; + } + _results = []; + for (k in options) { + v = options[k]; + _results.push(this.updateOption(k, v)); + } + return _results; + }; + PleaseWait.prototype.updateLoadingHtml = function(loadingHtml, immediately) { if (immediately == null) { immediately = false; diff --git a/build/please-wait.min.js b/build/please-wait.min.js index 0f42f6a..9feec7a 100644 --- a/build/please-wait.min.js +++ b/build/please-wait.min.js @@ -9,4 +9,4 @@ * @module pleaseWait * @version 0.0.1 */ -!function(a,b){"object"==typeof exports?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):b(a)}(this,function(a){var b,c,d,e;return c=function(){var a,b,c,d;a=document.createElement("fakeelement"),c={WebkitAnimation:"webkitAnimationEnd",OAnimation:"oAnimationEnd",msAnimation:"MSAnimationEnd",MozAnimation:"mozAnimationEnd",animation:"animationend"};for(b in c)if(d=c[b],null!=a.style[b])return d},e=c(),b=function(){function a(a){var b,c,d,f;b=this.constructor._defaultOptions,this.options={};for(c in b)f=b[c],this.options[c]=null!=a[c]?a[c]:f;this._loadingElem=document.createElement("div"),this._loadingHtmlToDisplay=[],this._loadingElem.className="pg-loading-screen",null!=this.options.backgroundColor&&(this._loadingElem.style.backgroundColor=this.options.backgroundColor),this._loadingElem.innerHTML=this.options.template,this._loadingHtmlElem=this._loadingElem.getElementsByClassName("pg-loading-html")[0],null!=this._loadingHtmlElem&&(this._loadingHtmlElem.innerHTML=this.options.loadingHtml),this._readyToShowLoadingHtml=!1,this._logoElem=this._loadingElem.getElementsByClassName("pg-loading-logo")[0],null!=this._logoElem&&(this._logoElem.src=this.options.logo),document.body.appendChild(this._loadingElem),this._loadingElem.className+=" pg-loading",d=function(a){return function(){return a._readyToShowLoadingHtml=!0,null!=e&&a._loadingHtmlElem.removeEventListener(e,d),a._loadingHtmlToDisplay.length>0?a._changeLoadingHtml():void 0}}(this),null!=this._loadingHtmlElem&&(null!=e?this._loadingHtmlElem.addEventListener(e,d):d(),this._loadingHtmlListener=function(a){return function(){return a._readyToShowLoadingHtml=!0,a._loadingHtmlElem.className=a._loadingHtmlElem.className.replace(" pg-loading ",""),null!=e&&a._loadingHtmlElem.removeEventListener(e,a._loadingHtmlListener),a._loadingHtmlToDisplay.length>0?a._changeLoadingHtml():void 0}}(this),this._removingHtmlListener=function(a){return function(){return a._loadingHtmlElem.innerHTML=a._loadingHtmlToDisplay.shift(),a._loadingHtmlElem.className=a._loadingHtmlElem.className.replace(" pg-removing "," pg-loading "),null!=e?(a._loadingHtmlElem.removeEventListener(e,a._removingHtmlListener),a._loadingHtmlElem.addEventListener(e,a._loadingHtmlListener)):a._loadingHtmlListener()}}(this))}return a._defaultOptions={backgroundColor:null,logo:null,loadingHtml:null,template:"
\n
\n
\n

\n \n

\n
\n
\n
\n
\n
"},a.prototype.finish=function(){var a;if(null!=this._loadingElem)return a=function(b){return function(){return document.body.removeChild(b._loadingElem),document.body.className+=" pg-loaded",null!=e&&b._loadingElem.removeEventListener(e,a),b._loadingElem=null}}(this),null!=e?(this._loadingElem.className+=" pg-loaded",this._loadingElem.addEventListener(e,a)):a()},a.prototype.updateOption=function(a,b){switch(a){case"backgroundColor":return this._loadingElem.style.backgroundColor=b;case"logo":return this._logoElem.src=b;case"loadingHtml":return this.updateLoadingHtml(b);default:throw new Error("Unknown option '"+a+"'")}},a.prototype.updateLoadingHtml=function(a,b){if(null==b&&(b=!1),null==this._loadingHtmlElem)throw new Error("The loading template does not have an element of class 'pg-loading-html'");return b?(this._loadingHtmlToDisplay=[a],this._readyToShowLoadingHtml=!0):this._loadingHtmlToDisplay.push(a),this._readyToShowLoadingHtml?this._changeLoadingHtml():void 0},a.prototype._changeLoadingHtml=function(){return this._readyToShowLoadingHtml=!1,this._loadingHtmlElem.removeEventListener(e,this._loadingHtmlListener),this._loadingHtmlElem.removeEventListener(e,this._removingHtmlListener),this._loadingHtmlElem.className=this._loadingHtmlElem.className.replace(" pg-loading ","").replace(" pg-removing ",""),null!=e?(this._loadingHtmlElem.className+=" pg-removing ",this._loadingHtmlElem.addEventListener(e,this._removingHtmlListener)):this._removingHtmlListener()},a}(),d=function(a){return null==a&&(a={}),new b(a)},a.pleaseWait=d,d}); \ No newline at end of file +!function(a,b){"object"==typeof exports?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):b(a)}(this,function(a){var b,c,d,e;return c=function(){var a,b,c,d;a=document.createElement("fakeelement"),c={WebkitAnimation:"webkitAnimationEnd",OAnimation:"oAnimationEnd",msAnimation:"MSAnimationEnd",MozAnimation:"mozAnimationEnd",animation:"animationend"};for(b in c)if(d=c[b],null!=a.style[b])return d},e=c(),b=function(){function a(a){var b,c,d,f;b=this.constructor._defaultOptions,this.options={};for(c in b)f=b[c],this.options[c]=null!=a[c]?a[c]:f;this._loadingElem=document.createElement("div"),this._loadingHtmlToDisplay=[],this._loadingElem.className="pg-loading-screen",null!=this.options.backgroundColor&&(this._loadingElem.style.backgroundColor=this.options.backgroundColor),this._loadingElem.innerHTML=this.options.template,this._loadingHtmlElem=this._loadingElem.getElementsByClassName("pg-loading-html")[0],null!=this._loadingHtmlElem&&(this._loadingHtmlElem.innerHTML=this.options.loadingHtml),this._readyToShowLoadingHtml=!1,this._logoElem=this._loadingElem.getElementsByClassName("pg-loading-logo")[0],null!=this._logoElem&&(this._logoElem.src=this.options.logo),document.body.appendChild(this._loadingElem),this._loadingElem.className+=" pg-loading",d=function(a){return function(){return a._readyToShowLoadingHtml=!0,null!=e&&a._loadingHtmlElem.removeEventListener(e,d),a._loadingHtmlToDisplay.length>0?a._changeLoadingHtml():void 0}}(this),null!=this._loadingHtmlElem&&(null!=e?this._loadingHtmlElem.addEventListener(e,d):d(),this._loadingHtmlListener=function(a){return function(){return a._readyToShowLoadingHtml=!0,a._loadingHtmlElem.className=a._loadingHtmlElem.className.replace(" pg-loading ",""),null!=e&&a._loadingHtmlElem.removeEventListener(e,a._loadingHtmlListener),a._loadingHtmlToDisplay.length>0?a._changeLoadingHtml():void 0}}(this),this._removingHtmlListener=function(a){return function(){return a._loadingHtmlElem.innerHTML=a._loadingHtmlToDisplay.shift(),a._loadingHtmlElem.className=a._loadingHtmlElem.className.replace(" pg-removing "," pg-loading "),null!=e?(a._loadingHtmlElem.removeEventListener(e,a._removingHtmlListener),a._loadingHtmlElem.addEventListener(e,a._loadingHtmlListener)):a._loadingHtmlListener()}}(this))}return a._defaultOptions={backgroundColor:null,logo:null,loadingHtml:null,template:"
\n
\n
\n

\n \n

\n
\n
\n
\n
\n
"},a.prototype.finish=function(){var a;if(null!=this._loadingElem)return a=function(b){return function(){return document.body.removeChild(b._loadingElem),document.body.className+=" pg-loaded",null!=e&&b._loadingElem.removeEventListener(e,a),b._loadingElem=null}}(this),null!=e?(this._loadingElem.className+=" pg-loaded",this._loadingElem.addEventListener(e,a)):a()},a.prototype.updateOption=function(a,b){switch(a){case"backgroundColor":return this._loadingElem.style.backgroundColor=b;case"logo":return this._logoElem.src=b;case"loadingHtml":return this.updateLoadingHtml(b);default:throw new Error("Unknown option '"+a+"'")}},a.prototype.updateOptions=function(a){var b,c,d;null==a&&(a={}),d=[];for(b in a)c=a[b],d.push(this.updateOption(b,c));return d},a.prototype.updateLoadingHtml=function(a,b){if(null==b&&(b=!1),null==this._loadingHtmlElem)throw new Error("The loading template does not have an element of class 'pg-loading-html'");return b?(this._loadingHtmlToDisplay=[a],this._readyToShowLoadingHtml=!0):this._loadingHtmlToDisplay.push(a),this._readyToShowLoadingHtml?this._changeLoadingHtml():void 0},a.prototype._changeLoadingHtml=function(){return this._readyToShowLoadingHtml=!1,this._loadingHtmlElem.removeEventListener(e,this._loadingHtmlListener),this._loadingHtmlElem.removeEventListener(e,this._removingHtmlListener),this._loadingHtmlElem.className=this._loadingHtmlElem.className.replace(" pg-loading ","").replace(" pg-removing ",""),null!=e?(this._loadingHtmlElem.className+=" pg-removing ",this._loadingHtmlElem.addEventListener(e,this._removingHtmlListener)):this._removingHtmlListener()},a}(),d=function(a){return null==a&&(a={}),new b(a)},a.pleaseWait=d,d}); \ No newline at end of file diff --git a/src/please-wait.coffee b/src/please-wait.coffee index e3e68a4..6ab1783 100644 --- a/src/please-wait.coffee +++ b/src/please-wait.coffee @@ -144,6 +144,10 @@ else throw new Error("Unknown option '#{option}'") + updateOptions: (options={}) -> + for k, v of options + @updateOption(k, v) + updateLoadingHtml: (loadingHtml, immediately=false) -> unless @_loadingHtmlElem? then throw new Error("The loading template does not have an element of class 'pg-loading-html'") if immediately