From f24f62dedcaa49cf87143296b65c0fe6509a09bd Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 18 Feb 2015 19:26:06 -0800 Subject: [PATCH] [Fixed Position] Begin adding element proxy classes Begin adding proxy classes to allow the toolbar to interact with elements in a fixed position view, WTD-879. --- .../features/layout/src/elements/Accessor.js | 26 ++++++++++++++ .../layout/src/elements/ElementProxies.js | 12 +++++++ .../layout/src/elements/ElementProxy.js | 35 +++++++++++++++++++ .../layout/src/elements/TelemetryProxy.js | 21 +++++++++++ 4 files changed, 94 insertions(+) create mode 100644 platform/features/layout/src/elements/Accessor.js create mode 100644 platform/features/layout/src/elements/ElementProxies.js create mode 100644 platform/features/layout/src/elements/ElementProxy.js create mode 100644 platform/features/layout/src/elements/TelemetryProxy.js diff --git a/platform/features/layout/src/elements/Accessor.js b/platform/features/layout/src/elements/Accessor.js new file mode 100644 index 0000000000..e2fa6564c6 --- /dev/null +++ b/platform/features/layout/src/elements/Accessor.js @@ -0,0 +1,26 @@ +/*global define*/ + +define( + [], + function () { + "use strict"; + + /** + * Utility function for creating getter-setter functions, + * since these are frequently useful for element proxies. + * @constructor + * @param {Object} object the object to get/set values upon + * @param {string} key the property to get/set + */ + function Accessor(object, key) { + return function (value) { + if (arguments.length > 0) { + object[key] = value; + } + return value; + }; + } + + return Accessor; + } +); \ No newline at end of file diff --git a/platform/features/layout/src/elements/ElementProxies.js b/platform/features/layout/src/elements/ElementProxies.js new file mode 100644 index 0000000000..e8d6b032e5 --- /dev/null +++ b/platform/features/layout/src/elements/ElementProxies.js @@ -0,0 +1,12 @@ +/*global define*/ + +define( + ['./TelemetryProxy'], + function (TelemetryProxy) { + "use strict"; + + return { + "fixed.telemetry": TelemetryProxy + }; + } +); \ No newline at end of file diff --git a/platform/features/layout/src/elements/ElementProxy.js b/platform/features/layout/src/elements/ElementProxy.js new file mode 100644 index 0000000000..963ff31706 --- /dev/null +++ b/platform/features/layout/src/elements/ElementProxy.js @@ -0,0 +1,35 @@ +/*global define*/ + +define( + ['./Accessor'], + function (Accessor) { + "use strict"; + + /** + * Abstract superclass for other classes which provide useful + * interfaces upon an elements in a fixed position view. + * This handles the generic operations (e.g. remove) so that + * subclasses only need to implement element-specific behaviors. + * @constructor + * @param element the telemetry element + * @param index the element's index within its array + * @param {Array} elements the full array of elements + */ + function ElementProxy(element, index, elements) { + return { + x: new Accessor(element, 'x'), + y: new Accessor(element, 'y'), + z: new Accessor(element, 'z'), + width: new Accessor(element, 'width'), + height: new Accessor(element, 'height'), + remove: function () { + if (elements[index] === element) { + elements.splice(index, 1); + } + } + }; + } + + return ElementProxy; + } +); \ No newline at end of file diff --git a/platform/features/layout/src/elements/TelemetryProxy.js b/platform/features/layout/src/elements/TelemetryProxy.js new file mode 100644 index 0000000000..610edb895c --- /dev/null +++ b/platform/features/layout/src/elements/TelemetryProxy.js @@ -0,0 +1,21 @@ +/*global define*/ + +define( + ['./ElementProxy'], + function (ElementProxy) { + 'use strict'; + + /** + * + */ + function TelemetryProxy(element, index, elements) { + var proxy = new ElementProxy(element, index, elements); + + proxy.id = element.id; + + return proxy; + } + + return TelemetryProxy; + } +); \ No newline at end of file