27 |
--------------------------------------------------------------------------------
/build/createjsTheme/theme.json:
--------------------------------------------------------------------------------
1 | {
2 | "yuiGridsUrl": "../assets/css/yui-cssgrids-min.css",
3 | "yuiSeedUrl": "../assets/js/yui-source.js"
4 | }
5 |
--------------------------------------------------------------------------------
/build/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "PreloadJS",
3 | "version": "1.0.0",
4 | "description": "PreloadJS Docs",
5 | "url": "http://www.createjs.com/preloadjs",
6 | "logo": "assets/docs-icon-PreloadJS.png",
7 | "repository": "git@github.com:CreateJS/PreloadJS.git",
8 | "devDependencies": {
9 | "grunt": "~0.4.5",
10 | "grunt-contrib-concat": "~0.5.0",
11 | "grunt-contrib-uglify": "~0.6.0",
12 | "grunt-contrib-yuidoc": "~0.5.2",
13 | "grunt-contrib-compress": "~0.12.0",
14 | "grunt-contrib-copy": "~0.7.0",
15 | "grunt-contrib-sass": "^0.8.1",
16 | "grunt-contrib-clean":"^0.4.0",
17 | "lodash": "~0.9.2"
18 | },
19 | "engine": "node >= 0.10.22"
20 | }
21 |
--------------------------------------------------------------------------------
/build/path.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | path: function(str) {
3 | return str.substr(str.lastIndexOf("/")+1);
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/build/tasks/updatebower.js:
--------------------------------------------------------------------------------
1 | module.exports = function (grunt) {
2 |
3 | grunt.registerTask('updatebower', function() {
4 | var file = '../bower.json';
5 | var version = grunt.config.get('version');
6 |
7 | if (!grunt.file.exists(file)) {
8 | grunt.log.error(file+' not found.');
9 | return;
10 | }
11 | if (version == "NEXT") {
12 | grunt.log.error("NEXT versions are not submitted to Bower.");
13 | return;
14 | }
15 |
16 | var json = grunt.file.readJSON(file);
17 | json.version = version;
18 | json.main = json.main.replace(/\d\.\d\.\d|NEXT/, version);
19 | grunt.file.write(file, JSON.stringify(json, null, '\t'));
20 | });
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/build/tasks/updateversion.js:
--------------------------------------------------------------------------------
1 | module.exports = function (grunt) {
2 |
3 | grunt.registerMultiTask('updateversion', function() {
4 | var newValues = {date:new Date().toUTCString(), version:this.data.version};
5 | replaceMetaData(this.data.file, newValues);
6 | });
7 |
8 | grunt.registerMultiTask('clearversion', function() {
9 | // Don't clear the version when building everything (the combined build will run this after its done)
10 | var buildArgs = grunt.config("buildArgs");
11 | if (buildArgs && buildArgs[0] == "all") {
12 | return;
13 | }
14 | replaceMetaData(this.data.file, {date:"", version:""});
15 | });
16 |
17 | function replaceMetaData(file, values) {
18 | if (!grunt.file.exists(file)) {
19 | grunt.log.error(file+' not found.');
20 | return;
21 | }
22 |
23 | var str = grunt.file.read(file);
24 |
25 | for(var n in values) {
26 | var pattern = new RegExp("(\/\\*="+n+"\\*\/\")(.*)(\";)", "g");
27 | var result = pattern.test(str);
28 | if (result) {
29 | str = str.replace(pattern, "$1"+values[n]+"$3");
30 | } else {
31 | grunt.log.error("Error -- Unable to resolve value:"+ pattern);
32 | }
33 | }
34 | grunt.file.write(file, str);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/build/updates/README.md:
--------------------------------------------------------------------------------
1 | ## Important ##
2 |
3 | The current YUIDocs does not support @readonly on properties (only attributes). This folder contains an updated
4 | `builder.js`, which injects this support.
5 |
6 | Copy `builder.js` into
7 | > node_modules/grunt-contrib-yuidoc/node-modules/yuidocjs/lib
8 |
9 | Without this file, properties will not show the "readonly" flag.
10 |
11 | Last tested with YUIDocs 0.5.2
--------------------------------------------------------------------------------
/docs/PreloadJS_docs.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreateJS/PreloadJS/4938426b9c19dd525167cda473ad4ed00082ffe7/docs/PreloadJS_docs.zip
--------------------------------------------------------------------------------
/docs/preloadjs_docs-NEXT.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreateJS/PreloadJS/4938426b9c19dd525167cda473ad4ed00082ffe7/docs/preloadjs_docs-NEXT.zip
--------------------------------------------------------------------------------
/examples/CustomLoader.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PreloadJS: Custom Loader
5 |
6 |
7 |
8 |
9 |
14 |
15 |
16 |
17 |
18 |
PreloadJS Custom Loaders in Plugins
19 |
This sample shows how to a plugin can provide a custom loader to PreloadJS. This enables plugins to
20 | create their own loader classes and instances (and add listeners or additional functionality), but rely
21 | on PreloadJS to manage everything else.
22 |
23 |
This example uses a simple image loader, and the plugin has an opportunity to modify it once it is loaded
24 | (by setting the image size).
25 | This sample shows the different approaches for loading fonts in PreloadJS. Currently supported are
26 | local font loading using a CSS file and manual definitions, and remote loading using Google Fonts. Currently,
27 | Typekit is not supported.
28 |
In this example, a PreloadJS plugin is defined, which parses a load item
26 | into an HTML image ID that is
27 | already present in the HTML DOM. PreloadJS will then use the image to do
28 | the loading, and the image
29 | will be displayed in its defined position when it is loaded.
This sample loads a number of images, and adds them to a canvas stage when they are complete. Click an image
17 | to put it at the back of the stack.
18 |
19 |
Note that when loading images locally, you need to ensure that PreloadJS uses tag loading or CORS to avoid
20 | cross-origin errors. Mouse interaction on images may not work locally when these errors occur.
An example of the SpriteSheetLoader, which automatically parses loaded JSON, and will internally preload
15 | associated images and instantiate a SpriteSheet instance before the complete event is fired.
16 |
Some browsers can not load images or access pixel data when running local files, and may throw a security
17 | error or not work unless the content is running on a server.
29 |
30 |
31 |
--------------------------------------------------------------------------------
/spikes/FontLoading/typekit.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/src/createjs/events/ErrorEvent.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Event
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | * Copyright (c) 2010 gskinner.com, inc.
6 | *
7 | * Permission is hereby granted, free of charge, to any person
8 | * obtaining a copy of this software and associated documentation
9 | * files (the "Software"), to deal in the Software without
10 | * restriction, including without limitation the rights to use,
11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | * copies of the Software, and to permit persons to whom the
13 | * Software is furnished to do so, subject to the following
14 | * conditions:
15 | *
16 | * The above copyright notice and this permission notice shall be
17 | * included in all copies or substantial portions of the Software.
18 | *
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 | * OTHER DEALINGS IN THE SOFTWARE.
27 | */
28 |
29 | /**
30 | * @module CreateJS
31 | */
32 |
33 | // namespace:
34 | this.createjs = this.createjs||{};
35 |
36 | (function() {
37 | "use strict";
38 |
39 | /**
40 | * A general error {{#crossLink "Event"}}{{/crossLink}}, that describes an error that occurred, as well as any details.
41 | * @class ErrorEvent
42 | * @param {String} [title] The error title
43 | * @param {String} [message] The error description
44 | * @param {Object} [data] Additional error data
45 | * @constructor
46 | */
47 | function ErrorEvent(title, message, data) {
48 | this.Event_constructor("error");
49 |
50 | /**
51 | * The short error title, which indicates the type of error that occurred.
52 | * @property title
53 | * @type String
54 | */
55 | this.title = title;
56 |
57 | /**
58 | * The verbose error message, containing details about the error.
59 | * @property message
60 | * @type String
61 | */
62 | this.message = message;
63 |
64 | /**
65 | * Additional data attached to an error.
66 | * @property data
67 | * @type {Object}
68 | */
69 | this.data = data;
70 | }
71 |
72 | var p = createjs.extend(ErrorEvent, createjs.Event);
73 |
74 | p.clone = function() {
75 | return new createjs.ErrorEvent(this.title, this.message, this.data);
76 | };
77 |
78 | createjs.ErrorEvent = createjs.promote(ErrorEvent, "Event");
79 |
80 | }());
--------------------------------------------------------------------------------
/src/createjs/utils/deprecate.js:
--------------------------------------------------------------------------------
1 | /*
2 | * extend
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | * Copyright (c) 2010 gskinner.com, inc.
6 | *
7 | * Permission is hereby granted, free of charge, to any person
8 | * obtaining a copy of this software and associated documentation
9 | * files (the "Software"), to deal in the Software without
10 | * restriction, including without limitation the rights to use,
11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | * copies of the Software, and to permit persons to whom the
13 | * Software is furnished to do so, subject to the following
14 | * conditions:
15 | *
16 | * The above copyright notice and this permission notice shall be
17 | * included in all copies or substantial portions of the Software.
18 | *
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 | * OTHER DEALINGS IN THE SOFTWARE.
27 | */
28 |
29 | /**
30 | * @module CreateJS
31 | */
32 |
33 | // namespace:
34 | this.createjs = this.createjs||{};
35 |
36 | /**
37 | * @class Utility Methods
38 | */
39 |
40 | /**
41 | * Wraps deprecated methods so they still be used, but throw warnings to developers.
42 | *
43 | * obj.deprecatedMethod = createjs.deprecate("Old Method Name", obj._fallbackMethod);
44 | *
45 | * The recommended approach for deprecated properties is:
46 | *
47 | * try {
48 | * Obj ect.defineProperties(object, {
49 | * readyOnlyProp: { get: createjs.deprecate("readOnlyProp", function() { return this.alternateProp; }) },
50 | * readWriteProp: {
51 | * get: createjs.deprecate("readOnlyProp", function() { return this.alternateProp; }),
52 | * set: createjs.deprecate("readOnlyProp", function(val) { this.alternateProp = val; })
53 | * });
54 | * } catch (e) {}
55 | *
56 | * @method deprecate
57 | * @param {Function} [fallbackMethod=null] A method to call when the deprecated method is used. See the example for how
58 | * @param {String} [name=null] The name of the method or property to display in the console warning.
59 | * to deprecate properties.
60 | * @return {Function} If a fallbackMethod is supplied, returns a closure that will call the fallback method after
61 | * logging the warning in the console.
62 | */
63 | createjs.deprecate = function(fallbackMethod, name) {
64 | "use strict";
65 | return function() {
66 | var msg = "Deprecated property or method '"+name+"'. See docs for info.";
67 | console && (console.warn ? console.warn(msg) : console.log(msg));
68 | return fallbackMethod && fallbackMethod.apply(this, arguments);
69 | }
70 | };
--------------------------------------------------------------------------------
/src/createjs/utils/extend.js:
--------------------------------------------------------------------------------
1 | /*
2 | * extend
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | * Copyright (c) 2010 gskinner.com, inc.
6 | *
7 | * Permission is hereby granted, free of charge, to any person
8 | * obtaining a copy of this software and associated documentation
9 | * files (the "Software"), to deal in the Software without
10 | * restriction, including without limitation the rights to use,
11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | * copies of the Software, and to permit persons to whom the
13 | * Software is furnished to do so, subject to the following
14 | * conditions:
15 | *
16 | * The above copyright notice and this permission notice shall be
17 | * included in all copies or substantial portions of the Software.
18 | *
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 | * OTHER DEALINGS IN THE SOFTWARE.
27 | */
28 |
29 | /**
30 | * @module CreateJS
31 | */
32 |
33 | // namespace:
34 | this.createjs = this.createjs||{};
35 |
36 | /**
37 | * @class Utility Methods
38 | */
39 |
40 | /**
41 | * Sets up the prototype chain and constructor property for a new class.
42 | *
43 | * This should be called right after creating the class constructor.
44 | *
45 | * function MySubClass() {}
46 | * createjs.extend(MySubClass, MySuperClass);
47 | * MySubClass.prototype.doSomething = function() { }
48 | *
49 | * var foo = new MySubClass();
50 | * console.log(foo instanceof MySuperClass); // true
51 | * console.log(foo.prototype.constructor === MySubClass); // true
52 | *
53 | * @method extend
54 | * @param {Function} subclass The subclass.
55 | * @param {Function} superclass The superclass to extend.
56 | * @return {Function} Returns the subclass's new prototype.
57 | */
58 | createjs.extend = function(subclass, superclass) {
59 | "use strict";
60 |
61 | function o() { this.constructor = subclass; }
62 | o.prototype = superclass.prototype;
63 | return (subclass.prototype = new o());
64 | };
65 |
--------------------------------------------------------------------------------
/src/createjs/utils/indexOf.js:
--------------------------------------------------------------------------------
1 | /*
2 | * indexOf
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | * Copyright (c) 2010 gskinner.com, inc.
6 | *
7 | * Permission is hereby granted, free of charge, to any person
8 | * obtaining a copy of this software and associated documentation
9 | * files (the "Software"), to deal in the Software without
10 | * restriction, including without limitation the rights to use,
11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | * copies of the Software, and to permit persons to whom the
13 | * Software is furnished to do so, subject to the following
14 | * conditions:
15 | *
16 | * The above copyright notice and this permission notice shall be
17 | * included in all copies or substantial portions of the Software.
18 | *
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 | * OTHER DEALINGS IN THE SOFTWARE.
27 | */
28 |
29 | /**
30 | * @module CreateJS
31 | */
32 |
33 | // namespace:
34 | this.createjs = this.createjs||{};
35 |
36 | /**
37 | * @class Utility Methods
38 | */
39 |
40 | /**
41 | * Finds the first occurrence of a specified value searchElement in the passed in array, and returns the index of
42 | * that value. Returns -1 if value is not found.
43 | *
44 | * var i = createjs.indexOf(myArray, myElementToFind);
45 | *
46 | * @method indexOf
47 | * @param {Array} array Array to search for searchElement
48 | * @param searchElement Element to find in array.
49 | * @return {Number} The first index of searchElement in array.
50 | */
51 | createjs.indexOf = function (array, searchElement){
52 | "use strict";
53 |
54 | for (var i = 0,l=array.length; i < l; i++) {
55 | if (searchElement === array[i]) {
56 | return i;
57 | }
58 | }
59 | return -1;
60 | };
61 |
--------------------------------------------------------------------------------
/src/createjs/utils/promote.js:
--------------------------------------------------------------------------------
1 | /*
2 | * promote
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | * Copyright (c) 2010 gskinner.com, inc.
6 | *
7 | * Permission is hereby granted, free of charge, to any person
8 | * obtaining a copy of this software and associated documentation
9 | * files (the "Software"), to deal in the Software without
10 | * restriction, including without limitation the rights to use,
11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | * copies of the Software, and to permit persons to whom the
13 | * Software is furnished to do so, subject to the following
14 | * conditions:
15 | *
16 | * The above copyright notice and this permission notice shall be
17 | * included in all copies or substantial portions of the Software.
18 | *
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 | * OTHER DEALINGS IN THE SOFTWARE.
27 | */
28 |
29 | /**
30 | * @module CreateJS
31 | */
32 |
33 | // namespace:
34 | this.createjs = this.createjs||{};
35 |
36 | /**
37 | * @class Utility Methods
38 | */
39 |
40 | /**
41 | * Promotes any methods on the super class that were overridden, by creating an alias in the format `prefix_methodName`.
42 | * It is recommended to use the super class's name as the prefix.
43 | * An alias to the super class's constructor is always added in the format `prefix_constructor`.
44 | * This allows the subclass to call super class methods without using `function.call`, providing better performance.
45 | *
46 | * For example, if `MySubClass` extends `MySuperClass`, and both define a `draw` method, then calling `promote(MySubClass, "MySuperClass")`
47 | * would add a `MySuperClass_constructor` method to MySubClass and promote the `draw` method on `MySuperClass` to the
48 | * prototype of `MySubClass` as `MySuperClass_draw`.
49 | *
50 | * This should be called after the class's prototype is fully defined.
51 | *
52 | * function ClassA(name) {
53 | * this.name = name;
54 | * }
55 | * ClassA.prototype.greet = function() {
56 | * return "Hello "+this.name;
57 | * }
58 | *
59 | * function ClassB(name, punctuation) {
60 | * this.ClassA_constructor(name);
61 | * this.punctuation = punctuation;
62 | * }
63 | * createjs.extend(ClassB, ClassA);
64 | * ClassB.prototype.greet = function() {
65 | * return this.ClassA_greet()+this.punctuation;
66 | * }
67 | * createjs.promote(ClassB, "ClassA");
68 | *
69 | * var foo = new ClassB("World", "!?!");
70 | * console.log(foo.greet()); // Hello World!?!
71 | *
72 | * @method promote
73 | * @param {Function} subclass The class to promote super class methods on.
74 | * @param {String} prefix The prefix to add to the promoted method names. Usually the name of the superclass.
75 | * @return {Function} Returns the subclass.
76 | */
77 | createjs.promote = function(subclass, prefix) {
78 | "use strict";
79 |
80 | var subP = subclass.prototype, supP = (Object.getPrototypeOf&&Object.getPrototypeOf(subP))||subP.__proto__;
81 | if (supP) {
82 | subP[(prefix+="_") + "constructor"] = supP.constructor; // constructor is not always innumerable
83 | for (var n in supP) {
84 | if (subP.hasOwnProperty(n) && (typeof supP[n] == "function")) { subP[prefix + n] = supP[n]; }
85 | }
86 | }
87 | return subclass;
88 | };
89 |
--------------------------------------------------------------------------------
/src/createjs/utils/proxy.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Proxy
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | * Copyright (c) 2010 gskinner.com, inc.
6 | *
7 | * Permission is hereby granted, free of charge, to any person
8 | * obtaining a copy of this software and associated documentation
9 | * files (the "Software"), to deal in the Software without
10 | * restriction, including without limitation the rights to use,
11 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
12 | * copies of the Software, and to permit persons to whom the
13 | * Software is furnished to do so, subject to the following
14 | * conditions:
15 | *
16 | * The above copyright notice and this permission notice shall be
17 | * included in all copies or substantial portions of the Software.
18 | *
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 | * OTHER DEALINGS IN THE SOFTWARE.
27 | */
28 |
29 | /**
30 | * @module CreateJS
31 | */
32 |
33 | // namespace:
34 | this.createjs = this.createjs||{};
35 |
36 | /**
37 | * Various utilities that the CreateJS Suite uses. Utilities are created as separate files, and will be available on the
38 | * createjs namespace directly.
39 | *
40 | *
Example
41 | *
42 | * myObject.addEventListener("change", createjs.proxy(myMethod, scope));
43 | *
44 | * @class Utility Methods
45 | * @main Utility Methods
46 | */
47 |
48 | (function() {
49 | "use strict";
50 |
51 | /**
52 | * A function proxy for methods. By default, JavaScript methods do not maintain scope, so passing a method as a
53 | * callback will result in the method getting called in the scope of the caller. Using a proxy ensures that the
54 | * method gets called in the correct scope.
55 | *
56 | * Additional arguments can be passed that will be applied to the function when it is called.
57 | *
58 | *
Example
59 | *
60 | * myObject.addEventListener("event", createjs.proxy(myHandler, this, arg1, arg2));
61 | *
62 | * function myHandler(arg1, arg2) {
63 | * // This gets called when myObject.myCallback is executed.
64 | * }
65 | *
66 | * @method proxy
67 | * @param {Function} method The function to call
68 | * @param {Object} scope The scope to call the method name on
69 | * @param {mixed} [arg] * Arguments that are appended to the callback for additional params.
70 | * @public
71 | * @static
72 | */
73 | createjs.proxy = function (method, scope) {
74 | var aArgs = Array.prototype.slice.call(arguments, 2);
75 | return function () {
76 | return method.apply(scope, Array.prototype.slice.call(arguments, 0).concat(aArgs));
77 | };
78 | }
79 |
80 | }());
81 |
--------------------------------------------------------------------------------
/src/preloadjs/data/Methods.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Methods
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function() {
38 |
39 | "use strict";
40 |
41 | /**
42 | * Defines the method types for XHR requests. Currently, PreloadJS only supports "POST" and "GET", however
43 | * any HTML method can be used with PreloadJS utilities.
44 | *
45 | * @class Methods
46 | * @static
47 | */
48 | var s = {};
49 |
50 | /**
51 | * Defines a POST request, use for a method value when loading data.
52 | * @property POST
53 | * @type {string}
54 | * @default post
55 | * @static
56 | */
57 | s.POST = "POST";
58 |
59 | /**
60 | * Defines a GET request, use for a method value when loading data.
61 | * @property GET
62 | * @type {string}
63 | * @default get
64 | * @static
65 | */
66 | s.GET = "GET";
67 |
68 | createjs.Methods = s;
69 | }());
70 |
--------------------------------------------------------------------------------
/src/preloadjs/events/ProgressEvent.js:
--------------------------------------------------------------------------------
1 | /*
2 | * ProgressEvent
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function (scope) {
38 | "use strict";
39 |
40 | // constructor
41 | /**
42 | * A CreateJS {{#crossLink "Event"}}{{/crossLink}} that is dispatched when progress changes.
43 | * @class ProgressEvent
44 | * @param {Number} loaded The amount that has been loaded. This can be any number relative to the total.
45 | * @param {Number} [total=1] The total amount that will load. This will default to 1, so if the `loaded` value is
46 | * a percentage (between 0 and 1), it can be omitted.
47 | * @todo Consider having this event be a "fileprogress" event as well
48 | * @constructor
49 | */
50 | function ProgressEvent(loaded, total) {
51 | this.Event_constructor("progress");
52 |
53 | /**
54 | * The amount that has been loaded (out of a total amount)
55 | * @property loaded
56 | * @type {Number}
57 | */
58 | this.loaded = loaded;
59 |
60 | /**
61 | * The total "size" of the load.
62 | * @property total
63 | * @type {Number}
64 | * @default 1
65 | */
66 | this.total = (total == null) ? 1 : total;
67 |
68 | /**
69 | * The percentage (out of 1) that the load has been completed. This is calculated using `loaded/total`.
70 | * @property progress
71 | * @type {Number}
72 | * @default 0
73 | */
74 | this.progress = (total == 0) ? 0 : this.loaded / this.total;
75 | };
76 |
77 | var p = createjs.extend(ProgressEvent, createjs.Event);
78 |
79 | /**
80 | * Returns a clone of the ProgressEvent instance.
81 | * @method clone
82 | * @return {ProgressEvent} a clone of the Event instance.
83 | **/
84 | p.clone = function() {
85 | return new createjs.ProgressEvent(this.loaded, this.total);
86 | };
87 |
88 | createjs.ProgressEvent = createjs.promote(ProgressEvent, "Event");
89 |
90 | }(window));
--------------------------------------------------------------------------------
/src/preloadjs/loaders/AbstractMediaLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * AbstractMediaLoader
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function () {
38 | "use strict";
39 |
40 | // constructor
41 | /**
42 | * The AbstractMediaLoader is a base class that handles some of the shared methods and properties of loaders that
43 | * handle HTML media elements, such as Video and Audio.
44 | * @class AbstractMediaLoader
45 | * @param {LoadItem|Object} loadItem
46 | * @param {Boolean} preferXHR
47 | * @param {String} type The type of media to load. Usually "video" or "audio".
48 | * @extends AbstractLoader
49 | * @constructor
50 | */
51 | function AbstractMediaLoader(loadItem, preferXHR, type) {
52 | this.AbstractLoader_constructor(loadItem, preferXHR, type);
53 |
54 | // public properties
55 | this.resultFormatter = this._formatResult;
56 |
57 | // protected properties
58 | this._tagSrcAttribute = "src";
59 |
60 | this.on("initialize", this._updateXHR, this);
61 | };
62 |
63 | var p = createjs.extend(AbstractMediaLoader, createjs.AbstractLoader);
64 |
65 | // static properties
66 | // public methods
67 | p.load = function () {
68 | // TagRequest will handle most of this, but Sound / Video need a few custom properties, so just handle them here.
69 | if (!this._tag) {
70 | this._tag = this._createTag(this._item.src);
71 | }
72 |
73 | var crossOrigin = this._item.crossOrigin;
74 | if (crossOrigin === true) { crossOrigin = "Anonymous"; }
75 | if (crossOrigin != null && !createjs.URLUtils.isLocal(this._item)) {
76 | this._tag.crossOrigin = crossOrigin;
77 | }
78 |
79 | this._tag.preload = "auto";
80 | this._tag.load();
81 |
82 | this.AbstractLoader_load();
83 | };
84 |
85 | // protected methods
86 | /**
87 | * Creates a new tag for loading if it doesn't exist yet.
88 | * @method _createTag
89 | * @private
90 | */
91 | p._createTag = function () {};
92 |
93 |
94 | p._createRequest = function() {
95 | if (!this._preferXHR) {
96 | this._request = new createjs.MediaTagRequest(this._item, this._tag || this._createTag(), this._tagSrcAttribute);
97 | } else {
98 | this._request = new createjs.XHRRequest(this._item);
99 | }
100 | };
101 |
102 | // protected methods
103 | /**
104 | * Before the item loads, set its mimeType and responseType.
105 | * @property _updateXHR
106 | * @param {Event} event
107 | * @private
108 | */
109 | p._updateXHR = function (event) {
110 | // Only exists for XHR
111 | if (event.loader.setResponseType) {
112 | event.loader.setResponseType("blob");
113 | }
114 | };
115 |
116 | /**
117 | * The result formatter for media files.
118 | * @method _formatResult
119 | * @param {AbstractLoader} loader
120 | * @returns {HTMLVideoElement|HTMLAudioElement}
121 | * @private
122 | */
123 | p._formatResult = function (loader) {
124 | this._tag.removeEventListener && this._tag.removeEventListener("canplaythrough", this._loadedHandler);
125 | this._tag.onstalled = null;
126 | if (this._preferXHR) {
127 | var URL = window.URL || window.webkitURL;
128 | var result = loader.getResult(true);
129 |
130 | loader.getTag().src = URL.createObjectURL(result);
131 | }
132 | return loader.getTag();
133 | };
134 |
135 | createjs.AbstractMediaLoader = createjs.promote(AbstractMediaLoader, "AbstractLoader");
136 |
137 | }());
138 |
--------------------------------------------------------------------------------
/src/preloadjs/loaders/BinaryLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * BinaryLoader
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function () {
38 | "use strict";
39 |
40 | // constructor
41 | /**
42 | * A loader for binary files. This is useful for loading web audio, or content that requires an ArrayBuffer.
43 | * @class BinaryLoader
44 | * @param {LoadItem|Object} loadItem
45 | * @extends AbstractLoader
46 | * @constructor
47 | */
48 | function BinaryLoader(loadItem) {
49 | this.AbstractLoader_constructor(loadItem, true, createjs.Types.BINARY);
50 | this.on("initialize", this._updateXHR, this);
51 | };
52 |
53 | var p = createjs.extend(BinaryLoader, createjs.AbstractLoader);
54 | var s = BinaryLoader;
55 |
56 | // static methods
57 | /**
58 | * Determines if the loader can load a specific item. This loader can only load items that are of type
59 | * {{#crossLink "Types/BINARY:property"}}{{/crossLink}}
60 | * @method canLoadItem
61 | * @param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
62 | * @returns {Boolean} Whether the loader can load the item.
63 | * @static
64 | */
65 | s.canLoadItem = function (item) {
66 | return item.type == createjs.Types.BINARY;
67 | };
68 |
69 | // private methods
70 | /**
71 | * Before the item loads, set the response type to "arraybuffer"
72 | * @property _updateXHR
73 | * @param {Event} event
74 | * @private
75 | */
76 | p._updateXHR = function (event) {
77 | event.loader.setResponseType("arraybuffer");
78 | };
79 |
80 | createjs.BinaryLoader = createjs.promote(BinaryLoader, "AbstractLoader");
81 |
82 | }());
83 |
--------------------------------------------------------------------------------
/src/preloadjs/loaders/CSSLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * CSSLoader
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function () {
38 | "use strict";
39 |
40 | // constructor
41 | /**
42 | * A loader for CSS files.
43 | * @class CSSLoader
44 | * @param {LoadItem|Object} loadItem
45 | * @param {Boolean} preferXHR
46 | * @extends AbstractLoader
47 | * @constructor
48 | */
49 | function CSSLoader(loadItem, preferXHR) {
50 | this.AbstractLoader_constructor(loadItem, preferXHR, createjs.Types.CSS);
51 |
52 | // public properties
53 | this.resultFormatter = this._formatResult;
54 |
55 | // protected properties
56 | this._tagSrcAttribute = "href";
57 |
58 | if (preferXHR) {
59 | this._tag = createjs.Elements.style();
60 | } else {
61 | this._tag = createjs.Elements.link();
62 | }
63 |
64 | this._tag.rel = "stylesheet";
65 | this._tag.type = "text/css";
66 | };
67 |
68 | var p = createjs.extend(CSSLoader, createjs.AbstractLoader);
69 | var s = CSSLoader;
70 |
71 | // static methods
72 | /**
73 | * Determines if the loader can load a specific item. This loader can only load items that are of type
74 | * {{#crossLink "Types/CSS:property"}}{{/crossLink}}.
75 | * @method canLoadItem
76 | * @param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
77 | * @returns {Boolean} Whether the loader can load the item.
78 | * @static
79 | */
80 | s.canLoadItem = function (item) {
81 | return item.type == createjs.Types.CSS;
82 | };
83 |
84 | // protected methods
85 | /**
86 | * The result formatter for CSS files.
87 | * @method _formatResult
88 | * @param {AbstractLoader} loader
89 | * @returns {HTMLLinkElement|HTMLStyleElement}
90 | * @private
91 | */
92 | p._formatResult = function (loader) {
93 | if (this._preferXHR) {
94 | var tag = loader.getTag();
95 |
96 | if (tag.styleSheet) { // IE
97 | tag.styleSheet.cssText = loader.getResult(true);
98 | } else {
99 | var textNode = createjs.Elements.text(loader.getResult(true));
100 | tag.appendChild(textNode);
101 | }
102 | } else {
103 | tag = this._tag;
104 | }
105 |
106 | createjs.DomUtils.appendToHead(tag);
107 |
108 | return tag;
109 | };
110 |
111 | createjs.CSSLoader = createjs.promote(CSSLoader, "AbstractLoader");
112 |
113 | }());
114 |
--------------------------------------------------------------------------------
/src/preloadjs/loaders/JSONLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * JSONLoader
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function () {
38 | "use strict";
39 |
40 | // constructor
41 | /**
42 | * A loader for JSON files. To load JSON cross-domain, use JSONP and the {{#crossLink "JSONPLoader"}}{{/crossLink}}
43 | * instead. To load JSON-formatted manifests, use {{#crossLink "ManifestLoader"}}{{/crossLink}}, and to
44 | * load EaselJS SpriteSheets, use {{#crossLink "SpriteSheetLoader"}}{{/crossLink}}.
45 | * @class JSONLoader
46 | * @param {LoadItem|Object} loadItem
47 | * @extends AbstractLoader
48 | * @constructor
49 | */
50 | function JSONLoader(loadItem) {
51 | this.AbstractLoader_constructor(loadItem, true, createjs.Types.JSON);
52 |
53 | // public properties
54 | this.resultFormatter = this._formatResult;
55 | };
56 |
57 | var p = createjs.extend(JSONLoader, createjs.AbstractLoader);
58 | var s = JSONLoader;
59 |
60 | // static methods
61 | /**
62 | * Determines if the loader can load a specific item. This loader can only load items that are of type
63 | * {{#crossLink "Types/JSON:property"}}{{/crossLink}}.
64 | * @method canLoadItem
65 | * @param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
66 | * @returns {Boolean} Whether the loader can load the item.
67 | * @static
68 | */
69 | s.canLoadItem = function (item) {
70 | return item.type == createjs.Types.JSON;
71 | };
72 |
73 | // protected methods
74 | /**
75 | * The result formatter for JSON files.
76 | * @method _formatResult
77 | * @param {AbstractLoader} loader
78 | * @returns {HTMLLinkElement|HTMLStyleElement}
79 | * @private
80 | */
81 | p._formatResult = function (loader) {
82 | var json = null;
83 | try {
84 | json = createjs.DataUtils.parseJSON(loader.getResult(true));
85 | } catch (e) {
86 | var event = new createjs.ErrorEvent("JSON_FORMAT", null, e);
87 | this._sendError(event);
88 | return e;
89 | }
90 |
91 | return json;
92 | };
93 |
94 | createjs.JSONLoader = createjs.promote(JSONLoader, "AbstractLoader");
95 |
96 | }());
97 |
--------------------------------------------------------------------------------
/src/preloadjs/loaders/JavaScriptLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * JavaScriptLoader
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function () {
38 | "use strict";
39 |
40 | // constructor
41 | /**
42 | * A loader for JavaScript files.
43 | * @class JavaScriptLoader
44 | * @param {LoadItem|Object} loadItem
45 | * @param {Boolean} preferXHR
46 | * @extends AbstractLoader
47 | * @constructor
48 | */
49 | function JavaScriptLoader(loadItem, preferXHR) {
50 | this.AbstractLoader_constructor(loadItem, preferXHR, createjs.Types.JAVASCRIPT);
51 |
52 | // public properties
53 | this.resultFormatter = this._formatResult;
54 |
55 | // protected properties
56 | this._tagSrcAttribute = "src";
57 | this.setTag(createjs.Elements.script());
58 | };
59 |
60 | var p = createjs.extend(JavaScriptLoader, createjs.AbstractLoader);
61 | var s = JavaScriptLoader;
62 |
63 | // static methods
64 | /**
65 | * Determines if the loader can load a specific item. This loader can only load items that are of type
66 | * {{#crossLink "Types/JAVASCRIPT:property"}}{{/crossLink}}
67 | * @method canLoadItem
68 | * @param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
69 | * @returns {Boolean} Whether the loader can load the item.
70 | * @static
71 | */
72 | s.canLoadItem = function (item) {
73 | return item.type == createjs.Types.JAVASCRIPT;
74 | };
75 |
76 | // protected methods
77 | /**
78 | * The result formatter for JavaScript files.
79 | * @method _formatResult
80 | * @param {AbstractLoader} loader
81 | * @returns {HTMLLinkElement|HTMLStyleElement}
82 | * @private
83 | */
84 | p._formatResult = function (loader) {
85 | var tag = loader.getTag();
86 | if (this._preferXHR) {
87 | tag.text = loader.getResult(true);
88 | }
89 | return tag;
90 | };
91 |
92 | createjs.JavaScriptLoader = createjs.promote(JavaScriptLoader, "AbstractLoader");
93 |
94 | }());
95 |
--------------------------------------------------------------------------------
/src/preloadjs/loaders/SVGLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * SVGLoader
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function () {
38 | "use strict";
39 |
40 | // constructor
41 | /**
42 | * A loader for SVG files.
43 | * @class SVGLoader
44 | * @param {LoadItem|Object} loadItem
45 | * @param {Boolean} preferXHR
46 | * @extends AbstractLoader
47 | * @constructor
48 | */
49 | function SVGLoader(loadItem, preferXHR) {
50 | this.AbstractLoader_constructor(loadItem, preferXHR, createjs.Types.SVG);
51 |
52 | // public properties
53 | this.resultFormatter = this._formatResult;
54 |
55 | // protected properties
56 | this._tagSrcAttribute = "data";
57 |
58 | if (preferXHR) {
59 | this.setTag(createjs.Elements.svg());
60 | } else {
61 | this.setTag(createjs.Elements.object());
62 | this.getTag().type = "image/svg+xml";
63 | }
64 | };
65 |
66 | var p = createjs.extend(SVGLoader, createjs.AbstractLoader);
67 | var s = SVGLoader;
68 |
69 | // static methods
70 | /**
71 | * Determines if the loader can load a specific item. This loader can only load items that are of type
72 | * {{#crossLink "Types/SVG:property"}}{{/crossLink}}
73 | * @method canLoadItem
74 | * @param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
75 | * @returns {Boolean} Whether the loader can load the item.
76 | * @static
77 | */
78 | s.canLoadItem = function (item) {
79 | return item.type == createjs.Types.SVG;
80 | };
81 |
82 | // protected methods
83 | /**
84 | * The result formatter for SVG files.
85 | * @method _formatResult
86 | * @param {AbstractLoader} loader
87 | * @returns {Object}
88 | * @private
89 | */
90 | p._formatResult = function (loader) {
91 | // mime should be image/svg+xml, but Opera requires text/xml
92 | var xml = createjs.DataUtils.parseXML(loader.getResult(true));
93 | var tag = loader.getTag();
94 |
95 | if (!this._preferXHR && document.body.contains(tag)) {
96 | document.body.removeChild(tag);
97 | }
98 |
99 | if (xml.documentElement != null) {
100 | var element = xml.documentElement;
101 | // Support loading an SVG from a different domain in ID
102 | if (document.importNode) {
103 | element = document.importNode(element, true);
104 | }
105 | tag.appendChild(element);
106 | return tag;
107 | } else { // For browsers that don't support SVG, just give them the XML. (IE 9-8)
108 | return xml;
109 | }
110 | };
111 |
112 | createjs.SVGLoader = createjs.promote(SVGLoader, "AbstractLoader");
113 |
114 | }());
115 |
--------------------------------------------------------------------------------
/src/preloadjs/loaders/SoundLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * SoundLoader
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function () {
38 | "use strict";
39 |
40 | // constructor
41 | /**
42 | * A loader for HTML audio files. PreloadJS can not load WebAudio files, as a WebAudio context is required, which
43 | * should be created by either a library playing the sound (such as SoundJS, or an
44 | * external framework that handles audio playback. To load content that can be played by WebAudio, use the
45 | * {{#crossLink "BinaryLoader"}}{{/crossLink}}, and handle the audio context decoding manually.
46 | * @class SoundLoader
47 | * @param {LoadItem|Object} loadItem
48 | * @param {Boolean} preferXHR
49 | * @extends AbstractMediaLoader
50 | * @constructor
51 | */
52 | function SoundLoader(loadItem, preferXHR) {
53 | this.AbstractMediaLoader_constructor(loadItem, preferXHR, createjs.Types.SOUND);
54 |
55 | // protected properties
56 | if (createjs.DomUtils.isAudioTag(loadItem)) {
57 | this._tag = loadItem;
58 | } else if (createjs.DomUtils.isAudioTag(loadItem.src)) {
59 | this._tag = loadItem;
60 | } else if (createjs.DomUtils.isAudioTag(loadItem.tag)) {
61 | this._tag = createjs.DomUtils.isAudioTag(loadItem) ? loadItem : loadItem.src;
62 | }
63 |
64 | if (this._tag != null) {
65 | this._preferXHR = false;
66 | }
67 | };
68 |
69 | var p = createjs.extend(SoundLoader, createjs.AbstractMediaLoader);
70 | var s = SoundLoader;
71 |
72 | // static methods
73 | /**
74 | * Determines if the loader can load a specific item. This loader can only load items that are of type
75 | * {{#crossLink "Types/SOUND:property"}}{{/crossLink}}.
76 | * @method canLoadItem
77 | * @param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
78 | * @returns {Boolean} Whether the loader can load the item.
79 | * @static
80 | */
81 | s.canLoadItem = function (item) {
82 | return item.type == createjs.Types.SOUND;
83 | };
84 |
85 | // protected methods
86 | p._createTag = function (src) {
87 | var tag = createjs.Elements.audio();
88 | tag.autoplay = false;
89 | tag.preload = "none";
90 |
91 | //LM: Firefox fails when this the preload="none" for other tags, but it needs to be "none" to ensure PreloadJS works.
92 | tag.src = src;
93 | return tag;
94 | };
95 |
96 | createjs.SoundLoader = createjs.promote(SoundLoader, "AbstractMediaLoader");
97 |
98 | }());
99 |
--------------------------------------------------------------------------------
/src/preloadjs/loaders/TextLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * TextLoader
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function () {
38 | "use strict";
39 |
40 | // constructor
41 | /**
42 | * A loader for Text files.
43 | * @class TextLoader
44 | * @param {LoadItem|Object} loadItem
45 | * @extends AbstractLoader
46 | * @constructor
47 | */
48 | function TextLoader(loadItem) {
49 | this.AbstractLoader_constructor(loadItem, true, createjs.Types.TEXT);
50 | };
51 |
52 | var p = createjs.extend(TextLoader, createjs.AbstractLoader);
53 | var s = TextLoader;
54 |
55 | // static methods
56 | /**
57 | * Determines if the loader can load a specific item. This loader loads items that are of type {{#crossLink "Types/TEXT:property"}}{{/crossLink}},
58 | * but is also the default loader if a file type can not be determined.
59 | * @method canLoadItem
60 | * @param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
61 | * @returns {Boolean} Whether the loader can load the item.
62 | * @static
63 | */
64 | s.canLoadItem = function (item) {
65 | return item.type == createjs.Types.TEXT;
66 | };
67 |
68 | createjs.TextLoader = createjs.promote(TextLoader, "AbstractLoader");
69 |
70 | }());
71 |
--------------------------------------------------------------------------------
/src/preloadjs/loaders/VideoLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * VideoLoader
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function () {
38 | "use strict";
39 |
40 | // constructor
41 | /**
42 | * A loader for video files.
43 | * @class VideoLoader
44 | * @param {LoadItem|Object} loadItem
45 | * @param {Boolean} preferXHR
46 | * @extends AbstractMediaLoader
47 | * @constructor
48 | */
49 | function VideoLoader(loadItem, preferXHR) {
50 | this.AbstractMediaLoader_constructor(loadItem, preferXHR, createjs.Types.VIDEO);
51 |
52 | if (createjs.DomUtils.isVideoTag(loadItem) || createjs.DomUtils.isVideoTag(loadItem.src)) {
53 | this.setTag(createjs.DomUtils.isVideoTag(loadItem)?loadItem:loadItem.src);
54 |
55 | // We can't use XHR for a tag that's passed in.
56 | this._preferXHR = false;
57 | } else {
58 | this.setTag(this._createTag());
59 | }
60 | };
61 |
62 | var p = createjs.extend(VideoLoader, createjs.AbstractMediaLoader);
63 | var s = VideoLoader;
64 |
65 | /**
66 | * Create a new video tag
67 | *
68 | * @returns {HTMLElement}
69 | * @private
70 | */
71 | p._createTag = function () {
72 | return createjs.Elements.video();
73 | };
74 |
75 | // static methods
76 | /**
77 | * Determines if the loader can load a specific item. This loader can only load items that are of type
78 | * {{#crossLink "Types/VIDEO:property"}}{{/crossLink}}.
79 | * @method canLoadItem
80 | * @param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
81 | * @returns {Boolean} Whether the loader can load the item.
82 | * @static
83 | */
84 | s.canLoadItem = function (item) {
85 | return item.type == createjs.Types.VIDEO;
86 | };
87 |
88 | createjs.VideoLoader = createjs.promote(VideoLoader, "AbstractMediaLoader");
89 |
90 | }());
91 |
--------------------------------------------------------------------------------
/src/preloadjs/loaders/XMLLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * XMLLoader
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function () {
38 | "use strict";
39 |
40 | // constructor
41 | /**
42 | * A loader for CSS files.
43 | * @class XMLLoader
44 | * @param {LoadItem|Object} loadItem
45 | * @extends AbstractLoader
46 | * @constructor
47 | */
48 | function XMLLoader(loadItem) {
49 | this.AbstractLoader_constructor(loadItem, true, createjs.Types.XML);
50 |
51 | // public properties
52 | this.resultFormatter = this._formatResult;
53 | };
54 |
55 | var p = createjs.extend(XMLLoader, createjs.AbstractLoader);
56 | var s = XMLLoader;
57 |
58 | // static methods
59 | /**
60 | * Determines if the loader can load a specific item. This loader can only load items that are of type
61 | * {{#crossLink "Types/XML:property"}}{{/crossLink}}.
62 | * @method canLoadItem
63 | * @param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
64 | * @returns {Boolean} Whether the loader can load the item.
65 | * @static
66 | */
67 | s.canLoadItem = function (item) {
68 | return item.type == createjs.Types.XML;
69 | };
70 |
71 | // protected methods
72 | /**
73 | * The result formatter for XML files.
74 | * @method _formatResult
75 | * @param {AbstractLoader} loader
76 | * @returns {XMLDocument}
77 | * @private
78 | */
79 | p._formatResult = function (loader) {
80 | return createjs.DataUtils.parseXML(loader.getResult(true));
81 | };
82 |
83 | createjs.XMLLoader = createjs.promote(XMLLoader, "AbstractLoader");
84 |
85 | }());
86 |
--------------------------------------------------------------------------------
/src/preloadjs/net/AbstractRequest.js:
--------------------------------------------------------------------------------
1 | /*
2 | * AbstractRequest
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function () {
38 | "use strict";
39 |
40 | /**
41 | * A base class for actual data requests, such as {{#crossLink "XHRRequest"}}{{/crossLink}}, {{#crossLink "TagRequest"}}{{/crossLink}},
42 | * and {{#crossLink "MediaRequest"}}{{/crossLink}}. PreloadJS loaders will typically use a data loader under the
43 | * hood to get data.
44 | * @class AbstractRequest
45 | * @param {LoadItem} item
46 | * @constructor
47 | */
48 | var AbstractRequest = function (item) {
49 | this._item = item;
50 | };
51 |
52 | var p = createjs.extend(AbstractRequest, createjs.EventDispatcher);
53 |
54 | // public methods
55 | /**
56 | * Begin a load.
57 | * @method load
58 | */
59 | p.load = function() {};
60 |
61 | /**
62 | * Clean up a request.
63 | * @method destroy
64 | */
65 | p.destroy = function() {};
66 |
67 | /**
68 | * Cancel an in-progress request.
69 | * @method cancel
70 | */
71 | p.cancel = function() {};
72 |
73 | createjs.AbstractRequest = createjs.promote(AbstractRequest, "EventDispatcher");
74 |
75 | }());
--------------------------------------------------------------------------------
/src/preloadjs/net/MediaTagRequest.js:
--------------------------------------------------------------------------------
1 | /*
2 | * MediaTagRequest
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | // namespace:
35 | this.createjs = this.createjs || {};
36 |
37 | (function () {
38 | "use strict";
39 |
40 | // constructor
41 | /**
42 | * An {{#crossLink "TagRequest"}}{{/crossLink}} that loads HTML tags for video and audio.
43 | * @class MediaTagRequest
44 | * @param {LoadItem} loadItem
45 | * @param {HTMLAudioElement|HTMLVideoElement} tag
46 | * @param {String} srcAttribute The tag attribute that specifies the source, such as "src", "href", etc.
47 | * @constructor
48 | */
49 | function MediaTagRequest(loadItem, tag, srcAttribute) {
50 | this.AbstractRequest_constructor(loadItem);
51 |
52 | // protected properties
53 | this._tag = tag;
54 | this._tagSrcAttribute = srcAttribute;
55 | this._loadedHandler = createjs.proxy(this._handleTagComplete, this);
56 | };
57 |
58 | var p = createjs.extend(MediaTagRequest, createjs.TagRequest);
59 | var s = MediaTagRequest;
60 |
61 | // public methods
62 | p.load = function () {
63 | var sc = createjs.proxy(this._handleStalled, this);
64 | this._stalledCallback = sc;
65 |
66 | var pc = createjs.proxy(this._handleProgress, this);
67 | this._handleProgress = pc;
68 |
69 | this._tag.addEventListener("stalled", sc);
70 | this._tag.addEventListener("progress", pc);
71 |
72 | // This will tell us when audio is buffered enough to play through, but not when its loaded.
73 | // The tag doesn't keep loading in Chrome once enough has buffered, and we have decided that behaviour is sufficient.
74 | this._tag.addEventListener && this._tag.addEventListener("canplaythrough", this._loadedHandler, false); // canplaythrough callback doesn't work in Chrome, so we use an event.
75 |
76 | this.TagRequest_load();
77 | };
78 |
79 | // private methods
80 | p._handleReadyStateChange = function () {
81 | clearTimeout(this._loadTimeout);
82 | // This is strictly for tags in browsers that do not support onload.
83 | var tag = this._tag;
84 |
85 | // Complete is for old IE support.
86 | if (tag.readyState == "loaded" || tag.readyState == "complete") {
87 | this._handleTagComplete();
88 | }
89 | };
90 |
91 | p._handleStalled = function () {
92 | //Ignore, let the timeout take care of it. Sometimes its not really stopped.
93 | };
94 |
95 | /**
96 | * An XHR request has reported progress.
97 | * @method _handleProgress
98 | * @param {Object} event The XHR progress event.
99 | * @private
100 | */
101 | p._handleProgress = function (event) {
102 | if (!event || event.loaded > 0 && event.total == 0) {
103 | return; // Sometimes we get no "total", so just ignore the progress event.
104 | }
105 |
106 | var newEvent = new createjs.ProgressEvent(event.loaded, event.total);
107 | this.dispatchEvent(newEvent);
108 | };
109 |
110 | // protected methods
111 | p._clean = function () {
112 | this._tag.removeEventListener && this._tag.removeEventListener("canplaythrough", this._loadedHandler);
113 | this._tag.removeEventListener("stalled", this._stalledCallback);
114 | this._tag.removeEventListener("progress", this._progressCallback);
115 |
116 | this.TagRequest__clean();
117 | };
118 |
119 | createjs.MediaTagRequest = createjs.promote(MediaTagRequest, "TagRequest");
120 |
121 | }());
122 |
--------------------------------------------------------------------------------
/src/preloadjs/utils/DataUtils.js:
--------------------------------------------------------------------------------
1 | /*
2 | * DataUtils
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | (function () {
35 |
36 | /**
37 | * A few data utilities for formatting different data types.
38 | * @class DataUtils
39 | */
40 | var s = {};
41 |
42 | // static methods
43 | /**
44 | * Parse XML using the DOM. This is required when preloading XML or SVG.
45 | * @method parseXML
46 | * @param {String} text The raw text or XML that is loaded by XHR.
47 | * @return {XML} An XML document
48 | * @static
49 | */
50 | s.parseXML = function (text) {
51 | var xml = null;
52 | // CocoonJS does not support XML parsing with either method.
53 |
54 | // Most browsers will use DOMParser
55 | // IE fails on certain SVG files, so we have a fallback below.
56 | try {
57 | if (window.DOMParser) {
58 | var parser = new DOMParser();
59 | xml = parser.parseFromString(text, "text/xml");
60 | }
61 | } catch (e) {
62 | }
63 |
64 | // Fallback for IE support.
65 | if (!xml) {
66 | try {
67 | xml = new ActiveXObject("Microsoft.XMLDOM");
68 | xml.async = false;
69 | xml.loadXML(text);
70 | } catch (e) {
71 | xml = null;
72 | }
73 | }
74 |
75 | return xml;
76 | };
77 |
78 | /**
79 | * Parse a string into an Object.
80 | * @method parseJSON
81 | * @param {String} value The loaded JSON string
82 | * @returns {Object} A JavaScript object.
83 | */
84 | s.parseJSON = function (value) {
85 | if (value == null) {
86 | return null;
87 | }
88 |
89 | try {
90 | return JSON.parse(value);
91 | } catch (e) {
92 | // TODO; Handle this with a custom error?
93 | throw e;
94 | }
95 | };
96 |
97 | createjs.DataUtils = s;
98 |
99 | }());
100 |
--------------------------------------------------------------------------------
/src/preloadjs/utils/DomUtils.js:
--------------------------------------------------------------------------------
1 | /*
2 | * DomUtils
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | (function () {
35 |
36 | /**
37 | * A few utilities for interacting with the dom.
38 | * @class DomUtils
39 | */
40 | var s = {
41 | container: null
42 | };
43 |
44 | s.appendToHead = function (el) {
45 | s.getHead().appendChild(el);
46 | }
47 |
48 | s.appendToBody = function (el) {
49 | if (s.container == null) {
50 | s.container = document.createElement("div");
51 | s.container.id = "preloadjs-container";
52 | var style = s.container.style;
53 | style.visibility = "hidden";
54 | style.position = "absolute";
55 | style.width = s.container.style.height = "10px";
56 | style.overflow = "hidden";
57 | style.transform = style.msTransform = style.webkitTransform = style.oTransform = "translate(-10px, -10px)"; //LM: Not working
58 | s.getBody().appendChild(s.container);
59 | }
60 | s.container.appendChild(el);
61 | }
62 |
63 | s.getHead = function () {
64 | return document.head || document.getElementsByTagName("head")[0];
65 | }
66 |
67 | s.getBody = function () {
68 | return document.body || document.getElementsByTagName("body")[0];
69 | }
70 |
71 | s.removeChild = function(el) {
72 | if (el.parent) {
73 | el.parent.removeChild(el);
74 | }
75 | }
76 |
77 | /**
78 | * Check if item is a valid HTMLImageElement
79 | * @method isImageTag
80 | * @param {Object} item
81 | * @returns {Boolean}
82 | * @static
83 | */
84 | s.isImageTag = function(item) {
85 | return item instanceof HTMLImageElement;
86 | };
87 |
88 | /**
89 | * Check if item is a valid HTMLAudioElement
90 | * @method isAudioTag
91 | * @param {Object} item
92 | * @returns {Boolean}
93 | * @static
94 | */
95 | s.isAudioTag = function(item) {
96 | if (window.HTMLAudioElement) {
97 | return item instanceof HTMLAudioElement;
98 | } else {
99 | return false;
100 | }
101 | };
102 |
103 | /**
104 | * Check if item is a valid HTMLVideoElement
105 | * @method isVideoTag
106 | * @param {Object} item
107 | * @returns {Boolean}
108 | * @static
109 | */
110 | s.isVideoTag = function(item) {
111 | if (window.HTMLVideoElement) {
112 | return item instanceof HTMLVideoElement;
113 | } else {
114 | return false;
115 | }
116 | };
117 |
118 | createjs.DomUtils = s;
119 |
120 | }());
121 |
--------------------------------------------------------------------------------
/src/preloadjs/utils/Elements.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Elements
3 | *
4 | * Visit http://createjs.com/ for documentation, updates and examples.
5 | *
6 | *
7 | * Copyright (c) 2012 gskinner.com, inc.
8 | *
9 | * Permission is hereby granted, free of charge, to any person
10 | * obtaining a copy of this software and associated documentation
11 | * files (the "Software"), to deal in the Software without
12 | * restriction, including without limitation the rights to use,
13 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
14 | * copies of the Software, and to permit persons to whom the
15 | * Software is furnished to do so, subject to the following
16 | * conditions:
17 | *
18 | * The above copyright notice and this permission notice shall be
19 | * included in all copies or substantial portions of the Software.
20 | *
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 | * OTHER DEALINGS IN THE SOFTWARE.
29 | */
30 |
31 | /**
32 | * @module PreloadJS
33 | */
34 |
35 | (function () {
36 |
37 | /**
38 | * Convenience methods for creating various elements used by PrelaodJS.
39 | *
40 | * @class DomUtils
41 | */
42 | var s = {};
43 |
44 | s.a = function() {
45 | return s.el("a");
46 | }
47 |
48 | s.svg = function() {
49 | return s.el("svg");
50 | }
51 |
52 | s.object = function() {
53 | return s.el("object");
54 | }
55 |
56 | s.image = function() {
57 | return s.el("image");
58 | }
59 |
60 | s.img = function() {
61 | return s.el("img");
62 | }
63 |
64 | s.style = function() {
65 | return s.el("style");
66 | }
67 |
68 | s.link = function() {
69 | return s.el("link");
70 | }
71 |
72 | s.script = function() {
73 | return s.el("script");
74 | }
75 |
76 | s.audio = function() {
77 | return s.el("audio");
78 | }
79 |
80 | s.video = function() {
81 | return s.el("video");
82 | }
83 |
84 | s.text = function(value) {
85 | return document.createTextNode(value);
86 | }
87 |
88 | s.el = function(name) {
89 | return document.createElement(name);
90 | }
91 |
92 | createjs.Elements = s;
93 |
94 | }());
95 |
--------------------------------------------------------------------------------
/src/preloadjs/utils/RequestUtils.js:
--------------------------------------------------------------------------------
1 | /*
2 | * RequestUtils
3 | * Visit http://createjs.com/ for documentation, updates and examples.
4 | *
5 | *
6 | * Copyright (c) 2012 gskinner.com, inc.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use,
12 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | * copies of the Software, and to permit persons to whom the
14 | * Software is furnished to do so, subject to the following
15 | * conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be
18 | * included in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 | * OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /**
31 | * @module PreloadJS
32 | */
33 |
34 | (function () {
35 |
36 | /**
37 | * Utilities that assist with parsing load items, and determining file types, etc.
38 | * @class RequestUtils
39 | */
40 | var s = {};
41 |
42 | /**
43 | * Determine if a specific type should be loaded as a binary file. Currently, only images and items marked
44 | * specifically as "binary" are loaded as binary. Note that audio is not a binary type, as we can not play
45 | * back using an audio tag if it is loaded as binary. Plugins can change the item type to binary to ensure they get
46 | * a binary result to work with. Binary files are loaded using XHR2. Types are defined as static constants on
47 | * {{#crossLink "AbstractLoader"}}{{/crossLink}}.
48 | * @method isBinary
49 | * @param {String} type The item type.
50 | * @return {Boolean} If the specified type is binary.
51 | * @static
52 | */
53 | s.isBinary = function (type) {
54 | switch (type) {
55 | case createjs.Types.IMAGE:
56 | case createjs.Types.BINARY:
57 | return true;
58 | default:
59 | return false;
60 | }
61 | };
62 |
63 | /**
64 | * Determine if a specific type is a text-based asset, and should be loaded as UTF-8.
65 | * @method isText
66 | * @param {String} type The item type.
67 | * @return {Boolean} If the specified type is text.
68 | * @static
69 | */
70 | s.isText = function (type) {
71 | switch (type) {
72 | case createjs.Types.TEXT:
73 | case createjs.Types.JSON:
74 | case createjs.Types.MANIFEST:
75 | case createjs.Types.XML:
76 | case createjs.Types.CSS:
77 | case createjs.Types.SVG:
78 | case createjs.Types.JAVASCRIPT:
79 | case createjs.Types.SPRITESHEET:
80 | return true;
81 | default:
82 | return false;
83 | }
84 | };
85 |
86 | /**
87 | * Determine the type of the object using common extensions. Note that the type can be passed in with the load item
88 | * if it is an unusual extension.
89 | * @method getTypeByExtension
90 | * @param {String} extension The file extension to use to determine the load type.
91 | * @return {String} The determined load type (for example, `createjs.Types.IMAGE`). Will return `null` if
92 | * the type can not be determined by the extension.
93 | * @static
94 | */
95 | s.getTypeByExtension = function (extension) {
96 | if (extension == null) {
97 | return createjs.Types.TEXT;
98 | }
99 |
100 | switch (extension.toLowerCase()) {
101 | case "jpeg":
102 | case "jpg":
103 | case "gif":
104 | case "png":
105 | case "webp":
106 | case "bmp":
107 | return createjs.Types.IMAGE;
108 | case "ogg":
109 | case "mp3":
110 | case "webm":
111 | case "aac":
112 | return createjs.Types.SOUND;
113 | case "mp4":
114 | case "webm":
115 | case "ts":
116 | return createjs.Types.VIDEO;
117 | case "json":
118 | return createjs.Types.JSON;
119 | case "xml":
120 | return createjs.Types.XML;
121 | case "css":
122 | return createjs.Types.CSS;
123 | case "js":
124 | return createjs.Types.JAVASCRIPT;
125 | case 'svg':
126 | return createjs.Types.SVG;
127 | default:
128 | return createjs.Types.TEXT;
129 | }
130 | };
131 |
132 | createjs.RequestUtils = s;
133 |
134 | }());
135 |
--------------------------------------------------------------------------------
/src/preloadjs/version.js:
--------------------------------------------------------------------------------
1 | this.createjs = this.createjs || {};
2 |
3 | (function () {
4 | "use strict";
5 |
6 | /**
7 | * Static class holding library specific information such as the version and buildDate of the library.
8 | * @class PreloadJS
9 | **/
10 | var s = createjs.PreloadJS = createjs.PreloadJS || {};
11 |
12 | /**
13 | * The version string for this release.
14 | * @property version
15 | * @type {String}
16 | * @static
17 | **/
18 | s.version = /*=version*/""; // injected by build process
19 |
20 | /**
21 | * The build date for this release in UTC format.
22 | * @property buildDate
23 | * @type {String}
24 | * @static
25 | **/
26 | s.buildDate = /*=date*/""; // injected by build process
27 |
28 | })();
29 |
--------------------------------------------------------------------------------
/tests/Gruntfile.js:
--------------------------------------------------------------------------------
1 | var url = require('url');
2 |
3 | module.exports = function (grunt) {
4 | grunt.initConfig(
5 | {
6 | pkg: grunt.file.readJSON('package.json'),
7 |
8 | jasmine: {
9 | run: {
10 | src: [
11 | '../lib/preloadjs-NEXT.js'
12 | ],
13 |
14 | options: {
15 | specs: 'spec/*Spec.js',
16 | helpers: [
17 | 'spec/Helpers.js'
18 | ],
19 | vendor: [
20 | '../_assets/libs/easeljs-NEXT.min.js'
21 | ],
22 | host: 'http://127.0.0.1:<%=connect.serve.options.port%>/'
23 | }
24 | }
25 | },
26 |
27 | connect: {
28 | serve: {
29 | options: {
30 | keepalive: true,
31 | base: [
32 | {
33 | path: __dirname,
34 | options: {
35 | index: '_SpecRunner.html'
36 | }
37 | }, '..', '../_assets/', '../lib/', './'
38 | ],
39 | useAvailablePort: true,
40 | port: 8000,
41 | open: true,
42 | // Used to test the POST / GET functionality, it just echo's back what data was sent.
43 | middleware: function (connect, options, middlewares) {
44 | middlewares.unshift(function (req, res, next) {
45 | if (req.method == "POST") {
46 | res.end(JSON.stringify(req.body));
47 | } else if(req.method == "GET") {
48 | var url_parts = url.parse(req.originalUrl, true);
49 | if (url_parts.query.foo != null) {
50 | res.end(JSON.stringify(url_parts.query));
51 | } else {
52 | next();
53 | }
54 | } else {
55 | next();
56 | }
57 | });
58 |
59 | var bodyParser = require('body-parser')
60 | middlewares.unshift(bodyParser.json());
61 | middlewares.unshift(bodyParser.urlencoded({extended: false}));
62 |
63 | return middlewares;
64 | },
65 | }
66 | }
67 | },
68 |
69 | listips: {
70 | run: {
71 | options: {
72 | label: "Normal"
73 | }
74 | }
75 | }
76 | }
77 | );
78 |
79 | grunt.registerTask('configureConnectHeadless', function () {
80 | grunt.config('connect.serve.options.keepalive', false);
81 | grunt.config('connect.serve.options.open', false);
82 | });
83 |
84 | // Load all the tasks we need
85 | grunt.loadNpmTasks('grunt-contrib-jasmine');
86 | grunt.loadNpmTasks('grunt-contrib-connect');
87 | grunt.loadTasks('tasks/');
88 |
89 | grunt.registerTask("default", "Launches browser-based tests", "serve");
90 | grunt.registerTask("serve", "Launches browser-based tests", ["jasmine:run:build", "listips", "connect"]);
91 |
92 | grunt.registerTask("headless", "phantom");
93 | grunt.registerTask("phantom", "Launches phantom-based tests", ["configureConnectHeadless", "connect", "jasmine"]);
94 | };
95 |
--------------------------------------------------------------------------------
/tests/README.md:
--------------------------------------------------------------------------------
1 | ## Setup and run tests ##
2 | * Run via Grunt
3 | * Install dependencies; npm install;
4 | * Run tests in browser: grunt;
5 | * Run headless: grunt jasmine;
6 |
7 |
--------------------------------------------------------------------------------
/tests/lib/jasmine-2.0.2/MIT.LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2008-2014 Pivotal Labs
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/tests/lib/jasmine-2.0.2/boot.js:
--------------------------------------------------------------------------------
1 | /**
2 | Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project.
3 |
4 | If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms.
5 |
6 | The location of `boot.js` can be specified and/or overridden in `jasmine.yml`.
7 |
8 | [jasmine-gem]: http://github.com/pivotal/jasmine-gem
9 | */
10 |
11 | (function() {
12 |
13 | /**
14 | * ## Require & Instantiate
15 | *
16 | * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference.
17 | */
18 | window.jasmine = jasmineRequire.core(jasmineRequire);
19 |
20 | /**
21 | * Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference.
22 | */
23 | jasmineRequire.html(jasmine);
24 |
25 | /**
26 | * Create the Jasmine environment. This is used to run all specs in a project.
27 | */
28 | var env = jasmine.getEnv();
29 |
30 | /**
31 | * ## The Global Interface
32 | *
33 | * Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged.
34 | */
35 | var jasmineInterface = jasmineRequire.interface(jasmine, env);
36 |
37 | /**
38 | * Add all of the Jasmine global/public interface to the proper global, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`.
39 | */
40 | if (typeof window == "undefined" && typeof exports == "object") {
41 | extend(exports, jasmineInterface);
42 | } else {
43 | extend(window, jasmineInterface);
44 | }
45 |
46 | /**
47 | * ## Runner Parameters
48 | *
49 | * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface.
50 | */
51 |
52 | var queryString = new jasmine.QueryString({
53 | getWindowLocation: function() { return window.location; }
54 | });
55 |
56 | var catchingExceptions = queryString.getParam("catch");
57 | env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions);
58 |
59 | /**
60 | * ## Reporters
61 | * The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any).
62 | */
63 | var htmlReporter = new jasmine.HtmlReporter({
64 | env: env,
65 | onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); },
66 | getContainer: function() { return document.body; },
67 | createElement: function() { return document.createElement.apply(document, arguments); },
68 | createTextNode: function() { return document.createTextNode.apply(document, arguments); },
69 | timer: new jasmine.Timer()
70 | });
71 |
72 | /**
73 | * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript.
74 | */
75 | env.addReporter(jasmineInterface.jsApiReporter);
76 | env.addReporter(htmlReporter);
77 |
78 | /**
79 | * Filter which specs will be run by matching the start of the full name against the `spec` query param.
80 | */
81 | var specFilter = new jasmine.HtmlSpecFilter({
82 | filterString: function() { return queryString.getParam("spec"); }
83 | });
84 |
85 | env.specFilter = function(spec) {
86 | return specFilter.matches(spec.getFullName());
87 | };
88 |
89 | /**
90 | * Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack.
91 | */
92 | window.setTimeout = window.setTimeout;
93 | window.setInterval = window.setInterval;
94 | window.clearTimeout = window.clearTimeout;
95 | window.clearInterval = window.clearInterval;
96 |
97 | /**
98 | * ## Execution
99 | *
100 | * Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded.
101 | */
102 | var currentWindowOnload = window.onload;
103 |
104 | window.onload = function() {
105 | if (currentWindowOnload) {
106 | currentWindowOnload();
107 | }
108 | htmlReporter.initialize();
109 | env.execute();
110 | };
111 |
112 | /**
113 | * Helper function for readability above.
114 | */
115 | function extend(destination, source) {
116 | for (var property in source) destination[property] = source[property];
117 | return destination;
118 | }
119 |
120 | }());
121 |
--------------------------------------------------------------------------------
/tests/lib/jasmine-2.0.2/console.js:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2008-2014 Pivotal Labs
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining
5 | a copy of this software and associated documentation files (the
6 | "Software"), to deal in the Software without restriction, including
7 | without limitation the rights to use, copy, modify, merge, publish,
8 | distribute, sublicense, and/or sell copies of the Software, and to
9 | permit persons to whom the Software is furnished to do so, subject to
10 | the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 | */
23 | function getJasmineRequireObj() {
24 | if (typeof module !== 'undefined' && module.exports) {
25 | return exports;
26 | } else {
27 | window.jasmineRequire = window.jasmineRequire || {};
28 | return window.jasmineRequire;
29 | }
30 | }
31 |
32 | getJasmineRequireObj().console = function(jRequire, j$) {
33 | j$.ConsoleReporter = jRequire.ConsoleReporter();
34 | };
35 |
36 | getJasmineRequireObj().ConsoleReporter = function() {
37 |
38 | var noopTimer = {
39 | start: function(){},
40 | elapsed: function(){ return 0; }
41 | };
42 |
43 | function ConsoleReporter(options) {
44 | var print = options.print,
45 | showColors = options.showColors || false,
46 | onComplete = options.onComplete || function() {},
47 | timer = options.timer || noopTimer,
48 | specCount,
49 | failureCount,
50 | failedSpecs = [],
51 | pendingCount,
52 | ansi = {
53 | green: '\x1B[32m',
54 | red: '\x1B[31m',
55 | yellow: '\x1B[33m',
56 | none: '\x1B[0m'
57 | };
58 |
59 | this.jasmineStarted = function() {
60 | specCount = 0;
61 | failureCount = 0;
62 | pendingCount = 0;
63 | print('Started');
64 | printNewline();
65 | timer.start();
66 | };
67 |
68 | this.jasmineDone = function() {
69 | printNewline();
70 | for (var i = 0; i < failedSpecs.length; i++) {
71 | specFailureDetails(failedSpecs[i]);
72 | }
73 |
74 | if(specCount > 0) {
75 | printNewline();
76 |
77 | var specCounts = specCount + ' ' + plural('spec', specCount) + ', ' +
78 | failureCount + ' ' + plural('failure', failureCount);
79 |
80 | if (pendingCount) {
81 | specCounts += ', ' + pendingCount + ' pending ' + plural('spec', pendingCount);
82 | }
83 |
84 | print(specCounts);
85 | } else {
86 | print('No specs found');
87 | }
88 |
89 | printNewline();
90 | var seconds = timer.elapsed() / 1000;
91 | print('Finished in ' + seconds + ' ' + plural('second', seconds));
92 |
93 | printNewline();
94 |
95 | onComplete(failureCount === 0);
96 | };
97 |
98 | this.specDone = function(result) {
99 | specCount++;
100 |
101 | if (result.status == 'pending') {
102 | pendingCount++;
103 | print(colored('yellow', '*'));
104 | return;
105 | }
106 |
107 | if (result.status == 'passed') {
108 | print(colored('green', '.'));
109 | return;
110 | }
111 |
112 | if (result.status == 'failed') {
113 | failureCount++;
114 | failedSpecs.push(result);
115 | print(colored('red', 'F'));
116 | }
117 | };
118 |
119 | return this;
120 |
121 | function printNewline() {
122 | print('\n');
123 | }
124 |
125 | function colored(color, str) {
126 | return showColors ? (ansi[color] + str + ansi.none) : str;
127 | }
128 |
129 | function plural(str, count) {
130 | return count == 1 ? str : str + 's';
131 | }
132 |
133 | function repeat(thing, times) {
134 | var arr = [];
135 | for (var i = 0; i < times; i++) {
136 | arr.push(thing);
137 | }
138 | return arr;
139 | }
140 |
141 | function indent(str, spaces) {
142 | var lines = (str || '').split('\n');
143 | var newArr = [];
144 | for (var i = 0; i < lines.length; i++) {
145 | newArr.push(repeat(' ', spaces).join('') + lines[i]);
146 | }
147 | return newArr.join('\n');
148 | }
149 |
150 | function specFailureDetails(result) {
151 | printNewline();
152 | print(result.fullName);
153 |
154 | for (var i = 0; i < result.failedExpectations.length; i++) {
155 | var failedExpectation = result.failedExpectations[i];
156 | printNewline();
157 | print(indent(failedExpectation.message, 2));
158 | print(indent(failedExpectation.stack, 2));
159 | }
160 |
161 | printNewline();
162 | }
163 | }
164 |
165 | return ConsoleReporter;
166 | };
167 |
--------------------------------------------------------------------------------
/tests/lib/jasmine-2.0.2/jasmine_favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CreateJS/PreloadJS/4938426b9c19dd525167cda473ad4ed00082ffe7/tests/lib/jasmine-2.0.2/jasmine_favicon.png
--------------------------------------------------------------------------------
/tests/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "PreloadJS-UnitTests",
3 | "version": "0.0.1",
4 | "description": "PreloadJS unit testing.",
5 | "url": "http://www.createjs.com/#!/PreloadJS",
6 | "logo": "assets/docs-icon-PreloadJS.png",
7 | "devDependencies": {
8 | "body-parser": "^1.9.2",
9 | "grunt": "~0.4.5",
10 | "grunt-contrib-connect": "^0.9.0",
11 | "grunt-contrib-jasmine": "^0.8.2"
12 | },
13 | "scripts": {
14 | "next":"cd ../build/ && grunt nextlib && cd ../tests && grunt"
15 | },
16 | "engine": "node >= 0.10.22"
17 | }
18 |
--------------------------------------------------------------------------------
/tests/spec/Helpers.js:
--------------------------------------------------------------------------------
1 | beforeEach(function () {
2 | this.baseAssetsPath = "../_assets/";
3 |
4 | this.getFilePath = function (fileObj) {
5 | var path = "";
6 | if (typeof fileObj == "string") {
7 | return this._formatFilePath(fileObj);
8 | } else if (fileObj.src instanceof Array) {
9 | for (var i=0;i= 0; i--) {
30 | var cssRules = document.styleSheets[i].cssRules ||
31 | document.styleSheets[i].rules || []; // IE support
32 | for (var c = 0; c < cssRules.length; c++) {
33 | if (cssRules[c].selectorText === selector) {
34 | return true;
35 | }
36 | }
37 | }
38 | return false;
39 | }
40 | });
41 |
--------------------------------------------------------------------------------
/tests/tasks/findopenport.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 gskinner.com, inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | module.exports = function (grunt) {
27 | var net = require('net');
28 | var _callback;
29 | var _ports;
30 | var _opts;
31 | var _done;
32 |
33 | grunt.registerMultiTask('findopenport', 'Prints a list of active ips.', function() {
34 | _opts = this.options();
35 |
36 | _done = this.async();
37 | _ports = _opts['ports'] || [80, 8888, 9000, 9999, 9001];
38 | checkNext();
39 | });
40 |
41 | function checkNext() {
42 | if (!_ports.length) {
43 | grunt.option(_portName, -1);
44 | _done();
45 | return;
46 | }
47 |
48 | check(_ports.shift(), function(success, port) {
49 | if (!success) {
50 | checkNext();
51 | } else {
52 | //grunt.option(_portName, port);
53 | var configNames = Array.isArray(_opts.configName)?_opts.configName:[_opts.configName];
54 |
55 | configNames.forEach(function(item) {
56 | grunt.config.set(item, port);
57 | });
58 | _done();
59 | }
60 | });
61 | }
62 |
63 | function check(port, callback) {
64 | var server = net.createServer();
65 | server.on('error', function(e) {
66 | callback(false, port);
67 | });
68 |
69 | server.listen(port, function() {
70 | callback(true, port);
71 | server.close();
72 | });
73 | }
74 | };
75 |
--------------------------------------------------------------------------------
/tests/tasks/listips.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2014 gskinner.com, inc.
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | module.exports = function (grunt) {
27 | var os = require('os');
28 |
29 | grunt.registerMultiTask('listips', 'Prints a list of active ips.', function() {
30 | var opts = this.options({"port": 80});
31 |
32 | var port = opts.port;
33 | var label = opts.label?'('+opts.label+') ':'';
34 |
35 | if (port == 80) {
36 | port = '';
37 | } else {
38 | port = ':'+port;
39 | }
40 |
41 | var interfaces = os.networkInterfaces();
42 | var addresses = [];
43 | for (var n in interfaces) {
44 | for (var n2 in interfaces[n]) {
45 | var address = interfaces[n][n2];
46 | if (address.family == 'IPv4' && !address.internal) {
47 | addresses.push('http://'+address.address+port);
48 | }
49 | }
50 | }
51 |
52 | addresses.push('http://localhost'+port);
53 | grunt.log.subhead('\n'+label+'Listening on:\n\t', addresses.join('\n\t '));
54 | });
55 | }
56 |
--------------------------------------------------------------------------------