05a92f4389
Wrap sync callback for the resize event in a `$timeout` so that it gets called asyncronously. Fixes error where `$apply` was geting called before previous `$apply` call finished. Angular allows only one `$apply` call at a time. See Angular.js reference. > [Error: $rootScope:inprog](https://docs.angularjs.org/error/$rootScope/inprog) Fixes: > *Error* ldn/angular in O/< > error[$rootScope:inprog] http://errors.angularjs.org/1.5.3/$rootScope/inprog?p0=%24digest Likely fixes other errors we're seeing related to resize events such as > *ReferenceError<unknown module>* in onresize > Can't find variable: tree
24 lines
844 B
JavaScript
24 lines
844 B
JavaScript
/**
|
|
* Adds an onresize event attribute that gets invokved when the size of the window changes.
|
|
*/
|
|
angular.module('quay').directive('onresize', function ($window, $parse, $timeout) {
|
|
return function (scope, element, attr) {
|
|
var fn = $parse(attr.onresize);
|
|
|
|
var notifyResized = function() {
|
|
// Angular.js enforces only one call to $apply can run at a time.
|
|
// Use $timeout to make the scope update safe, even when called within another $apply block,
|
|
// by scheduling it on the call stack.
|
|
// See docs: https://docs.angularjs.org/error/$rootScope/inprog
|
|
$timeout(function () {
|
|
fn(scope);
|
|
}, 0);
|
|
};
|
|
|
|
angular.element($window).on('resize', null, notifyResized);
|
|
|
|
scope.$on('$destroy', function() {
|
|
angular.element($window).off('resize', null, notifyResized);
|
|
});
|
|
};
|
|
});
|