Skip to content

Commit f9d24bc

Browse files
author
Lanny McNie
committed
Updated classes from the latest EaselJS
1 parent 561cbe9 commit f9d24bc

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

src/createjs/events/Event.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,12 @@ this.createjs = this.createjs||{};
183183
* @deprecated
184184
*/
185185
// p.initialize = function() {}; // searchable for devs wondering where it is.
186-
187186

188187
// public methods:
189188
/**
190-
* Sets {{#crossLink "Event/defaultPrevented"}}{{/crossLink}} to true.
191-
* Mirrors the DOM event standard.
189+
* Sets {{#crossLink "Event/defaultPrevented"}}{{/crossLink}} to true if the event is cancelable.
190+
* Mirrors the DOM level 2 event standard. In general, cancelable events that have `preventDefault()` called will
191+
* cancel the default behaviour associated with the event.
192192
* @method preventDefault
193193
**/
194194
p.preventDefault = function() {

src/createjs/events/EventDispatcher.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ this.createjs = this.createjs||{};
8181
* console.log(instance == this); // true, "on" uses dispatcher scope by default.
8282
* });
8383
*
84-
* If you want to use addEventListener instead, you may want to use function.bind() or a similar proxy to manage scope.
84+
* If you want to use addEventListener instead, you may want to use function.bind() or a similar proxy to manage
85+
* scope.
86+
*
87+
* <b>Browser support</b>
88+
* The event model in CreateJS can be used separately from the suite in any project, however the inheritance model
89+
* requires modern browsers (IE9+).
8590
*
8691
*
8792
* @class EventDispatcher
@@ -184,7 +189,11 @@ this.createjs = this.createjs||{};
184189
* only run once, associate arbitrary data with the listener, and remove the listener.
185190
*
186191
* This method works by creating an anonymous wrapper function and subscribing it with addEventListener.
187-
* The created anonymous function is returned for use with .removeEventListener (or .off).
192+
* The wrapper function is returned for use with `removeEventListener` (or `off`).
193+
*
194+
* <b>IMPORTANT:</b> To remove a listener added with `on`, you must pass in the returned wrapper function as the listener, or use
195+
* {{#crossLink "Event/remove"}}{{/crossLink}}. Likewise, each time you call `on` a NEW wrapper function is subscribed, so multiple calls
196+
* to `on` with the same params will create multiple listeners.
188197
*
189198
* <h4>Example</h4>
190199
*
@@ -254,6 +263,9 @@ this.createjs = this.createjs||{};
254263
/**
255264
* A shortcut to the removeEventListener method, with the same parameters and return value. This is a companion to the
256265
* .on method.
266+
*
267+
* <b>IMPORTANT:</b> To remove a listener added with `on`, you must pass in the returned wrapper function as the listener. See
268+
* {{#crossLink "EventDispatcher/on"}}{{/crossLink}} for an example.
257269
*
258270
* @method off
259271
* @param {String} type The string type of the event.
@@ -299,19 +311,24 @@ this.createjs = this.createjs||{};
299311
* @method dispatchEvent
300312
* @param {Object | String | Event} eventObj An object with a "type" property, or a string type.
301313
* While a generic object will work, it is recommended to use a CreateJS Event instance. If a string is used,
302-
* dispatchEvent will construct an Event instance with the specified type.
303-
* @return {Boolean} Returns the value of eventObj.defaultPrevented.
314+
* dispatchEvent will construct an Event instance if necessary with the specified type. This latter approach can
315+
* be used to avoid event object instantiation for non-bubbling events that may not have any listeners.
316+
* @param {Boolean} [bubbles] Specifies the `bubbles` value when a string was passed to eventObj.
317+
* @param {Boolean} [cancelable] Specifies the `cancelable` value when a string was passed to eventObj.
318+
* @return {Boolean} Returns false if `preventDefault()` was called on a cancelable event, true otherwise.
304319
**/
305-
p.dispatchEvent = function(eventObj) {
320+
p.dispatchEvent = function(eventObj, bubbles, cancelable) {
306321
if (typeof eventObj == "string") {
307-
// won't bubble, so skip everything if there's no listeners:
322+
// skip everything if there's no listeners and it doesn't bubble:
308323
var listeners = this._listeners;
309-
if (!listeners || !listeners[eventObj]) { return false; }
310-
eventObj = new createjs.Event(eventObj);
324+
if (!bubbles && (!listeners || !listeners[eventObj])) { return true; }
325+
eventObj = new createjs.Event(eventObj, bubbles, cancelable);
311326
} else if (eventObj.target && eventObj.clone) {
312327
// redispatching an active event object, so clone it:
313328
eventObj = eventObj.clone();
314329
}
330+
331+
// TODO: it would be nice to eliminate this. Maybe in favour of evtObj instanceof Event? Or !!evtObj.createEvent
315332
try { eventObj.target = this; } catch (e) {} // try/catch allows redispatching of native events
316333

317334
if (!eventObj.bubbles || !this.parent) {
@@ -330,7 +347,7 @@ this.createjs = this.createjs||{};
330347
list[i]._dispatchEvent(eventObj, 3);
331348
}
332349
}
333-
return eventObj.defaultPrevented;
350+
return !eventObj.defaultPrevented;
334351
};
335352

336353
/**

src/createjs/utils/extend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ this.createjs = this.createjs||{};
4444
*
4545
* function MySubClass() {}
4646
* createjs.extend(MySubClass, MySuperClass);
47-
* ClassB.prototype.doSomething = function() { }
47+
* MySubClass.prototype.doSomething = function() { }
4848
*
4949
* var foo = new MySubClass();
5050
* console.log(foo instanceof MySuperClass); // true

0 commit comments

Comments
 (0)