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

Commit 5298396

Browse files
committed
feat(layout): add element and attribute support.
you can now create a layout like : ```html <div ui-layout="{ flow : 'row' }"></div> or <ui-layout options="{ flow : 'row' }"></ui-layout> ```
1 parent 6da2196 commit 5298396

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

‎ui-layout.css‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
z-index: 99999;
2121
}
2222

23-
.ui-layout[flow="row"] > .ui-splitbar{
23+
.ui-layout-row > .ui-splitbar{
2424
top: 25%;
2525
height: 8px; width: 100%;
2626
cursor: row-resize;
2727
}
28-
.ui-layout[flow="column"] > .ui-splitbar{
28+
.ui-layout-column > .ui-splitbar{
2929
left: 25%;
3030
width: 8px; height: 100%;
3131
cursor: col-resize;

‎ui-layout.js‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,26 @@
3838
*/
3939
angular.module('ui.layout', [])
4040

41-
.directive('uiLayout', function(){
41+
.directive('uiLayout', ['$parse', function($parse){
4242

4343
var splitBarElem_htmlTemplate = '<div class="stretch ui-splitbar"></div>';
4444

4545
return {
46-
restrict: 'C',
46+
restrict: 'AE',
4747
compile: function compile(tElement, tAttrs) {
4848

4949
var _i, _childens = tElement.children(), _child_len = _childens.length;
50-
var isUsingColumnFlow = tAttrs.flow === 'column';
51-
// Force the layout to fill the parent space
52-
// fix no height layout...
53-
tElement.addClass('stretch');
50+
51+
// Parse `ui-layout` or `options` attributes (with no scope...)
52+
var opts = angular.extend({}, $parse(tAttrs.uiLayout)(), $parse(tAttrs.options)());
53+
var isUsingColumnFlow = opts.flow === 'column';
54+
55+
tElement
56+
// Force the layout to fill the parent space
57+
// fix no height layout...
58+
.addClass('stretch')
59+
// set the layout css class
60+
.addClass('ui-layout-' + opts.flow);
5461

5562
// Stretch all the children by default
5663
for (_i = 0; _i < _child_len ; ++_i){
@@ -79,11 +86,14 @@ angular.module('ui.layout', [])
7986
},
8087
controller: ['$scope', '$attrs', '$element', function uiLayoutCtrl($scope, $attrs, $element){
8188
// Gives to the children directives the access to the parent layout.
82-
return { flow : $attrs.flow, element : $element};
89+
return {
90+
opts : angular.extend({}, $scope.$eval($attrs.uiLayout), $scope.$eval($attrs.options)),
91+
element : $element
92+
};
8393
}]
8494
};
8595

86-
})
96+
}])
8797

8898

8999
.directive('uiSplitbar', function(){
@@ -100,7 +110,7 @@ angular.module('ui.layout', [])
100110
var _cache = {};
101111

102112
// Use relative mouse position
103-
var isUsingColumnFlow = parentLayout.flow === 'column';
113+
var isUsingColumnFlow = parentLayout.opts.flow === 'column';
104114
var mouseProperty = ( isUsingColumnFlow ? 'x' : 'y');
105115

106116
// Use bounding box / css property names

0 commit comments

Comments
 (0)