diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/util/autoscale.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/util/autoscale.directive.js index 15e45654a5..029a4e420f 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/util/autoscale.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/util/autoscale.directive.js @@ -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); }); };