Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new anchors in my-settings and handle offset sub-menu height #3032

Merged
merged 5 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions client/src/app/+admin/admin.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ my-top-menu-dropdown {
}

@include sub-menu-h1;

::ng-deep .anchor {
top: #{-($header-height + $sub-menu-height + 20px)}; // offsetTop scrollToAnchor
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<h1 class="sr-only" i18n>Settings</h1>
<div class="form-row"> <!-- preview -->
<div class="anchor" id="top"></div> <!-- top anchor -->

<div class="form-group col-12 col-lg-4 col-xl-3"></div>

<div class="form-group form-group-right col-12 col-lg-8 col-xl-9">
Expand Down
4 changes: 4 additions & 0 deletions client/src/app/+my-account/my-account.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@

@include sub-menu-h1;
}

::ng-deep .anchor {
top: #{-($header-height + $sub-menu-height + 20px)}; // offsetTop scrollToAnchor
}
13 changes: 9 additions & 4 deletions client/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,17 @@ export class AppComponent implements OnInit, AfterViewInit {
const scrollEvent = eventsObs.pipe(filter((e: Event): e is Scroll => e instanceof Scroll))

scrollEvent.subscribe(e => {
if (e.position) {
return this.viewportScroller.scrollToPosition(e.position)
// scrollToAnchor first to preserve anchor position when using history navigation
if (e.anchor) {
setTimeout(() => {
this.viewportScroller.scrollToAnchor(e.anchor)
})

return
}

if (e.anchor) {
return this.viewportScroller.scrollToAnchor(e.anchor)
if (e.position) {
return this.viewportScroller.scrollToPosition(e.position)
}

if (resetScroll) {
Expand Down
8 changes: 4 additions & 4 deletions client/src/app/menu/menu.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<div class="dropdown-divider"></div>

<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" routerLink="/my-account">
<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" routerLink="/my-account/settings" fragment="top">
<my-global-icon iconName="user" aria-hidden="true"></my-global-icon> <ng-container i18n>Account settings</ng-container>
</a>

Expand All @@ -37,13 +37,13 @@
<span class="ml-auto text-muted">{{ language }}</span>
</a>

<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" routerLink="/my-account/settings" fragment="video-settings">
<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" routerLink="/my-account/settings" fragment="video-languages-subtitles">
<my-global-icon iconName="video-lang" aria-hidden="true"></my-global-icon>
<span i18n>Videos:</span>
<span class="ml-auto text-muted">{{ videoLanguages.join(', ') }}</span>
</a>

<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" routerLink="/my-account/settings" fragment="video-settings">
<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" routerLink="/my-account/settings" fragment="video-sensitive-content-policy">
<my-global-icon class="hover-display-toggle" [ngClass]="{ 'not-displayed': user.nsfwPolicy === 'display' }" iconName="sensitive" aria-hidden="true"></my-global-icon>
<my-global-icon class="hover-display-toggle" [ngClass]="{ 'not-displayed': user.nsfwPolicy !== 'display' }" iconName="unsensitive" aria-hidden="true"></my-global-icon>
<span i18n>Sensitive:</span>
Expand All @@ -56,7 +56,7 @@
<input type="checkbox" [checked]="user.webTorrentEnabled"/><label class="ml-auto" for="switch">Toggle p2p</label>
</a>

<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" routerLink="/my-account">
<a ngbDropdownItem ngbDropdownToggle class="dropdown-item" routerLink="/my-account/settings" fragment="top">
<my-global-icon iconName="more-horizontal" aria-hidden="true"></my-global-icon> <ng-container i18n>More account settings</ng-container>
</a>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<form role="form" (ngSubmit)="updateDetails()" [formGroup]="form">
<div class="form-group form-group-select">
<div class="anchor" id="video-sensitive-content-policy"></div> <!-- video-sensitive-content-policy anchor -->
<label i18n for="nsfwPolicy">Default policy on videos containing sensitive content</label>
<my-help>
<ng-template ptTemplate="customHtml">
Expand All @@ -20,6 +21,7 @@
</div>

<div class="form-group form-group-select">
<div class="anchor" id="video-languages-subtitles"></div> <!-- video-languages-subtitles anchor -->
<label i18n for="videoLanguages">Only display videos in the following languages/subtitles</label>
<my-help>
<ng-template ptTemplate="customHtml">
Expand Down
6 changes: 5 additions & 1 deletion client/src/sass/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ $assets-path: '../assets/';
display: none !important;
}

html {
scroll-behavior: smooth;
}

body {
/*** theme ***/
// now beware node-sass requires interpolation
Expand Down Expand Up @@ -298,7 +302,7 @@ table {

.anchor {
position: relative;
top: #{-($header-height + 20px)};
top: #{-($header-height + 20px)}; // offsetTop scrollToAnchor
}

@media screen and (max-width: #{breakpoint(xxl)}) {
Expand Down