Commit 5f80a473 authored by Robert Knight's avatar Robert Knight

Simplify <excerpt> link function

Wrapping the init logic in `scope.$evalAsync()` used to be
necessary so that any code touching the '.excerpt' element
ran after that element had been transcluded into the DOM.

However, this is no longer necessary since all the init logic
now runs inside a `scope.$watch()` callback, which is invoked
after `ngIf` has inserted the '.excerpt' element into the DOM.
parent c7687b68
......@@ -69,38 +69,36 @@ function excerpt($timeout) {
return contentElem.scrollHeight > ctrl.collapsedHeight;
};
scope.$evalAsync(function () {
scope.$watch('vm.enabled()', function (isEnabled) {
if (isEnabled) {
contentElem = elem[0].querySelector('.excerpt');
// trigger a recalculation of ctrl.overflowing() and properties
// which depend upon it when embedded media loads.
//
// In future we might wish to trigger checking for other events
// outside of Angular's knowledge as well, eg. loading of embedded
// media
contentElem.addEventListener('load', checkForOverflowChange,
true /* capture. 'load' events do not bubble */);
updateContentMaxHeight();
} else {
contentElem = undefined;
}
});
scope.$watch('vm.collapse', function (isCollapsed) {
if (!contentElem) {
return;
}
scope.$watch('vm.enabled()', function (isEnabled) {
if (isEnabled) {
contentElem = elem[0].querySelector('.excerpt');
// trigger a recalculation of ctrl.overflowing() and properties
// which depend upon it when embedded media loads.
//
// In future we might wish to trigger checking for other events
// outside of Angular's knowledge as well, eg. loading of embedded
// media
contentElem.addEventListener('load', checkForOverflowChange,
true /* capture. 'load' events do not bubble */);
updateContentMaxHeight();
});
} else {
contentElem = undefined;
}
});
scope.$watch('vm.overflowing()', function () {
if (ctrl.onCollapsibleChanged) {
ctrl.onCollapsibleChanged({collapsible: ctrl.overflowing()});
}
});
scope.$watch('vm.collapse', function (isCollapsed) {
if (!contentElem) {
return;
}
updateContentMaxHeight();
});
scope.$watch('vm.overflowing()', function () {
if (ctrl.onCollapsibleChanged) {
ctrl.onCollapsibleChanged({collapsible: ctrl.overflowing()});
}
});
},
scope: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment