blob: 865149d4fbddc8a6556047034fb8e434128e5e7e [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) => {
Matteo Scandoloee655a12016-12-19 15:38:43 -080015 this.set(transtion.$to().name);
Matteo Scandolo5655bdc2016-12-16 08:32:15 -080016 });
17 }
18
19 get() {
20 return this.$window.document.title;
21 }
22
23 set(title: string) {
Matteo Scandoloee655a12016-12-19 15:38:43 -080024 this.$window.document.title = `${StyleConfig.projectName} - ${this.formatStateName(title)}`;
Matteo Scandolo5655bdc2016-12-16 08:32:15 -080025 }
26
27 private formatStateName(stateName: string): string {
28 // TODO pluralize and capitalize first letter only
Matteo Scandoloee655a12016-12-19 15:38:43 -080029 return stateName.replace('xos.', '').split('.').join(' > ');
Matteo Scandolo5655bdc2016-12-16 08:32:15 -080030 }
31}
32