mirror of
https://github.com/getredash/redash.git
synced 2026-05-13 16:01:20 -04:00
45 lines
877 B
JavaScript
45 lines
877 B
JavaScript
import { logger } from './utils';
|
|
|
|
function TitleService($rootScope) {
|
|
const Title = {
|
|
title: 'Redash',
|
|
set(newTitle) {
|
|
this.title = newTitle;
|
|
$rootScope.$broadcast('$titleChange');
|
|
},
|
|
get() {
|
|
return this.title;
|
|
},
|
|
};
|
|
|
|
return Title;
|
|
}
|
|
|
|
function title($rootScope, Title) {
|
|
return {
|
|
restrict: 'E',
|
|
link(scope, element) {
|
|
function updateTitle() {
|
|
const newTitle = Title.get();
|
|
logger('Updating title to: %s', newTitle);
|
|
element.text(newTitle);
|
|
}
|
|
|
|
$rootScope.$on('$routeChangeSuccess', (event, to) => {
|
|
if (to.title) {
|
|
Title.set(to.title);
|
|
}
|
|
});
|
|
$rootScope.$on('$titleChange', updateTitle);
|
|
},
|
|
};
|
|
}
|
|
|
|
export default function init(ngModule) {
|
|
ngModule
|
|
.factory('Title', TitleService)
|
|
.directive('title', title);
|
|
}
|
|
|
|
init.init = true;
|