code
stringlengths 10
343k
| docstring
stringlengths 36
21.9k
| func_name
stringlengths 1
3.35k
| language
stringclasses 1
value | repo
stringlengths 7
58
| path
stringlengths 4
131
| url
stringlengths 44
195
| license
stringclasses 5
values |
---|---|---|---|---|---|---|---|
p.removeEventListener = function(type, listener, useCapture) {
var listeners = useCapture ? this._captureListeners : this._listeners;
if (!listeners) { return; }
var arr = listeners[type];
if (!arr) { return; }
for (var i=0,l=arr.length; i<l; i++) {
if (arr[i] == listener) {
if (l==1) { delete(listeners[type]); } // allows for faster checks.
else { arr.splice(i,1); }
break;
}
}
}; | Removes the specified event listener.
<b>Important Note:</b> that you must pass the exact function reference used when the event was added. If a proxy
function, or function closure is used as the callback, the proxy/closure reference must be used - a new proxy or
closure will not work.
<h4>Example</h4>
displayObject.removeEventListener("click", handleClick);
@method removeEventListener
@param {String} type The string type of the event.
@param {Function | Object} listener The listener function or object.
@param {Boolean} [useCapture] For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.
* | p.removeEventListener ( type , listener , useCapture ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.removeAllEventListeners = function(type) {
if (!type) { this._listeners = this._captureListeners = null; }
else {
if (this._listeners) { delete(this._listeners[type]); }
if (this._captureListeners) { delete(this._captureListeners[type]); }
}
}; | Removes all listeners for the specified type, or all listeners of all types.
<h4>Example</h4>
// Remove all listeners
displayObject.removeAllEventListeners();
// Remove all click listeners
displayObject.removeAllEventListeners("click");
@method removeAllEventListeners
@param {String} [type] The string type of the event. If omitted, all listeners for all types will be removed.
* | p.removeAllEventListeners ( type ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.dispatchEvent = function(eventObj, bubbles, cancelable) {
if (typeof eventObj == "string") {
// skip everything if there's no listeners and it doesn't bubble:
var listeners = this._listeners;
if (!bubbles && (!listeners || !listeners[eventObj])) { return true; }
eventObj = new createjs.Event(eventObj, bubbles, cancelable);
} else if (eventObj.target && eventObj.clone) {
// redispatching an active event object, so clone it:
eventObj = eventObj.clone();
}
// TODO: it would be nice to eliminate this. Maybe in favour of evtObj instanceof Event? Or !!evtObj.createEvent
try { eventObj.target = this; } catch (e) {} // try/catch allows redispatching of native events
if (!eventObj.bubbles || !this.parent) {
this._dispatchEvent(eventObj, 2);
} else {
var top=this, list=[top];
while (top.parent) { list.push(top = top.parent); }
var i, l=list.length;
// capture & atTarget
for (i=l-1; i>=0 && !eventObj.propagationStopped; i--) {
list[i]._dispatchEvent(eventObj, 1+(i==0));
}
// bubbling
for (i=1; i<l && !eventObj.propagationStopped; i++) {
list[i]._dispatchEvent(eventObj, 3);
}
}
return !eventObj.defaultPrevented;
}; | Dispatches the specified event to all listeners.
<h4>Example</h4>
// Use a string event
this.dispatchEvent("complete");
// Use an Event instance
var event = new createjs.Event("progress");
this.dispatchEvent(event);
@method dispatchEvent
@param {Object | String | Event} eventObj An object with a "type" property, or a string type.
While a generic object will work, it is recommended to use a CreateJS Event instance. If a string is used,
dispatchEvent will construct an Event instance if necessary with the specified type. This latter approach can
be used to avoid event object instantiation for non-bubbling events that may not have any listeners.
@param {Boolean} [bubbles] Specifies the `bubbles` value when a string was passed to eventObj.
@param {Boolean} [cancelable] Specifies the `cancelable` value when a string was passed to eventObj.
@return {Boolean} Returns false if `preventDefault()` was called on a cancelable event, true otherwise.
* | p.dispatchEvent ( eventObj , bubbles , cancelable ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.hasEventListener = function(type) {
var listeners = this._listeners, captureListeners = this._captureListeners;
return !!((listeners && listeners[type]) || (captureListeners && captureListeners[type]));
}; | Indicates whether there is at least one listener for the specified event type.
@method hasEventListener
@param {String} type The string type of the event.
@return {Boolean} Returns true if there is at least one listener for the specified event.
* | p.hasEventListener ( type ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.willTrigger = function(type) {
var o = this;
while (o) {
if (o.hasEventListener(type)) { return true; }
o = o.parent;
}
return false;
}; | Indicates whether there is at least one listener for the specified event type on this object or any of its
ancestors (parent, parent's parent, etc). A return value of true indicates that if a bubbling event of the
specified type is dispatched from this object, it will trigger at least one listener.
This is similar to {{#crossLink "EventDispatcher/hasEventListener"}}{{/crossLink}}, but it searches the entire
event flow for a listener, not just this object.
@method willTrigger
@param {String} type The string type of the event.
@return {Boolean} Returns `true` if there is at least one listener for the specified event.
* | p.willTrigger ( type ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.toString = function() {
return "[EventDispatcher]";
}; | @method toString
@return {String} a string representation of the instance.
* | p.toString ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._dispatchEvent = function(eventObj, eventPhase) {
var l, arr, listeners = (eventPhase <= 2) ? this._captureListeners : this._listeners;
if (eventObj && listeners && (arr = listeners[eventObj.type]) && (l=arr.length)) {
try { eventObj.currentTarget = this; } catch (e) {}
try { eventObj.eventPhase = eventPhase|0; } catch (e) {}
eventObj.removed = false;
arr = arr.slice(); // to avoid issues with items being removed or added during the dispatch
for (var i=0; i<l && !eventObj.immediatePropagationStopped; i++) {
var o = arr[i];
if (o.handleEvent) { o.handleEvent(eventObj); }
else { o(eventObj); }
if (eventObj.removed) {
this.off(eventObj.type, o, eventPhase==1);
eventObj.removed = false;
}
}
}
if (eventPhase === 2) { this._dispatchEvent(eventObj, 2.1); }
}; | @method _dispatchEvent
@param {Object | Event} eventObj
@param {Object} eventPhase
@protected
* | p._dispatchEvent ( eventObj , eventPhase ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function Event(type, bubbles, cancelable) {
// public properties:
/**
* The type of event.
* @property type
* @type String
**/
this.type = type;
/**
* The object that generated an event.
* @property target
* @type Object
* @default null
* @readonly
*/
this.target = null;
/**
* The current target that a bubbling event is being dispatched from. For non-bubbling events, this will
* always be the same as target. For example, if childObj.parent = parentObj, and a bubbling event
* is generated from childObj, then a listener on parentObj would receive the event with
* target=childObj (the original target) and currentTarget=parentObj (where the listener was added).
* @property currentTarget
* @type Object
* @default null
* @readonly
*/
this.currentTarget = null;
/**
* For bubbling events, this indicates the current event phase:<OL>
* <LI> capture phase: starting from the top parent to the target</LI>
* <LI> at target phase: currently being dispatched from the target</LI>
* <LI> bubbling phase: from the target to the top parent</LI>
* </OL>
* @property eventPhase
* @type Number
* @default 0
* @readonly
*/
this.eventPhase = 0;
/**
* Indicates whether the event will bubble through the display list.
* @property bubbles
* @type Boolean
* @default false
* @readonly
*/
this.bubbles = !!bubbles;
/**
* Indicates whether the default behaviour of this event can be cancelled via
* {{#crossLink "Event/preventDefault"}}{{/crossLink}}. This is set via the Event constructor.
* @property cancelable
* @type Boolean
* @default false
* @readonly
*/
this.cancelable = !!cancelable;
/**
* The epoch time at which this event was created.
* @property timeStamp
* @type Number
* @default 0
* @readonly
*/
this.timeStamp = (new Date()).getTime();
/**
* Indicates if {{#crossLink "Event/preventDefault"}}{{/crossLink}} has been called
* on this event.
* @property defaultPrevented
* @type Boolean
* @default false
* @readonly
*/
this.defaultPrevented = false;
/**
* Indicates if {{#crossLink "Event/stopPropagation"}}{{/crossLink}} or
* {{#crossLink "Event/stopImmediatePropagation"}}{{/crossLink}} has been called on this event.
* @property propagationStopped
* @type Boolean
* @default false
* @readonly
*/
this.propagationStopped = false;
/**
* Indicates if {{#crossLink "Event/stopImmediatePropagation"}}{{/crossLink}} has been called
* on this event.
* @property immediatePropagationStopped
* @type Boolean
* @default false
* @readonly
*/
this.immediatePropagationStopped = false;
/**
* Indicates if {{#crossLink "Event/remove"}}{{/crossLink}} has been called on this event.
* @property removed
* @type Boolean
* @default false
* @readonly
*/
this.removed = false;
} | Contains properties and methods shared by all events for use with
{{#crossLink "EventDispatcher"}}{{/crossLink}}.
Note that Event objects are often reused, so you should never
rely on an event object's state outside of the call stack it was received in.
@class Event
@param {String} type The event type.
@param {Boolean} bubbles Indicates whether the event will bubble through the display list.
@param {Boolean} cancelable Indicates whether the default behaviour of this event can be cancelled.
@constructor
* | Event ( type , bubbles , cancelable ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.preventDefault = function() {
this.defaultPrevented = this.cancelable&&true;
}; | Sets {{#crossLink "Event/defaultPrevented"}}{{/crossLink}} to true if the event is cancelable.
Mirrors the DOM level 2 event standard. In general, cancelable events that have `preventDefault()` called will
cancel the default behaviour associated with the event.
@method preventDefault
* | p.preventDefault ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.stopPropagation = function() {
this.propagationStopped = true;
}; | Sets {{#crossLink "Event/propagationStopped"}}{{/crossLink}} to true.
Mirrors the DOM event standard.
@method stopPropagation
* | p.stopPropagation ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.stopImmediatePropagation = function() {
this.immediatePropagationStopped = this.propagationStopped = true;
}; | Sets {{#crossLink "Event/propagationStopped"}}{{/crossLink}} and
{{#crossLink "Event/immediatePropagationStopped"}}{{/crossLink}} to true.
Mirrors the DOM event standard.
@method stopImmediatePropagation
* | p.stopImmediatePropagation ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.remove = function() {
this.removed = true;
}; | Causes the active listener to be removed via removeEventListener();
myBtn.addEventListener("click", function(evt) {
// do stuff...
evt.remove(); // removes this listener.
});
@method remove
* | p.remove ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.clone = function() {
return new Event(this.type, this.bubbles, this.cancelable);
}; | Returns a clone of the Event instance.
@method clone
@return {Event} a clone of the Event instance.
* | p.clone ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.set = function(props) {
for (var n in props) { this[n] = props[n]; }
return this;
}; | Provides a chainable shortcut method for setting a number of properties on the instance.
@method set
@param {Object} props A generic object containing properties to copy to the instance.
@return {Event} Returns the instance the method is called on (useful for chaining calls.)
@chainable | p.set ( props ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.toString = function() {
return "[Event (type="+this.type+")]";
}; | Returns a string representation of this object.
@method toString
@return {String} a string representation of the instance.
* | p.toString ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function ErrorEvent(title, message, data) {
this.Event_constructor("error");
/**
* The short error title, which indicates the type of error that occurred.
* @property title
* @type String
*/
this.title = title;
/**
* The verbose error message, containing details about the error.
* @property message
* @type String
*/
this.message = message;
/**
* Additional data attached to an error.
* @property data
* @type {Object}
*/
this.data = data;
} | A general error {{#crossLink "Event"}}{{/crossLink}}, that describes an error that occurred, as well as any details.
@class ErrorEvent
@param {String} [title] The error title
@param {String} [message] The error description
@param {Object} [data] Additional error data
@constructor | ErrorEvent ( title , message , data ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function ProgressEvent(loaded, total) {
this.Event_constructor("progress");
/**
* The amount that has been loaded (out of a total amount)
* @property loaded
* @type {Number}
*/
this.loaded = loaded;
/**
* The total "size" of the load.
* @property total
* @type {Number}
* @default 1
*/
this.total = (total == null) ? 1 : total;
/**
* The percentage (out of 1) that the load has been completed. This is calculated using `loaded/total`.
* @property progress
* @type {Number}
* @default 0
*/
this.progress = (total == 0) ? 0 : this.loaded / this.total;
}; | A CreateJS {{#crossLink "Event"}}{{/crossLink}} that is dispatched when progress changes.
@class ProgressEvent
@param {Number} loaded The amount that has been loaded. This can be any number relative to the total.
@param {Number} [total=1] The total amount that will load. This will default to 1, so if the `loaded` value is
a percentage (between 0 and 1), it can be omitted.
@todo Consider having this event be a "fileprogress" event as well
@constructor | ProgressEvent ( loaded , total ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.clone = function() {
return new createjs.ProgressEvent(this.loaded, this.total);
}; | Returns a clone of the ProgressEvent instance.
@method clone
@return {ProgressEvent} a clone of the Event instance.
* | p.clone ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function LoadItem() {
/**
* The source of the file that is being loaded. This property is <b>required</b>. The source can either be a
* string (recommended), or an HTML tag.
* This can also be an object, but in that case it has to include a type and be handled by a plugin.
* @property src
* @type {String}
* @default null
*/
this.src = null;
/**
* The type file that is being loaded. The type of the file is usually inferred by the extension, but can also
* be set manually. This is helpful in cases where a file does not have an extension.
* @property type
* @type {String}
* @default null
*/
this.type = null;
/**
* A string identifier which can be used to reference the loaded object. If none is provided, this will be
* automatically set to the {{#crossLink "src:property"}}{{/crossLink}}.
* @property id
* @type {String}
* @default null
*/
this.id = null;
/**
* Determines if a manifest will maintain the order of this item, in relation to other items in the manifest
* that have also set the `maintainOrder` property to `true`. This only applies when the max connections has
* been set above 1 (using {{#crossLink "LoadQueue/setMaxConnections"}}{{/crossLink}}). Everything with this
* property set to `false` will finish as it is loaded. Ordered items are combined with script tags loading in
* order when {{#crossLink "LoadQueue/maintainScriptOrder:property"}}{{/crossLink}} is set to `true`.
* @property maintainOrder
* @type {Boolean}
* @default false
*/
this.maintainOrder = false;
/**
* A callback used by JSONP requests that defines what global method to call when the JSONP content is loaded.
* @property callback
* @type {String}
* @default null
*/
this.callback = null;
/**
* An arbitrary data object, which is included with the loaded object.
* @property data
* @type {Object}
* @default null
*/
this.data = null;
/**
* The request method used for HTTP calls. Both {{#crossLink "Methods/GET:property"}}{{/crossLink}} or
* {{#crossLink "Methods/POST:property"}}{{/crossLink}} request types are supported, and are defined as
* constants on {{#crossLink "AbstractLoader"}}{{/crossLink}}.
* @property method
* @type {String}
* @default GET
*/
this.method = createjs.Methods.GET;
/**
* An object hash of name/value pairs to send to the server.
* @property values
* @type {Object}
* @default null
*/
this.values = null;
/**
* An object hash of headers to attach to an XHR request. PreloadJS will automatically attach some default
* headers when required, including "Origin", "Content-Type", and "X-Requested-With". You may override the
* default headers by including them in your headers object.
* @property headers
* @type {Object}
* @default null
*/
this.headers = null;
/**
* Enable credentials for XHR requests.
* @property withCredentials
* @type {Boolean}
* @default false
*/
this.withCredentials = false;
/**
* Set the mime type of XHR-based requests. This is automatically set to "text/plain; charset=utf-8" for text
* based files (json, xml, text, css, js).
* @property mimeType
* @type {String}
* @default null
*/
this.mimeType = null;
/**
* Sets the crossOrigin attribute for CORS-enabled images loading cross-domain.
* @property crossOrigin
* @type {boolean}
* @default Anonymous
*/
this.crossOrigin = null;
/**
* The duration in milliseconds to wait before a request times out. This only applies to tag-based and and XHR
* (level one) loading, as XHR (level 2) provides its own timeout event.
* @property loadTimeout
* @type {Number}
* @default 8000 (8 seconds)
*/
this.loadTimeout = s.LOAD_TIMEOUT_DEFAULT;
}; | All loaders accept an item containing the properties defined in this class. If a raw object is passed instead,
it will not be affected, but it must contain at least a {{#crossLink "src:property"}}{{/crossLink}} property. A
string path or HTML tag is also acceptable, but it will be automatically converted to a LoadItem using the
{{#crossLink "create"}}{{/crossLink}} method by {{#crossLink "AbstractLoader"}}{{/crossLink}}
@class LoadItem
@constructor
@since 0.6.0 | LoadItem ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.create = function (value) {
if (typeof value == "string") {
var item = new LoadItem();
item.src = value;
return item;
} else if (value instanceof s) {
return value;
} else if (value instanceof Object && value.src) {
if (value.loadTimeout == null) {
value.loadTimeout = s.LOAD_TIMEOUT_DEFAULT;
}
return value;
} else {
throw new Error("Type not recognized.");
}
}; | Create a LoadItem.
<ul>
<li>String-based items are converted to a LoadItem with a populated {{#crossLink "src:property"}}{{/crossLink}}.</li>
<li>LoadItem instances are returned as-is</li>
<li>Objects are returned with any needed properties added</li>
</ul>
@method create
@param {LoadItem|String|Object} value The load item value
@returns {LoadItem|Object}
@static | s.create ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.isImageTag = function(item) {
return item instanceof HTMLImageElement;
}; | Check if item is a valid HTMLImageElement
@method isImageTag
@param {Object} item
@returns {Boolean}
@static | s.isImageTag ( item ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.isAudioTag = function(item) {
if (window.HTMLAudioElement) {
return item instanceof HTMLAudioElement;
} else {
return false;
}
}; | Check if item is a valid HTMLAudioElement
@method isAudioTag
@param {Object} item
@returns {Boolean}
@static | s.isAudioTag ( item ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.isVideoTag = function(item) {
if (window.HTMLVideoElement) {
return item instanceof HTMLVideoElement;
} else {
return false;
}
}; | Check if item is a valid HTMLVideoElement
@method isVideoTag
@param {Object} item
@returns {Boolean}
@static | s.isVideoTag ( item ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.isBinary = function (type) {
switch (type) {
case createjs.Types.IMAGE:
case createjs.Types.BINARY:
return true;
default:
return false;
}
}; | 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 <b>not</b> 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
{{#crossLink "AbstractLoader"}}{{/crossLink}}.
@method isBinary
@param {String} type The item type.
@return {Boolean} If the specified type is binary.
@static | s.isBinary ( type ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.isText = function (type) {
switch (type) {
case createjs.Types.TEXT:
case createjs.Types.JSON:
case createjs.Types.MANIFEST:
case createjs.Types.XML:
case createjs.Types.CSS:
case createjs.Types.SVG:
case createjs.Types.JAVASCRIPT:
case createjs.Types.SPRITESHEET:
return true;
default:
return false;
}
}; | Determine if a specific type is a text-based asset, and should be loaded as UTF-8.
@method isText
@param {String} type The item type.
@return {Boolean} If the specified type is text.
@static | s.isText ( type ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.getTypeByExtension = function (extension) {
if (extension == null) {
return createjs.Types.TEXT;
}
switch (extension.toLowerCase()) {
case "jpeg":
case "jpg":
case "gif":
case "png":
case "webp":
case "bmp":
return createjs.Types.IMAGE;
case "ogg":
case "mp3":
case "webm":
return createjs.Types.SOUND;
case "mp4":
case "webm":
case "ts":
return createjs.Types.VIDEO;
case "json":
return createjs.Types.JSON;
case "xml":
return createjs.Types.XML;
case "css":
return createjs.Types.CSS;
case "js":
return createjs.Types.JAVASCRIPT;
case 'svg':
return createjs.Types.SVG;
default:
return createjs.Types.TEXT;
}
}; | 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.
@method getTypeByExtension
@param {String} extension The file extension to use to determine the load type.
@return {String} The determined load type (for example, `createjs.Types.IMAGE`). Will return `null` if
the type can not be determined by the extension.
@static | s.getTypeByExtension ( extension ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.parseURI = function (path) {
var info = {
absolute: false,
relative: false,
protocol: null,
hostname: null,
port: null,
pathname: null,
search: null,
hash: null,
host: null
};
if (path == null) { return info; }
// Inject the path parts.
var parser = createjs.Elements.a();
parser.href = path;
for (var n in info) {
if (n in parser) {
info[n] = parser[n];
}
}
// Drop the query string
var queryIndex = path.indexOf("?");
if (queryIndex > -1) {
path = path.substr(0, queryIndex);
}
// Absolute
var match;
if (s.ABSOLUTE_PATT.test(path)) {
info.absolute = true;
// Relative
} else if (s.RELATIVE_PATT.test(path)) {
info.relative = true;
}
// Extension
if (match = path.match(s.EXTENSION_PATT)) {
info.extension = match[1].toLowerCase();
}
return info;
}; | Parse a file path to determine the information we need to work with it. Currently, PreloadJS needs to know:
<ul>
<li>If the path is absolute. Absolute paths start with a protocol (such as `http://`, `file://`, or
`//networkPath`)</li>
<li>If the path is relative. Relative paths start with `../` or `/path` (or similar)</li>
<li>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`.</li>
</ul>
@method parseURI
@param {String} path
@returns {Object} An Object with an `absolute` and `relative` Boolean values,
the pieces of the path (protocol, hostname, port, pathname, search, hash, host)
as well as an optional 'extension` property, which is the lowercase extension.
@static | s.parseURI ( path ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.formatQueryString = function (data, query) {
if (data == null) {
throw new Error("You must specify data.");
}
var params = [];
for (var n in data) {
params.push(n + "=" + escape(data[n]));
}
if (query) {
params = params.concat(query);
}
return params.join("&");
}; | Formats an object into a query string for either a POST or GET request.
@method formatQueryString
@param {Object} data The data to convert to a query string.
@param {Array} [query] Existing name/value pairs to append on to this query.
@static | s.formatQueryString ( data , query ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.buildURI = function (src, data) {
if (data == null) {
return src;
}
var query = [];
var idx = src.indexOf("?");
if (idx != -1) {
var q = src.slice(idx + 1);
query = query.concat(q.split("&"));
}
if (idx != -1) {
return src.slice(0, idx) + "?" + this.formatQueryString(data, query);
} else {
return src + "?" + this.formatQueryString(data, query);
}
}; | A utility method that builds a file path using a source and a data object, and formats it into a new path.
@method buildURI
@param {String} src The source path to add values to.
@param {Object} [data] Object used to append values to this request as a query string. Existing parameters on the
path will be preserved.
@returns {string} A formatted string that contains the path and the supplied parameters.
@static | s.buildURI ( src , data ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.isCrossDomain = function (item) {
var target = createjs.Elements.a();
target.href = item.src;
var host = createjs.Elements.a();
host.href = location.href;
var crossdomain = (target.hostname != "") &&
(target.port != host.port ||
target.protocol != host.protocol ||
target.hostname != host.hostname);
return crossdomain;
}; | @method isCrossDomain
@param {LoadItem|Object} item A load item with a `src` property.
@return {Boolean} If the load item is loading from a different domain than the current location.
@static | s.isCrossDomain ( item ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.isLocal = function (item) {
var target = createjs.Elements.a();
target.href = item.src;
return target.hostname == "" && target.protocol == "file:";
}; | @method isLocal
@param {LoadItem|Object} item A load item with a `src` property
@return {Boolean} If the load item is loading from the "file:" protocol. Assume that the host must be local as
well.
@static | s.isLocal ( item ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function AbstractLoader(loadItem, preferXHR, type) {
this.EventDispatcher_constructor();
// public properties
/**
* If the loader has completed loading. This provides a quick check, but also ensures that the different approaches
* used for loading do not pile up resulting in more than one `complete` {{#crossLink "Event"}}{{/crossLink}}.
* @property loaded
* @type {Boolean}
* @default false
*/
this.loaded = false;
/**
* Determine if the loader was canceled. Canceled loads will not fire complete events. Note that this property
* is readonly, so {{#crossLink "LoadQueue"}}{{/crossLink}} queues should be closed using {{#crossLink "LoadQueue/close"}}{{/crossLink}}
* instead.
* @property canceled
* @type {Boolean}
* @default false
* @readonly
*/
this.canceled = false;
/**
* The current load progress (percentage) for this item. This will be a number between 0 and 1.
*
* <h4>Example</h4>
*
* var queue = new createjs.LoadQueue();
* queue.loadFile("largeImage.png");
* queue.on("progress", function() {
* console.log("Progress:", queue.progress, event.progress);
* });
*
* @property progress
* @type {Number}
* @default 0
*/
this.progress = 0;
/**
* The type of item this loader will load. See {{#crossLink "AbstractLoader"}}{{/crossLink}} for a full list of
* supported types.
* @property type
* @type {String}
*/
this.type = type;
/**
* A formatter function that converts the loaded raw result into the final result. For example, the JSONLoader
* converts a string of text into a JavaScript object. Not all loaders have a resultFormatter, and this property
* can be overridden to provide custom formatting.
*
* Optionally, a resultFormatter can return a callback function in cases where the formatting needs to be
* asynchronous, such as creating a new image. The callback function is passed 2 parameters, which are callbacks
* to handle success and error conditions in the resultFormatter. Note that the resultFormatter method is
* called in the current scope, as well as the success and error callbacks.
*
* <h4>Example asynchronous resultFormatter</h4>
*
* function _formatResult(loader) {
* return function(success, error) {
* if (errorCondition) { error(errorDetailEvent); }
* success(result);
* }
* }
* @property resultFormatter
* @type {Function}
* @default null
*/
this.resultFormatter = null;
// protected properties
/**
* The {{#crossLink "LoadItem"}}{{/crossLink}} this loader represents. Note that this is null in a {{#crossLink "LoadQueue"}}{{/crossLink}},
* but will be available on loaders such as {{#crossLink "XMLLoader"}}{{/crossLink}} and {{#crossLink "ImageLoader"}}{{/crossLink}}.
* @property _item
* @type {LoadItem|Object}
* @private
*/
if (loadItem) {
this._item = createjs.LoadItem.create(loadItem);
} else {
this._item = null;
}
/**
* Whether the loader will try and load content using XHR (true) or HTML tags (false).
* @property _preferXHR
* @type {Boolean}
* @private
*/
this._preferXHR = preferXHR;
/**
* The loaded result after it is formatted by an optional {{#crossLink "resultFormatter"}}{{/crossLink}}. For
* items that are not formatted, this will be the same as the {{#crossLink "_rawResult:property"}}{{/crossLink}}.
* The result is accessed using the {{#crossLink "getResult"}}{{/crossLink}} method.
* @property _result
* @type {Object|String}
* @private
*/
this._result = null;
/**
* The loaded result before it is formatted. The rawResult is accessed using the {{#crossLink "getResult"}}{{/crossLink}}
* method, and passing `true`.
* @property _rawResult
* @type {Object|String}
* @private
*/
this._rawResult = null;
/**
* A list of items that loaders load behind the scenes. This does not include the main item the loader is
* responsible for loading. Examples of loaders that have sub-items include the {{#crossLink "SpriteSheetLoader"}}{{/crossLink}} and
* {{#crossLink "ManifestLoader"}}{{/crossLink}}.
* @property _loadItems
* @type {null}
* @protected
*/
this._loadedItems = null;
/**
* The attribute the items loaded using tags use for the source.
* @type {string}
* @default null
* @private
*/
this._tagSrcAttribute = null;
/**
* An HTML tag (or similar) that a loader may use to load HTML content, such as images, scripts, etc.
* @property _tag
* @type {Object}
* @private
*/
this._tag = null;
}; | The base loader, which defines all the generic methods, properties, and events. All loaders extend this class,
including the {{#crossLink "LoadQueue"}}{{/crossLink}}.
@class AbstractLoader
@param {LoadItem|object|string} loadItem The item to be loaded.
@param {Boolean} [preferXHR] Determines if the LoadItem should <em>try</em> and load using XHR, or take a
tag-based approach, which can be better in cross-domain situations. Not all loaders can load using one or the
other, so this is a suggested directive.
@param {String} [type] The type of loader. Loader types are defined as constants on the AbstractLoader class,
such as {{#crossLink "IMAGE:property"}}{{/crossLink}}, {{#crossLink "CSS:property"}}{{/crossLink}}, etc.
@extends EventDispatcher | AbstractLoader ( loadItem , preferXHR , type ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.getItem = function () {
return this._item;
}; | Get a reference to the manifest item that is loaded by this loader. In some cases this will be the value that was
passed into {{#crossLink "LoadQueue"}}{{/crossLink}} using {{#crossLink "LoadQueue/loadFile"}}{{/crossLink}} or
{{#crossLink "LoadQueue/loadManifest"}}{{/crossLink}}. However if only a String path was passed in, then it will
be a {{#crossLink "LoadItem"}}{{/crossLink}}.
@method getItem
@return {Object} The manifest item that this loader is responsible for loading.
@since 0.6.0 | p.getItem ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.getResult = function (raw) {
return raw ? this._rawResult : this._result;
}; | Get a reference to the content that was loaded by the loader (only available after the {{#crossLink "complete:event"}}{{/crossLink}}
event is dispatched.
@method getResult
@param {Boolean} [raw=false] Determines if the returned result will be the formatted content, or the raw loaded
data (if it exists).
@return {Object}
@since 0.6.0 | p.getResult ( raw ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.getTag = function () {
return this._tag;
}; | Return the `tag` this object creates or uses for loading.
@method getTag
@return {Object} The tag instance
@since 0.6.0 | p.getTag ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.setTag = function(tag) {
this._tag = tag;
}; | Set the `tag` this item uses for loading.
@method setTag
@param {Object} tag The tag instance
@since 0.6.0 | p.setTag ( tag ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.load = function () {
this._createRequest();
this._request.on("complete", this, this);
this._request.on("progress", this, this);
this._request.on("loadStart", this, this);
this._request.on("abort", this, this);
this._request.on("timeout", this, this);
this._request.on("error", this, this);
var evt = new createjs.Event("initialize");
evt.loader = this._request;
this.dispatchEvent(evt);
this._request.load();
}; | Begin loading the item. This method is required when using a loader by itself.
<h4>Example</h4>
var queue = new createjs.LoadQueue();
queue.on("complete", handleComplete);
queue.loadManifest(fileArray, false); // Note the 2nd argument that tells the queue not to start loading yet
queue.load();
@method load | p.load ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.cancel = function () {
this.canceled = true;
this.destroy();
}; | Close the the item. This will stop any open requests (although downloads using HTML tags may still continue in
the background), but events will not longer be dispatched.
@method cancel | p.cancel ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.destroy = function() {
if (this._request) {
this._request.removeAllEventListeners();
this._request.destroy();
}
this._request = null;
this._item = null;
this._rawResult = null;
this._result = null;
this._loadItems = null;
this.removeAllEventListeners();
}; | Clean up the loader.
@method destroy | p.destroy ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.getLoadedItems = function () {
return this._loadedItems;
}; | Get any items loaded internally by the loader. The enables loaders such as {{#crossLink "ManifestLoader"}}{{/crossLink}}
to expose items it loads internally.
@method getLoadedItems
@return {Array} A list of the items loaded by the loader.
@since 0.6.0 | p.getLoadedItems ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._createRequest = function() {
if (!this._preferXHR) {
this._request = new createjs.TagRequest(this._item, this._tag || this._createTag(), this._tagSrcAttribute);
} else {
this._request = new createjs.XHRRequest(this._item);
}
}; | Create an internal request used for loading. By default, an {{#crossLink "XHRRequest"}}{{/crossLink}} or
{{#crossLink "TagRequest"}}{{/crossLink}} is created, depending on the value of {{#crossLink "preferXHR:property"}}{{/crossLink}}.
Other loaders may override this to use different request types, such as {{#crossLink "ManifestLoader"}}{{/crossLink}},
which uses {{#crossLink "JSONLoader"}}{{/crossLink}} or {{#crossLink "JSONPLoader"}}{{/crossLink}} under the hood.
@method _createRequest
@protected | p._createRequest ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._createTag = function(src) { return null; }; | Create the HTML tag used for loading. This method does nothing by default, and needs to be implemented
by loaders that require tag loading.
@method _createTag
@param {String} src The tag source
@return {HTMLElement} The tag that was created
@protected | p._createTag ( src ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._sendLoadStart = function () {
if (this._isCanceled()) { return; }
this.dispatchEvent("loadstart");
}; | Dispatch a loadstart {{#crossLink "Event"}}{{/crossLink}}. Please see the {{#crossLink "AbstractLoader/loadstart:event"}}{{/crossLink}}
event for details on the event payload.
@method _sendLoadStart
@protected | p._sendLoadStart ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._sendProgress = function (value) {
if (this._isCanceled()) { return; }
var event = null;
if (typeof(value) == "number") {
this.progress = value;
event = new createjs.ProgressEvent(this.progress);
} else {
event = value;
this.progress = value.loaded / value.total;
event.progress = this.progress;
if (isNaN(this.progress) || this.progress == Infinity) { this.progress = 0; }
}
this.hasEventListener("progress") && this.dispatchEvent(event);
}; | Dispatch a {{#crossLink "ProgressEvent"}}{{/crossLink}}.
@method _sendProgress
@param {Number | Object} value The progress of the loaded item, or an object containing <code>loaded</code>
and <code>total</code> properties.
@protected | p._sendProgress ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._sendComplete = function () {
if (this._isCanceled()) { return; }
this.loaded = true;
var event = new createjs.Event("complete");
event.rawResult = this._rawResult;
if (this._result != null) {
event.result = this._result;
}
this.dispatchEvent(event);
}; | Dispatch a complete {{#crossLink "Event"}}{{/crossLink}}. Please see the {{#crossLink "AbstractLoader/complete:event"}}{{/crossLink}} event
@method _sendComplete
@protected | p._sendComplete ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._sendError = function (event) {
if (this._isCanceled() || !this.hasEventListener("error")) { return; }
if (event == null) {
event = new createjs.ErrorEvent("PRELOAD_ERROR_EMPTY"); // TODO: Populate error
}
this.dispatchEvent(event);
}; | Dispatch an error {{#crossLink "Event"}}{{/crossLink}}. Please see the {{#crossLink "AbstractLoader/error:event"}}{{/crossLink}}
event for details on the event payload.
@method _sendError
@param {ErrorEvent} event The event object containing specific error properties.
@protected | p._sendError ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._isCanceled = function () {
if (window.createjs == null || this.canceled) {
return true;
}
return false;
}; | Determine if the load has been canceled. This is important to ensure that method calls or asynchronous events
do not cause issues after the queue has been cleaned up.
@method _isCanceled
@return {Boolean} If the loader has been canceled.
@protected | p._isCanceled ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._resultFormatSuccess = function (result) {
this._result = result;
this._sendComplete();
}; | The "success" callback passed to {{#crossLink "AbstractLoader/resultFormatter"}}{{/crossLink}} asynchronous
functions.
@method _resultFormatSuccess
@param {Object} result The formatted result
@private | p._resultFormatSuccess ( result ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._resultFormatFailed = function (event) {
this._sendError(event);
}; | The "error" callback passed to {{#crossLink "AbstractLoader/resultFormatter"}}{{/crossLink}} asynchronous
functions.
@method _resultFormatSuccess
@param {Object} error The error event
@private | p._resultFormatFailed ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.toString = function () {
return "[PreloadJS AbstractLoader]";
}; | @method toString
@return {String} a string representation of the instance. | p.toString ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function AbstractMediaLoader(loadItem, preferXHR, type) {
this.AbstractLoader_constructor(loadItem, preferXHR, type);
// public properties
this.resultFormatter = this._formatResult;
// protected properties
this._tagSrcAttribute = "src";
this.on("initialize", this._updateXHR, this);
}; | The AbstractMediaLoader is a base class that handles some of the shared methods and properties of loaders that
handle HTML media elements, such as Video and Audio.
@class AbstractMediaLoader
@param {LoadItem|Object} loadItem
@param {Boolean} preferXHR
@param {String} type The type of media to load. Usually "video" or "audio".
@extends AbstractLoader
@constructor | AbstractMediaLoader ( loadItem , preferXHR , type ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._createTag = function () {}; | Creates a new tag for loading if it doesn't exist yet.
@method _createTag
@private | p._createTag ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._updateXHR = function (event) {
// Only exists for XHR
if (event.loader.setResponseType) {
event.loader.setResponseType("blob");
}
}; | Before the item loads, set its mimeType and responseType.
@property _updateXHR
@param {Event} event
@private | p._updateXHR ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._formatResult = function (loader) {
this._tag.removeEventListener && this._tag.removeEventListener("canplaythrough", this._loadedHandler);
this._tag.onstalled = null;
if (this._preferXHR) {
var URL = window.URL || window.webkitURL;
var result = loader.getResult(true);
loader.getTag().src = URL.createObjectURL(result);
}
return loader.getTag();
}; | The result formatter for media files.
@method _formatResult
@param {AbstractLoader} loader
@returns {HTMLVideoElement|HTMLAudioElement}
@private | p._formatResult ( loader ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
var AbstractRequest = function (item) {
this._item = item;
}; | A base class for actual data requests, such as {{#crossLink "XHRRequest"}}{{/crossLink}}, {{#crossLink "TagRequest"}}{{/crossLink}},
and {{#crossLink "MediaRequest"}}{{/crossLink}}. PreloadJS loaders will typically use a data loader under the
hood to get data.
@class AbstractRequest
@param {LoadItem} item
@constructor | AbstractRequest ( item ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.cancel = function() {}; | Cancel an in-progress request.
@method cancel | p.cancel ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function TagRequest(loadItem, tag, srcAttribute) {
this.AbstractRequest_constructor(loadItem);
// protected properties
/**
* The HTML tag instance that is used to load.
* @property _tag
* @type {HTMLElement}
* @protected
*/
this._tag = tag;
/**
* The tag attribute that specifies the source, such as "src", "href", etc.
* @property _tagSrcAttribute
* @type {String}
* @protected
*/
this._tagSrcAttribute = srcAttribute;
/**
* A method closure used for handling the tag load event.
* @property _loadedHandler
* @type {Function}
* @private
*/
this._loadedHandler = createjs.proxy(this._handleTagComplete, this);
/**
* Determines if the element was added to the DOM automatically by PreloadJS, so it can be cleaned up after.
* @property _addedToDOM
* @type {Boolean}
* @private
*/
this._addedToDOM = false;
}; | An {{#crossLink "AbstractRequest"}}{{/crossLink}} that loads HTML tags, such as images and scripts.
@class TagRequest
@param {LoadItem} loadItem
@param {HTMLElement} tag
@param {String} srcAttribute The tag attribute that specifies the source, such as "src", "href", etc. | TagRequest ( loadItem , tag , srcAttribute ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleReadyStateChange = function () {
clearTimeout(this._loadTimeout);
// This is strictly for tags in browsers that do not support onload.
var tag = this._tag;
// Complete is for old IE support.
if (tag.readyState == "loaded" || tag.readyState == "complete") {
this._handleTagComplete();
}
}; | Handle the readyStateChange event from a tag. We need this in place of the `onload` callback (mainly SCRIPT
and LINK tags), but other cases may exist.
@method _handleReadyStateChange
@private | p._handleReadyStateChange ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleError = function() {
this._clean();
this.dispatchEvent("error");
}; | Handle any error events from the tag.
@method _handleError
@protected | p._handleError ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleTagComplete = function () {
this._rawResult = this._tag;
this._result = this.resultFormatter && this.resultFormatter(this) || this._rawResult;
this._clean();
this.dispatchEvent("complete");
}; | Handle the tag's onload callback.
@method _handleTagComplete
@private | p._handleTagComplete ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleTimeout = function () {
this._clean();
this.dispatchEvent(new createjs.Event("timeout"));
}; | The tag request has not loaded within the time specified in loadTimeout.
@method _handleError
@param {Object} event The XHR error event.
@private | p._handleTimeout ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._clean = function() {
this._tag.onload = null;
this._tag.onreadystatechange = null;
this._tag.onerror = null;
if (this._addedToDOM && this._tag.parentNode != null) {
this._tag.parentNode.removeChild(this._tag);
}
clearTimeout(this._loadTimeout);
}; | Remove event listeners, but don't destroy the request object
@method _clean
@private | p._clean ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleStalled = function () {
//Ignore, let the timeout take care of it. Sometimes its not really stopped.
}; | Handle a stalled audio event. The main place this happens is with HTMLAudio in Chrome when playing back audio
that is already in a load, but not complete.
@method _handleStalled
@private | p._handleStalled ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function MediaTagRequest(loadItem, tag, srcAttribute) {
this.AbstractRequest_constructor(loadItem);
// protected properties
this._tag = tag;
this._tagSrcAttribute = srcAttribute;
this._loadedHandler = createjs.proxy(this._handleTagComplete, this);
}; | An {{#crossLink "TagRequest"}}{{/crossLink}} that loads HTML tags for video and audio.
@class MediaTagRequest
@param {LoadItem} loadItem
@param {HTMLAudioElement|HTMLVideoElement} tag
@param {String} srcAttribute The tag attribute that specifies the source, such as "src", "href", etc.
@constructor | MediaTagRequest ( loadItem , tag , srcAttribute ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleProgress = function (event) {
if (!event || event.loaded > 0 && event.total == 0) {
return; // Sometimes we get no "total", so just ignore the progress event.
}
var newEvent = new createjs.ProgressEvent(event.loaded, event.total);
this.dispatchEvent(newEvent);
}; | An XHR request has reported progress.
@method _handleProgress
@param {Object} event The XHR progress event.
@private | p._handleProgress ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function XHRRequest (item) {
this.AbstractRequest_constructor(item);
// protected properties
/**
* A reference to the XHR request used to load the content.
* @property _request
* @type {XMLHttpRequest | XDomainRequest | ActiveX.XMLHTTP}
* @private
*/
this._request = null;
/**
* A manual load timeout that is used for browsers that do not support the onTimeout event on XHR (XHR level 1,
* typically IE9).
* @property _loadTimeout
* @type {Number}
* @private
*/
this._loadTimeout = null;
/**
* The browser's XHR (XMLHTTPRequest) version. Supported versions are 1 and 2. There is no official way to detect
* the version, so we use capabilities to make a best guess.
* @property _xhrLevel
* @type {Number}
* @default 1
* @private
*/
this._xhrLevel = 1;
/**
* The response of a loaded file. This is set because it is expensive to look up constantly. This property will be
* null until the file is loaded.
* @property _response
* @type {mixed}
* @private
*/
this._response = null;
/**
* The response of the loaded file before it is modified. In most cases, content is converted from raw text to
* an HTML tag or a formatted object which is set to the <code>result</code> property, but the developer may still
* want to access the raw content as it was loaded.
* @property _rawResponse
* @type {String|Object}
* @private
*/
this._rawResponse = null;
this._canceled = false;
// Setup our event handlers now.
this._handleLoadStartProxy = createjs.proxy(this._handleLoadStart, this);
this._handleProgressProxy = createjs.proxy(this._handleProgress, this);
this._handleAbortProxy = createjs.proxy(this._handleAbort, this);
this._handleErrorProxy = createjs.proxy(this._handleError, this);
this._handleTimeoutProxy = createjs.proxy(this._handleTimeout, this);
this._handleLoadProxy = createjs.proxy(this._handleLoad, this);
this._handleReadyStateChangeProxy = createjs.proxy(this._handleReadyStateChange, this);
if (!this._createXHR(item)) {
//TODO: Throw error?
}
}; | A preloader that loads items using XHR requests, usually XMLHttpRequest. However XDomainRequests will be used
for cross-domain requests if possible, and older versions of IE fall back on to ActiveX objects when necessary.
XHR requests load the content as text or binary data, provide progress and consistent completion events, and
can be canceled during load. Note that XHR is not supported in IE 6 or earlier, and is not recommended for
cross-domain loading.
@class XHRRequest
@constructor
@param {Object} item The object that defines the file to load. Please see the {{#crossLink "LoadQueue/loadFile"}}{{/crossLink}}
for an overview of supported file properties.
@extends AbstractLoader | XHRRequest ( item ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.getResult = function (raw) {
if (raw && this._rawResponse) {
return this._rawResponse;
}
return this._response;
}; | Look up the loaded result.
@method getResult
@param {Boolean} [raw=false] Return a raw result instead of a formatted result. This applies to content
loaded via XHR such as scripts, XML, CSS, and Images. If there is no raw result, the formatted result will be
returned instead.
@return {Object} A result object containing the content that was loaded, such as:
<ul>
<li>An image tag (<image />) for images</li>
<li>A script tag for JavaScript (<script />). Note that scripts loaded with tags may be added to the
HTML head.</li>
<li>A style tag for CSS (<style />)</li>
<li>Raw text for TEXT</li>
<li>A formatted JavaScript object defined by JSON</li>
<li>An XML document</li>
<li>An binary arraybuffer loaded by XHR</li>
</ul>
Note that if a raw result is requested, but not found, the result will be returned instead. | p.getResult ( raw ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.getAllResponseHeaders = function () {
if (this._request.getAllResponseHeaders instanceof Function) {
return this._request.getAllResponseHeaders();
} else {
return null;
}
}; | Get all the response headers from the XmlHttpRequest.
<strong>From the docs:</strong> Return all the HTTP headers, excluding headers that are a case-insensitive match
for Set-Cookie or Set-Cookie2, as a single string, with each header line separated by a U+000D CR U+000A LF pair,
excluding the status line, and with each header name and header value separated by a U+003A COLON U+0020 SPACE
pair.
@method getAllResponseHeaders
@return {String}
@since 0.4.1 | p.getAllResponseHeaders ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.getResponseHeader = function (header) {
if (this._request.getResponseHeader instanceof Function) {
return this._request.getResponseHeader(header);
} else {
return null;
}
}; | Get a specific response header from the XmlHttpRequest.
<strong>From the docs:</strong> Returns the header field value from the response of which the field name matches
header, unless the field name is Set-Cookie or Set-Cookie2.
@method getResponseHeader
@param {String} header The header name to retrieve.
@return {String}
@since 0.4.1 | p.getResponseHeader ( header ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleLoadStart = function (event) {
clearTimeout(this._loadTimeout);
this.dispatchEvent("loadstart");
}; | The XHR request has reported a load start.
@method _handleLoadStart
@param {Object} event The XHR loadStart event.
@private | p._handleLoadStart ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleAbort = function (event) {
this._clean();
this.dispatchEvent(new createjs.ErrorEvent("XHR_ABORTED", null, event));
}; | The XHR request has reported an abort event.
@method handleAbort
@param {Object} event The XHR abort event.
@private | p._handleAbort ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleError = function (event) {
this._clean();
this.dispatchEvent(new createjs.ErrorEvent(event.message));
}; | The XHR request has reported an error event.
@method _handleError
@param {Object} event The XHR error event.
@private | p._handleError ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleReadyStateChange = function (event) {
if (this._request.readyState == 4) {
this._handleLoad();
}
}; | The XHR request has reported a readyState change. Note that older browsers (IE 7 & 8) do not provide an onload
event, so we must monitor the readyStateChange to determine if the file is loaded.
@method _handleReadyStateChange
@param {Object} event The XHR readyStateChange event.
@private | p._handleReadyStateChange ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleLoad = function (event) {
if (this.loaded) {
return;
}
this.loaded = true;
var error = this._checkError();
if (error) {
this._handleError(error);
return;
}
this._response = this._getResponse();
// Convert arraybuffer back to blob
if (this._responseType === 'arraybuffer') {
try {
this._response = new Blob([this._response]);
} catch (e) {
// Fallback to use BlobBuilder if Blob constructor is not supported
// Tested on Android 2.3 ~ 4.2 and iOS5 safari
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
if (e.name === 'TypeError' && window.BlobBuilder) {
var builder = new BlobBuilder();
builder.append(this._response);
this._response = builder.getBlob();
}
}
}
this._clean();
this.dispatchEvent(new createjs.Event("complete"));
}; | The XHR request has completed. This is called by the XHR request directly, or by a readyStateChange that has
<code>request.readyState == 4</code>. Only the first call to this method will be processed.
Note that This method uses {{#crossLink "_checkError"}}{{/crossLink}} to determine if the server has returned an
error code.
@method _handleLoad
@param {Object} event The XHR load event.
@private | p._handleLoad ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._handleTimeout = function (event) {
this._clean();
this.dispatchEvent(new createjs.ErrorEvent("PRELOAD_TIMEOUT", null, event));
}; | The XHR request has timed out. This is called by the XHR request directly, or via a <code>setTimeout</code>
callback.
@method _handleTimeout
@param {Object} [event] The XHR timeout event. This is occasionally null when called by the backup setTimeout.
@private | p._handleTimeout ( event ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._getResponse = function () {
if (this._response != null) {
return this._response;
}
if (this._request.response != null) {
return this._request.response;
}
// Android 2.2 uses .responseText
try {
if (this._request.responseText != null) {
return this._request.responseText;
}
} catch (e) {
}
// When loading XML, IE9 does not return .response, instead it returns responseXML.xml
try {
if (this._request.responseXML != null) {
return this._request.responseXML;
}
} catch (e) {
}
return null;
}; | Validate the response. Different browsers have different approaches, some of which throw errors when accessed
in other browsers. If there is no response, the <code>_response</code> property will remain null.
@method _getResponse
@private | p._getResponse ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._createXHR = function (item) {
// Check for cross-domain loads. We can't fully support them, but we can try.
var crossdomain = createjs.URLUtils.isCrossDomain(item);
var headers = {};
// Create the request. Fallback to whatever support we have.
var req = null;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
// This is 8 or 9, so use XDomainRequest instead.
if (crossdomain && req.withCredentials === undefined && window.XDomainRequest) {
req = new XDomainRequest();
}
} else { // Old IE versions use a different approach
for (var i = 0, l = s.ACTIVEX_VERSIONS.length; i < l; i++) {
var axVersion = s.ACTIVEX_VERSIONS[i];
try {
req = new ActiveXObject(axVersion);
break;
} catch (e) {
}
}
if (req == null) {
return false;
}
}
// Default to utf-8 for Text requests.
if (item.mimeType == null && createjs.RequestUtils.isText(item.type)) {
item.mimeType = "text/plain; charset=utf-8";
}
// IE9 doesn't support overrideMimeType(), so we need to check for it.
if (item.mimeType && req.overrideMimeType) {
req.overrideMimeType(item.mimeType);
}
// Determine the XHR level
this._xhrLevel = (typeof req.responseType === "string") ? 2 : 1;
var src = null;
if (item.method == createjs.Methods.GET) {
src = createjs.URLUtils.buildURI(item.src, item.values);
} else {
src = item.src;
}
// Open the request. Set cross-domain flags if it is supported (XHR level 1 only)
req.open(item.method || createjs.Methods.GET, src, true);
if (crossdomain && req instanceof XMLHttpRequest && this._xhrLevel == 1) {
headers["Origin"] = location.origin;
}
// To send data we need to set the Content-type header)
if (item.values && item.method == createjs.Methods.POST) {
headers["Content-Type"] = "application/x-www-form-urlencoded";
}
if (!crossdomain && !headers["X-Requested-With"]) {
headers["X-Requested-With"] = "XMLHttpRequest";
}
if (item.headers) {
for (var n in item.headers) {
headers[n] = item.headers[n];
}
}
for (n in headers) {
req.setRequestHeader(n, headers[n])
}
if (req instanceof XMLHttpRequest && item.withCredentials !== undefined) {
req.withCredentials = item.withCredentials;
}
this._request = req;
return true;
}; | Create an XHR request. Depending on a number of factors, we get totally different results.
<ol><li>Some browsers get an <code>XDomainRequest</code> when loading cross-domain.</li>
<li>XMLHttpRequest are created when available.</li>
<li>ActiveX.XMLHTTP objects are used in older IE browsers.</li>
<li>Text requests override the mime type if possible</li>
<li>Origin headers are sent for crossdomain requests in some browsers.</li>
<li>Binary loads set the response type to "arraybuffer"</li></ol>
@method _createXHR
@param {Object} item The requested item that is being loaded.
@return {Boolean} If an XHR request or equivalent was successfully created.
@private | p._createXHR ( item ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._clean = function () {
clearTimeout(this._loadTimeout);
if (this._request.removeEventListener != null) {
this._request.removeEventListener("loadstart", this._handleLoadStartProxy);
this._request.removeEventListener("progress", this._handleProgressProxy);
this._request.removeEventListener("abort", this._handleAbortProxy);
this._request.removeEventListener("error", this._handleErrorProxy);
this._request.removeEventListener("timeout", this._handleTimeoutProxy);
this._request.removeEventListener("load", this._handleLoadProxy);
this._request.removeEventListener("readystatechange", this._handleReadyStateChangeProxy);
} else {
this._request.onloadstart = null;
this._request.onprogress = null;
this._request.onabort = null;
this._request.onerror = null;
this._request.ontimeout = null;
this._request.onload = null;
this._request.onreadystatechange = null;
}
}; | A request has completed (or failed or canceled), and needs to be disposed.
@method _clean
@private | p._clean ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._checkError = function () {
var status = parseInt(this._request.status);
if (status >= 400 && status <= 599) {
return new Error(status);
} else if (status == 0) {
if ((/^https?:/).test(location.protocol)) { return new Error(0); }
return null; // Likely an embedded app.
} else {
return null;
}
};
/**
* Validate the response. Different browsers have different approaches, some of which throw errors when accessed
* in other browsers. If there is no response, the <code>_response</code> property will remain null.
* @method _getResponse
* @private
*/
p._getResponse = function () {
if (this._response != null) {
return this._response;
}
if (this._request.response != null) {
return this._request.response;
}
// Android 2.2 uses .responseText
try {
if (this._request.responseText != null) {
return this._request.responseText;
}
} catch (e) {
}
// When loading XML, IE9 does not return .response, instead it returns responseXML.xml
try {
if (this._request.responseXML != null) {
return this._request.responseXML;
}
} catch (e) {
}
return null;
};
/**
* Create an XHR request. Depending on a number of factors, we get totally different results.
* <ol><li>Some browsers get an <code>XDomainRequest</code> when loading cross-domain.</li>
* <li>XMLHttpRequest are created when available.</li>
* <li>ActiveX.XMLHTTP objects are used in older IE browsers.</li>
* <li>Text requests override the mime type if possible</li>
* <li>Origin headers are sent for crossdomain requests in some browsers.</li>
* <li>Binary loads set the response type to "arraybuffer"</li></ol>
* @method _createXHR
* @param {Object} item The requested item that is being loaded.
* @return {Boolean} If an XHR request or equivalent was successfully created.
* @private
*/
p._createXHR = function (item) {
// Check for cross-domain loads. We can't fully support them, but we can try.
var crossdomain = createjs.URLUtils.isCrossDomain(item);
var headers = {};
// Create the request. Fallback to whatever support we have.
var req = null;
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
// This is 8 or 9, so use XDomainRequest instead.
if (crossdomain && req.withCredentials === undefined && window.XDomainRequest) {
req = new XDomainRequest();
}
} else { // Old IE versions use a different approach
for (var i = 0, l = s.ACTIVEX_VERSIONS.length; i < l; i++) {
var axVersion = s.ACTIVEX_VERSIONS[i];
try {
req = new ActiveXObject(axVersion);
break;
} catch (e) {
}
}
if (req == null) {
return false;
}
}
// Default to utf-8 for Text requests.
if (item.mimeType == null && createjs.RequestUtils.isText(item.type)) {
item.mimeType = "text/plain; charset=utf-8";
}
// IE9 doesn't support overrideMimeType(), so we need to check for it.
if (item.mimeType && req.overrideMimeType) {
req.overrideMimeType(item.mimeType);
}
// Determine the XHR level
this._xhrLevel = (typeof req.responseType === "string") ? 2 : 1;
var src = null;
if (item.method == createjs.Methods.GET) {
src = createjs.URLUtils.buildURI(item.src, item.values);
} else {
src = item.src;
}
// Open the request. Set cross-domain flags if it is supported (XHR level 1 only)
req.open(item.method || createjs.Methods.GET, src, true);
if (crossdomain && req instanceof XMLHttpRequest && this._xhrLevel == 1) {
headers["Origin"] = location.origin;
}
// To send data we need to set the Content-type header)
if (item.values && item.method == createjs.Methods.POST) {
headers["Content-Type"] = "application/x-www-form-urlencoded";
}
if (!crossdomain && !headers["X-Requested-With"]) {
headers["X-Requested-With"] = "XMLHttpRequest";
}
if (item.headers) {
for (var n in item.headers) {
headers[n] = item.headers[n];
}
}
for (n in headers) {
req.setRequestHeader(n, headers[n])
}
if (req instanceof XMLHttpRequest && item.withCredentials !== undefined) {
req.withCredentials = item.withCredentials;
}
this._request = req;
return true;
};
/**
* A request has completed (or failed or canceled), and needs to be disposed.
* @method _clean
* @private
*/
p._clean = function () {
clearTimeout(this._loadTimeout);
if (this._request.removeEventListener != null) {
this._request.removeEventListener("loadstart", this._handleLoadStartProxy);
this._request.removeEventListener("progress", this._handleProgressProxy);
this._request.removeEventListener("abort", this._handleAbortProxy);
this._request.removeEventListener("error", this._handleErrorProxy);
this._request.removeEventListener("timeout", this._handleTimeoutProxy);
this._request.removeEventListener("load", this._handleLoadProxy);
this._request.removeEventListener("readystatechange", this._handleReadyStateChangeProxy);
} else {
this._request.onloadstart = null;
this._request.onprogress = null;
this._request.onabort = null;
this._request.onerror = null;
this._request.ontimeout = null;
this._request.onload = null;
this._request.onreadystatechange = null;
}
};
p.toString = function () {
return "[PreloadJS XHRRequest]";
};
createjs.XHRRequest = createjs.promote(XHRRequest, "AbstractRequest");
}()); | Determine if there is an error in the current load.
Currently this checks the status of the request for problem codes, and not actual response content:
<ul>
<li>Status codes between 400 and 599 (HTTP error range)</li>
<li>A status of 0, but *only when the application is running on a server*. If the application is running
on `file:`, then it may incorrectly treat an error on local (or embedded applications) as a successful
load.</li>
</ul>
@method _checkError
@return {Error} An error with the status code in the `message` argument.
@private | p._checkError ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
function SoundLoader(loadItem, preferXHR) {
this.AbstractMediaLoader_constructor(loadItem, preferXHR, createjs.Types.SOUND);
// protected properties
if (createjs.DomUtils.isAudioTag(loadItem)) {
this._tag = loadItem;
} else if (createjs.DomUtils.isAudioTag(loadItem.src)) {
this._tag = loadItem;
} else if (createjs.DomUtils.isAudioTag(loadItem.tag)) {
this._tag = createjs.DomUtils.isAudioTag(loadItem) ? loadItem : loadItem.src;
}
if (this._tag != null) {
this._preferXHR = false;
}
}; | A loader for HTML audio files. PreloadJS can not load WebAudio files, as a WebAudio context is required, which
should be created by either a library playing the sound (such as <a href="http://soundjs.com">SoundJS</a>, or an
external framework that handles audio playback. To load content that can be played by WebAudio, use the
{{#crossLink "BinaryLoader"}}{{/crossLink}}, and handle the audio context decoding manually.
@class SoundLoader
@param {LoadItem|Object} loadItem
@param {Boolean} preferXHR
@extends AbstractMediaLoader
@constructor | SoundLoader ( loadItem , preferXHR ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.canLoadItem = function (item) {
return item.type == createjs.Types.SOUND;
}; | Determines if the loader can load a specific item. This loader can only load items that are of type
{{#crossLink "Types/SOUND:property"}}{{/crossLink}}.
@method canLoadItem
@param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
@returns {Boolean} Whether the loader can load the item.
@static | s.canLoadItem ( item ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
s.create = function (value) {
if (typeof(value) === "string") {
// Handle the old API gracefully.
console && (console.warn || console.log)("Deprecated behaviour. Sound.play takes a configuration object instead of individual arguments. See docs for info.");
return new createjs.PlayPropsConfig().set({interrupt:value});
} else if (value == null || value instanceof s || value instanceof Object) {
return new createjs.PlayPropsConfig().set(value);
} else if (value == null) {
throw new Error("PlayProps configuration not recognized.");
}
}; | Creates a PlayPropsConfig from another PlayPropsConfig or an Object.
@method create
@param {PlayPropsConfig|Object} value The play properties
@returns {PlayPropsConfig}
@static | s.create ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.set = function(props) {
if (props != null) {
for (var n in props) { this[n] = props[n]; }
}
return this;
}; | Provides a chainable shortcut method for setting a number of properties on the instance.
<h4>Example</h4>
var PlayPropsConfig = new createjs.PlayPropsConfig().set({loop:-1, volume:0.7});
@method set
@param {Object} props A generic object containing properties to copy to the PlayPropsConfig instance.
@return {PlayPropsConfig} Returns the instance the method is called on (useful for chaining calls.) | p.set ( props ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.stop = function () {
this._position = 0;
this._paused = false;
this._handleStop();
this._cleanUp();
this.playState = createjs.Sound.PLAY_FINISHED;
return this;
}; | Stop playback of the instance. Stopped sounds will reset their position to 0, and calls to {{#crossLink "AbstractSoundInstance/resume"}}{{/crossLink}}
will fail. To start playback again, call {{#crossLink "AbstractSoundInstance/play"}}{{/crossLink}}.
If you don't want to lose your position use yourSoundInstance.paused = true instead. {{#crossLink "AbstractSoundInstance/paused"}}{{/crossLink}}.
<h4>Example</h4>
myInstance.stop();
@method stop
@return {AbstractSoundInstance} A reference to itself, intended for chaining calls. | p.stop ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.destroy = function() {
this._cleanUp();
this.src = null;
this.playbackResource = null;
this.removeAllEventListeners();
}; | Remove all external references and resources from AbstractSoundInstance. Note this is irreversible and AbstractSoundInstance will no longer work
@method destroy
@since 0.6.0 | p.destroy ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p.applyPlayProps = function(playProps) {
if (playProps.offset != null) { this._setPosition(playProps.offset) }
if (playProps.loop != null) { this._setLoop(playProps.loop); }
if (playProps.volume != null) { this._setVolume(playProps.volume); }
if (playProps.pan != null) { this._setPan(playProps.pan); }
if (playProps.startTime != null) {
this._setStartTime(playProps.startTime);
this._setDuration(playProps.duration);
}
return this;
}; | Takes an PlayPropsConfig or Object with the same properties and sets them on this instance.
@method applyPlayProps
@param {PlayPropsConfig | Object} playProps A PlayPropsConfig or object containing the same properties.
@since 0.6.1
@return {AbstractSoundInstance} A reference to itself, intended for chaining calls. | p.applyPlayProps ( playProps ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._getPaused = function() {
return this._paused;
}; | Please use {{#crossLink "AbstractSoundInstance/paused:property"}}{{/crossLink}} directly as a property.
@method _getPaused
@protected
@return {boolean} If the instance is currently paused
@since 0.6.0 | p._getPaused ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._setPaused = function (value) {
if ((value !== true && value !== false) || this._paused == value) {return;}
if (value == true && this.playState != createjs.Sound.PLAY_SUCCEEDED) {return;}
this._paused = value;
if(value) {
this._pause();
} else {
this._resume();
}
clearTimeout(this.delayTimeoutId);
return this;
}; | Please use {{#crossLink "AbstractSoundInstance/paused:property"}}{{/crossLink}} directly as a property
@method _setPaused
@protected
@param {boolean} value
@since 0.6.0
@return {AbstractSoundInstance} A reference to itself, intended for chaining calls. | p._setPaused ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._setVolume = function (value) {
if (value == this._volume) { return this; }
this._volume = Math.max(0, Math.min(1, value));
if (!this._muted) {
this._updateVolume();
}
return this;
}; | Please use {{#crossLink "AbstractSoundInstance/volume:property"}}{{/crossLink}} directly as a property
@method _setVolume
@protected
@param {Number} value The volume to set, between 0 and 1.
@return {AbstractSoundInstance} A reference to itself, intended for chaining calls. | p._setVolume ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._getVolume = function () {
return this._volume;
}; | Please use {{#crossLink "AbstractSoundInstance/volume:property"}}{{/crossLink}} directly as a property
@method _getVolume
@protected
@return {Number} The current volume of the sound instance. | p._getVolume ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._setMuted = function (value) {
if (value !== true && value !== false) {return;}
this._muted = value;
this._updateVolume();
return this;
}; | Please use {{#crossLink "AbstractSoundInstance/muted:property"}}{{/crossLink}} directly as a property
@method _setMuted
@protected
@param {Boolean} value If the sound should be muted.
@return {AbstractSoundInstance} A reference to itself, intended for chaining calls.
@since 0.6.0 | p._setMuted ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._getMuted = function () {
return this._muted;
}; | Please use {{#crossLink "AbstractSoundInstance/muted:property"}}{{/crossLink}} directly as a property
@method _getMuted
@protected
@return {Boolean} If the sound is muted.
@since 0.6.0 | p._getMuted ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._setPan = function (value) {
if(value == this._pan) { return this; }
this._pan = Math.max(-1, Math.min(1, value));
this._updatePan();
return this;
}; | Please use {{#crossLink "AbstractSoundInstance/pan:property"}}{{/crossLink}} directly as a property
@method _setPan
@protected
@param {Number} value The pan value, between -1 (left) and 1 (right).
@return {AbstractSoundInstance} Returns reference to itself for chaining calls | p._setPan ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._getPan = function () {
return this._pan;
}; | Please use {{#crossLink "AbstractSoundInstance/pan:property"}}{{/crossLink}} directly as a property
@method _getPan
@protected
@return {Number} The value of the pan, between -1 (left) and 1 (right). | p._getPan ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._getPosition = function () {
if (!this._paused && this.playState == createjs.Sound.PLAY_SUCCEEDED) {
this._position = this._calculateCurrentPosition();
}
return this._position;
}; | Please use {{#crossLink "AbstractSoundInstance/position:property"}}{{/crossLink}} directly as a property
@method _getPosition
@protected
@return {Number} The position of the playhead in the sound, in milliseconds. | p._getPosition ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._setPosition = function (value) {
this._position = Math.max(0, value);
if (this.playState == createjs.Sound.PLAY_SUCCEEDED) {
this._updatePosition();
}
return this;
}; | Please use {{#crossLink "AbstractSoundInstance/position:property"}}{{/crossLink}} directly as a property
@method _setPosition
@protected
@param {Number} value The position to place the playhead, in milliseconds.
@return {AbstractSoundInstance} Returns reference to itself for chaining calls | p._setPosition ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._getStartTime = function () {
return this._startTime;
}; | Please use {{#crossLink "AbstractSoundInstance/startTime:property"}}{{/crossLink}} directly as a property
@method _getStartTime
@protected
@return {Number} The startTime of the sound instance in milliseconds. | p._getStartTime ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._setStartTime = function (value) {
if (value == this._startTime) { return this; }
this._startTime = Math.max(0, value || 0);
this._updateStartTime();
return this;
}; | Please use {{#crossLink "AbstractSoundInstance/startTime:property"}}{{/crossLink}} directly as a property
@method _setStartTime
@protected
@param {number} value The new startTime time in milli seconds.
@return {AbstractSoundInstance} Returns reference to itself for chaining calls | p._setStartTime ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._getDuration = function () {
return this._duration;
}; | Please use {{#crossLink "AbstractSoundInstance/duration:property"}}{{/crossLink}} directly as a property
@method _getDuration
@protected
@return {Number} The duration of the sound instance in milliseconds. | p._getDuration ( ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
p._setDuration = function (value) {
if (value == this._duration) { return this; }
this._duration = Math.max(0, value || 0);
this._updateDuration();
return this;
}; | Please use {{#crossLink "AbstractSoundInstance/duration:property"}}{{/crossLink}} directly as a property
@method _setDuration
@protected
@param {number} value The new duration time in milli seconds.
@return {AbstractSoundInstance} Returns reference to itself for chaining calls
@since 0.6.0 | p._setDuration ( value ) | javascript | CreateJS/SoundJS | lib/soundjs.js | https://github.com/CreateJS/SoundJS/blob/master/lib/soundjs.js | MIT |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.