RequestUtils Class
Utilities that assist with parsing load items, and determining file types, etc.
Item Index
Methods
- buildPath static
- formatQueryString static
- getTypeByExtension static
- isAudioTag static
- isBinary static
- isCrossDomain static
- isImageTag static
- isLocal static
- isText static
- isVideoTag static
- parseURI static
Properties
- ABSOLUTE_PATH static
- EXTENSION_PATT static
- RELATIVE_PATH static
Methods
buildPath
-
src
-
[data]
A utility method that builds a file path using a source and a data object, and formats it into a new path.
Parameters:
Returns:
A formatted string that contains the path and the supplied parameters.
formatQueryString
-
data
-
[query]
Formats an object into a query string for either a POST or GET request.
getTypeByExtension
-
extension
Determine the type of the object using common extensions. Note that the type can be passed in with the load item if it is an unusual extension.
Parameters:
-
extension
StringThe file extension to use to determine the load type.
Returns:
The determined load type (for example, AbstractLoader.IMAGE
). Will return null
if
the type can not be determined by the extension.
isAudioTag
-
item
Check if item is a valid HTMLAudioElement
Parameters:
-
item
Object
Returns:
isBinary
-
type
Determine if a specific type should be loaded as a binary file. Currently, only images and items marked specifically as "binary" are loaded as binary. Note that audio is not a binary type, as we can not play back using an audio tag if it is loaded as binary. Plugins can change the item type to binary to ensure they get a binary result to work with. Binary files are loaded using XHR2. Types are defined as static constants on AbstractLoader.
Parameters:
-
type
StringThe item type.
Returns:
If the specified type is binary.
isCrossDomain
-
item
Returns:
If the load item is loading from a different domain than the current location.
isImageTag
-
item
Check if item is a valid HTMLImageElement
Parameters:
-
item
Object
Returns:
isLocal
-
item
Returns:
If the load item is loading from the "file:" protocol. Assume that the host must be local as well.
isText
-
type
Determine if a specific type is a text-based asset, and should be loaded as UTF-8.
Parameters:
-
type
StringThe item type.
Returns:
If the specified type is text.
isVideoTag
-
item
Check if item is a valid HTMLVideoElement
Parameters:
-
item
Object
Returns:
parseURI
-
path
Parse a file path to determine the information we need to work with it. Currently, PreloadJS needs to know:
- If the path is absolute. Absolute paths start with a protocol (such as
http://
,file://
, or//networkPath
) - If the path is relative. Relative paths start with
../
or/path
(or similar) - The file extension. This is determined by the filename with an extension. Query strings are dropped, and
the file path is expected to follow the format
name.ext
.
Parameters:
-
path
String
Returns:
An Object with an absolute
and relative
Boolean values, as well as an optional 'extension`
property, which is the lowercase extension.
Properties
EXTENSION_PATT
RegExp
static
The Regular Expression used to test file URLS for an extension. Note that URIs must already have the query string removed.