Skip to content

Commit

Permalink
fix(gridUtil): Fixes gridUtil.off.mousewheel event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
vhalbwachs committed Aug 29, 2015
1 parent 026b6d2 commit 4057c64
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/core/services/ui-grid-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
}
};
s.off.mousewheel = function (elm, fn) {
var $elm = angular.element(this);
var $elm = angular.element(elm);

var cbs = $elm.data('mousewheel-callbacks');
var handler = cbs[fn];
Expand Down
26 changes: 26 additions & 0 deletions test/unit/core/services/ui-grid-util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,4 +612,30 @@ describe('ui.grid.utilService', function() {
}).not.toThrow();
});
});

describe('on.mousewheel', function() {
it('should register a callback on a dom element', function () {
var div = document.createElement('div');
var $div = angular.element(div);
var callback = function(){};
gridUtil.on.mousewheel(div, callback);
expect(Object.keys($div.data('mousewheel-callbacks')).length).toEqual(1);
});
});

describe('off.mousewheel', function() {
it('should deregister a callback on a dom element', function () {
var div = document.createElement('div');
var $div = angular.element(div);
var callback1 = function(){return 1;};
var callback2 = function(){return 2;};
gridUtil.on.mousewheel(div, callback1);
gridUtil.on.mousewheel(div, callback2);
expect(Object.keys($div.data('mousewheel-callbacks')).length).toEqual(2);
gridUtil.off.mousewheel(div, callback1);
expect(Object.keys($div.data('mousewheel-callbacks')).length).toEqual(1);
gridUtil.off.mousewheel(div, callback2);
expect($div.data('mousewheel-callbacks')).toBe(undefined);
});
});
});

0 comments on commit 4057c64

Please sign in to comment.