diff options
| author | Jules Laplace <jules@okfoc.us> | 2016-09-02 13:24:55 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2016-09-02 13:24:55 -0400 |
| commit | 8def9579f2a78e80652d1e5e6f1eda510ae9a5dd (patch) | |
| tree | c56d664f04d55f0d75c6d4f5e2d6fc567054498d /site/public/assets/javascripts/vendor/loader.js | |
| parent | 4ed81fa59119cee66b0413c5662639ec81fea4dc (diff) | |
| parent | 5052d51aa4c55eabc736b3c76a783db2f5208289 (diff) | |
merge changes from twohustlers
Diffstat (limited to 'site/public/assets/javascripts/vendor/loader.js')
| -rw-r--r-- | site/public/assets/javascripts/vendor/loader.js | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/site/public/assets/javascripts/vendor/loader.js b/site/public/assets/javascripts/vendor/loader.js index 4c1c8cd..b939941 100644 --- a/site/public/assets/javascripts/vendor/loader.js +++ b/site/public/assets/javascripts/vendor/loader.js @@ -1,13 +1,17 @@ var Loader = Loader || (function(){ - function Loader (readyCallback){ + function Loader (readyCallback, view){ this.assets = {}; this.images = []; this.readyCallback = readyCallback; + this.count = 0 + this.view = view + this.loaded = false } // Register an asset as loading Loader.prototype.register = function(s){ this.assets[s] = false; + this.count += 1 } // Signal that an asset has loaded @@ -16,10 +20,18 @@ var Loader = Loader || (function(){ this.assets[s] = true; if (this.loaded) return; + + this.view && this.view.update( this.percentRemaining() ) + if (! this.isReady()) return; this.loaded = true; - this.readyCallback && this.readyCallback(); + if (this.view) { + this.view && this.view.finish(this.readyCallback) + } + else { + this.readyCallback && this.readyCallback(); + } } // (boolean) Is the loader ready? @@ -31,6 +43,11 @@ var Loader = Loader || (function(){ } return true; } + + // (float) Percentage of assets remaining + Loader.prototype.percentRemaining = function(){ + return this.remainingAssets() / this.count + } // (int) Number of assets remaining Loader.prototype.remainingAssets = function(){ @@ -38,7 +55,7 @@ var Loader = Loader || (function(){ for (var s in this.assets) { if (this.assets.hasOwnProperty(s) && this.assets[s] != true) { n++; - console.log('remaining: ' + s); + // console.log('remaining: ' + s); } } return n; |
