diff --git a/src/ui-scroll.js b/src/ui-scroll.js index bd82782..c550f47 100644 --- a/src/ui-scroll.js +++ b/src/ui-scroll.js @@ -224,10 +224,10 @@ angular.module('ui.scroll', []) $scope.$on('$destroy', () => { unbindEvents(); - viewport.unbind('mousewheel', wheelHandler); + viewport.off('mousewheel', wheelHandler); }); - viewport.bind('mousewheel', wheelHandler); + viewport.on('mousewheel', wheelHandler); initialize(); @@ -238,13 +238,13 @@ angular.module('ui.scroll', []) } function bindEvents() { - viewport.bind('resize', resizeAndScrollHandler); - viewport.bind('scroll', resizeAndScrollHandler); + viewport.on('resize', resizeAndScrollHandler); + viewport.on('scroll', resizeAndScrollHandler); } function unbindEvents() { - viewport.unbind('resize', resizeAndScrollHandler); - viewport.unbind('scroll', resizeAndScrollHandler); + viewport.off('resize', resizeAndScrollHandler); + viewport.off('scroll', resizeAndScrollHandler); } function reload() { diff --git a/test/BasicSetupSpec.js b/test/BasicSetupSpec.js index ffceaeb..1744aea 100644 --- a/test/BasicSetupSpec.js +++ b/test/BasicSetupSpec.js @@ -18,27 +18,29 @@ describe('uiScroll', function() { var scrollSettings = { datasource: 'myEmptyDatasource' }; it('should bind to window scroll and resize events and unbind them after the scope is destroyed', function() { - spyOn($.fn, 'bind').and.callThrough(); - spyOn($.fn, 'unbind').and.callThrough(); + spyOn($.fn, 'on').and.callThrough(); + spyOn($.fn, 'off').and.callThrough(); runTest(scrollSettings, function(viewport) { - expect($.fn.bind.calls.all().length).toBe(3); - expect($.fn.bind.calls.all()[0].args[0]).toBe('mousewheel'); - expect($.fn.bind.calls.all()[0].object[0]).toBe(viewport[0]); - expect($.fn.bind.calls.all()[1].args[0]).toBe('resize'); - expect($.fn.bind.calls.all()[1].object[0]).toBe(viewport[0]); - expect($.fn.bind.calls.all()[2].args[0]).toBe('scroll'); - expect($.fn.bind.calls.all()[2].object[0]).toBe(viewport[0]); + expect($.fn.on.calls.all().length).toBe(4); + expect($.fn.on.calls.all()[0].args[0]).toBe('visibilitychange'); + expect($.fn.on.calls.all()[1].args[0]).toBe('mousewheel'); + expect($.fn.on.calls.all()[1].object[0]).toBe(viewport[0]); + expect($.fn.on.calls.all()[2].args[0]).toBe('resize'); + expect($.fn.on.calls.all()[2].object[0]).toBe(viewport[0]); + expect($.fn.on.calls.all()[3].args[0]).toBe('scroll'); + expect($.fn.on.calls.all()[3].object[0]).toBe(viewport[0]); }, { cleanupTest: function(viewport, scope, $timeout) { $timeout(function() { - expect($.fn.unbind.calls.all().length).toBe(3); - expect($.fn.unbind.calls.all()[0].args[0]).toBe('resize'); - expect($.fn.unbind.calls.all()[0].object[0]).toBe(viewport[0]); - expect($.fn.unbind.calls.all()[1].args[0]).toBe('scroll'); - expect($.fn.unbind.calls.all()[1].object[0]).toBe(viewport[0]); - expect($.fn.unbind.calls.all()[2].args[0]).toBe('mousewheel'); - expect($.fn.unbind.calls.all()[2].object[0]).toBe(viewport[0]); + expect($.fn.off.calls.all().length).toBe(4); + expect($.fn.off.calls.all()[0].args[0]).toBe('visibilitychange'); + expect($.fn.off.calls.all()[1].args[0]).toBe('resize'); + expect($.fn.off.calls.all()[1].object[0]).toBe(viewport[0]); + expect($.fn.off.calls.all()[2].args[0]).toBe('scroll'); + expect($.fn.off.calls.all()[2].object[0]).toBe(viewport[0]); + expect($.fn.off.calls.all()[3].args[0]).toBe('mousewheel'); + expect($.fn.off.calls.all()[3].object[0]).toBe(viewport[0]); }); } } diff --git a/test/BasicTestsSpec.js b/test/BasicTestsSpec.js index 03a7409..64884dc 100644 --- a/test/BasicTestsSpec.js +++ b/test/BasicTestsSpec.js @@ -433,7 +433,7 @@ describe('uiScroll', function () { function (viewport) { var wheelEventElement = viewport[0]; - angular.element(document.body).bind('mousewheel', incrementDocumentScrollCount); //spy for wheel-events bubbling + angular.element(document.body).on('mousewheel', incrementDocumentScrollCount); //spy for wheel-events bubbling //simulate multiple wheel-scroll events within viewport @@ -458,7 +458,7 @@ describe('uiScroll', function () { }, { cleanupTest: function () { - angular.element(document.body).unbind('mousewheel', incrementDocumentScrollCount); + angular.element(document.body).off('mousewheel', incrementDocumentScrollCount); } } );