Merge pull request #2762 from NoelDeMartin/MOBILE-3750
MOBILE-3750: Improve accessibility of horizontal scrollsmain
commit
972e1e2a81
|
@ -4224,6 +4224,12 @@
|
||||||
"integrity": "sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug==",
|
"integrity": "sha512-1HcDas8SEj4z1Wc696tH56G8OlRaH/sqZOynNNB+HF0WOeXPaxTtbYzJY2oEfiUxjSKjhCKr+MvR7dCHcEelug==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@types/resize-observer-browser": {
|
||||||
|
"version": "0.1.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/resize-observer-browser/-/resize-observer-browser-0.1.5.tgz",
|
||||||
|
"integrity": "sha512-8k/67Z95Goa6Lznuykxkfhq9YU3l1Qe6LNZmwde1u7802a3x8v44oq0j91DICclxatTr0rNnhXx7+VTIetSrSQ==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"@types/source-list-map": {
|
"@types/source-list-map": {
|
||||||
"version": "0.1.2",
|
"version": "0.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/source-list-map/-/source-list-map-0.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/source-list-map/-/source-list-map-0.1.2.tgz",
|
||||||
|
|
|
@ -140,6 +140,7 @@
|
||||||
"@ionic/v4-migration-tslint": "^1.7.1",
|
"@ionic/v4-migration-tslint": "^1.7.1",
|
||||||
"@types/faker": "^5.1.3",
|
"@types/faker": "^5.1.3",
|
||||||
"@types/node": "^12.12.64",
|
"@types/node": "^12.12.64",
|
||||||
|
"@types/resize-observer-browser": "^0.1.5",
|
||||||
"@types/webpack-env": "^1.16.0",
|
"@types/webpack-env": "^1.16.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
"@typescript-eslint/eslint-plugin": "^4.22.0",
|
||||||
"@typescript-eslint/parser": "^4.22.0",
|
"@typescript-eslint/parser": "^4.22.0",
|
||||||
|
|
|
@ -2038,6 +2038,8 @@
|
||||||
"core.save": "moodle",
|
"core.save": "moodle",
|
||||||
"core.savechanges": "assign",
|
"core.savechanges": "assign",
|
||||||
"core.scanqr": "local_moodlemobileapp",
|
"core.scanqr": "local_moodlemobileapp",
|
||||||
|
"core.scrollbackward": "local_moodlemobileapp",
|
||||||
|
"core.scrollforward": "local_moodlemobileapp",
|
||||||
"core.search": "moodle",
|
"core.search": "moodle",
|
||||||
"core.searching": "local_moodlemobileapp",
|
"core.searching": "local_moodlemobileapp",
|
||||||
"core.searchresults": "moodle",
|
"core.searchresults": "moodle",
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
<ion-label>
|
<ion-label>
|
||||||
<h2>{{ 'addon.block_recentlyaccessedcourses.pluginname' | translate }}</h2>
|
<h2>{{ 'addon.block_recentlyaccessedcourses.pluginname' | translate }}</h2>
|
||||||
</ion-label>
|
</ion-label>
|
||||||
<div *ngIf="downloadCoursesEnabled && downloadEnabled && courses && courses.length > 1" class="core-button-spinner" slot="end">
|
<div slot="end">
|
||||||
|
<div *ngIf="downloadCoursesEnabled && downloadEnabled && courses && courses.length > 1" class="core-button-spinner">
|
||||||
<ion-button *ngIf="prefetchCoursesData.icon && !prefetchCoursesData.loading" fill="clear" color="dark"
|
<ion-button *ngIf="prefetchCoursesData.icon && !prefetchCoursesData.loading" fill="clear" color="dark"
|
||||||
(click)="prefetchCourses()" [attr.aria-label]="'core.courses.downloadcourses' | translate">
|
(click)="prefetchCourses()" [attr.aria-label]="'core.courses.downloadcourses' | translate">
|
||||||
<ion-icon [name]="prefetchCoursesData.icon" slot="icon-only" aria-hidden="true"></ion-icon>
|
<ion-icon [name]="prefetchCoursesData.icon" slot="icon-only" aria-hidden="true"></ion-icon>
|
||||||
|
@ -14,15 +15,25 @@
|
||||||
</ion-badge>
|
</ion-badge>
|
||||||
<ion-spinner *ngIf="!prefetchCoursesData.icon || prefetchCoursesData.loading"></ion-spinner>
|
<ion-spinner *ngIf="!prefetchCoursesData.icon || prefetchCoursesData.loading"></ion-spinner>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<core-horizontal-scroll-controls #scrollControls [aria-controls]="scrollElementId">
|
||||||
|
</core-horizontal-scroll-controls>
|
||||||
|
</div>
|
||||||
</ion-item-divider>
|
</ion-item-divider>
|
||||||
<core-loading [hideUntil]="loaded" class="core-loading-center safe-area-page">
|
<core-loading [hideUntil]="loaded" class="core-loading-center safe-area-page">
|
||||||
<core-empty-box *ngIf="courses.length == 0" image="assets/img/icons/courses.svg" inline="true"
|
<core-empty-box *ngIf="courses.length == 0" image="assets/img/icons/courses.svg" inline="true"
|
||||||
[message]="'addon.block_recentlyaccessedcourses.nocourses' | translate"></core-empty-box>
|
[message]="'addon.block_recentlyaccessedcourses.nocourses' | translate"></core-empty-box>
|
||||||
<!-- List of courses. -->
|
<!-- List of courses. -->
|
||||||
<div class="core-horizontal-scroll">
|
<div
|
||||||
|
[id]="scrollElementId"
|
||||||
|
class="core-horizontal-scroll"
|
||||||
|
(scroll)="scrollControls.updateScrollPosition()"
|
||||||
|
>
|
||||||
|
<div (onResize)="scrollControls.updateScrollPosition()" class="flex-row">
|
||||||
<ng-container *ngFor="let course of courses">
|
<ng-container *ngFor="let course of courses">
|
||||||
<core-courses-course-progress [course]="course" class="core-recentlyaccessedcourses"
|
<core-courses-course-progress [course]="course" class="core-recentlyaccessedcourses"
|
||||||
[showDownload]="downloadCourseEnabled && downloadEnabled"></core-courses-course-progress>
|
[showDownload]="downloadCourseEnabled && downloadEnabled"></core-courses-course-progress>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
|
|
|
@ -46,6 +46,7 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
|
||||||
|
|
||||||
downloadCourseEnabled = false;
|
downloadCourseEnabled = false;
|
||||||
downloadCoursesEnabled = false;
|
downloadCoursesEnabled = false;
|
||||||
|
scrollElementId!: string;
|
||||||
|
|
||||||
protected prefetchIconsInitialized = false;
|
protected prefetchIconsInitialized = false;
|
||||||
protected isDestroyed = false;
|
protected isDestroyed = false;
|
||||||
|
@ -62,6 +63,10 @@ export class AddonBlockRecentlyAccessedCoursesComponent extends CoreBlockBaseCom
|
||||||
* Component being initialized.
|
* Component being initialized.
|
||||||
*/
|
*/
|
||||||
async ngOnInit(): Promise<void> {
|
async ngOnInit(): Promise<void> {
|
||||||
|
// Generate unique id for scroll element.
|
||||||
|
const scrollId = CoreUtils.getUniqueId('AddonBlockRecentlyAccessedCoursesComponent-Scroll');
|
||||||
|
|
||||||
|
this.scrollElementId = `addon-block-recentlyaccessedcourses-scroll-${scrollId}`;
|
||||||
|
|
||||||
// Refresh the enabled flags if enabled.
|
// Refresh the enabled flags if enabled.
|
||||||
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
|
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
|
||||||
|
|
|
@ -1,8 +1,18 @@
|
||||||
<ion-item-divider sticky="true">
|
<ion-item-divider sticky="true">
|
||||||
<ion-label><h2>{{ 'addon.block_recentlyaccesseditems.pluginname' | translate }}</h2></ion-label>
|
<ion-label><h2>{{ 'addon.block_recentlyaccesseditems.pluginname' | translate }}</h2></ion-label>
|
||||||
|
<div slot="end">
|
||||||
|
<core-horizontal-scroll-controls #scrollControls [aria-controls]="scrollElementId">
|
||||||
|
</core-horizontal-scroll-controls>
|
||||||
|
</div>
|
||||||
</ion-item-divider>
|
</ion-item-divider>
|
||||||
<core-loading [hideUntil]="loaded" class="core-loading-center safe-area-page">
|
<core-loading [hideUntil]="loaded" class="core-loading-center safe-area-page">
|
||||||
<div class="core-horizontal-scroll" *ngIf="items && items.length > 0">
|
<div
|
||||||
|
[id]="scrollElementId"
|
||||||
|
[hidden]="!items || items.length === 0"
|
||||||
|
class="core-horizontal-scroll"
|
||||||
|
(scroll)="scrollControls.updateScrollPosition()"
|
||||||
|
>
|
||||||
|
<div *ngIf="items" (onResize)="scrollControls.updateScrollPosition()" class="flex-row">
|
||||||
<div *ngFor="let item of items">
|
<div *ngFor="let item of items">
|
||||||
<ion-card>
|
<ion-card>
|
||||||
<ion-item class="core-course-module-handler item-media ion-text-wrap" detail="false" (click)="action($event, item)"
|
<ion-item class="core-course-module-handler item-media ion-text-wrap" detail="false" (click)="action($event, item)"
|
||||||
|
@ -24,6 +34,7 @@
|
||||||
</ion-card>
|
</ion-card>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<core-empty-box *ngIf="items.length <= 0" image="assets/img/icons/activities.svg" inline="true"
|
<core-empty-box *ngIf="items.length <= 0" image="assets/img/icons/activities.svg" inline="true"
|
||||||
[message]="'addon.block_recentlyaccesseditems.noitems' | translate"></core-empty-box>
|
[message]="'addon.block_recentlyaccesseditems.noitems' | translate"></core-empty-box>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
@import "~theme/globals";
|
@import "~theme/globals";
|
||||||
|
|
||||||
:host {
|
:host {
|
||||||
.core-horizontal-scroll > div {
|
.core-horizontal-scroll > div > div {
|
||||||
@include horizontal_scroll_item(80%, 250px, 300px);
|
@include horizontal_scroll_item(80%, 250px, 300px);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ import {
|
||||||
import { CoreTextUtils } from '@services/utils/text';
|
import { CoreTextUtils } from '@services/utils/text';
|
||||||
import { CoreDomUtils } from '@services/utils/dom';
|
import { CoreDomUtils } from '@services/utils/dom';
|
||||||
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
|
import { CoreContentLinksHelper } from '@features/contentlinks/services/contentlinks-helper';
|
||||||
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component to render a recently accessed items block.
|
* Component to render a recently accessed items block.
|
||||||
|
@ -34,6 +35,7 @@ import { CoreContentLinksHelper } from '@features/contentlinks/services/contentl
|
||||||
export class AddonBlockRecentlyAccessedItemsComponent extends CoreBlockBaseComponent implements OnInit {
|
export class AddonBlockRecentlyAccessedItemsComponent extends CoreBlockBaseComponent implements OnInit {
|
||||||
|
|
||||||
items: AddonBlockRecentlyAccessedItemsItem[] = [];
|
items: AddonBlockRecentlyAccessedItemsItem[] = [];
|
||||||
|
scrollElementId!: string;
|
||||||
|
|
||||||
protected fetchContentDefaultError = 'Error getting recently accessed items data.';
|
protected fetchContentDefaultError = 'Error getting recently accessed items data.';
|
||||||
|
|
||||||
|
@ -41,6 +43,18 @@ export class AddonBlockRecentlyAccessedItemsComponent extends CoreBlockBaseCompo
|
||||||
super('AddonBlockRecentlyAccessedItemsComponent');
|
super('AddonBlockRecentlyAccessedItemsComponent');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
async ngOnInit(): Promise<void> {
|
||||||
|
// Generate unique id for scroll element.
|
||||||
|
const scrollId = CoreUtils.getUniqueId('AddonBlockRecentlyAccessedItemsComponent-Scroll');
|
||||||
|
|
||||||
|
this.scrollElementId = `addon-block-recentlyaccesseditems-scroll-${scrollId}`;
|
||||||
|
|
||||||
|
super.ngOnInit();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform the invalidate content function.
|
* Perform the invalidate content function.
|
||||||
*
|
*
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
<ion-label>
|
<ion-label>
|
||||||
<h2>{{ 'addon.block_starredcourses.pluginname' | translate }}</h2>
|
<h2>{{ 'addon.block_starredcourses.pluginname' | translate }}</h2>
|
||||||
</ion-label>
|
</ion-label>
|
||||||
<div *ngIf="downloadCoursesEnabled && downloadEnabled && courses && courses.length > 1" class="core-button-spinner" slot="end">
|
<div slot="end">
|
||||||
|
<div *ngIf="downloadCoursesEnabled && downloadEnabled && courses && courses.length > 1" class="core-button-spinner">
|
||||||
<ion-button *ngIf="prefetchCoursesData.icon && !prefetchCoursesData.loading" fill="clear" color="dark"
|
<ion-button *ngIf="prefetchCoursesData.icon && !prefetchCoursesData.loading" fill="clear" color="dark"
|
||||||
(click)="prefetchCourses()" [attr.aria-label]="'core.courses.downloadcourses' | translate">
|
(click)="prefetchCourses()" [attr.aria-label]="'core.courses.downloadcourses' | translate">
|
||||||
<ion-icon [name]="prefetchCoursesData.icon" slot="icon-only" aria-hidden="true"></ion-icon>
|
<ion-icon [name]="prefetchCoursesData.icon" slot="icon-only" aria-hidden="true"></ion-icon>
|
||||||
|
@ -14,15 +15,26 @@
|
||||||
</ion-badge>
|
</ion-badge>
|
||||||
<ion-spinner *ngIf="!prefetchCoursesData.icon || prefetchCoursesData.loading"></ion-spinner>
|
<ion-spinner *ngIf="!prefetchCoursesData.icon || prefetchCoursesData.loading"></ion-spinner>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<core-horizontal-scroll-controls #scrollControls [aria-controls]="scrollElementId">
|
||||||
|
</core-horizontal-scroll-controls>
|
||||||
|
</div>
|
||||||
</ion-item-divider>
|
</ion-item-divider>
|
||||||
<core-loading [hideUntil]="loaded" class="core-loading-center safe-area-page">
|
<core-loading [hideUntil]="loaded" class="core-loading-center safe-area-page">
|
||||||
<core-empty-box *ngIf="courses.length == 0" image="assets/img/icons/courses.svg" inline="true"
|
<core-empty-box *ngIf="courses.length == 0" image="assets/img/icons/courses.svg" inline="true"
|
||||||
[message]="'addon.block_starredcourses.nocourses' | translate"></core-empty-box>
|
[message]="'addon.block_starredcourses.nocourses' | translate"></core-empty-box>
|
||||||
<!-- List of courses. -->
|
<!-- List of courses. -->
|
||||||
<div class="core-horizontal-scroll" *ngIf="courses.length > 0">
|
<div
|
||||||
|
[hidden]="courses.length === 0"
|
||||||
|
[id]="scrollElementId"
|
||||||
|
class="core-horizontal-scroll"
|
||||||
|
(scroll)="scrollControls.updateScrollPosition()"
|
||||||
|
>
|
||||||
|
<div (onResize)="scrollControls.updateScrollPosition()" class="flex-row">
|
||||||
<ng-container *ngFor="let course of courses">
|
<ng-container *ngFor="let course of courses">
|
||||||
<core-courses-course-progress [course]="course" class="core-block_starredcourses"
|
<core-courses-course-progress [course]="course" class="core-block_starredcourses"
|
||||||
[showDownload]="downloadCourseEnabled && downloadEnabled"></core-courses-course-progress>
|
[showDownload]="downloadCourseEnabled && downloadEnabled"></core-courses-course-progress>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</core-loading>
|
</core-loading>
|
||||||
|
|
|
@ -46,6 +46,7 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
|
||||||
|
|
||||||
downloadCourseEnabled = false;
|
downloadCourseEnabled = false;
|
||||||
downloadCoursesEnabled = false;
|
downloadCoursesEnabled = false;
|
||||||
|
scrollElementId!: string;
|
||||||
|
|
||||||
protected prefetchIconsInitialized = false;
|
protected prefetchIconsInitialized = false;
|
||||||
protected isDestroyed = false;
|
protected isDestroyed = false;
|
||||||
|
@ -62,6 +63,11 @@ export class AddonBlockStarredCoursesComponent extends CoreBlockBaseComponent im
|
||||||
* Component being initialized.
|
* Component being initialized.
|
||||||
*/
|
*/
|
||||||
async ngOnInit(): Promise<void> {
|
async ngOnInit(): Promise<void> {
|
||||||
|
// Generate unique id for scroll element.
|
||||||
|
const scrollId = CoreUtils.getUniqueId('AddonBlockStarredCoursesComponent-Scroll');
|
||||||
|
|
||||||
|
this.scrollElementId = `addon-block-starredcourses-scroll-${scrollId}`;
|
||||||
|
|
||||||
// Refresh the enabled flags if enabled.
|
// Refresh the enabled flags if enabled.
|
||||||
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
|
this.downloadCourseEnabled = !CoreCourses.isDownloadCourseDisabledInSite();
|
||||||
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
|
this.downloadCoursesEnabled = !CoreCourses.isDownloadCoursesDisabledInSite();
|
||||||
|
|
|
@ -57,6 +57,7 @@ import { CoreTimerComponent } from './timer/timer';
|
||||||
import { CoreUserAvatarComponent } from './user-avatar/user-avatar';
|
import { CoreUserAvatarComponent } from './user-avatar/user-avatar';
|
||||||
import { CoreComboboxComponent } from './combobox/combobox';
|
import { CoreComboboxComponent } from './combobox/combobox';
|
||||||
import { CoreSpacerComponent } from './spacer/spacer';
|
import { CoreSpacerComponent } from './spacer/spacer';
|
||||||
|
import { CoreHorizontalScrollControlsComponent } from './horizontal-scroll-controls/horizontal-scroll-controls';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -96,6 +97,7 @@ import { CoreSpacerComponent } from './spacer/spacer';
|
||||||
CoreUserAvatarComponent,
|
CoreUserAvatarComponent,
|
||||||
CoreComboboxComponent,
|
CoreComboboxComponent,
|
||||||
CoreSpacerComponent,
|
CoreSpacerComponent,
|
||||||
|
CoreHorizontalScrollControlsComponent,
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
|
@ -142,6 +144,7 @@ import { CoreSpacerComponent } from './spacer/spacer';
|
||||||
CoreUserAvatarComponent,
|
CoreUserAvatarComponent,
|
||||||
CoreComboboxComponent,
|
CoreComboboxComponent,
|
||||||
CoreSpacerComponent,
|
CoreSpacerComponent,
|
||||||
|
CoreHorizontalScrollControlsComponent,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class CoreComponentsModule {}
|
export class CoreComponentsModule {}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
<ion-button
|
||||||
|
fill="clear"
|
||||||
|
color="dark"
|
||||||
|
(click)="scroll('backward')"
|
||||||
|
[hidden]="scrollPosition === 'hidden'"
|
||||||
|
[disabled]="scrollPosition === 'start'"
|
||||||
|
[attr.aria-label]="'core.scrollbackward' | translate"
|
||||||
|
[attr.aria-controls]="targetId"
|
||||||
|
>
|
||||||
|
<ion-icon name="fas-caret-left" slot="icon-only" aria-hidden="true"></ion-icon>
|
||||||
|
</ion-button>
|
||||||
|
|
||||||
|
<ion-button
|
||||||
|
fill="clear"
|
||||||
|
color="dark"
|
||||||
|
(click)="scroll('forward')"
|
||||||
|
[hidden]="scrollPosition === 'hidden'"
|
||||||
|
[disabled]="scrollPosition === 'end'"
|
||||||
|
[attr.aria-label]="'core.scrollforward' | translate"
|
||||||
|
[attr.aria-controls]="targetId"
|
||||||
|
>
|
||||||
|
<ion-icon name="fas-caret-right" slot="icon-only" aria-hidden="true"></ion-icon>
|
||||||
|
</ion-button>
|
|
@ -0,0 +1,10 @@
|
||||||
|
:host {
|
||||||
|
--flex-row-direction: row;
|
||||||
|
|
||||||
|
display: flex;
|
||||||
|
flex-direction: var(--flex-row-direction);
|
||||||
|
}
|
||||||
|
|
||||||
|
:host-context([dir="rtl"]) {
|
||||||
|
--flex-row-direction: row-reverse;
|
||||||
|
}
|
|
@ -0,0 +1,106 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { Component, Input } from '@angular/core';
|
||||||
|
import { Platform } from '@singletons';
|
||||||
|
|
||||||
|
const enum ScrollPosition {
|
||||||
|
Start = 'start',
|
||||||
|
End = 'end',
|
||||||
|
Middle = 'middle',
|
||||||
|
Hidden = 'hidden',
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'core-horizontal-scroll-controls',
|
||||||
|
templateUrl: 'core-horizontal-scroll-controls.html',
|
||||||
|
styleUrls: ['./horizontal-scroll-controls.scss'],
|
||||||
|
})
|
||||||
|
export class CoreHorizontalScrollControlsComponent {
|
||||||
|
|
||||||
|
// eslint-disable-next-line @angular-eslint/no-input-rename
|
||||||
|
@Input('aria-controls') targetId?: string;
|
||||||
|
|
||||||
|
scrollPosition: ScrollPosition = ScrollPosition.Hidden;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get target element.
|
||||||
|
*/
|
||||||
|
private get target(): HTMLElement | null {
|
||||||
|
return this.targetId && document.getElementById(this.targetId) || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scroll the target in the given direction.
|
||||||
|
*
|
||||||
|
* @param direction Scroll direction.
|
||||||
|
*/
|
||||||
|
scroll(direction: 'forward' | 'backward'): void {
|
||||||
|
if (!this.target) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const leftDelta = direction === 'forward' ? this.target.clientWidth : -this.target.clientWidth;
|
||||||
|
const newScrollLeft = Math.max(
|
||||||
|
Math.min(
|
||||||
|
this.target.scrollLeft + leftDelta,
|
||||||
|
this.target.scrollWidth - this.target.clientWidth,
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
|
||||||
|
this.target.scrollBy({
|
||||||
|
left: leftDelta,
|
||||||
|
behavior: 'smooth',
|
||||||
|
});
|
||||||
|
|
||||||
|
this.updateScrollPosition(newScrollLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the current scroll position.
|
||||||
|
*/
|
||||||
|
updateScrollPosition(scrollLeft?: number): void {
|
||||||
|
this.scrollPosition = this.getScrollPosition(scrollLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current scroll position.
|
||||||
|
*
|
||||||
|
* @param scrollLeft Scroll left to use for reference in the calculations.
|
||||||
|
* @returns Scroll position.
|
||||||
|
*/
|
||||||
|
private getScrollPosition(scrollLeft?: number): ScrollPosition {
|
||||||
|
scrollLeft = scrollLeft ?? this.target?.scrollLeft ?? 0;
|
||||||
|
|
||||||
|
if (!this.target || this.target.scrollWidth <= this.target.clientWidth) {
|
||||||
|
return ScrollPosition.Hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scrollLeft === 0) {
|
||||||
|
return Platform.isRTL ? ScrollPosition.End : ScrollPosition.Start;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Platform.isRTL && this.target.scrollWidth - scrollLeft === this.target.clientWidth) {
|
||||||
|
return ScrollPosition.End;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Platform.isRTL && this.target.scrollWidth + scrollLeft === this.target.clientWidth) {
|
||||||
|
return ScrollPosition.Start;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ScrollPosition.Middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -25,6 +25,7 @@ import { CoreLongPressDirective } from './long-press';
|
||||||
import { CoreSupressEventsDirective } from './supress-events';
|
import { CoreSupressEventsDirective } from './supress-events';
|
||||||
import { CoreUserLinkDirective } from './user-link';
|
import { CoreUserLinkDirective } from './user-link';
|
||||||
import { CoreAriaButtonClickDirective } from './aria-button';
|
import { CoreAriaButtonClickDirective } from './aria-button';
|
||||||
|
import { CoreOnResizeDirective } from './on-resize';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -39,6 +40,7 @@ import { CoreAriaButtonClickDirective } from './aria-button';
|
||||||
CoreSupressEventsDirective,
|
CoreSupressEventsDirective,
|
||||||
CoreUserLinkDirective,
|
CoreUserLinkDirective,
|
||||||
CoreAriaButtonClickDirective,
|
CoreAriaButtonClickDirective,
|
||||||
|
CoreOnResizeDirective,
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
CoreAutoFocusDirective,
|
CoreAutoFocusDirective,
|
||||||
|
@ -52,6 +54,7 @@ import { CoreAriaButtonClickDirective } from './aria-button';
|
||||||
CoreSupressEventsDirective,
|
CoreSupressEventsDirective,
|
||||||
CoreUserLinkDirective,
|
CoreUserLinkDirective,
|
||||||
CoreAriaButtonClickDirective,
|
CoreAriaButtonClickDirective,
|
||||||
|
CoreOnResizeDirective,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class CoreDirectivesModule {}
|
export class CoreDirectivesModule {}
|
||||||
|
|
|
@ -0,0 +1,99 @@
|
||||||
|
// (C) Copyright 2015 Moodle Pty Ltd.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
import { Directive, ElementRef, OnInit, Output, EventEmitter, OnDestroy } from '@angular/core';
|
||||||
|
import { CoreUtils } from '@services/utils/utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Directive to listen for element resize events.
|
||||||
|
*/
|
||||||
|
@Directive({
|
||||||
|
selector: '[onResize]',
|
||||||
|
})
|
||||||
|
export class CoreOnResizeDirective implements OnInit, OnDestroy {
|
||||||
|
|
||||||
|
@Output() onResize = new EventEmitter();
|
||||||
|
|
||||||
|
private element: HTMLElement;
|
||||||
|
private resizeObserver?: ResizeObserver;
|
||||||
|
private mutationObserver?: MutationObserver;
|
||||||
|
|
||||||
|
constructor(element: ElementRef) {
|
||||||
|
this.element = element.nativeElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
ngOnInit(): void {
|
||||||
|
'ResizeObserver' in window
|
||||||
|
? this.watchResize()
|
||||||
|
: this.watchMutations();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
this.resizeObserver?.disconnect();
|
||||||
|
this.mutationObserver?.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch resize events.
|
||||||
|
*/
|
||||||
|
private watchResize(): void {
|
||||||
|
this.resizeObserver = new ResizeObserver(() => this.onResize.emit());
|
||||||
|
|
||||||
|
this.resizeObserver.observe(this.element);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Watch mutation events to detect resizing.
|
||||||
|
*/
|
||||||
|
private watchMutations(): void {
|
||||||
|
let size = this.getElementSize();
|
||||||
|
const onMutation = () => {
|
||||||
|
const newSize = this.getElementSize();
|
||||||
|
|
||||||
|
if (newSize.width !== size.width || newSize.height !== size.height) {
|
||||||
|
size = newSize;
|
||||||
|
|
||||||
|
this.onResize.emit();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Debounce 20ms to let mutations resolve before checking the new size.
|
||||||
|
this.mutationObserver = new MutationObserver(CoreUtils.debounce(onMutation, 20));
|
||||||
|
|
||||||
|
this.mutationObserver.observe(this.element, {
|
||||||
|
subtree: true,
|
||||||
|
childList: true,
|
||||||
|
characterData: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get element size.
|
||||||
|
*
|
||||||
|
* @returns Element size.
|
||||||
|
*/
|
||||||
|
private getElementSize(): { width: number; height: number } {
|
||||||
|
return {
|
||||||
|
width: this.element.clientWidth,
|
||||||
|
height: this.element.clientHeight,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -270,6 +270,8 @@
|
||||||
"sorry": "Sorry...",
|
"sorry": "Sorry...",
|
||||||
"sort": "Sort",
|
"sort": "Sort",
|
||||||
"sortby": "Sort by",
|
"sortby": "Sort by",
|
||||||
|
"scrollbackward": "Scroll backward",
|
||||||
|
"scrollforward": "Scroll forward",
|
||||||
"start": "Start",
|
"start": "Start",
|
||||||
"storingfiles": "Storing files",
|
"storingfiles": "Storing files",
|
||||||
"strftimedate": "%d %B %Y",
|
"strftimedate": "%d %B %Y",
|
||||||
|
|
|
@ -32,6 +32,10 @@
|
||||||
text-transform: none;
|
text-transform: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.flex { display: flex; }
|
||||||
|
.inline-block { display: inline-block; }
|
||||||
|
.block { display: block; }
|
||||||
|
|
||||||
.flex-row {
|
.flex-row {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
"cordova",
|
"cordova",
|
||||||
"dom-mediacapture-record",
|
"dom-mediacapture-record",
|
||||||
"node",
|
"node",
|
||||||
|
"resize-observer-browser",
|
||||||
"webpack-env"
|
"webpack-env"
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
"faker",
|
"faker",
|
||||||
"jest",
|
"jest",
|
||||||
"node",
|
"node",
|
||||||
|
"resize-observer-browser",
|
||||||
"webpack-env"
|
"webpack-env"
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
"dom-mediacapture-record",
|
"dom-mediacapture-record",
|
||||||
"faker",
|
"faker",
|
||||||
"jest",
|
"jest",
|
||||||
"node"
|
"node",
|
||||||
|
"resize-observer-browser"
|
||||||
],
|
],
|
||||||
"paths": {
|
"paths": {
|
||||||
"@addons/*": ["addons/*"],
|
"@addons/*": ["addons/*"],
|
||||||
|
|
Loading…
Reference in New Issue