suppress bg reloading on page change

pull/23/head
HardiReady 2018-01-21 11:38:54 +01:00
parent cdb63ba41b
commit 5943a40576
4 changed files with 21 additions and 15 deletions

View File

@ -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'});
}
}

View File

@ -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,8 +55,10 @@ export class ArmyMemberComponent {
};
ngOnDestroy() {
if (this.router.url !== '/' + RouteConfig.overviewPath) {
this.document.getElementById('right').setAttribute('style', '');
}
}
backToOverview() {
this.router.navigate([RouteConfig.overviewPath]);

View File

@ -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,8 +37,10 @@ export class ArmyComponent {
};
ngOnDestroy() {
if (this.router.url.includes(RouteConfig.overviewPath)) {
this.document.getElementById('right').setAttribute('style', '');
}
}
select(memberId) {
this.router.navigate([{outlets: {'right': ['member', memberId]}}], {relativeTo: this.route});

View File

@ -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;';
}
};