Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit 24e4a54

Browse files
AgDudeSomeKittens
authored andcommitted
feat(events): Broadcast events on resize and toggle
Events are now broadcast on the ui-layout controller scope when on both resize and toggle. closes #34
1 parent 504d35d commit 24e4a54

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,30 @@ percentage
133133
</div>
134134
```
135135

136+
## Events
137+
138+
Events are broadcast on the scope where ui-layout is attached. This means they are available to any controller inside of a ui-layout container.
139+
140+
### ui.layout.toggle
141+
142+
Dispatched when a container is opened or closed using the chevron buttons.
143+
'''
144+
$scope.$on('ui.layout.toggle', function(e, container){
145+
if ( container.size > 0 ){
146+
console.log('container is open!');
147+
}
148+
});
149+
'''
150+
151+
### ui.layout.resize
152+
153+
Dispatched as a splitbar is dragged, debounced to occur only every 50ms.
154+
155+
'''
156+
$scope.$on('ui.layout.resize', function(e, beforeContainer, afterContainer){});
157+
'''
158+
159+
136160
## Testing
137161

138162
We use Karma and jshint to ensure the quality of the code. The easiest way to run these checks is to use grunt:

‎src/ui-layout.js‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* UI.Layout
55
*/
66
angular.module('ui.layout', [])
7-
.controller('uiLayoutCtrl', ['$scope', '$attrs', '$element', 'LayoutContainer', function uiLayoutCtrl($scope, $attrs, $element, LayoutContainer) {
7+
.controller('uiLayoutCtrl', ['$scope', '$attrs', '$element', '$timeout', 'LayoutContainer', function uiLayoutCtrl($scope, $attrs, $element, $timeout, LayoutContainer) {
88
var ctrl = this;
99
var opts = angular.extend({}, $scope.$eval($attrs.uiLayout), $scope.$eval($attrs.options));
1010
var numOfSplitbars = 0;
@@ -43,6 +43,7 @@ angular.module('ui.layout', [])
4343
ctrl.updateDisplay();
4444
};
4545

46+
var debounceEvent;
4647
function draw() {
4748
var position = ctrl.sizeProperties.flowProperty;
4849
var dividerSize = parseInt(opts.dividerSize);
@@ -90,7 +91,12 @@ angular.module('ui.layout', [])
9091
// move the splitbar
9192
ctrl.movingSplitbar[position] = newPosition;
9293

93-
//TODO: dispatch container resize event
94+
// broadcast an event that resize happened (debounced to 50ms)
95+
if(debounceEvent) $timeout.cancel(debounceEvent);
96+
debounceEvent = $timeout(function() {
97+
$scope.$broadcast('ui.layout.resize', beforeContainer, afterContainer);
98+
debounceEvent = null;
99+
}, 50);
94100
}
95101
}
96102
}
@@ -395,6 +401,7 @@ angular.module('ui.layout', [])
395401
}
396402
}
397403
});
404+
$scope.$broadcast('ui.layout.toggle', c);
398405

399406
return c.collapsed;
400407
};
@@ -439,6 +446,7 @@ angular.module('ui.layout', [])
439446
if(prevContainer) prevContainer.size -= (c.actualSize + endDiff);
440447
}
441448
});
449+
$scope.$broadcast('ui.layout.toggle', c);
442450

443451
return c.collapsed;
444452
};

0 commit comments

Comments
 (0)