Skip to content

Commit 8452425

Browse files
authored
Merge pull request #242 from darcyparker/replaceDeprecatedBindAndUnbind
Replace deprecated bind and unbind
2 parents 4c2d184 + 30ccd10 commit 8452425

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

src/ui-scroll.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,10 @@ angular.module('ui.scroll', [])
224224

225225
$scope.$on('$destroy', () => {
226226
unbindEvents();
227-
viewport.unbind('mousewheel', wheelHandler);
227+
viewport.off('mousewheel', wheelHandler);
228228
});
229229

230-
viewport.bind('mousewheel', wheelHandler);
230+
viewport.on('mousewheel', wheelHandler);
231231

232232
initialize();
233233

@@ -238,13 +238,13 @@ angular.module('ui.scroll', [])
238238
}
239239

240240
function bindEvents() {
241-
viewport.bind('resize', resizeAndScrollHandler);
242-
viewport.bind('scroll', resizeAndScrollHandler);
241+
viewport.on('resize', resizeAndScrollHandler);
242+
viewport.on('scroll', resizeAndScrollHandler);
243243
}
244244

245245
function unbindEvents() {
246-
viewport.unbind('resize', resizeAndScrollHandler);
247-
viewport.unbind('scroll', resizeAndScrollHandler);
246+
viewport.off('resize', resizeAndScrollHandler);
247+
viewport.off('scroll', resizeAndScrollHandler);
248248
}
249249

250250
function reload() {

test/BasicSetupSpec.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,29 @@ describe('uiScroll', function() {
1818
var scrollSettings = { datasource: 'myEmptyDatasource' };
1919

2020
it('should bind to window scroll and resize events and unbind them after the scope is destroyed', function() {
21-
spyOn($.fn, 'bind').and.callThrough();
22-
spyOn($.fn, 'unbind').and.callThrough();
21+
spyOn($.fn, 'on').and.callThrough();
22+
spyOn($.fn, 'off').and.callThrough();
2323
runTest(scrollSettings,
2424
function(viewport) {
25-
expect($.fn.bind.calls.all().length).toBe(3);
26-
expect($.fn.bind.calls.all()[0].args[0]).toBe('mousewheel');
27-
expect($.fn.bind.calls.all()[0].object[0]).toBe(viewport[0]);
28-
expect($.fn.bind.calls.all()[1].args[0]).toBe('resize');
29-
expect($.fn.bind.calls.all()[1].object[0]).toBe(viewport[0]);
30-
expect($.fn.bind.calls.all()[2].args[0]).toBe('scroll');
31-
expect($.fn.bind.calls.all()[2].object[0]).toBe(viewport[0]);
25+
expect($.fn.on.calls.all().length).toBe(4);
26+
expect($.fn.on.calls.all()[0].args[0]).toBe('visibilitychange');
27+
expect($.fn.on.calls.all()[1].args[0]).toBe('mousewheel');
28+
expect($.fn.on.calls.all()[1].object[0]).toBe(viewport[0]);
29+
expect($.fn.on.calls.all()[2].args[0]).toBe('resize');
30+
expect($.fn.on.calls.all()[2].object[0]).toBe(viewport[0]);
31+
expect($.fn.on.calls.all()[3].args[0]).toBe('scroll');
32+
expect($.fn.on.calls.all()[3].object[0]).toBe(viewport[0]);
3233
}, {
3334
cleanupTest: function(viewport, scope, $timeout) {
3435
$timeout(function() {
35-
expect($.fn.unbind.calls.all().length).toBe(3);
36-
expect($.fn.unbind.calls.all()[0].args[0]).toBe('resize');
37-
expect($.fn.unbind.calls.all()[0].object[0]).toBe(viewport[0]);
38-
expect($.fn.unbind.calls.all()[1].args[0]).toBe('scroll');
39-
expect($.fn.unbind.calls.all()[1].object[0]).toBe(viewport[0]);
40-
expect($.fn.unbind.calls.all()[2].args[0]).toBe('mousewheel');
41-
expect($.fn.unbind.calls.all()[2].object[0]).toBe(viewport[0]);
36+
expect($.fn.off.calls.all().length).toBe(4);
37+
expect($.fn.off.calls.all()[0].args[0]).toBe('visibilitychange');
38+
expect($.fn.off.calls.all()[1].args[0]).toBe('resize');
39+
expect($.fn.off.calls.all()[1].object[0]).toBe(viewport[0]);
40+
expect($.fn.off.calls.all()[2].args[0]).toBe('scroll');
41+
expect($.fn.off.calls.all()[2].object[0]).toBe(viewport[0]);
42+
expect($.fn.off.calls.all()[3].args[0]).toBe('mousewheel');
43+
expect($.fn.off.calls.all()[3].object[0]).toBe(viewport[0]);
4244
});
4345
}
4446
}

test/BasicTestsSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ describe('uiScroll', function () {
433433
function (viewport) {
434434
var wheelEventElement = viewport[0];
435435

436-
angular.element(document.body).bind('mousewheel', incrementDocumentScrollCount); //spy for wheel-events bubbling
436+
angular.element(document.body).on('mousewheel', incrementDocumentScrollCount); //spy for wheel-events bubbling
437437

438438
//simulate multiple wheel-scroll events within viewport
439439

@@ -458,7 +458,7 @@ describe('uiScroll', function () {
458458

459459
}, {
460460
cleanupTest: function () {
461-
angular.element(document.body).unbind('mousewheel', incrementDocumentScrollCount);
461+
angular.element(document.body).off('mousewheel', incrementDocumentScrollCount);
462462
}
463463
}
464464
);

0 commit comments

Comments
 (0)