11var Class = require ( '../utils/Class' ) ;
2+ var GetFastValue = require ( '../utils/object/GetFastValue' ) ;
23var CONST = require ( './const' ) ;
34var GetURL = require ( './GetURL' ) ;
45var MergeXHRSettings = require ( './MergeXHRSettings' ) ;
@@ -11,25 +12,40 @@ var File = new Class({
1112
1213 initialize :
1314
14- function File ( type , key , url , responseType , xhrSettings , config )
15+ // old signature: type, key, url, responseType, xhrSettings, config
16+ function File ( fileConfig )
1517 {
1618 // file type (image, json, etc) for sorting within the Loader
17- this . type = type ;
19+ this . type = GetFastValue ( fileConfig , ' type' , false ) ;
1820
1921 // unique cache key (unique within its file type)
20- this . key = key ;
22+ this . key = GetFastValue ( fileConfig , 'key' , false ) ;
23+
24+ if ( ! this . type || ! this . key )
25+ {
26+ throw new Error ( 'Error calling \'Loader.' + this . type + '\' invalid key provided.' ) ;
27+ }
2128
2229 // The URL of the file, not including baseURL
23- this . url = url ;
30+ this . url = GetFastValue ( fileConfig , 'url' , '' ) ;
31+
32+ if ( this . url === '' )
33+ {
34+ this . url = GetFastValue ( fileConfig , 'path' , '' ) + this . key + GetFastValue ( fileConfig , 'extension' , '' ) ;
35+ }
36+ else
37+ {
38+ this . url = GetFastValue ( fileConfig , 'path' , '' ) . concat ( this . url ) ;
39+ }
2440
2541 // Set when the Loader calls 'load' on this file
2642 this . src = '' ;
2743
28- this . xhrSettings = XHRSettings ( responseType ) ;
44+ this . xhrSettings = XHRSettings ( GetFastValue ( fileConfig , ' responseType' , undefined ) ) ;
2945
30- if ( xhrSettings )
46+ if ( GetFastValue ( fileConfig , ' xhrSettings' , false ) )
3147 {
32- this . xhrSettings = MergeXHRSettings ( this . xhrSettings , xhrSettings ) ;
48+ this . xhrSettings = MergeXHRSettings ( this . xhrSettings , GetFastValue ( fileConfig , ' xhrSettings' , { } ) ) ;
3349 }
3450
3551 this . xhrLoader = null ;
@@ -49,7 +65,7 @@ var File = new Class({
4965 this . data = undefined ;
5066
5167 // A config object that can be used by file types to store transitional data
52- this . config = config || { } ;
68+ this . config = GetFastValue ( fileConfig , ' config' , { } ) ;
5369
5470 // Multipart file? (i.e. an atlas and its json together)
5571 this . linkFile = undefined ;
0 commit comments