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) { ...@@ -69,38 +69,36 @@ function excerpt($timeout) {
return contentElem.scrollHeight > ctrl.collapsedHeight; return contentElem.scrollHeight > ctrl.collapsedHeight;
}; };
scope.$evalAsync(function () { scope.$watch('vm.enabled()', function (isEnabled) {
scope.$watch('vm.enabled()', function (isEnabled) { if (isEnabled) {
if (isEnabled) { contentElem = elem[0].querySelector('.excerpt');
contentElem = elem[0].querySelector('.excerpt');
// trigger a recalculation of ctrl.overflowing() and properties
// trigger a recalculation of ctrl.overflowing() and properties // which depend upon it when embedded media loads.
// which depend upon it when embedded media loads. //
// // In future we might wish to trigger checking for other events
// In future we might wish to trigger checking for other events // outside of Angular's knowledge as well, eg. loading of embedded
// outside of Angular's knowledge as well, eg. loading of embedded // media
// media contentElem.addEventListener('load', checkForOverflowChange,
contentElem.addEventListener('load', checkForOverflowChange, true /* capture. 'load' events do not bubble */);
true /* capture. 'load' events do not bubble */);
updateContentMaxHeight();
} else {
contentElem = undefined;
}
});
scope.$watch('vm.collapse', function (isCollapsed) {
if (!contentElem) {
return;
}
updateContentMaxHeight(); updateContentMaxHeight();
}); } else {
contentElem = undefined;
}
});
scope.$watch('vm.overflowing()', function () { scope.$watch('vm.collapse', function (isCollapsed) {
if (ctrl.onCollapsibleChanged) { if (!contentElem) {
ctrl.onCollapsibleChanged({collapsible: ctrl.overflowing()}); return;
} }
}); updateContentMaxHeight();
});
scope.$watch('vm.overflowing()', function () {
if (ctrl.onCollapsibleChanged) {
ctrl.onCollapsibleChanged({collapsible: ctrl.overflowing()});
}
}); });
}, },
scope: { 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