diff options
Diffstat (limited to 'node_modules/montage-user/core/core.js')
-rwxr-xr-x | node_modules/montage-user/core/core.js | 1130 |
1 files changed, 1130 insertions, 0 deletions
diff --git a/node_modules/montage-user/core/core.js b/node_modules/montage-user/core/core.js new file mode 100755 index 00000000..8c1f4249 --- /dev/null +++ b/node_modules/montage-user/core/core.js | |||
@@ -0,0 +1,1130 @@ | |||
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/core | ||
8 | @requires montage/core/shim | ||
9 | @requires montage/core/uuid | ||
10 | @requires montage/core/event/binding | ||
11 | @requires montage/core/event/event-manager | ||
12 | */ | ||
13 | require("core/shim"); | ||
14 | |||
15 | /** | ||
16 | @external Object | ||
17 | */ | ||
18 | |||
19 | /* Ecmascript 5 Methods. Should be external as WebKit doesn't need it, and loaded automatically */ | ||
20 | if (!Object.create) { | ||
21 | Object._creator = function _ObjectCreator() { | ||
22 | this.__proto__ = _ObjectCreator.prototype; | ||
23 | }; | ||
24 | Object.create = function(o, properties) { | ||
25 | this._creator.prototype = o || Object.prototype; | ||
26 | //Still needs to add properties.... | ||
27 | return new this._creator; | ||
28 | }; | ||
29 | |||
30 | Object.getPrototypeOf = function(o) { | ||
31 | return o.__proto__; | ||
32 | }; | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | @class module:montage/core/core.Montage | ||
37 | */ | ||
38 | var M = exports.Montage = Object.create(Object.prototype); | ||
39 | |||
40 | /** | ||
41 | Creates a new Montage object. | ||
42 | @function module:montage/core/core.Montage.create | ||
43 | @param {Object} aPrototype The prototype object to create the new object from. If not specified, the prototype is the Montage prototype. | ||
44 | @param {Object} [propertyDescriptor] An object that contains the initial properties and values for the new object. | ||
45 | @returns The new object | ||
46 | @example | ||
47 | <caption>Creating a "empty" Montage object, using Montage as the prototype</caption> | ||
48 | var alpha = Montage.create(); | ||
49 | @example | ||
50 | <caption>Creating a new Montage component with a property descriptor object.</caption> | ||
51 | var Button = Montage.create(Component , { | ||
52 | state: { | ||
53 | value: null | ||
54 | } | ||
55 | }); | ||
56 | */ | ||
57 | Object.defineProperty(M, "create", { | ||
58 | configurable: true, | ||
59 | value: function(aPrototype, propertyDescriptor) { | ||
60 | if (!propertyDescriptor) { | ||
61 | |||
62 | var newObject = Object.create(typeof aPrototype === "undefined" ? this : aPrototype); | ||
63 | |||
64 | if (typeof newObject.didCreate === "function") { | ||
65 | newObject.didCreate(); | ||
66 | } | ||
67 | |||
68 | if (newObject._dependenciesForProperty) { | ||
69 | newObject._dependencyListeners = {}; | ||
70 | } | ||
71 | |||
72 | return newObject; | ||
73 | } else { | ||
74 | var result = Object.create(aPrototype); | ||
75 | M.defineProperties(result, propertyDescriptor); | ||
76 | return result; | ||
77 | } | ||
78 | } | ||
79 | }); | ||
80 | |||
81 | var extendedPropertyAttributes = ["serializable", "modify"]; | ||
82 | |||
83 | // Extended property attributes, the property name format is "_" + attributeName + "AttributeProperties" | ||
84 | /** | ||
85 | @member external:Object#extendedPropertyAttributes | ||
86 | */ | ||
87 | extendedPropertyAttributes.forEach(function(name) { | ||
88 | Object.defineProperty(Object.prototype, "_" + name + "AttributeProperties", { | ||
89 | enumerable: false, | ||
90 | configurable: false, | ||
91 | writable: false, | ||
92 | value: {} | ||
93 | }); | ||
94 | }); | ||
95 | |||
96 | /** | ||
97 | Defines a property on a Montage object. | ||
98 | @function module:montage/core/core.Montage.defineProperty | ||
99 | @param {Object} obj The object on which to define the property. | ||
100 | @param {String} prop The name of the property to define, or modify. | ||
101 | @param {Object} descriptor A descriptor object that defines the properties being defined or modified. | ||
102 | @example | ||
103 | Montage.defineProperty(Object.prototype, "_eventListenerDescriptors", { | ||
104 | enumerable: false, | ||
105 | serializable: true, | ||
106 | value: null, | ||
107 | writable: true | ||
108 | }); | ||
109 | */ | ||
110 | Object.defineProperty(M, "defineProperty", { | ||
111 | |||
112 | value: function(obj, prop, descriptor) { | ||
113 | var dependencies = descriptor.dependencies; | ||
114 | //reset defaults appropriately for framework. | ||
115 | if ("__proto__" in descriptor) { | ||
116 | descriptor.__proto__ = ("value" in descriptor ? (typeof descriptor.value === "function" ? _defaultFunctionValueProperty : _defaultObjectValueProperty) : _defaultAccessorProperty); | ||
117 | } else { | ||
118 | var defaults; | ||
119 | if ("value" in descriptor) { | ||
120 | if (typeof descriptor.value === "function") { | ||
121 | defaults = _defaultFunctionValueProperty; | ||
122 | } else { | ||
123 | defaults = _defaultObjectValueProperty; | ||
124 | } | ||
125 | } else { | ||
126 | defaults = _defaultAccessorProperty; | ||
127 | } | ||
128 | for (var key in defaults) { | ||
129 | if (!(key in descriptor)) { | ||
130 | descriptor[key] = defaults[key]; | ||
131 | } | ||
132 | } | ||
133 | } | ||
134 | |||
135 | |||
136 | if (!descriptor.hasOwnProperty("enumerable") && prop.charAt(0) === "_") { | ||
137 | descriptor.enumerable = false; | ||
138 | } | ||
139 | if (dependencies) { | ||
140 | var i = 0, | ||
141 | independentProperty; | ||
142 | |||
143 | for (; (independentProperty = dependencies[i]); i++) { | ||
144 | M.addDependencyToProperty(obj, independentProperty, prop); | ||
145 | } | ||
146 | |||
147 | } | ||
148 | |||
149 | if ("serializable" in descriptor) { | ||
150 | // get the _serializableAttributeProperties property or creates it through the entire chain if missing. | ||
151 | getAttributeProperties(obj, "serializable")[prop] = descriptor.serializable; | ||
152 | } | ||
153 | |||
154 | if ("modify" in descriptor) { | ||
155 | getAttributeProperties(obj, "modify")[prop] = descriptor.modify; | ||
156 | } | ||
157 | |||
158 | //this is added to enable value properties with [] or Objects that are new for every instance | ||
159 | if (descriptor.distinct === true && typeof descriptor.value === "object") { | ||
160 | (function(internalProperty, value) { | ||
161 | Object.defineProperty(obj, internalProperty, { | ||
162 | enumerable: false, | ||
163 | configurable: true, | ||
164 | writable: true, | ||
165 | value: null | ||
166 | }); | ||
167 | if (value.constructor === Object && Object.getPrototypeOf(value) === Object.prototype) { | ||
168 | // we have an object literal {...} | ||
169 | if (Object.keys(value).length !== 0) { | ||
170 | Object.defineProperty(obj, prop, { | ||
171 | configurable: true, | ||
172 | get: function() { | ||
173 | //Special case for object to copy the values | ||
174 | var returnValue = this[internalProperty]; | ||
175 | if (!returnValue) { | ||
176 | var k; | ||
177 | returnValue = {}; | ||
178 | for (k in value) { | ||
179 | returnValue[k] = value[k]; | ||
180 | } | ||
181 | this[internalProperty] = returnValue; | ||
182 | } | ||
183 | return returnValue; | ||
184 | }, | ||
185 | set: function(value) { | ||
186 | this[internalProperty] = value; | ||
187 | } | ||
188 | }); | ||
189 | } else { | ||
190 | Object.defineProperty(obj, prop, { | ||
191 | configurable: true, | ||
192 | get: function() { | ||
193 | return this[internalProperty] || (this[internalProperty] = {}); | ||
194 | }, | ||
195 | set: function(value) { | ||
196 | this[internalProperty] = value; | ||
197 | } | ||
198 | }); | ||
199 | } | ||
200 | |||
201 | } else if ((value.__proto__ || Object.getPrototypeOf(value)) === __cached__arrayProto) { | ||
202 | // we have an array literal [...] | ||
203 | if (value.length !== 0) { | ||
204 | Object.defineProperty(obj, prop, { | ||
205 | configurable: true, | ||
206 | get: function() { | ||
207 | //Special case for object to copy the values | ||
208 | var returnValue = this[internalProperty]; | ||
209 | if (!returnValue) { | ||
210 | var i, k; | ||
211 | returnValue = []; | ||
212 | for (i = 0; typeof (k = value[i]) !== "undefined"; i++) { | ||
213 | returnValue[i] = k; | ||
214 | } | ||
215 | this[internalProperty] = returnValue; | ||
216 | } | ||
217 | return returnValue; | ||
218 | }, | ||
219 | set: function(value) { | ||
220 | this[internalProperty] = value; | ||
221 | } | ||
222 | }); | ||
223 | |||
224 | } else { | ||
225 | Object.defineProperty(obj, prop, { | ||
226 | configurable: true, | ||
227 | get: function() { | ||
228 | //Special case for array as isArray fails | ||