From 861ea8bab79cca0abd0aef70b9589066ce82b80e Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 11 Sep 2015 13:12:24 -0700 Subject: [PATCH 1/3] [Common UI] Poll split pane position Poll to position the splitter in an mct-split-pane, in order to detect later style changes. #53. --- platform/commonUI/general/bundle.json | 2 +- .../general/src/directives/MCTSplitPane.js | 14 +++++++++++++- .../commonUI/general/src/directives/MCTSplitter.js | 7 ++----- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index 33242ccdcf..d6146c437e 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -135,7 +135,7 @@ { "key": "mctSplitPane", "implementation": "directives/MCTSplitPane.js", - "depends": [ "$parse", "$log" ] + "depends": [ "$parse", "$log", "$interval" ] }, { "key": "mctSplitter", diff --git a/platform/commonUI/general/src/directives/MCTSplitPane.js b/platform/commonUI/general/src/directives/MCTSplitPane.js index 688689d79f..4391358fec 100644 --- a/platform/commonUI/general/src/directives/MCTSplitPane.js +++ b/platform/commonUI/general/src/directives/MCTSplitPane.js @@ -28,6 +28,7 @@ define( // Pixel width to allocate for the splitter itself var DEFAULT_ANCHOR = 'left', + POLLING_INTERVAL = 15, // milliseconds CHILDREN_WARNING_MESSAGE = [ "Invalid mct-split-pane contents.", "This element should contain exactly three", @@ -94,7 +95,7 @@ define( * @memberof platform/commonUI/general * @constructor */ - function MCTSplitPane($parse, $log) { + function MCTSplitPane($parse, $log, $interval) { var anchors = { left: true, right: true, @@ -105,6 +106,7 @@ define( function controller($scope, $element, $attrs) { var anchorKey = $attrs.anchor || DEFAULT_ANCHOR, anchor, + activeInterval, positionParsed = $parse($attrs.position), position; // Start undefined, until explicitly set @@ -193,6 +195,16 @@ define( $element.children().eq(anchor.reversed ? 2 : 0)[0] )); + // And poll for position changes enforced by styles + activeInterval = $interval(function () { + getSetPosition(getSetPosition()); + }, POLLING_INTERVAL, false); + + // ...and stop polling when we're destroyed. + $scope.$on('$destroy', function () { + $interval.cancel(activeInterval); + }); + // Interface exposed by controller, for mct-splitter to user return { position: getSetPosition, diff --git a/platform/commonUI/general/src/directives/MCTSplitter.js b/platform/commonUI/general/src/directives/MCTSplitter.js index 5216c69358..1b4264a840 100644 --- a/platform/commonUI/general/src/directives/MCTSplitter.js +++ b/platform/commonUI/general/src/directives/MCTSplitter.js @@ -44,14 +44,11 @@ define( */ function MCTSplitter() { function link(scope, element, attrs, mctSplitPane) { - var initialPosition; + var initialPosition, + activeInterval; element.addClass("splitter"); - // Now that we have the above class, the splitter width - // will have changed, so trigger a positioning update. - mctSplitPane.position(mctSplitPane.position()); - scope.splitter = { // Begin moving this splitter startMove: function () { From 3a3829682cc44b4ac93ce13d650d46acd5033aac Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 11 Sep 2015 13:33:17 -0700 Subject: [PATCH 2/3] [Common UI] Only trigger digest on change ...from mct-split-pane. --- platform/commonUI/general/src/directives/MCTSplitPane.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/commonUI/general/src/directives/MCTSplitPane.js b/platform/commonUI/general/src/directives/MCTSplitPane.js index 4391358fec..abc54f772e 100644 --- a/platform/commonUI/general/src/directives/MCTSplitPane.js +++ b/platform/commonUI/general/src/directives/MCTSplitPane.js @@ -164,14 +164,14 @@ define( // Getter-setter for the pixel offset of the splitter, // relative to the current edge. function getSetPosition(value) { - var min, max; + var min, max, prior = position; if (typeof value === 'number') { position = value; enforceExtrema(); updateElementPositions(); // Pass change up so this state can be shared - if (positionParsed.assign) { + if (positionParsed.assign && position !== prior) { positionParsed.assign($scope, position); } } From 47bfe402941244fc131cb9e6986872210a599340 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 11 Sep 2015 13:40:25 -0700 Subject: [PATCH 3/3] [Common UI] Remove unused variable ...from mct-splitter directive. --- platform/commonUI/general/src/directives/MCTSplitter.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform/commonUI/general/src/directives/MCTSplitter.js b/platform/commonUI/general/src/directives/MCTSplitter.js index 1b4264a840..c163c107e0 100644 --- a/platform/commonUI/general/src/directives/MCTSplitter.js +++ b/platform/commonUI/general/src/directives/MCTSplitter.js @@ -44,8 +44,7 @@ define( */ function MCTSplitter() { function link(scope, element, attrs, mctSplitPane) { - var initialPosition, - activeInterval; + var initialPosition; element.addClass("splitter");