blob: e3b8d42adc5ae91141e5ade9dae1290d32e749b9 [file] [log] [blame]
Matteo Scandolo828d1e82017-01-17 14:49:38 -08001import {IXosStyleConfig} from '../../../index';
Matteo Scandolo5655bdc2016-12-16 08:32:15 -08002export interface IXosPageTitleService {
3 get(): string;
4 set(title: string): void;
5 formatStateName(stateName: string): string;
6}
7
8export class PageTitle {
Matteo Scandolo828d1e82017-01-17 14:49:38 -08009 static $inject = ['$window', '$transitions', 'StyleConfig'];
Matteo Scandolo5655bdc2016-12-16 08:32:15 -080010 constructor(
11 private $window: angular.IWindowService,
Matteo Scandolo828d1e82017-01-17 14:49:38 -080012 private $transitions: any, // missing definition
13 private StyleConfig: IXosStyleConfig
Matteo Scandolo5655bdc2016-12-16 08:32:15 -080014 ) {
Matteo Scandolo5655bdc2016-12-16 08:32:15 -080015 this.$transitions.onSuccess({ to: '**' }, (transtion) => {
Matteo Scandoloee655a12016-12-19 15:38:43 -080016 this.set(transtion.$to().name);
Matteo Scandolo5655bdc2016-12-16 08:32:15 -080017 });
18 }
19
20 get() {
21 return this.$window.document.title;
22 }
23
24 set(title: string) {
Matteo Scandolo828d1e82017-01-17 14:49:38 -080025 this.$window.document.title = `${this.StyleConfig.projectName} - ${this.formatStateName(title)}`;
Matteo Scandolo5655bdc2016-12-16 08:32:15 -080026 }
27
28 private formatStateName(stateName: string): string {
29 // TODO pluralize and capitalize first letter only
Matteo Scandoloee655a12016-12-19 15:38:43 -080030 return stateName.replace('xos.', '').split('.').join(' > ');
Matteo Scandolo5655bdc2016-12-16 08:32:15 -080031 }
32}
33