Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 186
Toggle containers programmatically#152
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
afb35b94c55a275188e54f3952b5aeb391b9fd7242c78acf98743f85a1246348bcc68bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -41,7 +41,8 @@ angular.module('ui.layout', []) | ||
| opts.sizes = opts.sizes || []; | ||
| opts.maxSizes = opts.maxSizes || []; | ||
| opts.minSizes = opts.minSizes || []; | ||
| opts.dividerSize = opts.dividerSize || 10; //default divider size set to 10 | ||
| opts.dividerSize = opts.dividerSize || 10; | ||
| opts.collapsed = opts.collapsed || []; | ||
| ctrl.opts = opts; | ||
| @@ -239,14 +240,14 @@ angular.module('ui.layout', []) | ||
| for(i=0; i < ctrl.containers.length; i++) { | ||
| if(!LayoutContainer.isSplitbar(ctrl.containers[i])) { | ||
| var child = ctrl.containers[i].element; | ||
| var container = ctrl.containers[i], | ||
| child = container.element; | ||
| opts.maxSizes[i] = child.attr('max-size') || child.attr('data-max-size') || opts.maxSizes[i] || null; | ||
| opts.minSizes[i] = child.attr('min-size') || child.attr('data-min-size') || opts.minSizes[i] || null; | ||
| opts.sizes[i] = child.attr('size') || child.attr('data-size') || opts.sizes[i] || 'auto'; | ||
| //opts.collapsed[i] = child.attr('collapsed') || opts.collapsed[i] || false; | ||
| opts.sizes[i] = child.attr('size') || child.attr('data-size') || opts.sizes[i]; | ||
| opts.sizes[i] = optionValue(opts.sizes[i]) || 'auto'; | ||
| opts.minSizes[i] = optionValue(opts.minSizes[i]); | ||
| opts.maxSizes[i] = optionValue(opts.maxSizes[i]); | ||
| @@ -304,10 +305,14 @@ angular.module('ui.layout', []) | ||
| var newSize = (opts.sizes[i] === 'auto') ? autoSize : opts.sizes[i]; | ||
| c.size = (newSize !== null) ? newSize : autoSize; | ||
| } else { | ||
| c.size = dividerSize; | ||
| } | ||
| if (c.collapsed) { | ||
| c.actualSize = c.size; | ||
| c.size = 0; | ||
| } | ||
| usedSpace += c.size; | ||
| } | ||
| } | ||
| @@ -328,6 +333,7 @@ angular.module('ui.layout', []) | ||
| numOfSplitbars++; | ||
| } | ||
| container.index = index; | ||
| ctrl.containers.splice(index, 0, container); | ||
| ctrl.updateDisplay(); | ||
| @@ -773,17 +779,20 @@ angular.module('ui.layout', []) | ||
| }]) | ||
| .directive('uiLayoutContainer', ['LayoutContainer', '$compile', function(LayoutContainer, $compile) { | ||
| .directive('uiLayoutContainer', ['LayoutContainer', '$compile', '$timeout', function(LayoutContainer, $compile, $timeout) { | ||
| return { | ||
| restrict: 'AE', | ||
| require: '^uiLayout', | ||
| scope: {}, | ||
| scope: { | ||
| collapsed: '=' | ||
| }, | ||
| compile: function() { | ||
| return { | ||
| pre: function(scope, element, attrs, ctrl) { | ||
| scope.container = LayoutContainer.Container(); | ||
| scope.container.element = element; | ||
| scope.container.collapsed = scope.collapsed; | ||
| ctrl.addContainer(scope.container); | ||
| @@ -796,6 +805,26 @@ angular.module('ui.layout', []) | ||
| if(!element.hasClass('stretch')) element.addClass('stretch'); | ||
| if(!element.hasClass('ui-layout-container')) element.addClass('ui-layout-container'); | ||
| scope.$watch('collapsed', function (val, old) { | ||
| if (angular.isDefined(old) && val !== old) { | ||
| var index = scope.container.index; | ||
| var splitter = ctrl.containers[index + 1], | ||
| el; | ||
| if (splitter) { | ||
| el = splitter.element[0].children[0]; | ||
| } else { | ||
| splitter = ctrl.containers[index - 1]; | ||
| el = splitter.element[0].children[1]; | ||
| } | ||
| $timeout(function(){ | ||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I hate to be a stickler but I was thinking more about using $q instead of $timeout. In my opinion $timeout isn't really appropriate here. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aha. This is the trick I know how to get around "$digest in progess" error, which was thrown after trying to trigger the click. Not sure how to use $q here. ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, why it $timeout not appropriate. I thought this is a common way how to get around $digest error, to execute a routine in another digest cycle with $timeout. | ||
| angular.element(el).triggerHandler('click'); | ||
| }); | ||
| } | ||
| }); | ||
| scope.$watch('container.size', function(newValue) { | ||
| element.css(ctrl.sizeProperties.sizeProperty, newValue + 'px'); | ||
| }); | ||
| @@ -822,6 +851,16 @@ angular.module('ui.layout', []) | ||
| }; | ||
| }]) | ||
| .directive('uiLayoutLoaded', function() { | ||
| return { | ||
| restrict: 'A', | ||
| priority: -100, | ||
| link: function($scope){ | ||
| $scope.$broadcast('ui.layout.loaded'); | ||
| } | ||
| }; | ||
| }) | ||
| .factory('LayoutContainer', function() { | ||
| // Base container that can be locked and resized | ||
| function BaseContainer() { | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why drop
autoas an option?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the next line takes care of it in case there's no size provided by the user. Am I missing something?