Advertisement
Guest User

app.component.ts

a guest
Apr 26th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component } from '@angular/core';
  2. import { animate, style, state, transition, trigger } from '@angular/animations';
  3. import { Router, NavigationEnd } from '@angular/router';
  4. import { StaticService } from './services/static.service';
  5.  
  6. @Component({
  7.     selector: 'test-app',
  8.     templateUrl: './app.component.html',
  9.     styleUrls: ['./app.component.scss'],
  10.     host: {'(window:scroll)': 'fixedMenuToggle($event)'},
  11.     animations: [
  12.         trigger('enterAnimation', [
  13.             state('false', style({ opacity: 1 })),
  14.             state('true', style({ opacity: 1 })),
  15.             transition('0 => 1', [style({opacity: 0}) ,animate('.2s', style({opacity: 1}))] )
  16.         ])
  17.     ]
  18. })
  19.  
  20. export class AppComponent {
  21.  
  22.     fixedMenu: boolean;
  23.     menuStatus: boolean;
  24.     menuChange: boolean;
  25.     userLanguage: string;
  26.  
  27.     constructor(private local: StaticService, private router: Router){
  28.  
  29.         this.fixedMenu = false;
  30.  
  31.         router.events.forEach((event) => {
  32.             if(event instanceof NavigationEnd) {
  33.  
  34.                 this.local.mobileMenu = false;
  35.  
  36.                 if(this.router.url.indexOf('/main') < 0){
  37.                     this.local.summonerData = false;
  38.                     this.local.summonerLoading = false;
  39.                     this.menuChange = false;
  40.                 } else {
  41.                     this.menuChange = true;
  42.                 }
  43.  
  44.                 if(this.router.url == "/" || this.router.url == "/search"){
  45.                     this.menuStatus = false;
  46.                 } else {
  47.                     this.menuStatus = true;
  48.                 }
  49.             }
  50.         });
  51.  
  52.         if(navigator.language){
  53.             if(navigator.language.indexOf('-') > 0){
  54.                 this.userLanguage = navigator.language.split('-')[0];
  55.             }else{
  56.                 this.userLanguage = navigator.language;
  57.             }
  58.         }else{
  59.             this.userLanguage = 'en';
  60.         }
  61.  
  62.         // First Language Set
  63.         if(!this.local.getLanguage()){
  64.             this.local.setLanguage(this.userLanguage);
  65.         }
  66.  
  67.         // First Region Set
  68.         if(this.userLanguage){
  69.             var languageToRegion = this.local.languageToRegion();
  70.  
  71.             for(var lang in languageToRegion){
  72.                 if(languageToRegion[lang].lang == this.userLanguage && !this.local.getRegion()){
  73.                     this.local.setRegion(languageToRegion[lang].region);
  74.                 }
  75.             }
  76.         }
  77.  
  78.     }
  79.  
  80.     fixedMenuToggle(event) {
  81.         this.local.mobileMenu = false;
  82.         if(window.pageYOffset > 110){
  83.             this.fixedMenu = true;
  84.         } else {
  85.             this.fixedMenu = false;
  86.         }
  87.         //console.debug("Scroll Event", window.pageYOffset );
  88.     }
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement