Skip to content

Commit b2650b0

Browse files
committed
Merge branch 'Deprecated'
2 parents 4cd4bf5 + 43c85f8 commit b2650b0

File tree

5 files changed

+191
-40
lines changed

5 files changed

+191
-40
lines changed

build/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
"../src/createjs/utils/extend.js",
66
"../src/createjs/utils/promote.js",
7+
"../src/createjs/utils/deprecate.js",
78
"../src/createjs/utils/indexOf.js",
89
"../src/createjs/utils/proxy.js",
910
"../src/createjs/utils/BrowserDetect.js",

src/createjs/utils/deprecate.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
console && (console.warn || console.log)("Deprecated property or method '"+name+"'. See docs for info.");
67+
return fallbackMethod && fallbackMethod.apply(this, arguments);
68+
}
69+
};

src/preloadjs/loaders/AbstractLoader.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,30 @@ this.createjs = this.createjs || {};
194194
var p = createjs.extend(AbstractLoader, createjs.EventDispatcher);
195195
var s = AbstractLoader;
196196

197+
// Remove these @deprecated properties after 1.0
198+
try {
199+
Object.defineProperties(s, {
200+
POST: { get: createjs.deprecate(function() { return createjs.Methods.POST; }, "AbstractLoader.POST") },
201+
GET: { get: createjs.deprecate(function() { return createjs.Methods.GET; }, "AbstractLoader.GET") },
202+
203+
BINARY: { get: createjs.deprecate(function() { return createjs.Types.BINARY; }, "AbstractLoader.BINARY") },
204+
CSS: { get: createjs.deprecate(function() { return createjs.Types.CSS; }, "AbstractLoader.CSS") },
205+
FONT: { get: createjs.deprecate(function() { return createjs.Types.FONT; }, "AbstractLoader.FONT") },
206+
FONTCSS: { get: createjs.deprecate(function() { return createjs.Types.FONTCSS; }, "AbstractLoader.FONTCSS") },
207+
IMAGE: { get: createjs.deprecate(function() { return createjs.Types.IMAGE; }, "AbstractLoader.IMAGE") },
208+
JAVASCRIPT: { get: createjs.deprecate(function() { return createjs.Types.JAVASCRIPT; }, "AbstractLoader.JAVASCRIPT") },
209+
JSON: { get: createjs.deprecate(function() { return createjs.Types.JSON; }, "AbstractLoader.JSON") },
210+
JSONP: { get: createjs.deprecate(function() { return createjs.Types.JSONP; }, "AbstractLoader.JSONP") },
211+
MANIFEST: { get: createjs.deprecate(function() { return createjs.Types.MANIFEST; }, "AbstractLoader.MANIFEST") },
212+
SOUND: { get: createjs.deprecate(function() { return createjs.Types.SOUND; }, "AbstractLoader.SOUND") },
213+
VIDEO: { get: createjs.deprecate(function() { return createjs.Types.VIDEO; }, "AbstractLoader.VIDEO") },
214+
SPRITESHEET: { get: createjs.deprecate(function() { return createjs.Types.SPRITESHEET; }, "AbstractLoader.SPRITESHEET") },
215+
SVG: { get: createjs.deprecate(function() { return createjs.Types.SVG; }, "AbstractLoader.SVG") },
216+
TEXT: { get: createjs.deprecate(function() { return createjs.Types.TEXT; }, "AbstractLoader.TEXT") },
217+
XML: { get: createjs.deprecate(function() { return createjs.Types.XML; }, "AbstractLoader.XML") }
218+
});
219+
} catch (e) {}
220+
197221
// Events
198222
/**
199223
* The {{#crossLink "ProgressEvent"}}{{/crossLink}} that is fired when the overall progress changes. Prior to

src/soundjs/Sound.js

Lines changed: 91 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -442,36 +442,63 @@ this.createjs = this.createjs || {};
442442

443443

444444
// class getter / setter properties
445+
445446
/**
446447
* Set the master volume of Sound. The master volume is multiplied against each sound's individual volume. For
447448
* example, if master volume is 0.5 and a sound's volume is 0.5, the resulting volume is 0.25. To set individual
448-
* sound volume, use AbstractSoundInstance {{#crossLink "AbstractSoundInstance/volume:property"}}{{/crossLink}} instead.
449+
* sound volume, use AbstractSoundInstance {{#crossLink "AbstractSoundInstance/volume:property"}}{{/crossLink}}
450+
* instead.
449451
*
450452
* <h4>Example</h4>
451453
*
452454
* createjs.Sound.volume = 0.5;
453455
*
454-
*
455456
* @property volume
456457
* @type {Number}
457458
* @default 1
458459
* @since 0.6.1
459460
*/
461+
462+
/**
463+
* The internal volume level. Use {{#crossLink "Sound/volume:property"}}{{/crossLink}} to adjust the master volume.
464+
* @property _masterVolume
465+
* @type {number}
466+
* @default 1
467+
* @private
468+
*/
460469
s._masterVolume = 1;
461-
Object.defineProperty(s, "volume", {
462-
get: function () {return this._masterVolume;},
463-
set: function (value) {
464-
if (Number(value) == null) {return false;}
465-
value = Math.max(0, Math.min(1, value));
466-
s._masterVolume = value;
467-
if (!this.activePlugin || !this.activePlugin.setVolume || !this.activePlugin.setVolume(value)) {
468-
var instances = this._instances;
469-
for (var i = 0, l = instances.length; i < l; i++) {
470-
instances[i].setMasterVolume(value);
471-
}
472-
}
470+
471+
/**
472+
* Use the {{#crossLink "Sound/volume:property"}}{{/crossLink}} property instead.
473+
* @method _getMasterVolume
474+
* @private
475+
* @static
476+
* @return {Number}
477+
**/
478+
s._getMasterVolume = function() {
479+
return this._masterVolume;
480+
};
481+
// Sound.getMasterVolume is @deprecated. Remove for 1.1+
482+
s.getVolume = createjs.deprecate(s._getMasterVolume, "Sound.getVolume");
483+
/**
484+
* Use the {{#crossLink "Sound/volume:property"}}{{/crossLink}} property instead.
485+
* @method _setMasterVolume
486+
* @static
487+
* @private
488+
**/
489+
s._setMasterVolume = function(value) {
490+
if (Number(value) == null) { return; }
491+
value = Math.max(0, Math.min(1, value));
492+
s._masterVolume = value;
493+
if (!this.activePlugin || !this.activePlugin.setVolume || !this.activePlugin.setVolume(value)) {
494+
var instances = this._instances;
495+
for (var i = 0, l = instances.length; i < l; i++) {
496+
instances[i].setMasterVolume(value);
473497
}
474-
});
498+
}
499+
};
500+
// Sound.stMasterVolume is @deprecated. Remove for 1.1+
501+
s.setVolume = createjs.deprecate(s._setMasterVolume, "Sound.setVolume");
475502

476503
/**
477504
* Mute/Unmute all audio. Note that muted audio still plays at 0 volume. This global mute value is maintained
@@ -489,22 +516,39 @@ this.createjs = this.createjs || {};
489516
* @since 0.6.1
490517
*/
491518
s._masterMute = false;
492-
// OJR references to the methods were not working, so the code had to be duplicated here
493-
Object.defineProperty(s, "muted", {
494-
get: function () {return this._masterMute;},
495-
set: function (value) {
496-
if (value == null) {return false;}
497-
498-
this._masterMute = value;
499-
if (!this.activePlugin || !this.activePlugin.setMute || !this.activePlugin.setMute(value)) {
500-
var instances = this._instances;
501-
for (var i = 0, l = instances.length; i < l; i++) {
502-
instances[i].setMasterMute(value);
503-
}
504-
}
505-
return true;
519+
520+
/**
521+
* Use the {{#crossLink "Sound/muted:property"}}{{/crossLink}} property instead.
522+
* @method _getMute
523+
* @returns {Boolean}
524+
* @static
525+
* @private
526+
*/
527+
s._getMute = function () {
528+
return this._masterMute;
529+
};
530+
// Sound.getMute is @deprecated. Remove for 1.1+
531+
s.getMute = createjs.deprecate(s._getMute, "Sound.getMute");
532+
533+
/**
534+
* Use the {{#crossLink "Sound/muted:property"}}{{/crossLink}} property instead.
535+
* @method _setMute
536+
* @param {Boolean} value The muted value
537+
* @static
538+
* @private
539+
*/
540+
s._setMute = function (value) {
541+
if (value == null) { return; }
542+
this._masterMute = value;
543+
if (!this.activePlugin || !this.activePlugin.setMute || !this.activePlugin.setMute(value)) {
544+
var instances = this._instances;
545+
for (var i = 0, l = instances.length; i < l; i++) {
546+
instances[i].setMasterMute(value);
506547
}
507-
});
548+
}
549+
};
550+
// Sound.setMute is @deprecated. Remove for 1.1+
551+
s.setMute = createjs.deprecate(s._setMute, "Sound.setMute");
508552

509553
/**
510554
* Get the active plugins capabilities, which help determine if a plugin can be used in the current environment,
@@ -540,12 +584,23 @@ this.createjs = this.createjs || {};
540584
* @readOnly
541585
* @since 0.6.1
542586
*/
543-
Object.defineProperty(s, "capabilities", {
544-
get: function () {
545-
if (s.activePlugin == null) {return null;}
546-
return s.activePlugin._capabilities;
547-
},
548-
set: function (value) { return false;}
587+
588+
/**
589+
* Use the {{#crossLink "Sound/capabilities:property"}}{{/crossLink}} property instead.
590+
* @returns {null}
591+
* @private
592+
*/
593+
s._getCapabilities = function() {
594+
if (s.activePlugin == null) { return null; }
595+
return s.activePlugin._capabilities;
596+
};
597+
// Sound.getCapabilities is @deprecated. Remove for 1.1+
598+
s.getCapabilities = createjs.deprecate(s._getCapabilities, "Sound.getCapabilities");
599+
600+
Object.defineProperties(s, {
601+
volume: { get: s._getMasterVolume, set: s._setMasterVolume },
602+
muted: { get: s._getMute, set: s._setMute },
603+
capabilities: { get: s._getCapabilities }
549604
});
550605

551606

src/soundjs/data/PlayPropsConfig.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,12 @@ this.createjs = this.createjs || {};
153153
* @static
154154
*/
155155
s.create = function (value) {
156-
if (value == null || value instanceof s || value instanceof Object) {
157-
var ppc = new createjs.PlayPropsConfig();
158-
ppc.set(value);
159-
return ppc;
156+
if (typeof(value) === "string") {
157+
// Handle the old API gracefully.
158+
console && (console.warn || console.log)("Deprecated behaviour. Sound.play takes a configuration object instead of individual arguments. See docs for info.");
159+
return createjs.PlayPropsConfig().set({interrupt:value});
160+
} else if (value == null || value instanceof s || value instanceof Object) {
161+
return new createjs.PlayPropsConfig().set(value);
160162
} else if (value == null) {
161163
throw new Error("PlayProps configuration not recognized.");
162164
}

0 commit comments

Comments
 (0)