From 5943a40576d91261467b5f8fc953f4ac4da2302e Mon Sep 17 00:00:00 2001 From: HardiReady Date: Sun, 21 Jan 2018 11:38:54 +0100 Subject: [PATCH] suppress bg reloading on page change --- static/src/app/app.component.ts | 2 +- static/src/app/army/army-member.component.ts | 12 +++++------- static/src/app/army/army.component.ts | 13 ++++++------- static/src/app/global.helpers.ts | 9 +++++++++ 4 files changed, 21 insertions(+), 15 deletions(-) create mode 100644 static/src/app/global.helpers.ts diff --git a/static/src/app/app.component.ts b/static/src/app/app.component.ts index 21105b0..9df1f2f 100644 --- a/static/src/app/app.component.ts +++ b/static/src/app/app.component.ts @@ -30,7 +30,7 @@ export class AppComponent { } if (event instanceof NavigationEnd) { this.loading = false; - if (router.url.includes('overview')) { + if (router.url.includes(RouteConfig.overviewPath)) { window.scrollTo({left: 0, top: 0, behavior: 'smooth'}); } } diff --git a/static/src/app/army/army-member.component.ts b/static/src/app/army/army-member.component.ts index 5d45dc6..19b0f7b 100644 --- a/static/src/app/army/army-member.component.ts +++ b/static/src/app/army/army-member.component.ts @@ -7,6 +7,7 @@ import {RouteConfig} from "../app.config"; import {AwardingService} from "../services/army-management/awarding.service"; import {Fraction} from "../utils/fraction.enum"; import {DOCUMENT} from "@angular/common"; +import {CSSHelpers} from "../global.helpers"; @Component({ @@ -37,12 +38,7 @@ export class ArmyMemberComponent { ngOnInit() { // set background image css - const backgroundCss = ' background-image: url(../assets/bg.jpg);\n' + - ' background-size: cover;\n' + - ' background-attachment: fixed;\n' + - ' background-position: center;\n' + - ' background-repeat: no-repeat;'; - this.document.getElementById('right').setAttribute('style', backgroundCss); + this.document.getElementById('right').setAttribute('style', CSSHelpers.getBackgroundCSS('../assets/bg.jpg')); this.subscription = this.route.params .map(params => params['id']) @@ -59,7 +55,9 @@ export class ArmyMemberComponent { }; ngOnDestroy() { - this.document.getElementById('right').setAttribute('style', ''); + if (this.router.url !== '/' + RouteConfig.overviewPath) { + this.document.getElementById('right').setAttribute('style', ''); + } } backToOverview() { diff --git a/static/src/app/army/army.component.ts b/static/src/app/army/army.component.ts index a7e100f..069b6d2 100644 --- a/static/src/app/army/army.component.ts +++ b/static/src/app/army/army.component.ts @@ -4,6 +4,8 @@ import {ArmyService} from "../services/army-service/army.service"; import {ActivatedRoute, Router} from "@angular/router"; import {Fraction} from "../utils/fraction.enum"; import {DOCUMENT} from "@angular/common"; +import {RouteConfig} from "../app.config"; +import {CSSHelpers} from "../global.helpers"; @Component({ @@ -25,12 +27,7 @@ export class ArmyComponent { ngOnInit() { // set background image css - const backgroundCss = ' background-image: url(../assets/bg.jpg);\n' + - ' background-size: cover;\n' + - ' background-attachment: fixed;\n' + - ' background-position: center;\n' + - ' background-repeat: no-repeat;'; - this.document.getElementById('right').setAttribute('style', backgroundCss); + this.document.getElementById('right').setAttribute('style', CSSHelpers.getBackgroundCSS('../assets/bg.jpg')); // init army data this.armyService.getArmy() @@ -40,7 +37,9 @@ export class ArmyComponent { }; ngOnDestroy() { - this.document.getElementById('right').setAttribute('style', ''); + if (this.router.url.includes(RouteConfig.overviewPath)) { + this.document.getElementById('right').setAttribute('style', ''); + } } select(memberId) { diff --git a/static/src/app/global.helpers.ts b/static/src/app/global.helpers.ts new file mode 100644 index 0000000..4bd3346 --- /dev/null +++ b/static/src/app/global.helpers.ts @@ -0,0 +1,9 @@ +export const CSSHelpers = { + getBackgroundCSS: (imageUrl) => { + return 'background-image: url(' + imageUrl + ');' + + 'background-size: cover;' + + 'background-attachment: fixed;' + + 'background-position: center;' + + 'background-repeat: no-repeat;'; + } +}; -- 2.25.1