blob: 6f7e0c3a94d17dbf18011e90948567975328bd38 [file] [log] [blame]
Matteo Scandolo5655bdc2016-12-16 08:32:15 -08001import {StyleConfig} from '../../config/style.config';
2export interface IXosPageTitleService {
3 get(): string;
4 set(title: string): void;
5 formatStateName(stateName: string): string;
6}
7
8export class PageTitle {
9 static $inject = ['$window', '$transitions'];
10 constructor(
11 private $window: angular.IWindowService,
12 private $transitions: any // missing definition
13 ) {
14 console.log('page title');
15 this.$transitions.onSuccess({ to: '**' }, (transtion) => {
16 this.set(this.formatStateName(transtion.$to().name));
17 });
18 }
19
20 get() {
21 return this.$window.document.title;
22 }
23
24 set(title: string) {
25 this.$window.document.title = `${StyleConfig.projectName} - ${title}`;
26 }
27
28 private formatStateName(stateName: string): string {
29 // TODO pluralize and capitalize first letter only
30 return stateName.replace('xos.', '').toUpperCase();
31 }
32}
33