43 |
44 |
45 |
--------------------------------------------------------------------------------
/_assets/css/shared.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 3em auto;
3 | padding: 0;
4 | background-color: #eaebee;
5 | font-family: Arial, Verdana, sans-serif;
6 | font-size: 14px;
7 | font-weight: normal;
8 | color: #333;
9 | line-height: 1.4em;
10 | }
11 |
12 | a:link, a:visited {
13 | color: #39f;
14 | text-decoration: none;
15 | }
16 |
17 | a:hover {
18 | text-decoration: underline;
19 | }
20 |
21 | h1, h2 {
22 | color: #FFF;
23 | font-size: 1.6em;
24 | margin-bottom: 0;
25 | padding: 1.5em;
26 | padding-bottom: 1.2em;
27 | background: #374252;
28 | text-transform: uppercase;
29 | }
30 |
31 | h1::after {
32 | display: block;
33 | content: "";
34 | background: url('../art/logo_createjs.svg') no-repeat;
35 | height:1.5em;
36 | width: 6em;
37 | margin-top: -0.3em;
38 | float: right;
39 | }
40 |
41 | h1 em {
42 | font-weight: 200;
43 | font-style: normal;
44 | }
45 |
46 | h2 {
47 | font-size: 1.3em;
48 | padding: 1em;
49 | padding-bottom: 0.8em;
50 | }
51 |
52 | h3 {
53 | background: #e0e1e5;
54 | color: #374252;
55 | font-size: 1.25em;
56 | padding: 0.5em;
57 | margin-top: 1.25em;
58 | margin-bottom: -0.5em;
59 | position: relative;
60 | }
61 |
62 | code {
63 | color: black;
64 | background-color: rgba(255, 230, 0, 0.33);
65 | padding: 1px 3px;
66 | font-family: Courier New, Courier, serif;
67 | font-weight: bold;
68 | }
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/ISSUE_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ### TODO
2 | - [ ] Is this a question or bug? [Stack Overflow](https://stackoverflow.com/questions/tagged/createjs) is a much better place to ask any questions you may have.
3 |
4 | - [ ] Did you search the [issues](https://github.com/CreateJS/PreloadJS/issues) to see if someone else has already reported your issue? If yes, please add more details if you have any!
5 |
6 | - [ ] If you're using an older [version](https://github.com/CreateJS/PreloadJS/blob/master/VERSIONS.txt), have you tried the latest?
7 |
8 | - [ ] If you're requesting a new feature; provide as many details as you can. Why do you want this feature? Do you have ideas for how this feature should be implemented? Pseudocode is always welcome!
9 |
10 |
11 | ### Issue Details
12 | * Version used (Ex; 1.0):
13 |
14 |
15 | * Describe whats happening (Include any relevant console errors, a [Gist](https://gist.github.com/) is preferred for longer errors):
16 |
17 |
18 |
19 | * OS & Browser version *(Please be specific)* (Ex; Windows 10 Home, Chrome 62.0.3202.94):
20 |
21 |
22 |
23 | * Do you know of any workarounds?
24 |
25 |
26 |
27 | * Provide any extra details that will help us fix your issue. Including a link to a [CodePen.io](https://codepen.io) or [JSFiddle.net](https://jsfiddle.net) example that shows the issue in isolation will greatly increase the chance of getting a quick response.
28 |
--------------------------------------------------------------------------------
/_assets/static/demoStyles.css:
--------------------------------------------------------------------------------
1 | /*Stylesheet*/
2 |
3 | BODY, HTML {
4 | margin: 0;
5 | padding: 0;
6 | font-family: Arial, Verdana, sans-serif;
7 | font-size: 12px;
8 | font-weight: normal;
9 | color: #ccc;
10 | background-color: #333;
11 | }
12 |
13 | BODY {}
14 |
15 |
16 | p {
17 | margin: 10px 0;
18 | }
19 |
20 | a:link, a:visited {
21 | color: #e7841d;
22 | font-weight: bold;
23 | }
24 | a:hover {
25 | }
26 |
27 | #header {
28 | padding: 20px;
29 | background-color: #222;
30 | }
31 | #header h1 {
32 | font-weight: normal;
33 | font-size: 24px;
34 | margin: 0;
35 | padding: 0;
36 | }
37 |
38 | #header p {
39 | margin: 0;
40 | padding: 0;
41 |
42 | font-size: 14px;
43 | color: #777;
44 | }
45 |
46 | #header:after{
47 | content: "";
48 | position: absolute;
49 | }
50 |
51 |
52 | .content {
53 | width: 980px;
54 | height: 420px;
55 | padding: 10px;
56 |
57 | position: absolute;
58 | top: 50%;
59 | left: 50%;
60 | margin-top: -210px;
61 | margin-left: -490px;
62 |
63 | color: #777;
64 |
65 | border: 1px solid #555;
66 | background-color: #ccc;
67 | }
68 |
69 | #loader {
70 | display: none;
71 | }
72 | .loader {
73 | width: 100%;
74 | height: 50px;
75 | position: absolute;
76 | text-align:center;
77 | margin-top: 250px;
78 | background: url('loader.gif') no-repeat;
79 | background-position: 50% 50%;
80 | display: block !important;
81 | }
82 |
83 | #error {
84 | display:none;
85 | width: 960px;
86 | text-align: left;
87 | padding: 10px;
88 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PreloadJS
2 |
3 | PreloadJS is a library to make working with asset preloading easier. It provides a consistent API for loading different
4 | file types, automatic detection of XHR (XMLHttpRequest) availability with a fallback to tag-base loading, composite
5 | progress events, and a plugin model to assist with preloading in other libraries such as [SoundJS](http://www.createjs.com/soundjs/).
6 |
7 | ## Example
8 |
9 | ```javascript
10 | var queue = new createjs.LoadQueue(false);
11 | queue.on("fileload", handleFileComplete);
12 | queue.loadFile('http://createjs.com/assets/images/png/createjs-badge-dark.png');
13 | function handleFileComplete(event) {
14 | document.body.appendChild(event.result);
15 | }
16 | ```
17 |
18 | ## Support and Resources
19 | * Find examples and more information at the [PreloadJS web site](http://www.preloadjs.com/)
20 | * Read the [documentation](http://createjs.com/docs/preloadjs/)
21 | * Discuss, share projects, and interact with other users on [reddit](http://www.reddit.com/r/createjs/).
22 | * Ask technical questions on [Stack Overflow](http://stackoverflow.com/questions/tagged/preloadjs).
23 | * File verified bugs or formal feature requests using Issues on [GitHub](https://github.com/createjs/PreloadJS/issues).
24 | * Have a look at the included [examples](https://github.com/CreateJS/PreloadJS/tree/master/examples) and
25 | [API documentation](http://createjs.com/docs/preloadjs/) for more in-depth information.
26 |
27 | Built by [gskinner.com](http://www.gskinner.com), and is released for free under the MIT license, which means you can
28 | use it for almost any purpose (including commercial projects). We appreciate credit where possible, but it is not a requirement.
29 |
30 |
31 | ## Classes
32 |
33 | **LoadQueue**
34 | The main class that manages all preloading. Instantiate a LoadQueue instance, load a file or manifest, and track
35 | progress and complete events. Check out the [docs](http://createjs.com/docs/preloadjs/) for more information.
--------------------------------------------------------------------------------
/examples/PluginSample.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PreloadJS: Plugin Sample
5 |
6 |
7 |
8 |
9 |
10 |
18 |
19 |
20 |
21 |
22 |
23 |
Example: Plugin
24 |
25 |
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.
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
39 |
40 |
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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/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 | }());
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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/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/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/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/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/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 |
--------------------------------------------------------------------------------
/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 |
26 |
27 |
28 |
29 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/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/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/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/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/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/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/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/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/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 |
--------------------------------------------------------------------------------
/examples/FontLoader.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PreloadJS: Font Loading
5 |
6 |
7 |
8 |
9 |
19 |
20 |
21 |
22 |
23 |
PreloadJS Font Loading Approaches
24 |
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 |
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.
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
31 |
32 |
33 |
34 |
160 |
161 |
162 |
163 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/examples/SpriteSheet.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | EaselJS: Sprite Sheet Example
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
Sprite Sheets
13 |
14 |
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.
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
28 |
29 |
31 |
32 |
154 |
155 |
156 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/_assets/art/logo_createjs.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/examples/PreloadQueue.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PreloadJS: Queue Example
5 |
6 |
7 |
8 |
9 |
10 |
55 |
56 |
57 |
58 |
59 |
Preload Queue
60 |
61 |
Click "load another" to add another image the the overall queue. As
62 | images are added, the preload progress reflects
63 | the overall loaded progress. Click "load all" to queue everything at
64 | once.
65 | Note that when loading images and sounds locally, you need to ensure
66 | that PreloadJS uses tag loading to avoid
67 | cross-origin errors.
68 |
69 |
70 |
71 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
93 |
94 |
95 |
96 |
222 |
223 |
224 |
225 |
--------------------------------------------------------------------------------
/src/preloadjs/loaders/ImageLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * ImageLoader
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 | // namespace:
31 | this.createjs = this.createjs || {};
32 |
33 | (function () {
34 | "use strict";
35 |
36 | // constructor
37 | /**
38 | * A loader for image files.
39 | * @class ImageLoader
40 | * @param {LoadItem|Object} loadItem
41 | * @param {Boolean} preferXHR
42 | * @extends AbstractLoader
43 | * @constructor
44 | */
45 | function ImageLoader (loadItem, preferXHR) {
46 | this.AbstractLoader_constructor(loadItem, preferXHR, createjs.Types.IMAGE);
47 |
48 | // public properties
49 | this.resultFormatter = this._formatResult;
50 |
51 | // protected properties
52 | this._tagSrcAttribute = "src";
53 |
54 | // Check if the preload item is already a tag.
55 | if (createjs.DomUtils.isImageTag(loadItem)) {
56 | this._tag = loadItem;
57 | } else if (createjs.DomUtils.isImageTag(loadItem.src)) {
58 | this._tag = loadItem.src;
59 | } else if (createjs.DomUtils.isImageTag(loadItem.tag)) {
60 | this._tag = loadItem.tag;
61 | }
62 |
63 | if (this._tag != null) {
64 | this._preferXHR = false;
65 | } else {
66 | this._tag = createjs.Elements.img();
67 | }
68 |
69 | this.on("initialize", this._updateXHR, this);
70 | };
71 |
72 | var p = createjs.extend(ImageLoader, createjs.AbstractLoader);
73 | var s = ImageLoader;
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/IMAGE: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.IMAGE;
86 | };
87 |
88 | // public methods
89 | p.load = function () {
90 | if (this._tag.src != "" && this._tag.complete) {
91 | this._request._handleTagComplete();
92 | this._sendComplete();
93 | return;
94 | }
95 |
96 | var crossOrigin = this._item.crossOrigin;
97 | if (crossOrigin === true) { crossOrigin = "Anonymous"; }
98 | if (crossOrigin != null && !createjs.URLUtils.isLocal(this._item)) {
99 | this._tag.crossOrigin = crossOrigin;
100 | }
101 |
102 | this.AbstractLoader_load();
103 | };
104 |
105 | // protected methods
106 | /**
107 | * Before the item loads, set its mimeType and responseType.
108 | * @property _updateXHR
109 | * @param {Event} event
110 | * @private
111 | */
112 | p._updateXHR = function (event) {
113 | event.loader.mimeType = 'text/plain; charset=x-user-defined-binary';
114 |
115 | // Only exists for XHR
116 | if (event.loader.setResponseType) {
117 | event.loader.setResponseType("blob");
118 | }
119 | };
120 |
121 | /**
122 | * The result formatter for Image files.
123 | * @method _formatResult
124 | * @param {AbstractLoader} loader
125 | * @returns {HTMLImageElement}
126 | * @private
127 | */
128 | p._formatResult = function (loader) {
129 | return this._formatImage;
130 | };
131 |
132 | /**
133 | * The asynchronous image formatter function. This is required because images have
134 | * a short delay before they are ready.
135 | * @method _formatImage
136 | * @param {Function} successCallback The method to call when the result has finished formatting
137 | * @param {Function} errorCallback The method to call if an error occurs during formatting
138 | * @private
139 | */
140 | p._formatImage = function (successCallback, errorCallback) {
141 | var tag = this._tag;
142 | var URL = window.URL || window.webkitURL;
143 |
144 | if (!this._preferXHR) {
145 |
146 | //document.body.removeChild(tag);
147 | } else if (URL) {
148 | var objURL = URL.createObjectURL(this.getResult(true));
149 | tag.src = objURL;
150 |
151 | tag.addEventListener("load", this._cleanUpURL, false);
152 | tag.addEventListener("error", this._cleanUpURL, false);
153 | } else {
154 | tag.src = this._item.src;
155 | }
156 |
157 | if (tag.complete) {
158 | successCallback(tag);
159 | } else {
160 | tag.onload = createjs.proxy(function() {
161 | successCallback(this._tag);
162 | tag.onload = tag.onerror = null;
163 | }, this);
164 |
165 | tag.onerror = createjs.proxy(function(event) {
166 | errorCallback(new createjs.ErrorEvent('IMAGE_FORMAT', null, event));
167 | tag.onload = tag.onerror = null;
168 | }, this);
169 | }
170 | };
171 |
172 | /**
173 | * Clean up the ObjectURL, the tag is done with it. Note that this function is run
174 | * as an event listener without a proxy/closure, as it doesn't require it - so do not
175 | * include any functionality that requires scope without changing it.
176 | * @method _cleanUpURL
177 | * @param event
178 | * @private
179 | */
180 | p._cleanUpURL = function (event) {
181 | var URL = window.URL || window.webkitURL;
182 | URL.revokeObjectURL(event.target.src);
183 | };
184 |
185 | createjs.ImageLoader = createjs.promote(ImageLoader, "AbstractLoader");
186 |
187 | }());
188 |
--------------------------------------------------------------------------------
/src/preloadjs/net/TagRequest.js:
--------------------------------------------------------------------------------
1 | /*
2 | * TagRequest
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 "AbstractRequest"}}{{/crossLink}} that loads HTML tags, such as images and scripts.
43 | * @class TagRequest
44 | * @param {LoadItem} loadItem
45 | * @param {HTMLElement} tag
46 | * @param {String} srcAttribute The tag attribute that specifies the source, such as "src", "href", etc.
47 | */
48 | function TagRequest(loadItem, tag, srcAttribute) {
49 | this.AbstractRequest_constructor(loadItem);
50 |
51 | // protected properties
52 | /**
53 | * The HTML tag instance that is used to load.
54 | * @property _tag
55 | * @type {HTMLElement}
56 | * @protected
57 | */
58 | this._tag = tag;
59 |
60 | /**
61 | * The tag attribute that specifies the source, such as "src", "href", etc.
62 | * @property _tagSrcAttribute
63 | * @type {String}
64 | * @protected
65 | */
66 | this._tagSrcAttribute = srcAttribute;
67 |
68 | /**
69 | * A method closure used for handling the tag load event.
70 | * @property _loadedHandler
71 | * @type {Function}
72 | * @private
73 | */
74 | this._loadedHandler = createjs.proxy(this._handleTagComplete, this);
75 |
76 | /**
77 | * Determines if the element was added to the DOM automatically by PreloadJS, so it can be cleaned up after.
78 | * @property _addedToDOM
79 | * @type {Boolean}
80 | * @private
81 | */
82 | this._addedToDOM = false;
83 |
84 | };
85 |
86 | var p = createjs.extend(TagRequest, createjs.AbstractRequest);
87 |
88 | // public methods
89 | p.load = function () {
90 | this._tag.onload = createjs.proxy(this._handleTagComplete, this);
91 | this._tag.onreadystatechange = createjs.proxy(this._handleReadyStateChange, this);
92 | this._tag.onerror = createjs.proxy(this._handleError, this);
93 |
94 | var evt = new createjs.Event("initialize");
95 | evt.loader = this._tag;
96 |
97 | this.dispatchEvent(evt);
98 |
99 | this._loadTimeout = setTimeout(createjs.proxy(this._handleTimeout, this), this._item.loadTimeout);
100 |
101 | this._tag[this._tagSrcAttribute] = this._item.src;
102 |
103 | // wdg:: Append the tag AFTER setting the src, or SVG loading on iOS will fail.
104 | if (this._tag.parentNode == null) {
105 | createjs.DomUtils.appendToBody(this._tag);
106 | this._addedToDOM = true;
107 | }
108 | };
109 |
110 | p.destroy = function() {
111 | this._clean();
112 | this._tag = null;
113 |
114 | this.AbstractRequest_destroy();
115 | };
116 |
117 | // private methods
118 | /**
119 | * Handle the readyStateChange event from a tag. We need this in place of the `onload` callback (mainly SCRIPT
120 | * and LINK tags), but other cases may exist.
121 | * @method _handleReadyStateChange
122 | * @private
123 | */
124 | p._handleReadyStateChange = function () {
125 | clearTimeout(this._loadTimeout);
126 | // This is strictly for tags in browsers that do not support onload.
127 | var tag = this._tag;
128 |
129 | // Complete is for old IE support.
130 | if (tag.readyState == "loaded" || tag.readyState == "complete") {
131 | this._handleTagComplete();
132 | }
133 | };
134 |
135 | /**
136 | * Handle any error events from the tag.
137 | * @method _handleError
138 | * @protected
139 | */
140 | p._handleError = function() {
141 | this._clean();
142 | this.dispatchEvent("error");
143 | };
144 |
145 | /**
146 | * Handle the tag's onload callback.
147 | * @method _handleTagComplete
148 | * @private
149 | */
150 | p._handleTagComplete = function () {
151 | this._rawResult = this._tag;
152 | this._result = this.resultFormatter && this.resultFormatter(this) || this._rawResult;
153 |
154 | this._clean();
155 |
156 | this.dispatchEvent("complete");
157 | };
158 |
159 | /**
160 | * The tag request has not loaded within the time specified in loadTimeout.
161 | * @method _handleError
162 | * @param {Object} event The XHR error event.
163 | * @private
164 | */
165 | p._handleTimeout = function () {
166 | this._clean();
167 | this.dispatchEvent(new createjs.Event("timeout"));
168 | };
169 |
170 | /**
171 | * Remove event listeners, but don't destroy the request object
172 | * @method _clean
173 | * @private
174 | */
175 | p._clean = function() {
176 | this._tag.onload = null;
177 | this._tag.onreadystatechange = null;
178 | this._tag.onerror = null;
179 | if (this._addedToDOM && this._tag.parentNode != null) {
180 | this._tag.parentNode.removeChild(this._tag);
181 | }
182 | clearTimeout(this._loadTimeout);
183 | };
184 |
185 | /**
186 | * Handle a stalled audio event. The main place this happens is with HTMLAudio in Chrome when playing back audio
187 | * that is already in a load, but not complete.
188 | * @method _handleStalled
189 | * @private
190 | */
191 | p._handleStalled = function () {
192 | //Ignore, let the timeout take care of it. Sometimes its not really stopped.
193 | };
194 |
195 | createjs.TagRequest = createjs.promote(TagRequest, "AbstractRequest");
196 |
197 | }());
198 |
--------------------------------------------------------------------------------
/src/preloadjs/loaders/JSONPLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * JSONPLoader
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 JSONP files, which are JSON-formatted text files, wrapped in a callback. To load regular JSON
43 | * without a callback use the {{#crossLink "JSONLoader"}}{{/crossLink}} instead. To load JSON-formatted manifests,
44 | * use {{#crossLink "ManifestLoader"}}{{/crossLink}}, and to load EaselJS SpriteSheets, use
45 | * {{#crossLink "SpriteSheetLoader"}}{{/crossLink}}.
46 | *
47 | * JSONP is a format that provides a solution for loading JSON files cross-domain without requiring CORS.
48 | * JSONP files are loaded as JavaScript, and the "callback" is executed once they are loaded. The callback in the
49 | * JSONP must match the callback passed to the loadItem.
50 | *
51 | *
60 | *
61 | * var loadItem = {id:"json", type:"jsonp", src:"http://server.com/text.json", callback:"callbackName"}
62 | * var queue = new createjs.LoadQueue();
63 | * queue.on("complete", handleComplete);
64 | * queue.loadItem(loadItem);
65 | *
66 | * function handleComplete(event) }
67 | * var json = queue.getResult("json");
68 | * console.log(json.obj.bool); // true
69 | * }
70 | *
71 | * JSONP files loaded concurrently require a unique callback. To ensure JSONP files are loaded in order,
72 | * either use the {{#crossLink "LoadQueue/setMaxConnections"}}{{/crossLink}} method (set to 1), or set
73 | * {{#crossLink "LoadItem/maintainOrder:property"}}{{/crossLink}} on items with the same callback.
74 | *
75 | * Important note: Some browsers will prevent JSONP from firing the callback if the file was loaded as JSON, and not
76 | * JavaScript. You may have to have your server give you a JavaScript mime-type for this to work.
77 | *
78 | * @class JSONPLoader
79 | * @param {LoadItem|Object} loadItem
80 | * @extends AbstractLoader
81 | * @constructor
82 | */
83 | function JSONPLoader(loadItem) {
84 | this.AbstractLoader_constructor(loadItem, false, createjs.Types.JSONP);
85 | this.setTag(createjs.Elements.script());
86 | this.getTag().type = "text/javascript";
87 | };
88 |
89 | var p = createjs.extend(JSONPLoader, createjs.AbstractLoader);
90 | var s = JSONPLoader;
91 |
92 |
93 | // static methods
94 | /**
95 | * Determines if the loader can load a specific item. This loader can only load items that are of type
96 | * {{#crossLink "Types/JSONP:property"}}{{/crossLink}}.
97 | * @method canLoadItem
98 | * @param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
99 | * @returns {Boolean} Whether the loader can load the item.
100 | * @static
101 | */
102 | s.canLoadItem = function (item) {
103 | return item.type == createjs.Types.JSONP;
104 | };
105 |
106 | // public methods
107 | p.cancel = function () {
108 | this.AbstractLoader_cancel();
109 | this._dispose();
110 | };
111 |
112 | /**
113 | * Loads the JSONp file. Because of the unique loading needs of JSONp
114 | * we don't use the AbstractLoader.load() method.
115 | *
116 | * @method load
117 | *
118 | */
119 | p.load = function () {
120 | if (this._item.callback == null) {
121 | throw new Error('callback is required for loading JSONP requests.');
122 | }
123 |
124 | // TODO: Look into creating our own iFrame to handle the load
125 | // In the first attempt, FF did not get the result
126 | // result instanceof Object did not work either
127 | // so we would need to clone the result.
128 | if (window[this._item.callback] != null) {
129 | throw new Error(
130 | "JSONP callback '" +
131 | this._item.callback +
132 | "' already exists on window. You need to specify a different callback or re-name the current one.");
133 | }
134 |
135 | window[this._item.callback] = createjs.proxy(this._handleLoad, this);
136 | createjs.DomUtils.appendToBody(this._tag);
137 |
138 | this._loadTimeout = setTimeout(createjs.proxy(this._handleTimeout, this), this._item.loadTimeout);
139 |
140 | // Load the tag
141 | this._tag.src = this._item.src;
142 | };
143 |
144 | // private methods
145 | /**
146 | * Handle the JSONP callback, which is a public method defined on `window`.
147 | * @method _handleLoad
148 | * @param {Object} data The formatted JSON data.
149 | * @private
150 | */
151 | p._handleLoad = function (data) {
152 | this._result = this._rawResult = data;
153 | this._sendComplete();
154 |
155 | this._dispose();
156 | };
157 |
158 | /**
159 | * The tag request has not loaded within the time specfied in loadTimeout.
160 | * @method _handleError
161 | * @param {Object} event The XHR error event.
162 | * @private
163 | */
164 | p._handleTimeout = function () {
165 | this._dispose();
166 | this.dispatchEvent(new createjs.ErrorEvent("timeout"));
167 | };
168 |
169 | /**
170 | * Clean up the JSONP load. This clears out the callback and script tag that this loader creates.
171 | * @method _dispose
172 | * @private
173 | */
174 | p._dispose = function () {
175 | createjs.DomUtils.removeChild(this._tag);
176 | delete window[this._item.callback];
177 |
178 | clearTimeout(this._loadTimeout);
179 | };
180 |
181 | createjs.JSONPLoader = createjs.promote(JSONPLoader, "AbstractLoader");
182 |
183 | }());
184 |
--------------------------------------------------------------------------------
/src/preloadjs/utils/URLUtils.js:
--------------------------------------------------------------------------------
1 | /*
2 | * URLUtils
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 URLUtils
39 | */
40 | var s = {};
41 |
42 | /**
43 | * The Regular Expression used to test file URLS for an absolute path.
44 | * @property ABSOLUTE_PATH
45 | * @type {RegExp}
46 | * @static
47 | */
48 | s.ABSOLUTE_PATT = /^(?:\w+:)?\/{2}/i;
49 |
50 | /**
51 | * The Regular Expression used to test file URLS for a relative path.
52 | * @property RELATIVE_PATH
53 | * @type {RegExp}
54 | * @static
55 | */
56 | s.RELATIVE_PATT = (/^[./]*?\//i);
57 |
58 | /**
59 | * The Regular Expression used to test file URLS for an extension. Note that URIs must already have the query string
60 | * removed.
61 | * @property EXTENSION_PATT
62 | * @type {RegExp}
63 | * @static
64 | */
65 | s.EXTENSION_PATT = /\/?[^/]+\.(\w{1,5})$/i;
66 |
67 | /**
68 | * Parse a file path to determine the information we need to work with it. Currently, PreloadJS needs to know:
69 | *
70 | *
If the path is absolute. Absolute paths start with a protocol (such as `http://`, `file://`, or
71 | * `//networkPath`)
72 | *
If the path is relative. Relative paths start with `../` or `/path` (or similar)
73 | *
The file extension. This is determined by the filename with an extension. Query strings are dropped, and
74 | * the file path is expected to follow the format `name.ext`.
75 | *
76 | *
77 | * @method parseURI
78 | * @param {String} path
79 | * @returns {Object} An Object with an `absolute` and `relative` Boolean values,
80 | * the pieces of the path (protocol, hostname, port, pathname, search, hash, host)
81 | * as well as an optional 'extension` property, which is the lowercase extension.
82 | *
83 | * @static
84 | */
85 | s.parseURI = function (path) {
86 | var info = {
87 | absolute: false,
88 | relative: false,
89 | protocol: null,
90 | hostname: null,
91 | port: null,
92 | pathname: null,
93 | search: null,
94 | hash: null,
95 | host: null
96 | };
97 |
98 | if (path == null) { return info; }
99 |
100 | // Inject the path parts.
101 | var parser = createjs.Elements.a();
102 | parser.href = path;
103 |
104 | for (var n in info) {
105 | if (n in parser) {
106 | info[n] = parser[n];
107 | }
108 | }
109 |
110 | // Drop the query string
111 | var queryIndex = path.indexOf("?");
112 | if (queryIndex > -1) {
113 | path = path.substr(0, queryIndex);
114 | }
115 |
116 | // Absolute
117 | var match;
118 | if (s.ABSOLUTE_PATT.test(path)) {
119 | info.absolute = true;
120 |
121 | // Relative
122 | } else if (s.RELATIVE_PATT.test(path)) {
123 | info.relative = true;
124 | }
125 |
126 | // Extension
127 | if (match = path.match(s.EXTENSION_PATT)) {
128 | info.extension = match[1].toLowerCase();
129 | }
130 |
131 | return info;
132 | };
133 |
134 | /**
135 | * Formats an object into a query string for either a POST or GET request.
136 | * @method formatQueryString
137 | * @param {Object} data The data to convert to a query string.
138 | * @param {Array} [query] Existing name/value pairs to append on to this query.
139 | * @static
140 | */
141 | s.formatQueryString = function (data, query) {
142 | if (data == null) {
143 | throw new Error("You must specify data.");
144 | }
145 | var params = [];
146 | for (var n in data) {
147 | params.push(n + "=" + escape(data[n]));
148 | }
149 | if (query) {
150 | params = params.concat(query);
151 | }
152 | return params.join("&");
153 | };
154 |
155 | /**
156 | * A utility method that builds a file path using a source and a data object, and formats it into a new path.
157 | * @method buildURI
158 | * @param {String} src The source path to add values to.
159 | * @param {Object} [data] Object used to append values to this request as a query string. Existing parameters on the
160 | * path will be preserved.
161 | * @returns {string} A formatted string that contains the path and the supplied parameters.
162 | * @static
163 | */
164 | s.buildURI = function (src, data) {
165 | if (data == null) {
166 | return src;
167 | }
168 |
169 | var query = [];
170 | var idx = src.indexOf("?");
171 |
172 | if (idx != -1) {
173 | var q = src.slice(idx + 1);
174 | query = query.concat(q.split("&"));
175 | }
176 |
177 | if (idx != -1) {
178 | return src.slice(0, idx) + "?" + this.formatQueryString(data, query);
179 | } else {
180 | return src + "?" + this.formatQueryString(data, query);
181 | }
182 | };
183 |
184 | /**
185 | * @method isCrossDomain
186 | * @param {LoadItem|Object} item A load item with a `src` property.
187 | * @return {Boolean} If the load item is loading from a different domain than the current location.
188 | * @static
189 | */
190 | s.isCrossDomain = function (item) {
191 | var target = createjs.Elements.a();
192 | target.href = item.src;
193 |
194 | var host = createjs.Elements.a();
195 | host.href = location.href;
196 |
197 | var crossdomain = (target.hostname != "") &&
198 | (target.port != host.port ||
199 | target.protocol != host.protocol ||
200 | target.hostname != host.hostname);
201 | return crossdomain;
202 | };
203 |
204 | /**
205 | * @method isLocal
206 | * @param {LoadItem|Object} item A load item with a `src` property
207 | * @return {Boolean} If the load item is loading from the "file:" protocol. Assume that the host must be local as
208 | * well.
209 | * @static
210 | */
211 | s.isLocal = function (item) {
212 | var target = createjs.Elements.a();
213 | target.href = item.src;
214 | return target.hostname == "" && target.protocol == "file:";
215 | };
216 |
217 | createjs.URLUtils = s;
218 |
219 | }());
220 |
--------------------------------------------------------------------------------
/src/preloadjs/data/Types.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Types
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 load types that PreloadJS supports by default. This is typically used when passing a type override to
43 | * a {{#crossLink "LoadQueue"}}{{/crossLink}}.
44 | *
45 | *
Example
46 | *
47 | * queue.loadFile({src:"https://somecdn/wfossn3", type:createjs.Types.IMAGE});
48 | *
49 | * You can also use the string value:
50 | *
51 | * queue.loadFile({src:"https://somecdn/wfossn3", type:"image"});
52 | *
53 | * @class Types
54 | * @static
55 | */
56 |
57 | var s = {};
58 |
59 | /**
60 | * The preload type for generic binary types. Note that images are loaded as binary files when using XHR.
61 | * @property BINARY
62 | * @type {String}
63 | * @default binary
64 | * @static
65 | * @since 0.6.0
66 | */
67 | s.BINARY = "binary";
68 |
69 | /**
70 | * The preload type for css files. CSS files are loaded using a <link> when loaded with XHR, or a
71 | * <style> tag when loaded with tags.
72 | * @property CSS
73 | * @type {String}
74 | * @default css
75 | * @static
76 | * @since 0.6.0
77 | */
78 | s.CSS = "css";
79 |
80 | /**
81 | * The preload type for font files.
82 | * @property FONT
83 | * @type {String}
84 | * @default font
85 | * @static
86 | * @since 0.9.0
87 | */
88 | s.FONT = "font";
89 |
90 | /**
91 | * The preload type for fonts specified with CSS (such as Google fonts)
92 | * @property FONTCSS
93 | * @type {String}
94 | * @default fontcss
95 | * @static
96 | * @since 0.9.0
97 | */
98 | s.FONTCSS = "fontcss";
99 |
100 | /**
101 | * The preload type for image files, usually png, gif, or jpg/jpeg. Images are loaded into an <image> tag.
102 | * @property IMAGE
103 | * @type {String}
104 | * @default image
105 | * @static
106 | * @since 0.6.0
107 | */
108 | s.IMAGE = "image";
109 |
110 | /**
111 | * The preload type for javascript files, usually with the "js" file extension. JavaScript files are loaded into a
112 | * <script> tag.
113 | *
114 | * Since version 0.4.1+, due to how tag-loaded scripts work, all JavaScript files are automatically injected into
115 | * the body of the document to maintain parity between XHR and tag-loaded scripts. In version 0.4.0 and earlier,
116 | * only tag-loaded scripts are injected.
117 | * @property JAVASCRIPT
118 | * @type {String}
119 | * @default javascript
120 | * @static
121 | * @since 0.6.0
122 | */
123 | s.JAVASCRIPT = "javascript";
124 |
125 | /**
126 | * The preload type for json files, usually with the "json" file extension. JSON data is loaded and parsed into a
127 | * JavaScript object. Note that if a `callback` is present on the load item, the file will be loaded with JSONP,
128 | * no matter what the {{#crossLink "LoadQueue/preferXHR:property"}}{{/crossLink}} property is set to, and the JSON
129 | * must contain a matching wrapper function.
130 | * @property JSON
131 | * @type {String}
132 | * @default json
133 | * @static
134 | * @since 0.6.0
135 | */
136 | s.JSON = "json";
137 |
138 | /**
139 | * The preload type for jsonp files, usually with the "json" file extension. JSON data is loaded and parsed into a
140 | * JavaScript object. You are required to pass a callback parameter that matches the function wrapper in the JSON.
141 | * Note that JSONP will always be used if there is a callback present, no matter what the {{#crossLink "LoadQueue/preferXHR:property"}}{{/crossLink}}
142 | * property is set to.
143 | * @property JSONP
144 | * @type {String}
145 | * @default jsonp
146 | * @static
147 | * @since 0.6.0
148 | */
149 | s.JSONP = "jsonp";
150 |
151 | /**
152 | * The preload type for json-based manifest files, usually with the "json" file extension. The JSON data is loaded
153 | * and parsed into a JavaScript object. PreloadJS will then look for a "manifest" property in the JSON, which is an
154 | * Array of files to load, following the same format as the {{#crossLink "LoadQueue/loadManifest"}}{{/crossLink}}
155 | * method. If a "callback" is specified on the manifest object, then it will be loaded using JSONP instead,
156 | * regardless of what the {{#crossLink "LoadQueue/preferXHR:property"}}{{/crossLink}} property is set to.
157 | * @property MANIFEST
158 | * @type {String}
159 | * @default manifest
160 | * @static
161 | * @since 0.6.0
162 | */
163 | s.MANIFEST = "manifest";
164 |
165 | /**
166 | * The preload type for sound files, usually mp3, ogg, or wav. When loading via tags, audio is loaded into an
167 | * <audio> tag.
168 | * @property SOUND
169 | * @type {String}
170 | * @default sound
171 | * @static
172 | * @since 0.6.0
173 | */
174 | s.SOUND = "sound";
175 |
176 | /**
177 | * The preload type for video files, usually mp4, ts, or ogg. When loading via tags, video is loaded into an
178 | * <video> tag.
179 | * @property VIDEO
180 | * @type {String}
181 | * @default video
182 | * @static
183 | * @since 0.6.0
184 | */
185 | s.VIDEO = "video";
186 |
187 | /**
188 | * The preload type for SpriteSheet files. SpriteSheet files are JSON files that contain string image paths.
189 | * @property SPRITESHEET
190 | * @type {String}
191 | * @default spritesheet
192 | * @static
193 | * @since 0.6.0
194 | */
195 | s.SPRITESHEET = "spritesheet";
196 |
197 | /**
198 | * The preload type for SVG files.
199 | * @property SVG
200 | * @type {String}
201 | * @default svg
202 | * @static
203 | * @since 0.6.0
204 | */
205 | s.SVG = "svg";
206 |
207 | /**
208 | * The preload type for text files, which is also the default file type if the type can not be determined. Text is
209 | * loaded as raw text.
210 | * @property TEXT
211 | * @type {String}
212 | * @default text
213 | * @static
214 | * @since 0.6.0
215 | */
216 | s.TEXT = "text";
217 |
218 | /**
219 | * The preload type for xml files. XML is loaded into an XML document.
220 | * @property XML
221 | * @type {String}
222 | * @default xml
223 | * @static
224 | * @since 0.6.0
225 | */
226 | s.XML = "xml";
227 |
228 | createjs.Types = s;
229 | }());
230 |
--------------------------------------------------------------------------------
/examples/MediaGrid.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PreloadJS: Multimedia Preload Example
5 |
6 |
7 |
8 |
9 |
10 |
58 |
59 |
60 |
61 |
62 |
63 |
Example: Media Grid
64 |
65 |
PreloadJS can load a variety of media. In this example, click each
66 | example to load its related item.
67 | Once the item is loaded, it will display (image, svg), play (sound),
68 | apply to the document (css), or display
69 | an alert (script). Note that when loading images, sounds, css, scripts,
70 | or svg locally, you need to ensure
71 | that PreloadJS uses tag loading to avoid cross-origin errors. Other
72 | media types will not load locally.
73 |
74 |
75 |
76 | Click an item to load it.
79 |
80 |
81 |
82 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
114 |
115 |
116 |
117 |
120 |
121 |
122 |
123 |
125 |
126 |
127 |
128 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
138 |
139 |
251 |
252 |
253 |
254 |
--------------------------------------------------------------------------------
/src/preloadjs/loaders/SpriteSheetLoader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * SpriteSheetLoader
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 EaselJS SpriteSheets. Images inside the spritesheet definition are loaded before the loader
43 | * completes. To load SpriteSheets using JSONP, specify a {{#crossLink "LoadItem/callback:property"}}{{/crossLink}}
44 | * as part of the {{#crossLink "LoadItem"}}{{/crossLink}}. Note that the {{#crossLink "JSONLoader"}}{{/crossLink}}
45 | * and {{#crossLink "JSONPLoader"}}{{/crossLink}} are higher priority loaders, so SpriteSheets must
46 | * set the {{#crossLink "LoadItem"}}{{/crossLink}} {{#crossLink "LoadItem/type:property"}}{{/crossLink}} property
47 | * to {{#crossLink "Types/SPRITESHEET:property"}}{{/crossLink}}.
48 | *
49 | * The {{#crossLink "LoadItem"}}{{/crossLink}} {{#crossLink "LoadItem/crossOrigin:property"}}{{/crossLink}} as well
50 | * as the {{#crossLink "LoadQueue's"}}{{/crossLink}} `basePath` argument and {{#crossLink "LoadQueue/_preferXHR"}}{{/crossLink}}
51 | * property supplied to the {{#crossLink "LoadQueue"}}{{/crossLink}} are passed on to the sub-manifest that loads
52 | * the SpriteSheet images.
53 | *
54 | * Note that the SpriteSheet JSON does not respect the {{#crossLink "LoadQueue/_preferXHR:property"}}{{/crossLink}}
55 | * property, which should instead be determined by the presence of a {{#crossLink "LoadItem/callback:property"}}{{/crossLink}}
56 | * property on the SpriteSheet load item. This is because the JSON loaded will have a different format depending on
57 | * if it is loaded as JSON, so just changing `preferXHR` is not enough to change how it is loaded.
58 | * @class SpriteSheetLoader
59 | * @param {LoadItem|Object} loadItem
60 | * @extends AbstractLoader
61 | * @constructor
62 | */
63 | function SpriteSheetLoader(loadItem, preferXHR) {
64 | this.AbstractLoader_constructor(loadItem, preferXHR, createjs.Types.SPRITESHEET);
65 |
66 | // protected properties
67 | /**
68 | * An internal queue which loads the SpriteSheet's images.
69 | * @method _manifestQueue
70 | * @type {LoadQueue}
71 | * @private
72 | */
73 | this._manifestQueue = null;
74 | }
75 |
76 | var p = createjs.extend(SpriteSheetLoader, createjs.AbstractLoader);
77 | var s = SpriteSheetLoader;
78 |
79 | // static properties
80 | /**
81 | * The amount of progress that the manifest itself takes up.
82 | * @property SPRITESHEET_PROGRESS
83 | * @type {number}
84 | * @default 0.25 (25%)
85 | * @private
86 | * @static
87 | */
88 | s.SPRITESHEET_PROGRESS = 0.25;
89 |
90 | // static methods
91 | /**
92 | * Determines if the loader can load a specific item. This loader can only load items that are of type
93 | * {{#crossLink "Types/SPRITESHEET:property"}}{{/crossLink}}
94 | * @method canLoadItem
95 | * @param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
96 | * @returns {Boolean} Whether the loader can load the item.
97 | * @static
98 | */
99 | s.canLoadItem = function (item) {
100 | return item.type == createjs.Types.SPRITESHEET;
101 | };
102 |
103 | // public methods
104 | p.destroy = function() {
105 | this.AbstractLoader_destroy();
106 | this._manifestQueue.close();
107 | };
108 |
109 | // protected methods
110 | p._createRequest = function() {
111 | var callback = this._item.callback;
112 | if (callback != null) {
113 | this._request = new createjs.JSONPLoader(this._item);
114 | } else {
115 | this._request = new createjs.JSONLoader(this._item);
116 | }
117 | };
118 |
119 | p.handleEvent = function (event) {
120 | switch (event.type) {
121 | case "complete":
122 | this._rawResult = event.target.getResult(true);
123 | this._result = event.target.getResult();
124 | this._sendProgress(s.SPRITESHEET_PROGRESS);
125 | this._loadManifest(this._result);
126 | return;
127 | case "progress":
128 | event.loaded *= s.SPRITESHEET_PROGRESS;
129 | this.progress = event.loaded / event.total;
130 | if (isNaN(this.progress) || this.progress == Infinity) { this.progress = 0; }
131 | this._sendProgress(event);
132 | return;
133 | }
134 | this.AbstractLoader_handleEvent(event);
135 | };
136 |
137 | /**
138 | * Create and load the images once the SpriteSheet JSON has been loaded.
139 | * @method _loadManifest
140 | * @param {Object} json
141 | * @private
142 | */
143 | p._loadManifest = function (json) {
144 | if (json && json.images) {
145 | var queue = this._manifestQueue = new createjs.LoadQueue(this._preferXHR, this._item.path, this._item.crossOrigin);
146 | queue.on("complete", this._handleManifestComplete, this, true);
147 | queue.on("fileload", this._handleManifestFileLoad, this);
148 | queue.on("progress", this._handleManifestProgress, this);
149 | queue.on("error", this._handleManifestError, this, true);
150 | queue.loadManifest(json.images);
151 | }
152 | };
153 |
154 | /**
155 | * An item from the {{#crossLink "_manifestQueue:property"}}{{/crossLink}} has completed.
156 | * @method _handleManifestFileLoad
157 | * @param {Event} event
158 | * @private
159 | */
160 | p._handleManifestFileLoad = function (event) {
161 | var image = event.result;
162 | if (image != null) {
163 | var images = this.getResult().images;
164 | var pos = images.indexOf(event.item.src);
165 | images[pos] = image;
166 | }
167 | };
168 |
169 | /**
170 | * The images have completed loading. This triggers the {{#crossLink "AbstractLoader/complete:event"}}{{/crossLink}}
171 | * {{#crossLink "Event"}}{{/crossLink}} from the SpriteSheetLoader.
172 | * @method _handleManifestComplete
173 | * @param {Event} event
174 | * @private
175 | */
176 | p._handleManifestComplete = function (event) {
177 | this._result = new createjs.SpriteSheet(this._result);
178 | this._loadedItems = this._manifestQueue.getItems(true);
179 | this._sendComplete();
180 | };
181 |
182 | /**
183 | * The images {{#crossLink "LoadQueue"}}{{/crossLink}} has reported progress.
184 | * @method _handleManifestProgress
185 | * @param {ProgressEvent} event
186 | * @private
187 | */
188 | p._handleManifestProgress = function (event) {
189 | this.progress = event.progress * (1 - s.SPRITESHEET_PROGRESS) + s.SPRITESHEET_PROGRESS;
190 | this._sendProgress(this.progress);
191 | };
192 |
193 | /**
194 | * An image has reported an error.
195 | * @method _handleManifestError
196 | * @param {ErrorEvent} event
197 | * @private
198 | */
199 | p._handleManifestError = function (event) {
200 | var newEvent = new createjs.Event("fileerror");
201 | newEvent.item = event.data;
202 | this.dispatchEvent(newEvent);
203 | };
204 |
205 | createjs.SpriteSheetLoader = createjs.promote(SpriteSheetLoader, "AbstractLoader");
206 |
207 | }());
208 |
--------------------------------------------------------------------------------
/src/preloadjs/data/LoadItem.js:
--------------------------------------------------------------------------------
1 | /*
2 | * LoadItem
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 | * All loaders accept an item containing the properties defined in this class. If a raw object is passed instead,
42 | * it will not be affected, but it must contain at least a {{#crossLink "src:property"}}{{/crossLink}} property. A
43 | * string path or HTML tag is also acceptable, but it will be automatically converted to a LoadItem using the
44 | * {{#crossLink "create"}}{{/crossLink}} method by {{#crossLink "AbstractLoader"}}{{/crossLink}}
45 | * @class LoadItem
46 | * @constructor
47 | * @since 0.6.0
48 | */
49 | function LoadItem() {
50 | /**
51 | * The source of the file that is being loaded. This property is required. The source can either be a
52 | * string (recommended), or an HTML tag.
53 | * This can also be an object, but in that case it has to include a type and be handled by a plugin.
54 | * @property src
55 | * @type {String}
56 | * @default null
57 | */
58 | this.src = null;
59 |
60 | /**
61 | * The type file that is being loaded. The type of the file is usually inferred by the extension, but can also
62 | * be set manually. This is helpful in cases where a file does not have an extension.
63 | * @property type
64 | * @type {String}
65 | * @default null
66 | */
67 | this.type = null;
68 |
69 | /**
70 | * A string identifier which can be used to reference the loaded object. If none is provided, this will be
71 | * automatically set to the {{#crossLink "src:property"}}{{/crossLink}}.
72 | * @property id
73 | * @type {String}
74 | * @default null
75 | */
76 | this.id = null;
77 |
78 | /**
79 | * Determines if a manifest will maintain the order of this item, in relation to other items in the manifest
80 | * that have also set the `maintainOrder` property to `true`. This only applies when the max connections has
81 | * been set above 1 (using {{#crossLink "LoadQueue/setMaxConnections"}}{{/crossLink}}). Everything with this
82 | * property set to `false` will finish as it is loaded. Ordered items are combined with script tags loading in
83 | * order when {{#crossLink "LoadQueue/maintainScriptOrder:property"}}{{/crossLink}} is set to `true`.
84 | * @property maintainOrder
85 | * @type {Boolean}
86 | * @default false
87 | */
88 | this.maintainOrder = false;
89 |
90 | /**
91 | * A callback used by JSONP requests that defines what global method to call when the JSONP content is loaded.
92 | * @property callback
93 | * @type {String}
94 | * @default null
95 | */
96 | this.callback = null;
97 |
98 | /**
99 | * An arbitrary data object, which is included with the loaded object.
100 | * @property data
101 | * @type {Object}
102 | * @default null
103 | */
104 | this.data = null;
105 |
106 | /**
107 | * The request method used for HTTP calls. Both {{#crossLink "Methods/GET:property"}}{{/crossLink}} or
108 | * {{#crossLink "Methods/POST:property"}}{{/crossLink}} request types are supported, and are defined as
109 | * constants on {{#crossLink "AbstractLoader"}}{{/crossLink}}.
110 | * @property method
111 | * @type {String}
112 | * @default GET
113 | */
114 | this.method = createjs.Methods.GET;
115 |
116 | /**
117 | * An object hash of name/value pairs to send to the server.
118 | * @property values
119 | * @type {Object}
120 | * @default null
121 | */
122 | this.values = null;
123 |
124 | /**
125 | * An object hash of headers to attach to an XHR request. PreloadJS will automatically attach some default
126 | * headers when required, including "Origin", "Content-Type", and "X-Requested-With". You may override the
127 | * default headers by including them in your headers object.
128 | * @property headers
129 | * @type {Object}
130 | * @default null
131 | */
132 | this.headers = null;
133 |
134 | /**
135 | * Enable credentials for XHR requests.
136 | * @property withCredentials
137 | * @type {Boolean}
138 | * @default false
139 | */
140 | this.withCredentials = false;
141 |
142 | /**
143 | * Set the mime type of XHR-based requests. This is automatically set to "text/plain; charset=utf-8" for text
144 | * based files (json, xml, text, css, js).
145 | * @property mimeType
146 | * @type {String}
147 | * @default null
148 | */
149 | this.mimeType = null;
150 |
151 | /**
152 | * Sets the crossOrigin attribute for CORS-enabled images loading cross-domain.
153 | * @property crossOrigin
154 | * @type {boolean}
155 | * @default Anonymous
156 | */
157 | this.crossOrigin = null;
158 |
159 | /**
160 | * The duration in milliseconds to wait before a request times out. This only applies to tag-based and and XHR
161 | * (level one) loading, as XHR (level 2) provides its own timeout event.
162 | * @property loadTimeout
163 | * @type {Number}
164 | * @default 8000 (8 seconds)
165 | */
166 | this.loadTimeout = s.LOAD_TIMEOUT_DEFAULT;
167 | };
168 |
169 | var p = LoadItem.prototype = {};
170 | var s = LoadItem;
171 |
172 | /**
173 | * Default duration in milliseconds to wait before a request times out. This only applies to tag-based and and XHR
174 | * (level one) loading, as XHR (level 2) provides its own timeout event.
175 | * @property LOAD_TIMEOUT_DEFAULT
176 | * @type {number}
177 | * @static
178 | */
179 | s.LOAD_TIMEOUT_DEFAULT = 8000;
180 |
181 | /**
182 | * Create a LoadItem.
183 | *
184 | *
String-based items are converted to a LoadItem with a populated {{#crossLink "src:property"}}{{/crossLink}}.
185 | *
LoadItem instances are returned as-is
186 | *
Objects are returned with any needed properties added
187 | *
188 | * @method create
189 | * @param {LoadItem|String|Object} value The load item value
190 | * @returns {LoadItem|Object}
191 | * @static
192 | */
193 | s.create = function (value) {
194 | if (typeof value == "string") {
195 | var item = new LoadItem();
196 | item.src = value;
197 | return item;
198 | } else if (value instanceof s) {
199 | return value;
200 | } else if (value instanceof Object && value.src) {
201 | if (value.loadTimeout == null) {
202 | value.loadTimeout = s.LOAD_TIMEOUT_DEFAULT;
203 | }
204 | return value;
205 | } else {
206 | throw new Error("Type not recognized.");
207 | }
208 | };
209 |
210 | /**
211 | * Provides a chainable shortcut method for setting a number of properties on the instance.
212 | *
213 | *
Example
214 | *
215 | * var loadItem = new createjs.LoadItem().set({src:"image.png", maintainOrder:true});
216 | *
217 | * @method set
218 | * @param {Object} props A generic object containing properties to copy to the LoadItem instance.
219 | * @return {LoadItem} Returns the instance the method is called on (useful for chaining calls.)
220 | */
221 | p.set = function(props) {
222 | for (var n in props) { this[n] = props[n]; }
223 | return this;
224 | };
225 |
226 | createjs.LoadItem = s;
227 |
228 | }());
229 |
--------------------------------------------------------------------------------