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