blob: fb1e5a79a919d3b965e2dad3012819a8c21168c4 [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 ) {
Matteo Scandolo5655bdc2016-12-16 08:32:15 -080014 this.$transitions.onSuccess({ to: '**' }, (transtion) => {
15 this.set(this.formatStateName(transtion.$to().name));
16 });
17 }
18
19 get() {
20 return this.$window.document.title;
21 }
22
23 set(title: string) {
24 this.$window.document.title = `${StyleConfig.projectName} - ${title}`;
25 }
26
27 private formatStateName(stateName: string): string {
28 // TODO pluralize and capitalize first letter only
29 return stateName.replace('xos.', '').toUpperCase();
30 }
31}
32