diff options
author | Armen Kesablyan | 2012-05-17 14:01:38 -0700 |
---|---|---|
committer | Armen Kesablyan | 2012-05-17 14:01:38 -0700 |
commit | 6c8f3525b839e82cf43df43700a0160ee2c5458f (patch) | |
tree | 3fb801fa54b759c5568d75bb467e02652ce77c3e /node_modules/montage/core/event/binding.js | |
parent | e8ae5db7ce7023b638375cbc27a3f7b7a2f77b23 (diff) | |
parent | 342c97ac9b727b22a7b0bfefca4d2a168bc3055b (diff) | |
download | ninja-6c8f3525b839e82cf43df43700a0160ee2c5458f.tar.gz |
Merge branch 'refs/heads/dom-architecture' into binding
Conflicts:
css/ninja.css
scss/imports/scss/_toolbar.scss
Signed-off-by: Armen Kesablyan <armen@motorola.com>
Diffstat (limited to 'node_modules/montage/core/event/binding.js')
-rwxr-xr-x | node_modules/montage/core/event/binding.js | 953 |
1 files changed, 49 insertions, 904 deletions
diff --git a/node_modules/montage/core/event/binding.js b/node_modules/montage/core/event/binding.js index 709a5d85..2e226372 100755 --- a/node_modules/montage/core/event/binding.js +++ b/node_modules/montage/core/event/binding.js | |||
@@ -14,439 +14,20 @@ | |||
14 | */ | 14 | */ |
15 | 15 | ||
16 | var Montage = require("montage").Montage, | 16 | var Montage = require("montage").Montage, |
17 | ChangeEventConstructor = require("core/event/mutable-event")._Change, | 17 | ChangeNotification = require("core/change-notification").ChangeNotification, |
18 | ChangeTypes = require("core/event/mutable-event").ChangeTypes, | ||
19 | Serializer = require("core/serializer").Serializer, | 18 | Serializer = require("core/serializer").Serializer, |
20 | Deserializer = require("core/deserializer").Deserializer, | 19 | Deserializer = require("core/deserializer").Deserializer, |
21 | logger = require("core/logger").logger("binding"); | 20 | logger = require("core/logger").logger("binding"), |
22 | defaultEventManager = require("core/event/event-manager").defaultEventManager, | 21 | defaultEventManager = require("core/event/event-manager").defaultEventManager, |
23 | AT_TARGET = 2, | 22 | AT_TARGET = 2, |
24 | UNDERSCORE = "_"; | 23 | UNDERSCORE = "_"; |
25 | 24 | ||
26 | |||
27 | /** | ||
28 | @member external:Array#dispatchChangeEvent | ||
29 | */ | ||
30 | Object.defineProperty(Array.prototype, "dispatchChangeEvent", {value: false, enumerable: false, writable: true}); | ||
31 | |||
32 | /** | ||
33 | @member external:Array#dispatchChangeAtIndexEvent | ||
34 | */ | ||
35 | Object.defineProperty(Array.prototype, "dispatchChangeAtIndexEvent", {value: false, enumerable: false, writable: true}); | ||
36 | |||
37 | /** | ||
38 | @member external:Array#dispatchChangeAtLengthEvent | ||
39 | */ | ||
40 | Object.defineProperty(Array.prototype, "dispatchChangeAtLengthEvent", {value: false, enumerable: false, writable: true}); | ||
41 | |||
42 | /** | 25 | /** |
43 | @class module:montage/core/event/binding.ChangeEventDispatchingArray | 26 | @class module:montage/core/event/binding.ChangeEventDispatchingArray |
44 | */ | 27 | */ |
45 | var ChangeEventDispatchingArray = exports.ChangeEventDispatchingArray = []; | 28 | var ChangeEventDispatchingArray = exports.ChangeEventDispatchingArray = []; |
46 | 29 | ||
47 | /** | 30 | /** |
48 | @function external:Array#addContentEventListener | ||
49 | @param {string} type Event type | ||
50 | @param {object|function} listener Event listener. | ||
51 | @param {boolean} useCapture Specifies whether to listen for the event during the capture phase. | ||
52 | */ | ||
53 | Object.defineProperty(Array.prototype, "addContentEventListener", { | ||
54 | value: function(type, listener, useCapture) { | ||
55 | }, | ||
56 | enumerable: false, | ||
57 | configurable: true | ||
58 | }); | ||
59 | |||
60 | |||
61 | Object.defineProperty(ChangeEventDispatchingArray, "_splice", { | ||
62 | value: Array.prototype.splice, | ||
63 | enumerable: false, | ||
64 | configurable: true | ||
65 | }); | ||
66 | |||
67 | /** | ||
68 | @function module:montage/core/event/binding.ChangeEventDispatchingArray#splice | ||
69 | @param {string} type Event type | ||
70 | @param {object|function} listener Event listener. | ||
71 | @param {boolean} useCapture Specifies whether to listen for the event during the capture phase. | ||
72 | */ | ||
73 | Object.defineProperty(ChangeEventDispatchingArray, "splice", { | ||
74 | value: function(index, howMany/*[, element1[, ...[, elementN]]]*/) { | ||
75 | |||
76 | var originalCount = this.length, | ||
77 | addedCount = arguments.length - 2, /* elements to add less the index and howMany parameters*/ | ||
78 | removedCount, | ||
79 | netChange, | ||
80 | i, changeType, changeEvent, affectedIndexCount, startIndex, changeIndex, | ||
81 | removedMembers, | ||
82 | addedMembers = []; | ||
83 | |||
84 | if (addedCount > 0) { | ||
85 | addedMembers = this.slice.call(arguments, 2); | ||
86 | } | ||
87 | |||
88 | // Index may be positive (from the front) or negative (from the back) figure out the positive one | ||
89 | // now in anticipation of needing it when dispatching events | ||
90 | startIndex = index >= 0 ? index : this.length + index; | ||
91 | removedMembers = this._splice.apply(this, arguments); | ||
92 | removedCount = removedMembers.length; | ||
93 | |||
94 | netChange = addedCount - removedCount; | ||
95 | |||
96 | // Find the most accurate propertyChange type for this splice, | ||
97 | // For the most part it's considered a modification unless the length of the array was modified | ||
98 | // if only to not bother notifying listeners for changes of the length of this array | ||
99 | changeType = ChangeTypes.MODIFICATION; | ||
100 | |||
101 | if (netChange > 0) { | ||
102 | changeType = ChangeTypes.ADDITION; | ||
103 | } else if (netChange < 0) { | ||
104 | changeType = ChangeTypes.REMOVAL; | ||
105 | } | ||
106 | |||
107 | if (this.dispatchChangeEvent) { | ||
108 | changeEvent = new ChangeEventConstructor(); | ||
109 | changeEvent.minus = removedMembers; | ||
110 | changeEvent.plus = addedMembers; | ||
111 | changeEvent.changeIndex = index; | ||
112 | changeEvent.propertyChange = changeType; | ||
113 | this.dispatchEvent(changeEvent); | ||
114 | } | ||
115 | |||
116 | if (this.dispatchChangeAtIndexEvent) { | ||
117 | |||
118 | if (typeof howMany === "undefined") { | ||
119 | // no howMany argument given: remove all elements after index? | ||
120 | // TODO this may only be in some implementations | ||
121 | affectedIndexCount = originalCount + addedCount; | ||
122 | } else if (0 === netChange) { | ||
123 | // No net change; affects only how many expected | ||
124 | affectedIndexCount = addedCount; | ||
125 | } else if (netChange > 0) { | ||
126 | // Net gain; affects from start to end of original array + net gain | ||
127 | affectedIndexCount = (originalCount - startIndex) + (netChange); | ||
128 | } else { | ||
129 | // Net loss; affects from start to end of original array | ||
130 | affectedIndexCount = originalCount - startIndex; | ||
131 | } | ||
132 | |||
133 | for (i = 0; i < affectedIndexCount; i++) { | ||
134 | changeIndex = startIndex + i; | ||
135 | |||
136 | changeEvent = new ChangeEventConstructor(); | ||
137 | changeEvent.type = "change@" + changeIndex; | ||
138 | |||
139 | // old value at changeIndex was either: | ||
140 | // - removed outright, or replaced | ||
141 | // - moved somewhere in the array due to a gain or loss | ||
142 | changeEvent.minus = (i < removedCount) ? removedMembers[i] : this[changeIndex + netChange]; | ||
143 | |||
144 | changeEvent.plus = this[changeIndex]; | ||
145 | changeEvent.changeIndex = changeIndex; | ||
146 | changeEvent.propertyChange = changeType; | ||
147 | this.dispatchEvent(changeEvent); | ||
148 | } | ||
149 | } | ||
150 | |||
151 | return removedMembers; | ||
152 | }, | ||
153 | enumerable: false, | ||
154 | configurable: true | ||
155 | }); | ||
156 | //Removes the first element from an array and returns that element. This method changes the length of the array. | ||
157 | Object.defineProperty(ChangeEventDispatchingArray, "_shift", { | ||
158 | value: Array.prototype.shift, | ||
159 | enumerable: false, | ||
160 | configurable: true | ||
161 | }); | ||
162 | |||
163 | /** | ||
164 | @function module:montage/core/event/binding.ChangeEventDispatchingArray#shift | ||
165 | */ | ||
166 | Object.defineProperty(ChangeEventDispatchingArray, "shift", { | ||
167 | value: function() { | ||
168 | |||
169 | if (0 === this.length) { | ||
170 | return; | ||
171 | } | ||
172 | |||
173 | var result, i, countI, changeEvent; | ||
174 | |||
175 | result = this._shift.call(this); | ||
176 | |||
177 | if (this.dispatchChangeEvent) { | ||
178 | changeEvent = new ChangeEventConstructor(); | ||
179 | changeEvent.minus = result; | ||
180 | changeEvent.plus = this[0]; | ||
181 | changeEvent.changeIndex = 0; | ||
182 | changeEvent.propertyChange = ChangeTypes.REMOVAL; | ||
183 | this.dispatchEvent(changeEvent); | ||
184 | } | ||
185 | |||
186 | if (this.dispatchChangeAtIndexEvent) { | ||
187 | // A single item was just removed form the front; notify all index listeners | ||
188 | // (including listeners for the index that is now undefined at the end) | ||
189 | for (i = 0,countI = this.length + 1; i < countI; i++) { | ||
190 | changeEvent = new ChangeEventConstructor(); | ||
191 | changeEvent.type = "change@" + i; | ||
192 | changeEvent.minus = i === 0 ? result : this[i - 1]; | ||
193 | changeEvent.plus = this[i]; | ||
194 | changeEvent.changeIndex = i; | ||
195 | changeEvent.propertyChange = ChangeTypes.REMOVAL; | ||
196 | this.dispatchEvent(changeEvent); | ||
197 | } | ||
198 | } | ||
199 | return result; | ||
200 | }, | ||
201 | enumerable: false, | ||
202 | configurable: true | ||
203 | }); | ||
204 | |||
205 | //Adds one or more elements to the beginning of an array and returns the new length of the array. | ||
206 | Object.defineProperty(ChangeEventDispatchingArray, "_unshift", { | ||
207 | value: Array.prototype.unshift, | ||
208 | enumerable: false, | ||
209 | configurable: true | ||
210 | }); | ||
211 | |||
212 | /** | ||
213 | @function module:montage/core/event/binding.ChangeEventDispatchingArray#unshift | ||
214 | */ | ||
215 | Object.defineProperty(ChangeEventDispatchingArray, "unshift", { | ||
216 | value: function() { | ||
217 | |||
218 | var addedCount = arguments.length, i, countI, changeEvent; | ||
219 | |||
220 | countI = this._unshift.apply(this, arguments); | ||
221 | |||
222 |