1var File = function(url, object){
2 File.list = Array.isArray(File.list)? File.list : [];
3 File.progress = File.progress || 0;
4 this.progress = 0;
5 this.object = object;
6 this.url = url;
7};
8
9File.indexOf = function(term){
10 for(var index in File.list){
11 var file = File.list[index];
12 if (file.equals(term) || file.url === term || file.object === term) {
13 return index;
14 }
15 }
16 return -1;
17};
18
19File.find = function(term){
20 var index = File.indexOf(term);
21 return ~index && File.list[index];
22};
23
24File.prototype.equals = function(file){
25 var isFileType = file instanceof File;
26 return isFileType && this.url === file.url && this.object === file.object;
27};
28
29File.prototype.save = function(update){
30 update = typeof update === 'undefined'? true : update;
31 if(Array.isArray(File.list)){
32 var index = File.indexOf(this);
33 if(~index && update) {
34 File.list[index] = this;
35 console.warn('File `%s` has been loaded before and updated now for: %O.', this.url, this);
36 }else File.list.push(this);
37 console.log(File.list)
38 }else{
39 File.list = [this];
40 }
41 return this;
42};