BVB Source Codes

PreloadJS Show ManifestLoader.js Source code

Return Download PreloadJS: download ManifestLoader.js Source code - Download PreloadJS Source code - Type:.js
  1. /*
  2.  * ManifestLoader
  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 manifests. Items inside the manifest are loaded before the loader completes. To load manifests
  43.          * using JSONP, specify a {{#crossLink "LoadItem/callback:property"}}{{/crossLink}} as part of the
  44.          * {{#crossLink "LoadItem"}}{{/crossLink}}.
  45.          *
  46.          * The list of files in the manifest must be defined on the top-level JSON object in a `manifest` property. This
  47.          * example shows a sample manifest definition, as well as how to to include a sub-manifest.
  48.          *
  49.          *              {
  50.          *                      "path": "assets/",
  51.          *                  "manifest": [
  52.          *                              "image.png",
  53.          *                              {"src": "image2.png", "id":"image2"},
  54.          *                              {"src": "sub-manifest.json", "type":"manifest", "callback":"jsonCallback"}
  55.          *                  ]
  56.          *              }
  57.          *
  58.          * When a ManifestLoader has completed loading, the parent loader (usually a {{#crossLink "LoadQueue"}}{{/crossLink}},
  59.          * but could also be another ManifestLoader) will inherit all the loaded items, so you can access them directly.
  60.          *
  61.          * Note that the {{#crossLink "JSONLoader"}}{{/crossLink}} and {{#crossLink "JSONPLoader"}}{{/crossLink}} are
  62.          * higher priority loaders, so manifests <strong>must</strong> set the {{#crossLink "LoadItem"}}{{/crossLink}}
  63.          * {{#crossLink "LoadItem/type:property"}}{{/crossLink}} property to {{#crossLink "AbstractLoader/MANIFEST:property"}}{{/crossLink}}.
  64.          * @class ManifestLoader
  65.          * @param {LoadItem|Object} loadItem
  66.          * @extends AbstractLoader
  67.          * @constructor
  68.          */
  69.         function ManifestLoader(loadItem) {
  70.                 this.AbstractLoader_constructor(loadItem, null, createjs.AbstractLoader.MANIFEST);
  71.  
  72.         // Public Properties
  73.                 /**
  74.                  * An array of the plugins registered using {{#crossLink "LoadQueue/installPlugin"}}{{/crossLink}},
  75.                  * used to pass plugins to new LoadQueues that may be created.
  76.                  * @property _plugins
  77.                  * @type {Array}
  78.                  * @private
  79.                  * @since 0.6.1
  80.                  */
  81.                 this.plugins = null;
  82.  
  83.  
  84.         // Protected Properties
  85.                 /**
  86.                  * An internal {{#crossLink "LoadQueue"}}{{/crossLink}} that loads the contents of the manifest.
  87.                  * @property _manifestQueue
  88.                  * @type {LoadQueue}
  89.                  * @private
  90.                  */
  91.                 this._manifestQueue = null;
  92.         };
  93.  
  94.         var p = createjs.extend(ManifestLoader, createjs.AbstractLoader);
  95.         var s = ManifestLoader;
  96.  
  97.         // static properties
  98.         /**
  99.          * The amount of progress that the manifest itself takes up.
  100.          * @property MANIFEST_PROGRESS
  101.          * @type {number}
  102.          * @default 0.25 (25%)
  103.          * @private
  104.          * @static
  105.          */
  106.         s.MANIFEST_PROGRESS = 0.25;
  107.  
  108.         // static methods
  109.         /**
  110.          * Determines if the loader can load a specific item. This loader can only load items that are of type
  111.          * {{#crossLink "AbstractLoader/MANIFEST:property"}}{{/crossLink}}
  112.          * @method canLoadItem
  113.          * @param {LoadItem|Object} item The LoadItem that a LoadQueue is trying to load.
  114.          * @returns {Boolean} Whether the loader can load the item.
  115.          * @static
  116.          */
  117.         s.canLoadItem = function (item) {
  118.                 return item.type == createjs.AbstractLoader.MANIFEST;
  119.         };
  120.  
  121.         // public methods
  122.         p.load = function () {
  123.                 this.AbstractLoader_load();
  124.         };
  125.  
  126.         // protected methods
  127.         p._createRequest = function() {
  128.                 var callback = this._item.callback;
  129.                 if (callback != null) {
  130.                         this._request = new createjs.JSONPLoader(this._item);
  131.                 } else {
  132.                         this._request = new createjs.JSONLoader(this._item);
  133.                 }
  134.         };
  135.  
  136.         p.handleEvent = function (event) {
  137.                 switch (event.type) {
  138.                         case "complete":
  139.                                 this._rawResult = event.target.getResult(true);
  140.                                 this._result = event.target.getResult();
  141.                                 this._sendProgress(s.MANIFEST_PROGRESS);
  142.                                 this._loadManifest(this._result);
  143.                                 return;
  144.                         case "progress":
  145.                                 event.loaded *= s.MANIFEST_PROGRESS;
  146.                                 this.progress = event.loaded / event.total;
  147.                                 if (isNaN(this.progress) || this.progress == Infinity) { this.progress = 0; }
  148.                                 this._sendProgress(event);
  149.                                 return;
  150.                 }
  151.                 this.AbstractLoader_handleEvent(event);
  152.         };
  153.  
  154.         p.destroy = function() {
  155.                 this.AbstractLoader_destroy();
  156.                 this._manifestQueue.close();
  157.         };
  158.  
  159.         /**
  160.          * Create and load the manifest items once the actual manifest has been loaded.
  161.          * @method _loadManifest
  162.          * @param {Object} json
  163.          * @private
  164.          */
  165.         p._loadManifest = function (json) {
  166.                 if (json && json.manifest) {
  167.                         var queue = this._manifestQueue = new createjs.LoadQueue();
  168.                         queue.on("fileload", this._handleManifestFileLoad, this);
  169.                         queue.on("progress", this._handleManifestProgress, this);
  170.                         queue.on("complete", this._handleManifestComplete, this, true);
  171.                         queue.on("error", this._handleManifestError, this, true);
  172.                         for(var i = 0, l = this.plugins.length; i < l; i++) {   // conserve order of plugins
  173.                                 queue.installPlugin(this.plugins[i]);
  174.                         }
  175.                         queue.loadManifest(json);
  176.                 } else {
  177.                         this._sendComplete();
  178.                 }
  179.         };
  180.  
  181.         /**
  182.          * An item from the {{#crossLink "_manifestQueue:property"}}{{/crossLink}} has completed.
  183.          * @method _handleManifestFileLoad
  184.          * @param {Event} event
  185.          * @private
  186.          */
  187.         p._handleManifestFileLoad = function (event) {
  188.                 event.target = null;
  189.                 this.dispatchEvent(event);
  190.         };
  191.  
  192.         /**
  193.          * The manifest has completed loading. This triggers the {{#crossLink "AbstractLoader/complete:event"}}{{/crossLink}}
  194.          * {{#crossLink "Event"}}{{/crossLink}} from the ManifestLoader.
  195.          * @method _handleManifestComplete
  196.          * @param {Event} event
  197.          * @private
  198.          */
  199.         p._handleManifestComplete = function (event) {
  200.                 this._loadedItems = this._manifestQueue.getItems(true);
  201.                 this._sendComplete();
  202.         };
  203.  
  204.         /**
  205.          * The manifest has reported progress.
  206.          * @method _handleManifestProgress
  207.          * @param {ProgressEvent} event
  208.          * @private
  209.          */
  210.         p._handleManifestProgress = function (event) {
  211.                 this.progress = event.progress * (1 - s.MANIFEST_PROGRESS) + s.MANIFEST_PROGRESS;
  212.                 this._sendProgress(this.progress);
  213.         };
  214.  
  215.         /**
  216.          * The manifest has reported an error with one of the files.
  217.          * @method _handleManifestError
  218.          * @param {ErrorEvent} event
  219.          * @private
  220.          */
  221.         p._handleManifestError = function (event) {
  222.                 var newEvent = new createjs.Event("fileerror");
  223.                 newEvent.item = event.data;
  224.                 this.dispatchEvent(newEvent);
  225.         };
  226.  
  227.         createjs.ManifestLoader = createjs.promote(ManifestLoader, "AbstractLoader");
  228.  
  229. }());
  230.  
