# HG changeset patch # User Guido Berhoerster # Date 1542796747 -3600 # Node ID 49ec0da1e69849e1d4567efb624a5fa1cbdbfe28 # Parent b0827360b8e43655b336b3bb020999f610e52e57 Replace tab list scroll bar with scroll buttons diff -r b0827360b8e4 -r 49ec0da1e698 sidebar/images/scroll-arrow.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sidebar/images/scroll-arrow.svg Wed Nov 21 11:39:07 2018 +0100 @@ -0,0 +1,11 @@ + + + + diff -r b0827360b8e4 -r 49ec0da1e698 sidebar/js/tab-collection-manager.js --- a/sidebar/js/tab-collection-manager.js Mon Nov 19 17:26:17 2018 +0100 +++ b/sidebar/js/tab-collection-manager.js Wed Nov 21 11:39:07 2018 +0100 @@ -38,6 +38,8 @@ document.body.addEventListener('click', this); + window.addEventListener('optimizedResize', this); + this.isInitialized = true; } @@ -104,6 +106,7 @@ 'to tab collections'); this.tabCollectionsElement .prepend(this.createTabCollectionNode(tabCollection)); + this.handleResize(); } replaceTabCollection(tabCollection) { @@ -111,6 +114,7 @@ this.tabCollectionsElement.querySelector(`[data-tab-collection-uuid=` + `"${tabCollection.uuid}"]`) .replaceWith(this.createTabCollectionNode(tabCollection)); + this.handleResize(); } removeTabCollection(tabCollectionUuid) { @@ -158,6 +162,31 @@ this.sortTabCollections(); } + handleTabCollectionChanged(tabCollectionContainerElement) { + let tabsElement = tabCollectionContainerElement + .querySelector('.tab-collection-tabs'); + let scrollLeftElement = tabCollectionContainerElement + .querySelector('.scroll-left'); + let scrollRightElement = tabCollectionContainerElement + .querySelector('.scroll-right'); + if (tabsElement.scrollWidth > tabsElement.clientWidth) { + scrollLeftElement.classList.add('scroll-visible'); + scrollRightElement.classList.add('scroll-visible'); + } else { + scrollLeftElement.classList.remove('scroll-visible'); + scrollRightElement.classList.remove('scroll-visible'); + } + } + + handleResize() { + let tabCollectionContainerElements = + document.querySelectorAll('.tab-collection-tabs-container'); + for (let tabCollectionContainerElement of + tabCollectionContainerElements) { + this.handleTabCollectionChanged(tabCollectionContainerElement); + } + } + handleEvent(ev) { console.log('DOM event', ev); if (ev.type === 'click') { @@ -191,6 +220,19 @@ tabCollectionUuid, tabUuid }); + } else if (ev.target.classList.contains('tabs-scroll-button')) { + // scroll tab list + let tabsElement = ev.target + .closest('.tab-collection-tabs-container') + .querySelector('.tab-collection-tabs'); + if (ev.target.classList.contains('scroll-left')) { + tabsElement.scrollLeft = Math.max(tabsElement.scrollLeft - + tabsElement.clientWidth * .75, 0); + } else { + tabsElement.scrollLeft = Math.min(tabsElement.scrollLeft + + tabsElement.clientWidth * .75, + tabsElement.scrollLeftMax); + } } else { let tabItemElement = ev.target.closest('.tab-item'); if (tabItemElement !== null) { @@ -207,6 +249,9 @@ }); } } + } else if (ev.type === 'optimizedResize') { + // window has been resized + this.handleResize(); } } } @@ -219,5 +264,23 @@ return; } + function throttleResize(type, name, obj) { + obj = obj || window; + var isRunning = false; + var func = function() { + if (isRunning) { + return; + } + + isRunning = true; + requestAnimationFrame(function() { + obj.dispatchEvent(new CustomEvent(name)); + isRunning = false; + }); + }; + obj.addEventListener(type, func); + }; + throttleResize('resize', 'optimizedResize'); + tabManager = new TabManager(); }); diff -r b0827360b8e4 -r 49ec0da1e698 sidebar/style/tab-collection-manager.css --- a/sidebar/style/tab-collection-manager.css Mon Nov 19 17:26:17 2018 +0100 +++ b/sidebar/style/tab-collection-manager.css Wed Nov 21 11:39:07 2018 +0100 @@ -18,6 +18,14 @@ --font-size-body-20: 15px; --font-size-body-10: 13px; + --scroll-button-image-width: 24px; + --scroll-button-image-height: var(--scroll-button-image-width); + --scroll-button-padding: 4px; + --scroll-button-width: calc(2 * var(--scroll-button-padding) + + var(--scroll-button-image-width)); + --scroll-button-height: var(--scroll-button-width); + --scroll-button-highlight: var(--grey-90-a10); + --thumbnail-width: 224px; --thumbnail-height: 128px; --thumbnail-shadow: var(--box-shadow-border), 0 1px 4px var(--grey-90-a30); @@ -112,7 +120,6 @@ padding-left: 0; margin: 0; list-style: none; - overflow: auto; } .tab-collection-actions { @@ -146,8 +153,37 @@ text-decoration: underline; } +.tabs-scroll-button { + visibility: hidden; + position: absolute; + margin-top: calc(var(--remove-tab-overlap) + var(--thumbnail-height) / 2 - + var(--scroll-button-height) / 2); + width: var(--scroll-button-width); + height: var(--scroll-button-height); + background: url(../images/scroll-arrow.svg) + var(--scroll-button-padding)/var(--scroll-button-image-width) no-repeat + var(--scroll-button-highlight); + border-radius: 4px; + z-index: 999; + transition: visibility 300ms; +} + +.tab-collection-tabs-container:hover .tabs-scroll-button.scroll-visible { + visibility: visible; +} + +.tabs-scroll-button.scroll-left { + left: 0; +} + +.tabs-scroll-button.scroll-right { + transform: scaleX(-1); + right: 0; +} + .tab-collection-tabs { - margin: 4px 0 0 0; + overflow: hidden; + scroll-behavior: smooth; } .tab-item { diff -r b0827360b8e4 -r 49ec0da1e698 sidebar/tab-collection-manager.html --- a/sidebar/tab-collection-manager.html Mon Nov 19 17:26:17 2018 +0100 +++ b/sidebar/tab-collection-manager.html Wed Nov 21 11:39:07 2018 +0100 @@ -23,8 +23,12 @@
  • - +
    +
    +
    + +