Skip to content

Commit

Permalink
Merge pull request #19 from B-3PO/Features/Issues/#13
Browse files Browse the repository at this point in the history
added isOpen function to panelService, panelDirective, and $panel on …
  • Loading branch information
B-3PO authored Aug 6, 2016
2 parents 9ab6edd + cd2f8b0 commit 77d76d4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
25 changes: 25 additions & 0 deletions src/expansionPanels.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ describe('material.components.expansionPanels', function () {
expect(element.parent().find('md-backdrop').length).toEqual(0);
}));


it('should return false for isOpen', inject(function($mdExpansionPanel) {
var element = getDirective({componentId: 'expansionPanelId'});
expect($mdExpansionPanel('expansionPanelId').isOpen()).toBe(false);
}));

it('should return true for isOpen', inject(function($mdExpansionPanel) {
var element = getDirective({componentId: 'expansionPanelId'});
$mdExpansionPanel('expansionPanelId').expand();
flushAnimations();

expect($mdExpansionPanel('expansionPanelId').isOpen()).toBe(true);
}));
});


Expand Down Expand Up @@ -365,6 +378,18 @@ describe('material.components.expansionPanels', function () {
expect(element.scope()).toBeUndefined();
}));

it('should return false for isOpen', inject(function($mdExpansionPanel) {
var element = getDirective();
expect(element.scope().$panel.isOpen()).toBe(false);
}));

it('should return true for isOpen', inject(function($mdExpansionPanel) {
var element = getDirective();
element.scope().$panel.expand();
flushAnimations();
expect(element.scope().$panel.isOpen()).toBe(true);
}));


describe('Focused', function () {
it('should be the focused element', function () {
Expand Down
31 changes: 19 additions & 12 deletions src/js/expansionPanel.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function expansionPanelDirective() {
var backdrop;
var inited = false;
var registerOnInit = false;
var isOpen = false;
var _isOpen = false;
var isDisabled = false;
var debouncedUpdateScroll = $$rAF.throttle(updateScroll);
var debouncedUpdateResize = $$rAF.throttle(updateResize);
Expand Down Expand Up @@ -136,7 +136,8 @@ function expansionPanelDirective() {
$scope.$panel = {
collapse: collapse,
expand: expand,
remove: remove
remove: remove,
isOpen: isOpen
};

$scope.$on('$destroy', function () {
Expand Down Expand Up @@ -189,26 +190,32 @@ function expansionPanelDirective() {
collapse: collapse,
remove: remove,
onRemove: onRemove,
isOpen: isOpen,
addClickCatcher: addClickCatcher,
removeClickCatcher: removeClickCatcher,
componentId: $attrs.mdComponentId
}, $attrs.mdComponentId);

if (vm.epxansionPanelGroupCtrl) {
vm.epxansionPanelGroupCtrl.addPanel(vm.componentId, {
expand: vm.expand,
collapse: vm.collapse,
remove: vm.remove,
onRemove: vm.onRemove,
destroy: vm.destroy,
expand: expand,
collapse: collapse,
remove: remove,
onRemove: onRemove,
destroy: destroy,
isOpen: isOpen
});
}
}


function isOpen() {
return _isOpen;
}

function expand(options) {
if (isOpen === true || isDisabled === true) { return; }
isOpen = true;
if (_isOpen === true || isDisabled === true) { return; }
_isOpen = true;
options = options || {};

var deferred = $q.defer();
Expand Down Expand Up @@ -240,8 +247,8 @@ function expansionPanelDirective() {


function collapse(options) {
if (isOpen === false) { return; }
isOpen = false;
if (_isOpen === false) { return; }
_isOpen = false;
options = options || {};

var deferred = $q.defer();
Expand Down Expand Up @@ -281,7 +288,7 @@ function expansionPanelDirective() {
deregister = undefined;
}

if (options.animation === false || isOpen === false) {
if (options.animation === false || _isOpen === false) {
$scope.$destroy();
$element.remove();
deferred.resolve();
Expand Down

0 comments on commit 77d76d4

Please sign in to comment.