diff options
Diffstat (limited to 'node_modules/montage/core/event')
-rwxr-xr-x | node_modules/montage/core/event/action-event-listener.js | 76 | ||||
-rwxr-xr-x | node_modules/montage/core/event/binding.js | 1413 | ||||
-rwxr-xr-x | node_modules/montage/core/event/event-manager.js | 2075 | ||||
-rwxr-xr-x | node_modules/montage/core/event/mutable-event.js | 234 |
4 files changed, 3798 insertions, 0 deletions
diff --git a/node_modules/montage/core/event/action-event-listener.js b/node_modules/montage/core/event/action-event-listener.js new file mode 100755 index 00000000..bbe5baad --- /dev/null +++ b/node_modules/montage/core/event/action-event-listener.js | |||
@@ -0,0 +1,76 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /** | ||
7 | @module montage/core/event/action-event-listener | ||
8 | @requires montage/core/core | ||
9 | */ | ||
10 | var Montage = require("montage").Montage; | ||
11 | |||
12 | /** | ||
13 | @class module:montage/core/event/action-event-listener.ActionEventListener | ||
14 | @extends module:montage/core/core.Montage | ||
15 | */ | ||
16 | var ActionEventListener = exports.ActionEventListener = Montage.create(Montage, /** @lends module:montage/core/event/action-event-listener.ActionEventListener# */ { | ||
17 | |||
18 | /** | ||
19 | The object to handle the event. | ||
20 | @type {Property} | ||
21 | @default {Event handler} null | ||
22 | */ | ||
23 | handler: { | ||
24 | value: null | ||
25 | }, | ||
26 | |||
27 | /** | ||
28 | The action (function) to invoke on the handler object. | ||
29 | @type {Property} | ||
30 | @default {Event handler} null | ||
31 | */ | ||
32 | action: { | ||
33 | value: null | ||
34 | }, | ||
35 | |||
36 | /** | ||
37 | Returns a new ActionEventListener instance with the specified handler and action. | ||
38 | @function | ||
39 | @param {Event} handler The event handler. | ||
40 | @param {Event} action The event handler action. | ||
41 | @returns itself | ||
42 | */ | ||
43 | initWithHandler_action_: { | ||
44 | value: function(handler, action) { | ||
45 | this.handler = handler; | ||
46 | this.action = action; | ||
47 | |||
48 | return this; | ||
49 | } | ||
50 | }, | ||
51 | |||
52 | /** | ||
53 | @private | ||
54 | */ | ||
55 | handleEvent: { | ||
56 | value: function(event) { | ||
57 | if (typeof this.action === "function") { | ||
58 | // TODO call this in what context? | ||
59 | this.action(event); | ||
60 | } else { | ||
61 | this.handler[this.action](event); | ||
62 | } | ||
63 | } | ||
64 | }, | ||
65 | |||
66 | /** | ||
67 | @private | ||
68 | */ | ||
69 | serializeSelf: { | ||
70 | value: function(serializer) { | ||
71 | serializer.setReference("handler", this.handler); | ||
72 | serializer.set("action", this.action); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | }); | ||
diff --git a/node_modules/montage/core/event/binding.js b/node_modules/montage/core/event/binding.js new file mode 100755 index 00000000..0ce154a1 --- /dev/null +++ b/node_modules/montage/core/event/binding.js | |||
@@ -0,0 +1,1413 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | /** | ||
8 | @module montage/core/event/binding | ||
9 | @requires montage/core/core | ||
10 | @requires montage/core/event/mutable-event | ||
11 | @requires montage/core/serializer | ||
12 | @requires montage/core/deserializer | ||
13 | @requires montage/core/event/event-manager | ||
14 | */ | ||
15 | |||
16 | var Montage = require("montage").Montage, | ||
17 | ChangeEventConstructor = require("core/event/mutable-event")._Change, | ||
18 | ChangeTypes = require("core/event/mutable-event").ChangeTypes, | ||
19 | Serializer = require("core/serializer").Serializer, | ||
20 | Deserializer = require("core/deserializer").Deserializer, | ||
21 | defaultEventManager = require("core/event/event-manager").defaultEventManager, | ||
22 | AT_TARGET = 2; | ||
23 | |||
24 | /** | ||
25 | @member external:Array#dispatchChangeEvent | ||
26 | */ | ||
27 | Object.defineProperty(Array.prototype, "dispatchChangeEvent", {value: false, enumerable: false, writable: true}); | ||
28 | |||
29 | /** | ||
30 | @member external:Array#dispatchChangeAtIndexEvent | ||
31 | */ | ||
32 | Object.defineProperty(Array.prototype, "dispatchChangeAtIndexEvent", {value: false, enumerable: false, writable: true}); | ||
33 | |||
34 | /** | ||
35 | @member external:Array#dispatchChangeAtLengthEvent | ||
36 | */ | ||
37 | Object.defineProperty(Array.prototype, "dispatchChangeAtLengthEvent", {value: false, enumerable: false, writable: true}); | ||
38 | |||
39 | /** | ||
40 | @class module:montage/core/event/binding.ChangeEventDispatchingArray | ||
41 | */ | ||
42 | var ChangeEventDispatchingArray = exports.ChangeEventDispatchingArray = []; | ||
43 | |||
44 | /** | ||
45 | @function external:Array#addContentEventListener | ||
46 | @param {string} type Event type | ||
47 | @param {object|function} listener Event listener. | ||
48 | @param {boolean} useCapture Specifies whether to listen for the event during the capture phase. | ||
49 | */ | ||
50 | Object.defineProperty(Array.prototype, "addContentEventListener", { | ||
51 | value: function(type, listener, useCapture) { | ||
52 | }, | ||
53 | enumerable: false, | ||
54 | configurable: true | ||
55 | }); | ||
56 | |||
57 | |||
58 | Object.defineProperty(ChangeEventDispatchingArray, "_splice", { | ||
59 | value: Array.prototype.splice, | ||
60 | enumerable: false, | ||
61 | configurable: true | ||
62 | }); | ||
63 | |||
64 | /** | ||
65 | @function module:montage/core/event/binding.ChangeEventDispatchingArray#splice | ||
66 | @param {string} type Event type | ||
67 | @param {object|function} listener Event listener. | ||
68 | @param {boolean} useCapture Specifies whether to listen for the event during the capture phase. | ||
69 | */ | ||
70 | Object.defineProperty(ChangeEventDispatchingArray, "splice", { | ||
71 | value: function(index, howMany/*[, element1[, ...[, elementN]]]*/) { | ||
72 | |||
73 | var originalCount = this.length, | ||
74 | addedCount = arguments.length - 2, /* elements to add less the index and howMany parameters*/ | ||
75 | removedCount, | ||
76 | netChange, | ||
77 | i, changeType, changeEvent, affectedIndexCount, startIndex, changeIndex, | ||
78 | removedMembers, | ||
79 | addedMembers = []; | ||
80 | |||
81 | if (addedCount > 0) { | ||
82 | addedMembers = this.slice.call(arguments, 2); | ||
83 | } | ||
84 | |||
85 | // Index may be positive (from the front) or negative (from the back) figure out the positive one | ||
86 | // now in anticipation of needing it when dispatching events | ||
87 | startIndex = index >= 0 ? index : this.length + index; | ||
88 | removedMembers = this._splice.apply(this, arguments); | ||
89 | removedCount = removedMembers.length; | ||
90 | |||
91 | // I stopped caring about whether or not this splice could be considered an ADDITION or REMOVAL | ||
92 | // all splices result in a modification now; we could change this if we want to | ||
93 | changeType = ChangeTypes.MODIFICATION; | ||
94 | |||
95 | if (this.dispatchChangeEvent) { | ||
96 | changeEvent = new ChangeEventConstructor(); | ||
97 | changeEvent.minus = removedMembers; | ||
98 | changeEvent.plus = addedMembers; | ||
99 | changeEvent.changeIndex = index; | ||
100 | changeEvent.propertyChange = changeType; | ||
101 | this.dispatchEvent(changeEvent); | ||
102 | } | ||
103 | |||
104 | if (this.dispatchChangeAtIndexEvent) { | ||
105 | |||
106 | netChange = addedCount - removedCount; | ||
107 | |||
108 | if (typeof howMany === "undefined") { | ||
109 | // no howMany argument given: remove all elements after index? | ||
110 | // TODO this may only be in some implementations | ||
111 | affectedIndexCount = originalCount + addedCount; | ||
112 | } else if (0 === netChange) { | ||
113 | // No net change; affects only how many expected | ||
114 | affectedIndexCount = addedCount; | ||
115 | } else if (netChange > 0) { | ||
116 | // Net gain; affects from start to end of original array + net gain | ||
117 | affectedIndexCount = (originalCount - startIndex) + (netChange); | ||
118 | } else { | ||
119 | // Net loss; affects from start to end of original array | ||
120 | affectedIndexCount = originalCount - startIndex; | ||
121 | } | ||
122 | |||
123 | for (i = 0; i < affectedIndexCount; i++) { | ||
124 | changeIndex = startIndex + i; | ||
125 | |||
126 | changeEvent = new ChangeEventConstructor(); | ||
127 | changeEvent.type = "change@" + changeIndex; | ||
128 | |||
129 | // old value at changeIndex was either: | ||
130 | // - removed outright, or replaced | ||
131 | // - moved somewhere in the array due to a gain or loss | ||
132 | changeEvent.minus = (i < removedCount) ? removedMembers[i] : this[changeIndex + netChange]; | ||
133 | |||
134 | changeEvent.plus = this[changeIndex]; | ||
135 | changeEvent.changeIndex = changeIndex; | ||
136 | changeEvent.propertyChange = changeType; | ||
137 | this.dispatchEvent(changeEvent); | ||
138 | } | ||