      1 /**
      2  * Hilo
      3  * Copyright 2015 alibaba.com
      4  * Licensed under the MIT License
      5  */
      6
      7 /**
      8  * @private
      9  * @class 图片资源加载器。
     10  * @module hilo/loader/ImageLoader
     11  * @requires hilo/core/Class
     12  */
     13 var ImageLoader = Class.create({
     14     load: function(data){
     15         var me = this;
     16
     17         var image = new Image();
     18         if(data.crossOrigin){
     19             image.crossOrigin = "Anonymous";
     20         }
     21
     22         image.onload = function(){
     23             me.onLoad(image);
     24         };
     25         image.onerror = image.onabort = me.onError.bind(image);
     26         image.src = data.src + (data.noCache ? (data.src.indexOf('?') == -1 ? '?' : '&') + 't=' + (+new Date()) : '');
     27     },
     28
     29     onLoad: function(image){
     30         image.onload = image.onerror = image.onabort = null;
     31         return image;
     32     },
     33
     34     onError: function(e){
     35         var image = e.target;
     36         image.onload = image.onerror = image.onabort = null;
     37         return e;
     38     }
     39
     40 });