Skip to content

Commit

Permalink
fix(loading): Prevent clicks on modal views when loading is active. C…
Browse files Browse the repository at this point in the history
…loses #1720
  • Loading branch information
perrygovier committed Jul 3, 2014
1 parent c2dbb31 commit 7630bd4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions js/angular/service/loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ function($document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $c
ionic.requestAnimationFrame(function() {
self.isShown && self.element.addClass('active');
ionic.DomUtil.centerElementByMarginTwice(self.element[0]);
$document[0].body.classList.add('loading-active');
});
}
});
Expand All @@ -133,6 +134,7 @@ function($document, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $c
$ionicBackdrop.getElement().removeClass('backdrop-loading');
}
self.element.removeClass('active');
$document[0].body.classList.remove('loading-active');
setTimeout(function() {
!self.isShown && self.element.removeClass('visible');
}, 200);
Expand Down
8 changes: 8 additions & 0 deletions scss/_modal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,19 @@
}
}

// disable clicks on all but the modal
.modal-open {
pointer-events: none;

.modal,
.modal-backdrop {
pointer-events: auto;
}
// prevent clicks on modal when loading overlay is active though
&.loading-active {
.modal,
.modal-backdrop {
pointer-events: none;
}
}
}
11 changes: 11 additions & 0 deletions test/unit/angular/service/loading.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ describe('$ionicLoading service', function() {
expect($ionicBackdrop._element.hasClass('backdrop-loading')).toBe(false);
}));

it('should add and remove loading-active class to body', inject(function($ionicLoading, $timeout) {
// used by _modal.scss to prevent clicks on modal screen when loading is active
var loader = TestUtil.unwrapPromise($ionicLoading._getLoader());
ionic.requestAnimationFrame = function(cb) { cb(); };
loader.show({});
$timeout.flush();
expect(angular.element(document.body).hasClass('loading-active')).toBe(true);
loader.hide();
expect(angular.element(document.body).hasClass('loading-active')).toBe(false);
}));

});

describe('.hide()', function() {
Expand Down

0 comments on commit 7630bd4

Please sign in to comment.