diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index 8d0d7e39a4..b8213f8c77 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -24,54 +24,59 @@ "controllers": [ { "key": "TreeNodeController", - "implementation": "TreeNodeController.js", + "implementation": "controllers/TreeNodeController.js", "depends": [ "$scope", "$timeout" ] }, { "key": "ActionGroupController", - "implementation": "ActionGroupController.js", + "implementation": "controllers/ActionGroupController.js", "depends": [ "$scope" ] }, { "key": "ToggleController", - "implementation": "ToggleController.js" + "implementation": "controllers/ToggleController.js" }, { "key": "ContextMenuController", - "implementation": "ContextMenuController.js", + "implementation": "controllers/ContextMenuController.js", "depends": [ "$scope" ] }, { "key": "ClickAwayController", - "implementation": "ClickAwayController.js", + "implementation": "controllers/ClickAwayController.js", "depends": [ "$scope", "$document" ] }, { "key": "ViewSwitcherController", - "implementation": "ViewSwitcherController.js", + "implementation": "controllers/ViewSwitcherController.js", "depends": [ "$scope" ] }, { "key": "BottomBarController", - "implementation": "BottomBarController.js", + "implementation": "controllers/BottomBarController.js", "depends": [ "indicators[]" ] }, { "key": "GetterSetterController", - "implementation": "GetterSetterController.js", + "implementation": "controllers/GetterSetterController.js", "depends": [ "$scope" ] } ], "directives": [ { "key": "mctContainer", - "implementation": "MCTContainer.js", + "implementation": "directives/MCTContainer.js", "depends": [ "containers[]" ] }, { "key": "mctDrag", - "implementation": "MCTDrag.js", + "implementation": "directives/MCTDrag.js", "depends": [ "$document" ] + }, + { + "key": "mctResize", + "implementation": "directives/MCTResize.js", + "depends": [ "$timeout" ] } ], "containers": [ diff --git a/platform/commonUI/general/src/ActionGroupController.js b/platform/commonUI/general/src/controllers/ActionGroupController.js similarity index 100% rename from platform/commonUI/general/src/ActionGroupController.js rename to platform/commonUI/general/src/controllers/ActionGroupController.js diff --git a/platform/commonUI/general/src/BottomBarController.js b/platform/commonUI/general/src/controllers/BottomBarController.js similarity index 100% rename from platform/commonUI/general/src/BottomBarController.js rename to platform/commonUI/general/src/controllers/BottomBarController.js diff --git a/platform/commonUI/general/src/ClickAwayController.js b/platform/commonUI/general/src/controllers/ClickAwayController.js similarity index 100% rename from platform/commonUI/general/src/ClickAwayController.js rename to platform/commonUI/general/src/controllers/ClickAwayController.js diff --git a/platform/commonUI/general/src/ContextMenuController.js b/platform/commonUI/general/src/controllers/ContextMenuController.js similarity index 100% rename from platform/commonUI/general/src/ContextMenuController.js rename to platform/commonUI/general/src/controllers/ContextMenuController.js diff --git a/platform/commonUI/general/src/GetterSetterController.js b/platform/commonUI/general/src/controllers/GetterSetterController.js similarity index 100% rename from platform/commonUI/general/src/GetterSetterController.js rename to platform/commonUI/general/src/controllers/GetterSetterController.js diff --git a/platform/commonUI/general/src/ToggleController.js b/platform/commonUI/general/src/controllers/ToggleController.js similarity index 100% rename from platform/commonUI/general/src/ToggleController.js rename to platform/commonUI/general/src/controllers/ToggleController.js diff --git a/platform/commonUI/general/src/TreeNodeController.js b/platform/commonUI/general/src/controllers/TreeNodeController.js similarity index 100% rename from platform/commonUI/general/src/TreeNodeController.js rename to platform/commonUI/general/src/controllers/TreeNodeController.js diff --git a/platform/commonUI/general/src/ViewSwitcherController.js b/platform/commonUI/general/src/controllers/ViewSwitcherController.js similarity index 100% rename from platform/commonUI/general/src/ViewSwitcherController.js rename to platform/commonUI/general/src/controllers/ViewSwitcherController.js diff --git a/platform/commonUI/general/src/MCTContainer.js b/platform/commonUI/general/src/directives/MCTContainer.js similarity index 100% rename from platform/commonUI/general/src/MCTContainer.js rename to platform/commonUI/general/src/directives/MCTContainer.js diff --git a/platform/commonUI/general/src/MCTDrag.js b/platform/commonUI/general/src/directives/MCTDrag.js similarity index 100% rename from platform/commonUI/general/src/MCTDrag.js rename to platform/commonUI/general/src/directives/MCTDrag.js diff --git a/platform/commonUI/general/src/directives/MCTResize.js b/platform/commonUI/general/src/directives/MCTResize.js new file mode 100644 index 0000000000..10e4256c50 --- /dev/null +++ b/platform/commonUI/general/src/directives/MCTResize.js @@ -0,0 +1,82 @@ +/*global define*/ + +define( + [], + function () { + "use strict"; + + // Default resize interval + var DEFAULT_INTERVAL = 100; + + /** + * The mct-resize directive allows the size of a displayed + * HTML element to be tracked. This is done by polling, + * since the DOM API does not currently provide suitable + * events to watch this reliably. + * + * Attributes related to this directive are interpreted as + * follows: + * + * * `mct-resize`: An Angular expression to evaluate when + * the size changes; the variable `bounds` will be provided + * with two fields, `width` and `height`, both in pixels. + * * `mct-resize-interval`: Optional; the interval, in milliseconds, + * at which to watch for updates. In some cases checking for + * resize can carry a cost (it forces recalculation of + * positions within the document) so it may be preferable to watch + * infrequently. If omitted, a default of 100ms will be used. + * This is an Angular expression, and it will be re-evaluated after + * each interval. + * + * @constructor + * + */ + function MCTResize($timeout) { + + // Link; start listening for changes to an element's size + function link(scope, element, attrs) { + var lastBounds; + + // Determine how long to wait before the next update + function currentInterval() { + return attrs.mctResizeInterval ? + scope.$eval(attrs.mctResizeInterval) : + DEFAULT_INTERVAL; + } + + // Evaluate mct-resize with the current bounds + function fireEval(bounds) { + // Only update when bounds actually change + if (!lastBounds || + lastBounds.width !== bounds.width || + lastBounds.height !== bounds.height) { + scope.$eval(attrs.mctResize, { bounds: bounds }); + lastBounds = bounds; + } + } + + // Callback to fire after each timeout; + // update bounds and schedule another timeout + function onInterval() { + fireEval({ + width: element[0].offsetWidth, + height: element[0].offsetHeight + }); + $timeout(onInterval, currentInterval()); + } + + // Handle the initial callback + onInterval(); + } + + return { + // mct-resize only makes sense as an attribute + restrict: "A", + // Link function, to begin watching for changes + link: link + }; + } + + return MCTResize; + } +); \ No newline at end of file