HTML and CSS Reference
In-Depth Information
// Find a supported type
extension =
.detect(function(extension) {
return snd.canPlayType(Q.audioMimeTypes[extension]) ?
extension : null;
// No supported audio = trigger ok callback anyway
if(!extension) {
// If sound is turned off,
// call the callback immediately
$(snd).on('canplaythrough',function() {
snd.src = Q.options.audioPath + baseName + "." + extension;
return snd;
// Loader for other file types, just store the data
// returned from an ajax call
Q.loadAssetOther = function(key,src,callback,errorCallback) {
$.get(Q.options.dataPath + src,function(data) {
Each of the three loader methods performs the same task with a different asset type, which amounts to provid-
ing a consistent call to a callback containing the passed in key and the loaded object in question. A helper meth-
od to remove the extension from a filename is also defined.
Q.loadAssetImage creates an Image object and links the callback to the load event method.
Q.loadAssetOther just uses the jQuery get method to load data into a buffer and trigger the callback
when it's loaded.
Finally, the Q.loadAssetAudio creates an Audio element and then determines if the Audio tag is
available or whether sound is turned on normally. In cases in which the sound tag isn't supported, or the sound
is turned off, the method calls the callback immediately and returns.
The Audio loader also needs to do some extra work to ensure the audio file loaded is supported by the
browser. To do this it keeps a hash called Q.audioMimeTypes that maps file extensions to audio mime types.
Search WWH ::

Custom Search