Change navbar to sticky only at top. Make page-content header sticky. Fix a bug in icons component
This commit is contained in:
parent
ca07367d23
commit
52f1abfdbf
|
@ -1,82 +1,45 @@
|
|||
import {
|
||||
AfterViewInit,
|
||||
ChangeDetectorRef,
|
||||
Component,
|
||||
ElementRef,
|
||||
HostListener,
|
||||
OnDestroy,
|
||||
ViewChild
|
||||
} from "@angular/core";
|
||||
import {Observable, Subscription} from "rxjs";
|
||||
import {distinctUntilChanged} from "rxjs/operators";
|
||||
import {ChangeDetectorRef, Component, HostListener, OnDestroy, OnInit} from "@angular/core";
|
||||
|
||||
@Component({
|
||||
selector: '[page-content]',
|
||||
template: `
|
||||
<div id="page_content">
|
||||
<div #header id="page_content_header" class="uk-container uk-container-large">
|
||||
<div #header id="page_content_header" uk-sticky="show-on-up: true; animation: uk-animation-slide-top; media: @m" [attr.offset]="offset">
|
||||
<div class="uk-container uk-container-large">
|
||||
<ng-content select="[header]"></ng-content>
|
||||
</div>
|
||||
<div id="page_content_inner" class="uk-section uk-container uk-container-large" [ngStyle]="{'margin-top.px': (height)?height.toString():'0'}">
|
||||
</div>
|
||||
<div id="page_content_inner" class="uk-section uk-container uk-container-large">
|
||||
<ng-content select="[inner]"></ng-content>
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
})
|
||||
export class PageContentComponent implements OnDestroy, AfterViewInit{
|
||||
public height = 0;
|
||||
private subscription: Subscription;
|
||||
@ViewChild('header') header: ElementRef;
|
||||
export class PageContentComponent implements OnInit, OnDestroy{
|
||||
private current;
|
||||
public offset: string;
|
||||
|
||||
constructor(private cdr: ChangeDetectorRef) {
|
||||
}
|
||||
|
||||
@HostListener('window:resize', ['$event'])
|
||||
onResize(event) {
|
||||
this.height = this.getHeight();
|
||||
@HostListener('window:scroll', ['$event.target']) // for window scroll events
|
||||
scroll(e) {
|
||||
let scroll = e.scrollingElement.scrollTop;
|
||||
if (scroll > this.current) {
|
||||
this.offset = '0';
|
||||
} else {
|
||||
this.offset = getComputedStyle(document.documentElement).getPropertyValue('--structure-header-height');
|
||||
}
|
||||
this.current = scroll;
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
|
||||
getHeight(): number{
|
||||
return this.header.nativeElement.offsetHeight;
|
||||
ngOnInit() {
|
||||
if(typeof window !== "undefined") {
|
||||
this.current = window.pageYOffset;
|
||||
}
|
||||
|
||||
setupHeightMutationObserver() {
|
||||
if (typeof document !== 'undefined') {
|
||||
const observable = new Observable<number>(observer => {
|
||||
const callback = (mutationsList, observer2) => {
|
||||
observer.next(this.getHeight());
|
||||
};
|
||||
|
||||
// Create an observer instance linked to the callback function
|
||||
const elementObserver = new MutationObserver(callback);
|
||||
|
||||
// Options for the observer (which mutations to observe)
|
||||
const config = {attributes: true, attributeFilter: ['class'], childList: true, subtree: true};
|
||||
// Start observing the target node for configured mutations
|
||||
elementObserver.observe(this.header.nativeElement, config);
|
||||
});
|
||||
|
||||
this.subscription = observable
|
||||
.pipe(
|
||||
distinctUntilChanged()//if the value hasn't changed, don't continue
|
||||
)
|
||||
.subscribe(newHeight => {
|
||||
this.height = this.getHeight();
|
||||
this.cdr.detectChanges();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.setupHeightMutationObserver();
|
||||
this.height = this.getHeight();
|
||||
this.cdr.detectChanges();
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
if(this.subscription) {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
[class.uk-open]="isTheActiveMenuItem(item)"
|
||||
[class.uk-parent]="item.items.length > 1">
|
||||
<a *ngIf="item.items.length <= 1" [routerLink]="(item.route)?item.route:null"
|
||||
[attr.uk-tooltip]="item.title"
|
||||
[title]="item.title"
|
||||
[queryParams]=item.params [queryParamsHandling]="queryParamsHandling">
|
||||
<div class="uk-grid uk-flex-middle uk-flex-center" uk-grid>
|
||||
<div *ngIf="item.icon" class="uk-width-auto">
|
||||
|
|
|
@ -1,20 +1,11 @@
|
|||
<div *ngIf="showMenu">
|
||||
<div *ngIf="(properties.environment =='beta' || properties.environment =='development') && showLogo && header.badge"
|
||||
class="uk-visible@m">
|
||||
<a [routerLink]="header.route" [href]="header.url"><img class="large-beta-indication"
|
||||
[src]="'assets/common-assets/'+(properties.environment =='beta'?'beta_flag.svg':'prototype_flag.svg')"
|
||||
alt="BETA" style="height: 104px; width: 104px ">
|
||||
</a>
|
||||
</div>
|
||||
<div class="tm-header-mobile uk-hidden@m">
|
||||
<nav class="uk-navbar-container uk-navbar" uk-navbar=""
|
||||
[class.uk-navbar-transparent]="header.stickyAnimation === false">
|
||||
<div *ngIf="(properties.environment =='beta' || properties.environment =='development') && showLogo && header.badge"
|
||||
class="uk-position-top-left">
|
||||
<img class="small-beta-indication"
|
||||
[src]="'assets/common-assets/'+(properties.environment =='beta'?'beta_flag.svg':'prototype_flag.svg')"
|
||||
alt="BETA" style="height: 60px; width: 60px ">
|
||||
<div class="uk-hidden@m">
|
||||
<div [ngClass]="portal + '-menu'">
|
||||
<div *ngIf="(properties.environment =='beta' || properties.environment =='development') && showLogo && header.badge">
|
||||
<img class="uk-position-top-left" [src]="'assets/common-assets/'+(properties.environment =='beta'?'beta_flag.svg':'prototype_flag.svg')"
|
||||
alt="BETA" style="height: 100px; width: 100px; z-index: 1000">
|
||||
</div>
|
||||
<nav class="uk-navbar-container uk-navbar" uk-navbar="">
|
||||
<div *ngIf="!onlyTop || userMenu" class="uk-navbar-left">
|
||||
<a *ngIf="!offCanvasFlip" class="uk-navbar-toggle" href="#tm-mobile" uk-toggle="" style="z-index:1000;">
|
||||
<div uk-navbar-toggle-icon="" class="uk-navbar-toggle-icon uk-icon custom-navbar-toggle-icon"></div>
|
||||
|
@ -31,8 +22,6 @@
|
|||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
<div *ngIf="specialAnnouncementContent" class="uk-hidden@m" [innerHTML]="specialAnnouncementContent">
|
||||
</div>
|
||||
<div #canvas id="tm-mobile" [attr.uk-offcanvas]="(offCanvasFlip?'flip:'+(offCanvasFlip + ';'):'') + 'overlay: true'"
|
||||
class="uk-offcanvas uk-hidden@m"
|
||||
style="z-index:9999;">
|
||||
|
@ -98,17 +87,14 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="specialAnnouncementContent" class="uk-visible@m" [innerHTML]="specialAnnouncementContent"></div>
|
||||
</div>
|
||||
<div class="uk-visible@m">
|
||||
<div [class]="'uk-sticky uk-navbar-transparent '+portal+'-menu'"
|
||||
uk-sticky="show-on-up: true" media="768" cls-active="uk-active uk-navbar-sticky"
|
||||
[attr.animation]="(header.stickyAnimation != false ?'uk-animation-slide-top':null)"
|
||||
top=".tm-header + [class*="uk-section"]" cls-inactive="uk-navbar-transparent" style="">
|
||||
<div
|
||||
*ngIf="(properties.environment =='beta' || properties.environment =='development') && showLogo && header.badge">
|
||||
<img class="beta-indication-sticky"
|
||||
[src]="'assets/common-assets/'+(properties.environment =='beta'?'beta_flag.svg':'prototype_flag.svg')"
|
||||
alt="BETA" style="height: 102px; width: 102px">
|
||||
<div class="uk-navbar-transparent" [ngClass]="portal + '-menu'"
|
||||
uk-sticky="show-on-up: true" media="@m" cls-active="uk-active uk-navbar-sticky" cls-inactive="uk-navbar-transparent"
|
||||
[attr.animation]="(header.stickyAnimation?'uk-animation-slide-top':null)">
|
||||
<div *ngIf="(properties.environment =='beta' || properties.environment =='development') && showLogo && header.badge">
|
||||
<img class="uk-position-top-left" [src]="'assets/common-assets/'+(properties.environment =='beta'?'beta_flag.svg':'prototype_flag.svg')"
|
||||
alt="BETA" style="height: 100px; width: 100px; z-index: 1000">
|
||||
</div>
|
||||
<nav class="uk-navbar uk-flex uk-navbar-container uk-padding-large uk-padding-remove-vertical" uk-navbar>
|
||||
<ng-container *ngIf="!onlyTop">
|
||||
|
|
|
@ -52,7 +52,6 @@ export class NavigationBarComponent implements OnInit, OnDestroy {
|
|||
subs: Subscription[] = [];
|
||||
showEntity = {};
|
||||
showPage = {};
|
||||
specialAnnouncementContent: string = null;
|
||||
|
||||
public additionalMenuItems: MenuItem[] = [];
|
||||
public featuredMenuItems: MenuItem[] = [];
|
||||
|
|
|
@ -123,11 +123,11 @@ export class IconsComponent implements AfterViewInit {
|
|||
ngAfterViewInit() {
|
||||
if(this.svg) {
|
||||
let svg: Element = this.icon.nativeElement.getElementsByTagName('svg').item(0);
|
||||
if(!this.defaultSize) {
|
||||
if(!this.defaultSize && svg) {
|
||||
svg.setAttribute("width", (this.ratio * IconsComponent.DEFAULT_ICON_SIZE).toString());
|
||||
svg.setAttribute("height", (this.ratio * IconsComponent.DEFAULT_ICON_SIZE).toString());
|
||||
}
|
||||
if(this.gradient) {
|
||||
if(this.gradient && svg) {
|
||||
this.addGradient(svg);
|
||||
} else {
|
||||
this.style = {
|
||||
|
|
Loading…
Reference in New Issue