downloadManifestLoader.js Source code - Download PreloadJS Source code
Related Source Codes/Software:
gotraining - Go Training Class Material : ... 2017-04-29
eigen - The Art World in Your Pocket or Your Trendy Tech C... 2017-04-29
rack-cors - Rack Middleware for handling Cross-Origin Resource... 2017-04-29
react-redux-tutorial - react-redux-tutorial in Chinese, catalog &&... 2017-04-29
swifter - Tiny http server engine written in Swift programmi... 2017-04-29
boto3 - AWS SDK for Python http://a... 2017-04-30
Fluidbox - Replicating and improving the lightbox module seen... 2017-04-30
jo - JSON output from a shell 2017-04-30
qTip2 - qTip2 - Pretty powerful tooltips ... 2017-04-30
swing - A swipeable cards interface. The swipe-left/swipe-... 2017-04-30
growth - Growth - App to help you Be Awesome Developer &... 2017-05-06
TourGuide - TourGuide is an Android library that aims to provi... 2017-05-06
urh - Universal Radio Hacker: investigate wireless proto... 2017-05-06
Gutenberg - A meaningful web typography starter kit. 2017-05-06
NiftyDialogEffects - Nifty Modal Dialog Effect 2017-05-06
opengapps - The main repository of the Open GApps Project ... 2017-05-06
The micro CMS network asked administration system (the original PHP168 S series) v20161230 - 1, upgraded the mobile version. 2, upgrade the st... 2017-05-06
The news industry marketing website HTML 5 v5.7 site source code - Dedecms latest version of kernel development and o... 2017-05-06
Dream weaving white large entrepreneurial wealth information class site template v1.0 - Dream white large entrepreneurial wealth of inform... 2017-05-06

 Back to top