From fdca73a5d55f0bdbc8437d3a9a07bfa25250efb8 Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 13 Apr 2015 13:16:48 -0600 Subject: [PATCH] fix(backdrop): dont allow counter to go below 0 --- js/angular/service/backdrop.js | 19 ++++++++++++------- js/angular/service/clickBlock.js | 2 +- test/unit/angular/directive/backdrop.unit.js | 6 ++---- test/unit/angular/service/loading.unit.js | 14 -------------- 4 files changed, 15 insertions(+), 26 deletions(-) diff --git a/js/angular/service/backdrop.js b/js/angular/service/backdrop.js index 7879858ff90..8433a63c4f8 100644 --- a/js/angular/service/backdrop.js +++ b/js/angular/service/backdrop.js @@ -34,11 +34,12 @@ */ IonicModule .factory('$ionicBackdrop', [ - '$document', '$timeout', -function($document, $timeout) { + '$document', '$timeout', '$$rAF', '$$q', +function($document, $timeout, $$rAF, $$q) { var el = jqLite('
'); var backdropHolds = 0; + var backdropIsActive = false; $document[0].body.appendChild(el[0]); @@ -64,20 +65,24 @@ function($document, $timeout) { }; function retain() { - if ((++backdropHolds) === 1) { + backdropHolds++; + if (backdropHolds === 1) { el.addClass('visible'); - ionic.requestAnimationFrame(function() { - backdropHolds && el.addClass('active'); + $$rAF(function() { + // If we're still at >0 backdropHolds after async... + if (backdropHolds >= 1) el.addClass('active'); }); } } function release() { - if ((--backdropHolds) === 0) { + if (backdropHolds === 1) { el.removeClass('active'); $timeout(function() { - !backdropHolds && el.removeClass('visible'); + // If we're still at 0 backdropHolds after async... + if (backdropHolds === 0) el.removeClass('visible'); }, 400, false); } + backdropHolds = Math.max(0, backdropHolds - 1); } function getElement() { diff --git a/js/angular/service/clickBlock.js b/js/angular/service/clickBlock.js index 9ec33202ab5..14684669f20 100644 --- a/js/angular/service/clickBlock.js +++ b/js/angular/service/clickBlock.js @@ -35,7 +35,7 @@ function($document, $ionicBody, $timeout) { show: function(autoExpire) { pendingShow = true; $timeout.cancel(fallbackTimer); - fallbackTimer = $timeout(this.hide, autoExpire || 310); + fallbackTimer = $timeout(this.hide, autoExpire || 310, false); addClickBlock(); }, hide: function() { diff --git a/test/unit/angular/directive/backdrop.unit.js b/test/unit/angular/directive/backdrop.unit.js index d37dc758693..34b11a7e7ea 100644 --- a/test/unit/angular/directive/backdrop.unit.js +++ b/test/unit/angular/directive/backdrop.unit.js @@ -1,8 +1,6 @@ describe('$ionicBackdrop service', function() { - beforeEach(module('ionic')); - - beforeEach(inject(function($animate) { - ionic.requestAnimationFrame = function(cb) { cb(); }; + beforeEach(module('ionic', function($provide) { + $provide.value('$$rAF', function(cb) { cb(); }); })); it('should add active on retain', inject(function($ionicBackdrop) { diff --git a/test/unit/angular/service/loading.unit.js b/test/unit/angular/service/loading.unit.js index 840b68c22cc..e3dee335fc1 100644 --- a/test/unit/angular/service/loading.unit.js +++ b/test/unit/angular/service/loading.unit.js @@ -157,20 +157,6 @@ describe('$ionicLoading service', function() { expect(loader.isShown).toBe(false); expect(loader.element.hasClass('active')).toBe(false); })); - it('show should only active after raf is still isShown', inject(function($ionicLoading) { - var loader = TestUtil.unwrapPromise($ionicLoading._getLoader()); - var rafCallback; - ionic.requestAnimationFrame = function(cb) { - rafCallback = cb; - }; - loader.show({}); - expect(loader.isShown).toBe(true); - loader.hide(); - expect(loader.isShown).toBe(false); - rafCallback(); - expect(loader.element.hasClass('active')).toBe(false); - ionic.requestAnimationFrame = function(cb) { cb(); }; - })); describe("back button", function() { it('.show() should register back button action', inject(function($ionicLoading, $ionicPlatform, $timeout) {