diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-04-13 16:45:01 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-04-13 16:45:20 -0400 |
| commit | e791ea8b3d6855b62962e4c89ad2c9f86126daf1 (patch) | |
| tree | 09709428f7845337954ef79dd12e6f6e71b5e883 /site/public/assets/javascripts/vendor/loader.js | |
| parent | 741bb035e10a1d89dfaa60ab79d25a63d2ff4726 (diff) | |
stub in loader
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; |
