Commit b3c373e2 authored by Robert Knight's avatar Robert Knight

Simplify logic for locating the scrollRoot element

Currently the app only ever has one `<thread-list>` instance, so
we can simplify the logic that gets the scroll root to just query for a
hard-coded selector.
parent 3a173f65
...@@ -82,7 +82,7 @@ describe('threadList', function () { ...@@ -82,7 +82,7 @@ describe('threadList', function () {
// Create a scrollable container for the `<thread-list>` so that scrolling // Create a scrollable container for the `<thread-list>` so that scrolling
// can be tested. // can be tested.
var parentEl = document.createElement('div'); var parentEl = document.createElement('div');
parentEl.classList.add('js-scrollable'); parentEl.classList.add('js-thread-list-scroll-root');
parentEl.style.overflow = 'scroll'; parentEl.style.overflow = 'scroll';
parentEl.style.height = '100px'; parentEl.style.height = '100px';
...@@ -213,15 +213,9 @@ describe('threadList', function () { ...@@ -213,15 +213,9 @@ describe('threadList', function () {
sinon.match(annotFixtures.annotation)); sinon.match(annotFixtures.annotation));
}); });
// See https://github.com/hypothesis/client/issues/341 it('uses the correct scroll root', function () {
it('finds correct scroll root if `window.getComputedStyle` fails', function () { createThreadList();
sinon.stub(window, 'getComputedStyle').returns(null);
var element = createThreadList();
element.scope.$digest();
var scrollRoot = fakeVirtualThread.options.scrollRoot; var scrollRoot = fakeVirtualThread.options.scrollRoot;
assert.isTrue(scrollRoot.classList.contains('js-scrollable')); assert.isTrue(scrollRoot.classList.contains('js-thread-list-scroll-root'));
window.getComputedStyle.restore();
}); });
}); });
...@@ -43,39 +43,6 @@ var virtualThreadOptions = { ...@@ -43,39 +43,6 @@ var virtualThreadOptions = {
}, },
}; };
/**
* Return true if the given element is scrollable.
*/
function isScrollable(el) {
// Check the computed style to see if this element is marked as scrollable.
var computedStyle = window.getComputedStyle(el);
if (computedStyle !== null && computedStyle.overflowY === 'scroll') {
return true;
}
// In Firefox, `getComputedStyle` may return `null` if `window` is inside a
// non-rendered (`display:none`) iframe. In this case, fall back to requiring
// the developer to annotate the element with a special class.
// See https://bugzilla.mozilla.org/show_bug.cgi?id=548397 and
// https://github.com/w3c/csswg-drafts/issues/572
return el.classList.contains('js-scrollable');
}
/**
* Return the closest ancestor of `el` which is scrollable.
*
* @param {Element} el
*/
function closestScrollableAncestor(el) {
var parentEl = el;
while (parentEl !== document.body) {
if (isScrollable(parentEl)) {
return parentEl;
}
parentEl = parentEl.parentElement;
}
return parentEl;
}
// @ngInject // @ngInject
function ThreadListController($element, $scope, VirtualThreadList) { function ThreadListController($element, $scope, VirtualThreadList) {
// `visibleThreads` keeps track of the subset of all threads matching the // `visibleThreads` keeps track of the subset of all threads matching the
...@@ -86,7 +53,12 @@ function ThreadListController($element, $scope, VirtualThreadList) { ...@@ -86,7 +53,12 @@ function ThreadListController($element, $scope, VirtualThreadList) {
// `scrollRoot` is the `Element` to scroll when scrolling a given thread into // `scrollRoot` is the `Element` to scroll when scrolling a given thread into
// view. // view.
this.scrollRoot = closestScrollableAncestor($element[0]); //
// For now there is only one `<thread-list>` instance in the whole
// application so we simply require the scroll root to be annotated with a
// specific class. A more generic mechanism was removed due to issues in
// Firefox. See https://github.com/hypothesis/client/issues/341
this.scrollRoot = document.querySelector('.js-thread-list-scroll-root');
var options = Object.assign({ var options = Object.assign({
scrollRoot: this.scrollRoot, scrollRoot: this.scrollRoot,
......
<div class="app-content-wrapper js-scrollable" h-branding="appBackgroundColor"> <div class="app-content-wrapper js-thread-list-scroll-root" h-branding="appBackgroundColor">
<top-bar <top-bar
auth="vm.auth" auth="vm.auth"
on-login="vm.login()" on-login="vm.login()"
......
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