1 /**
  2  * The MIT License (MIT)
  3  *
  4  * Copyright (c) 2016 DeNA Co., Ltd.
  5  *
  6  * Permission is hereby granted, free of charge, to any person obtaining a copy
  7  * of this software and associated documentation files (the "Software"), to deal
  8  * in the Software without restriction, including without limitation the rights
  9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10  * copies of the Software, and to permit persons to whom the Software is
 11  * furnished to do so, subject to the following conditions:
 12  *
 13  * The above copyright notice and this permission notice shall be included in
 14  * all copies or substantial portions of the Software.
 15  *
 16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 22  * SOFTWARE.
 23  */
 24 
 25 /// <reference path="base.js"/>
 26 /// <reference path="loader.js"/>
 27 /// <reference path="user_agent.js"/>
 28 
 29 /**
 30  * A class that provides methods to customize this library.
 31  * @constructor
 32  */
 33 createjs.Config = function() {
 34 };
 35 
 36 /**
 37  * The version number used by the loader cache.
 38  * @type {number}
 39  * @private
 40  */
 41 createjs.Config.cacheVersion_ = 1;
 42 
 43 /**
 44  * Whether to use workaround code for Android browsers.
 45  * @type {Object.<string,number>}
 46  * @private
 47  */
 48 createjs.Config.useAndroidWorkarounds_ = {};
 49 
 50 /**
 51  * Whether the host browser can play <video> elements inline.
 52  * @type {number}
 53  * @private
 54  */
 55 createjs.Config.canPlayInline_ = -1;
 56 
 57 /**
 58  * Deletes all files in the cache.
 59  * @const
 60  */
 61 createjs.Config.clearCache = function() {
 62   createjs.Loader.resetCache();
 63 };
 64 
 65 /**
 66  * Returns the version number of the loader cache.
 67  * @return {number}
 68  * @const
 69  */
 70 createjs.Config.getCacheVersion = function() {
 71   /// <returns type="number"/>
 72   if (!createjs.USE_CACHE) {
 73     return 1;
 74   }
 75   return createjs.Config.cacheVersion_;
 76 };
 77 
 78 /**
 79  * Sets the version number of the loader cache.
 80  * @param {number} version
 81  * @const
 82  */
 83 createjs.Config.setCacheVersion = function(version) {
 84   /// <param type="number" name="version"/>
 85   if (createjs.USE_CACHE) {
 86     createjs.Config.cacheVersion_ = version;
 87   }
 88 };
 89 
 90 /**
 91  * Returns whether to use workaround code for Android browsers.
 92  * @param {string} context
 93  * @return {number}
 94  * @const
 95  */
 96 createjs.Config.useAndroidWorkarounds = function(context) {
 97   /// <param type="string" name="context"/>
 98   /// <returns type="number"/>
 99   return createjs.Config.useAndroidWorkarounds_[context] || 0;
100 };
101 
102 /**
103  * Sets whether to use workaround code for Android browsers.
104  * @param {string} context
105  * @param {number} value
106  * @const
107  */
108 createjs.Config.setUseAndroidWorkarounds = function(context, value) {
109   /// <param type="string" name="context"/>
110   /// <param type="number" name="value"/>
111   createjs.Config.useAndroidWorkarounds_[context] = createjs.parseInt(value);
112 };
113 
114 /**
115  * Returns whether the createjs.Sound class should use the FrameAudioPlayer
116  * class instead of the BufferAudioPlayer class.
117  * @return {boolean}
118  * @const
119  */
120 createjs.Config.useFrame = function() {
121   /// <returns type="boolean"/>
122   if (!createjs.USE_FRAME) {
123     return false;
124   }
125   // Android browsers (on Android 4.3 or earlier) cannot send ArrayBuffer
126   // objects with the postMessage() method and it is impossible to use the
127   // FrameAudioPlayer class on them.
128   return !createjs.UserAgent.isAndroidBrowser();
129 };
130 
131 /**
132  * Returns whether the host browser can play <video> elements inline.
133  * @return {number}
134  * @const
135  */
136 createjs.Config.canPlayInline = function() {
137   /// <returns type="number"/>
138   if (createjs.Config.canPlayInline_ < 0) {
139     // Mobile Safari on iOS 9 or earlier cannot play <video> elements inline.
140     // (This "Mobile Safari" does NOT include web apps.) Use the media query
141     // instead of a version check as written in the WebKit blog
142     //   <http://webkit.org/blog/6784/new-video-policies-for-ios/>.
143     if (!createjs.UserAgent.isIPhone() ||
144         navigator['standalone'] ||
145         createjs.global.matchMedia('(-webkit-video-playback-inline)').matches) {
146       createjs.Config.canPlayInline_ = 1;
147     } else {
148       createjs.Config.canPlayInline_ = 0;
149     }
150   }
151   return createjs.Config.canPlayInline_;
152 };
153 
154 /**
155  * A table of exported functions.
156  * @type {Object}
157  * @const
158  */
159 createjs.Config.exports = createjs.exportStatic('createjs.Config', {
160   'clearCache': createjs.Config.clearCache,
161   'setCacheVersion': createjs.Config.setCacheVersion,
162   'setUseAndroidWorkarounds': createjs.Config.setUseAndroidWorkarounds
163 });
164