var GetURL = require('./GetURL'); var CONST = require('./const'); var XHRLoader = require('./XHRLoader'); var XHRSettings = require('./XHRSettings'); var File = function (type, key, url, responseType){ this.type = type; this.key = key; _AN_Write_url('url', this, false , url); _AN_Write_src('src', this, false , ''); this.xhrSettings = XHRSettings(responseType); this.xhrLoader = null ; this.state = CONST.FILE_PENDING; this.bytesTotal = 0; this.bytesLoaded = -1; this.percentComplete = -1; this.crossOrigin = undefined; this.data = undefined; this.multipart = undefined; this.linkFile = undefined; this.callback = null ; } ; File.prototype.constructor = File; File.prototype = { resetXHR: function (){ this.xhrLoader.onload = undefined; this.xhrLoader.onerror = undefined; this.xhrLoader.onprogress = undefined; } , onLoad: function (event){ console.log('image loaded'); this.resetXHR(); this.callback(this, true ); } , onError: function (event){ this.resetXHR(); this.callback(this, false ); } , onProgress: function (event){ this.bytesLoaded = event.loaded; this.bytesTotal = event.total; this.percentComplete = Math.min((this.bytesLoaded / this.bytesTotal), 1); console.log(this.percentComplete + '% (' + this.bytesLoaded + ' bytes)'); } , onProcess: function (callback){ this.state = CONST.FILE_PROCESSING; callback(this); this.onComplete(); } , onComplete: function (){ console.log('File completed, ready to add to the Loader store'); this.state = CONST.FILE_COMPLETE; } , load: function (callback, baseURL, globalXHR){ if (baseURL === undefined) { baseURL = ''; } this.callback = callback; _AN_Write_src('src', this, false , GetURL(this, baseURL)); this.xhrLoader = XHRLoader(this, globalXHR); } } ; module.exports = File;