angular-sticky-table-header
Advanced tools
Comparing version 0.2.0 to 0.2.1
{ | ||
"name": "angular-sticky-table-header", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Sticky headers for tables", | ||
@@ -5,0 +5,0 @@ "main": "dist/angular-sticky-table-header.js", |
@@ -58,2 +58,3 @@ angular.module('watchDom', []).constant('watchDomOptions', { | ||
clone: null, | ||
windowEvents: {}, | ||
createClone: function () { | ||
@@ -65,3 +66,3 @@ return angular.element(scope.tr).clone(true, true).addClass(options.cloneClassName).appendTo(element.find('thead')); | ||
scope.clone = scope.createClone(); | ||
scope.sizeClone(); | ||
$timeout(scope.sizeClone); | ||
}, 200), | ||
@@ -128,9 +129,14 @@ removeClones: function () { | ||
addEvents: function () { | ||
angular.element($window).on({ | ||
'resize.angularStickyTableHeader': _.debounce(scope.setClonedCellWidths.bind(scope), options.interval), | ||
'scroll.angularStickyTableHeader': _.debounce(scope.checkScroll.bind(scope), options.interval) | ||
}); | ||
scope.windowEvents = { | ||
scroll: _.debounce(scope.checkScroll.bind(scope), options.interval), | ||
resize: _.debounce(scope.setClonedCellWidths.bind(scope), options.interval) | ||
}; | ||
angular.element($window).on(scope.windowEvents); | ||
}, | ||
removeEvents: function () { | ||
angular.element($window).off('.angularStickyTableHeader'); | ||
if (!scope.windowEvents.resize || !scope.windowEvents.scroll) { | ||
return; | ||
} | ||
angular.element($window).off(scope.windowEvents); | ||
scope.windowEvents = {}; | ||
}, | ||
@@ -137,0 +143,0 @@ changeDisabled: function (disabled, old) { |
{ | ||
"name": "angular-sticky-table-header", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Sticky headers for tables", | ||
@@ -5,0 +5,0 @@ "main": "dist/angular-sticky-table-header.js", |
@@ -50,2 +50,6 @@ angular | ||
// store references to events bound to the | ||
// $window, so they can be safely removed | ||
windowEvents: {}, | ||
createClone: function () { | ||
@@ -65,3 +69,3 @@ | ||
scope.clone = scope.createClone(); | ||
scope.sizeClone(); | ||
$timeout(scope.sizeClone); | ||
@@ -176,7 +180,11 @@ }, 200), | ||
angular.element($window).on({ | ||
'resize.angularStickyTableHeader': _.debounce(scope.setClonedCellWidths.bind(scope), options.interval), | ||
'scroll.angularStickyTableHeader': _.debounce(scope.checkScroll.bind(scope), options.interval) | ||
}); | ||
scope.windowEvents = { | ||
scroll: _.debounce(scope.checkScroll.bind(scope), options.interval), | ||
resize: _.debounce(scope.setClonedCellWidths.bind(scope), options.interval) | ||
}; | ||
angular | ||
.element($window) | ||
.on(scope.windowEvents); | ||
}, | ||
@@ -186,3 +194,11 @@ | ||
angular.element($window).off('.angularStickyTableHeader'); | ||
if (!scope.windowEvents.resize || !scope.windowEvents.scroll) { | ||
return; | ||
} | ||
angular | ||
.element($window) | ||
.off(scope.windowEvents); | ||
scope.windowEvents = {}; | ||
@@ -189,0 +205,0 @@ }, |
@@ -81,3 +81,3 @@ // Generated by CoffeeScript 1.7.1 | ||
describe('#resetClone', function() { | ||
it('should call #removeClones, #createClone, and #sizeClone', function() { | ||
it('should call #removeClones, #createClone, and #sizeClone', inject(function($timeout) { | ||
spyOn(this.scope, 'removeClones'); | ||
@@ -87,6 +87,7 @@ spyOn(this.scope, 'createClone'); | ||
this.scope.resetClone(); | ||
$timeout.flush(); | ||
expect(this.scope.removeClones).toHaveBeenCalled(); | ||
expect(this.scope.createClone).toHaveBeenCalled(); | ||
return expect(this.scope.sizeClone).toHaveBeenCalled(); | ||
}); | ||
})); | ||
return it('should set scope.clone to the value returned by #createClone', function() { | ||
@@ -281,2 +282,68 @@ this.scope.clone = null; | ||
}); | ||
describe('#addEvents', function() { | ||
it('should store decorated resize and scroll events on scope.windowEvents', function() { | ||
this.scope.windowEvents = null; | ||
this.scope.addEvents(); | ||
expect(angular.isFunction(this.scope.windowEvents.resize)).toBe(true); | ||
return expect(angular.isFunction(this.scope.windowEvents.scroll)).toBe(true); | ||
}); | ||
return it('should bind those events to the $window', inject(function($window) { | ||
spyOn(($()).__proto__, 'on'); | ||
spyOn(angular, 'element').andCallThrough(); | ||
this.scope.addEvents(); | ||
expect(angular.element).toHaveBeenCalledWith($window); | ||
return expect(($()).__proto__.on).toHaveBeenCalledWith(this.scope.windowEvents); | ||
})); | ||
}); | ||
describe('#removeEvents', function() { | ||
it('should not reset scope.windowEvents or unbind events from the $window if windowEvents.resize or windowEvents.scroll are falsey', function() { | ||
var events; | ||
spyOn(($()).__proto__, 'on'); | ||
events = { | ||
resize: null, | ||
scroll: null | ||
}; | ||
this.scope.windowEvents = angular.copy(events); | ||
this.scope.removeEvents(); | ||
expect(($()).__proto__.on).not.toHaveBeenCalled(); | ||
expect(this.scope.windowEvents).toEqual(events); | ||
this.scope.windowEvents = { | ||
resize: true, | ||
scroll: null | ||
}; | ||
this.scope.windowEvents = angular.copy(events); | ||
this.scope.removeEvents(); | ||
expect(($()).__proto__.on).not.toHaveBeenCalled(); | ||
expect(this.scope.windowEvents).toEqual(events); | ||
this.scope.windowEvents = { | ||
resize: null, | ||
scroll: true | ||
}; | ||
this.scope.windowEvents = angular.copy(events); | ||
this.scope.removeEvents(); | ||
expect(($()).__proto__.on).not.toHaveBeenCalled(); | ||
return expect(this.scope.windowEvents).toEqual(events); | ||
}); | ||
it('should unbind events from the $window', inject(function($window) { | ||
var events; | ||
events = { | ||
resize: true, | ||
scroll: true | ||
}; | ||
this.scope.windowEvents = angular.copy(events); | ||
spyOn(($()).__proto__, 'off'); | ||
spyOn(angular, 'element').andCallThrough(); | ||
this.scope.removeEvents(); | ||
expect(angular.element).toHaveBeenCalledWith($window); | ||
return expect(($()).__proto__.off).toHaveBeenCalledWith(events); | ||
})); | ||
return it('should set scope.windowEvents to an empty object', function() { | ||
this.scope.windowEvents = { | ||
resize: true, | ||
scroll: true | ||
}; | ||
this.scope.removeEvents(); | ||
return expect(this.scope.windowEvents).toEqual({}); | ||
}); | ||
}); | ||
describe('#changeDisabled', function() { | ||
@@ -283,0 +350,0 @@ it('shouldn\'t call anything if the 1st argument is identical to the 2nd argument', function() { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56963
779