UNPKG

acha-framework

Version:

is a modular framework on both client (angular.js) and server (node.js) side, it provides security, orm, ioc, obfuscation and ...

116 lines 4.2 kB
(function (window, document, undefined) { window.achasoft = window.achasoft || {}; const AssetLoader = function (module, isPanel) { const self = this; this.assets = []; this.register('/framework/scripts/frameworks.debug.js'); this.register('/framework/scripts/plugins.debug.js'); this.register('/framework/scripts/frontend.pack.js'); this.register('/framework/scripts/services.pack.js'); this.register('/framework/scripts/directives.pack.js'); this.register('/framework/scripts/templates.debug.js'); this.register('/application/scripts/shared-templates.debug.js'); if (module) { if (typeof module === 'string') { module = [module]; } if (Array.isArray(module)) { module.forEach(function (mod) { self.register('/application/scripts/' + mod + '-frameworks.debug.js'); self.register('/application/scripts/' + mod + '-plugins.debug.js'); self.register('/application/scripts/' + mod + '-frontend.pack.js'); self.register('/application/scripts/' + mod + '-services.pack.js'); self.register('/application/scripts/' + mod + '-directives.pack.js'); self.register('/application/scripts/' + mod + '-templates.debug.js'); }); } } if (isPanel) { this.register('/framework/scripts/panel/frameworks.debug.js'); this.register('/framework/scripts/panel/plugins.debug.js'); this.register('/framework/scripts/panel/frontend.pack.js'); this.register('/framework/scripts/panel/services.pack.js'); this.register('/framework/scripts/panel/directives.pack.js'); this.register('/framework/scripts/panel/templates.debug.js'); } }; AssetLoader.prototype.register = function (asset) { asset = asset.trim(); if (!asset) { return; } var index = this.assets.indexOf(asset); if (index === -1) { this.assets.push(asset); } }; AssetLoader.prototype.clear = function () { this.assets = []; }; AssetLoader.prototype.download = function (onStart, onProgress, onDone) { if (!this.assets.length) { return; } var self = this; var percent = 0; var step = Math.round(100 / this.assets.length); var debug = document.getElementsByTagName('body')[0].getAttribute('data-debug') !== 'false'; var download = function (index) { var url = self.assets[index].replace('.debug', debug ? '' : '.min').replace('.pack', debug ? '' : '.pack'); $script(url, function () { percent += step; if (percent > 100) { percent = 100; } if (onProgress) { onProgress(percent); } index++; if (index <= self.assets.length - 1) { download(index); return; } if (onDone) { onDone(); } }); }; if (onStart) { onStart(); } download(0); }; AssetLoader.prototype.lazyLoad = function (callback) { var startDate, stopDate; var element = document.querySelector('#acha-application-loader .text'); var onStart = function () { startDate = new Date(); console.log('demanding...'); }; var onProgress = function (percent) { element.innerHTML = percent + '%'; console.log(percent + ' % downloaded'); }; var onDone = function () { stopDate = new Date(); var dif = stopDate.getTime() - startDate.getTime(); element.innerHTML = '100%'; console.log('download completed in : ', dif / 1000, ' seconds'); console.log('launching...'); startDate = new Date(); $(document).ready(function () { angular.bootstrap(document, ['frontend']); $('#acha-application-loader').remove(); $('body').removeClass('application-loading'); $('.hide-before-launch').removeClass('hide-before-launch'); stopDate = new Date(); var dif = stopDate.getTime() - startDate.getTime(); console.log('launched in : ', dif / 1000, ' seconds'); if (callback) callback(); }); }; this.download(onStart, onProgress, onDone); }; window.achasoft.AssetLoader = AssetLoader; }(window, document));