Skip to content

Commit 1a30fc0

Browse files
updated docs and params names for newly added static methods
1 parent 10eaa46 commit 1a30fc0

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

v3/src/loader/File.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,33 +162,51 @@ var File = new Class({
162162

163163
});
164164

165-
File.createObjectURL = function (data, response, defaultType)
165+
/**
166+
* Static method for creating object URL using URL API and setting it as image 'src' attribute.
167+
* If URL API is not supported (usually on old browsers) it falls back to creating Base64 encoded url using FileReader.
168+
*
169+
* @method createObjectURL
170+
* @static
171+
* @param image {Image} Image object which 'src' attribute should be set to object URL.
172+
* @param blob {Blob} A Blob object to create an object URL for.
173+
* @param defaultType {string} Default mime type used if blob type is not available.
174+
*/
175+
File.createObjectURL = function (image, blob, defaultType)
166176
{
167177
if(URL)
168178
{
169-
data.src = URL.createObjectURL(response);
179+
image.src = URL.createObjectURL(blob);
170180
}
171181
else
172182
{
173183
var reader = new FileReader();
174184

175185
reader.onload = function()
176186
{
177-
delete data.crossOrigin;
178-
data.src = 'data:' + (response.type || defaultType) + ';base64,' + reader.result.split(',')[1];
187+
delete image.crossOrigin;
188+
image.src = 'data:' + (blob.type || defaultType) + ';base64,' + reader.result.split(',')[1];
179189
};
180190

181-
reader.onerror = data.onerror;
191+
reader.onerror = image.onerror;
182192

183-
reader.readAsDataURL(response);
193+
reader.readAsDataURL(blob);
184194
}
185195
};
186196

187-
File.revokeObjectURL = function (data)
197+
/**
198+
* Static method for releasing an existing object URL which was previously created
199+
* by calling {@link File#createObjectURL} method.
200+
*
201+
* @method revokeObjectURL
202+
* @static
203+
* @param image {Image} Image object which 'src' attribute should be revoked.
204+
*/
205+
File.revokeObjectURL = function (image)
188206
{
189207
if(URL)
190208
{
191-
URL.revokeObjectURL(data.src);
209+
URL.revokeObjectURL(image.src);
192210
}
193211
};
194212

0 commit comments

Comments
 (0)