mirror of
https://github.com/hiloteam/Hilo.git
synced 2026-01-18 16:04:19 +00:00
6 lines
2.1 KiB
JavaScript
6 lines
2.1 KiB
JavaScript
/**
|
|
* hilojs 2.0.3 for amd
|
|
* Copyright 2016 alibaba.com
|
|
* Licensed under the MIT License
|
|
*/
|
|
define("hilo/loader/LoadQueue",["hilo/core/Class","hilo/event/EventMixin","hilo/loader/ImageLoader","hilo/loader/ScriptLoader"],function(e,o,r,n){function t(e){var o,r,n=/\/?[^\/]+?\.(\w+)\??(\?\S+)?$/i;return(o=e.match(n))&&(r=o[1].toLowerCase()),r||null}var a=e.create({Mixes:o,constructor:function(e){this._source=[],this.add(e)},maxConnections:2,_source:null,_loaded:0,_connections:0,_currentIndex:-1,add:function(e){var o=this;return e&&(e=e instanceof Array?e:[e],o._source=o._source.concat(e)),o},get:function(e){if(e)for(var o=this._source,r=0;r<o.length;r++){var n=o[r];if(n.id===e||n.src===e)return n}return null},getContent:function(e){var o=this.get(e);return o&&o.content},removeContent:function(e){if(e)for(var o=this._source,r=0;r<o.length;r++){var n=o[r];if(n.id===e||n.src===e)return void o.splice(r,1)}},start:function(){var e=this;return e._loadNext(),e},_loadNext:function(){var e=this,o=e._source,r=o.length;if(e._loaded>=r)return void e.fire("complete");if(e._currentIndex<r-1&&e._connections<e.maxConnections){var n=++e._currentIndex,t=o[n],a=e._getLoader(t);if(a){var i=a.onLoad,c=a.onError;a.onLoad=function(o){a.onLoad=i,a.onError=c;var r=i&&i.call(a,o)||o.target;e._onItemLoad(n,r)},a.onError=function(o){a.onLoad=i,a.onError=c,c&&c.call(a,o),e._onItemError(n,o)},e._connections++}e._loadNext(),a&&a.load(t)}},_getLoader:function(e){var o=e.loader;if(o)return o;var a=e.type||t(e.src);switch(a){case"png":case"jpg":case"jpeg":case"gif":case"webp":o=new r;break;case"js":case"jsonp":o=new n}return o},_onItemLoad:function(e,o){var r=this,n=r._source[e];n.loaded=!0,n.content=o,r._connections--,r._loaded++,r.fire("load",n),r._loadNext()},_onItemError:function(e,o){var r=this,n=r._source[e];n.error=o,r._connections--,r._loaded++,r.fire("error",n),r._loadNext()},getSize:function(e){for(var o=0,r=this._source,n=0;n<r.length;n++){var t=r[n];o+=(e?t.loaded&&t.size:t.size)||0}return o},getLoaded:function(){return this._loaded},getTotal:function(){return this._source.length}});return a}); |