2020-05-18 14:37:52 +02:00
|
|
|
/**
|
|
|
|
* The main component that renders single TabComponent
|
|
|
|
* instances.
|
|
|
|
*/
|
2022-04-06 16:01:25 +02:00
|
|
|
import {
|
|
|
|
AfterContentInit,
|
|
|
|
Component,
|
|
|
|
ContentChildren,
|
|
|
|
EventEmitter,
|
2022-04-08 17:26:27 +02:00
|
|
|
HostListener, Input,
|
2022-04-06 16:01:25 +02:00
|
|
|
Output,
|
|
|
|
QueryList,
|
|
|
|
} from '@angular/core';
|
2022-02-22 23:37:18 +01:00
|
|
|
import {TabComponent} from './tab.component';
|
2020-05-18 14:37:52 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-tabs',
|
2022-04-06 16:01:25 +02:00
|
|
|
template: `
|
2023-01-27 13:42:09 +01:00
|
|
|
<div id="mytabs" class="uk-grid uk-margin-top landing-tab uk-margin-remove-left">
|
|
|
|
<div class="uk-margin-medium-right uk uk-padding-remove uk-width-expand" >
|
2022-04-06 16:01:25 +02:00
|
|
|
<div class=" uk-width-1-1" uk-slider="finite: true">
|
|
|
|
<div class="uk-position-relative " >
|
|
|
|
<div class="uk-slider-container ">
|
|
|
|
<ul class=" uk-slider-items " style="flex-wrap: nowrap !important;" >
|
|
|
|
<ng-container *ngFor="let tab of tabs.toArray(); let i=index">
|
|
|
|
<ng-container *ngIf="!tab.customClass">
|
|
|
|
<li [ngClass]="tab.customClass" (click)="selectTab(tab)" >
|
|
|
|
<ul class="uk-tab">
|
2022-04-06 17:02:15 +02:00
|
|
|
<li [class.uk-active]="tab.active" [class.uk-disabled]="tab.disabled">
|
2022-04-06 16:01:25 +02:00
|
|
|
<a class="uk-width-1-1 uk-height-1-1 uk-flex uk-flex-center" [ngClass]="tab.tabIcon ? 'uk-flex-column' : ''">
|
|
|
|
<icon *ngIf="tab.tabIcon" [svg]="tab.tabIcon.svg" [ratio]="tab.tabIcon.ratio?tab.tabIcon.ratio:1" class="uk-margin-small-bottom"
|
|
|
|
[ngClass]="(selected === tab.tabId)?tab.tabIcon.active:null"></icon>
|
|
|
|
<div>{{tab.title}}</div>
|
2022-04-06 17:02:15 +02:00
|
|
|
<div *ngIf="tab.num && !tab.disabled" class="">({{tab.num | number}})</div>
|
|
|
|
<div *ngIf="tab.disabled" class="">(-)</div>
|
2022-04-06 16:01:25 +02:00
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</li>
|
|
|
|
</ng-container>
|
|
|
|
</ng-container>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div class="">
|
2022-07-17 15:01:39 +02:00
|
|
|
<a class="uk-position-center-left uk-blur-background" uk-slider-item="previous"><span uk-icon="chevron-left"></span></a>
|
|
|
|
<a class="uk-position-center-right uk-blur-background" uk-slider-item="next"><span uk-icon="chevron-right"></span></a>
|
2022-04-06 16:01:25 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-06 17:02:15 +02:00
|
|
|
<ng-container *ngFor="let tab of tabs.toArray(); let i=index">
|
|
|
|
<ng-container *ngIf="tab.customClass">
|
2023-01-27 13:42:09 +01:00
|
|
|
<div class="uk-width-small">
|
2023-07-06 15:29:17 +02:00
|
|
|
<ul class="uk-tab uk-height-1-1" [class.uk-flex-right]="tab.tabId == 'statistics'">
|
2022-04-06 16:01:25 +02:00
|
|
|
<li [ngClass]="tab.customClass" (click)="selectTab(tab)" [class.uk-active]="tab.active" >
|
2022-04-08 17:26:27 +02:00
|
|
|
<a class="uk-width-1-1 uk-height-1-1 uk-flex uk-flex-center featuredTab" [ngClass]="tab.tabIcon ? 'uk-flex-column' : ''">
|
|
|
|
<!--<icon *ngIf="tab.tabIcon" [svg]="tab.tabIcon.svg" [ratio]="tab.tabIcon.ratio?tab.tabIcon.ratio:1" class="uk-margin-small-bottom"
|
|
|
|
[ngClass]="(selected === tab.tabId)?tab.tabIcon.active:null"></icon>-->
|
|
|
|
<span *ngIf="tab.tabId=='statistics'" class="material-icons">bar_chart</span>
|
2022-04-06 17:02:15 +02:00
|
|
|
<div>{{tab.title}}</div>
|
2022-04-06 16:01:25 +02:00
|
|
|
<div *ngIf="tab.num" class="number">{{tab.num | number}}</div>
|
|
|
|
</a>
|
|
|
|
</li>
|
2022-04-06 17:02:15 +02:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</ng-container>
|
|
|
|
</ng-container>
|
2020-05-18 14:37:52 +02:00
|
|
|
</div>
|
2023-01-27 13:42:09 +01:00
|
|
|
`
|
2020-05-18 14:37:52 +02:00
|
|
|
})
|
2022-03-10 18:45:44 +01:00
|
|
|
export class TabsComponent implements AfterContentInit {
|
2022-04-06 16:01:25 +02:00
|
|
|
|
2022-02-22 23:37:18 +01:00
|
|
|
public customClass: string;
|
2020-05-18 14:37:52 +02:00
|
|
|
@ContentChildren(TabComponent) tabs: QueryList<TabComponent>;
|
|
|
|
@Output() public selectedActiveTab: EventEmitter<any> = new EventEmitter();
|
2022-04-20 16:40:18 +02:00
|
|
|
@Input() offsetForSticky:number=0;
|
2022-04-08 17:26:27 +02:00
|
|
|
@Input() isSticky:boolean;
|
|
|
|
@Output() isStickyChange :EventEmitter<boolean> = new EventEmitter();
|
2022-03-10 18:45:44 +01:00
|
|
|
public selected: string;
|
2022-04-06 16:01:25 +02:00
|
|
|
disableScroll = false;
|
|
|
|
@HostListener("window:scroll", [])
|
|
|
|
onWindowScroll() {
|
|
|
|
this.scroll();
|
|
|
|
}
|
2022-03-10 18:45:44 +01:00
|
|
|
ngAfterContentInit() {
|
|
|
|
if(this.tabs.length > 0) {
|
|
|
|
this.selected = this.tabs.get(0).tabId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-06 16:01:25 +02:00
|
|
|
selectTab(tab: TabComponent, scroll=true){
|
|
|
|
this.unSelectTab(this.selected, tab.tabId);
|
|
|
|
tab.active = true;
|
2022-03-10 18:45:44 +01:00
|
|
|
this.selected = tab.tabId;
|
2020-05-26 22:12:37 +02:00
|
|
|
this.selectedActiveTab.emit(tab.tabId);
|
2022-04-06 16:01:25 +02:00
|
|
|
if(scroll) {
|
|
|
|
this.disableScroll = true;
|
|
|
|
setTimeout(() => {
|
|
|
|
window.scrollTo({
|
2022-06-16 09:22:40 +02:00
|
|
|
top: document.getElementById(tab.tabId) ? document.getElementById(tab.tabId).offsetTop - (this.isSticky?250:180) : 250,
|
2022-04-06 16:01:25 +02:00
|
|
|
behavior: 'smooth'
|
|
|
|
});
|
|
|
|
setTimeout(() => {
|
|
|
|
this.disableScroll = false;
|
|
|
|
}, 600);
|
|
|
|
}, 200);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scroll(){
|
2022-04-08 17:26:27 +02:00
|
|
|
let tabDistanceFromCurrentViewTop = document.getElementById("main-tabs-div") ? document.getElementById("main-tabs-div").getBoundingClientRect().top : null;
|
2022-04-20 16:40:18 +02:00
|
|
|
if((tabDistanceFromCurrentViewTop <= this.offsetForSticky)){
|
2022-04-08 17:26:27 +02:00
|
|
|
this.isStickyChange.emit(true);
|
|
|
|
this.isSticky =true;
|
2022-04-20 16:40:18 +02:00
|
|
|
}else if(!(tabDistanceFromCurrentViewTop <= this.offsetForSticky)){
|
2022-04-08 17:26:27 +02:00
|
|
|
this.isStickyChange.emit(false);
|
|
|
|
this.isSticky =false;
|
|
|
|
}
|
2022-04-06 16:01:25 +02:00
|
|
|
if(this.disableScroll){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// console.log(window.scrollY)
|
|
|
|
let currentTabView = null;
|
|
|
|
let windowInnerHeight = window && window.innerHeight ? window.innerHeight : 300;
|
|
|
|
// console.log("find CT", windowInnerHeight)
|
|
|
|
for (let tab of this.tabs) {
|
|
|
|
|
|
|
|
let distanceFromCurrentViewTop = document.getElementById(tab.tabId) ? document.getElementById(tab.tabId).getBoundingClientRect().top : null;
|
|
|
|
// console.log(pos, distanceFromCurrentViewTop, windowInnerHeight/2);
|
|
|
|
if (distanceFromCurrentViewTop != null && distanceFromCurrentViewTop <= windowInnerHeight / 2) {
|
|
|
|
currentTabView = tab;
|
|
|
|
|
|
|
|
} else if (distanceFromCurrentViewTop != null && distanceFromCurrentViewTop > windowInnerHeight) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// console.log("current currentTabView", currentTabView.tabId)
|
|
|
|
if (currentTabView && this.selected != currentTabView.tabId) {
|
|
|
|
this.selectTab(currentTabView, false);
|
|
|
|
this.disableScroll =true;
|
|
|
|
setTimeout(() => {
|
|
|
|
this.disableScroll = false;
|
|
|
|
}, 600);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
unSelectTab(oldTabId, newTabId){
|
|
|
|
for (let tab of this.tabs) {
|
|
|
|
if(tab.tabId == oldTabId){
|
|
|
|
tab.active = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.selected = newTabId;
|
2020-05-26 22:12:37 +02:00
|
|
|
}
|
2020-05-18 14:37:52 +02:00
|
|
|
}
|