clean up that windows resizer event

This commit is contained in:
Mads Rasmussen
2018-08-10 14:17:12 +02:00
parent 23e81a67fa
commit ec139ca16c

View File

@@ -16,7 +16,7 @@
**/
angular.module("umbraco.directives")
.directive('autoScale', function ($window) {
.directive('autoScale', function ($window, $timeout, windowResizeListener) {
return function (scope, el, attrs) {
var totalOffset = 0;
@@ -26,12 +26,23 @@ angular.module("umbraco.directives")
totalOffset += offsety;
}
setTimeout(function () {
el.height(window.height() - (el.offset().top + totalOffset));
}, 500);
$timeout(function () {
setElementSize();
});
window.bind("resize", function () {
function setElementSize() {
el.height(window.height() - (el.offset().top + totalOffset));
}
var resizeCallback = function() {
setElementSize();
};
windowResizeListener.register(resizeCallback);
//ensure to unregister from all events and kill jquery plugins
scope.$on('$destroy', function () {
windowResizeListener.unregister(resizeCallback);
});
};