Skip to content

Commit

Permalink
Fix jumping and stuck side menu
Browse files Browse the repository at this point in the history
  • Loading branch information
MisRob committed Dec 17, 2021
1 parent c6a6095 commit e90e7ef
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions kolibri/plugins/learn/assets/src/views/TopicsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<div v-else class="page">
<!-- Header with thumbail and tagline -->
<div v-if="!windowIsSmall" class="header">
<div v-if="!windowIsSmall" ref="header" class="header">
<KGrid>
<KGridItem
class="breadcrumbs"
Expand Down Expand Up @@ -237,6 +237,7 @@
v-if="!!windowIsLarge"
v-model="searchTerms"
:topicsListDisplayed="!desktopSearchActive"
class="side-panel"
topicPage="True"
:topics="topics"
:activeActivityButtons="activeActivityButtons"
Expand All @@ -248,10 +249,7 @@
:availableLabels="labels"
:showChannels="false"
position="embedded"
:style="{ position: 'fixed',
marginTop: stickyTop,
paddingTop: '24px',
paddingBottom: '200px' }"
:style="sidePanelStyleOverrides"
@currentCategory="handleShowSearchModal"
@loadMoreTopics="handleLoadMoreInTopic"
/>
Expand Down Expand Up @@ -427,7 +425,7 @@
},
data: function() {
return {
stickyTop: '388px',
sidePanelStyleOverrides: {},
currentViewStyle: 'card',
currentCategory: null,
showSearchModal: false,
Expand Down Expand Up @@ -659,21 +657,25 @@
option == 'search' ? (this.mobileSearchActive = true) : (this.mobileSearchActive = false);
this.sidePanelIsOpen = !this.sidePanelIsOpen;
},
// Stick the side panel to top. That can be on the very top of the viewport
// or right under the 'Browse channel' toolbar, depending on whether the toolbar
// is visible or no (the toolbar hides on smaller resolutions when scrolling
// down and appears again when scrolling up).
// Takes effect only when the side panel is not displayed full-screen.
stickyCalculation() {
let header = document.getElementsByClassName('header')[0];
let topbar = document.getElementsByClassName('ui-toolbar')[0];
if (header) {
let position = header.getBoundingClientRect();
let topbarPosition = topbar.getBoundingClientRect();
if (position.bottom >= 64) {
this.stickyTop = `${position.bottom}px`;
} else if (position.bottom < 0 && topbarPosition.bottom < 0) {
this.stickyTop = '0px';
} else {
this.stickyTop = '64px';
}
const header = this.$refs.header;
const topbar = document.querySelector('.scrolling-header');
const headerBottom = header ? header.getBoundingClientRect().bottom : 0;
const topbarBottom = topbar ? topbar.getBoundingClientRect().bottom : 0;
if (headerBottom < Math.max(topbarBottom, 0)) {
this.sidePanelStyleOverrides = {
position: 'fixed',
top: `${Math.max(0, headerBottom, topbarBottom)}px`,
height: '100%',
};
} else {
null;
this.sidePanelStyleOverrides = {};
}
},
handleShowMore(topicId) {
Expand Down Expand Up @@ -721,6 +723,8 @@

<style lang="scss" scoped>
$header-height: 324px;
.page {
position: relative;
overflow-x: hidden;
Expand All @@ -729,7 +733,7 @@
.header {
position: relative;
width: 100%;
height: 324px;
height: $header-height;
padding-top: 32px;
padding-bottom: 48px;
padding-left: 32px;
Expand All @@ -756,6 +760,13 @@
margin-bottom: 0;
}
.side-panel {
position: absolute;
top: $header-height;
height: calc(100% - #{$header-height});
padding-top: 16px;
}
.main-content-grid {
position: relative;
margin: 24px;
Expand Down

0 comments on commit e90e7ef

Please sign in to comment.