Commit 835fcb5e authored by colemanw's avatar colemanw

Set CMS page title from Angular

parent 9bb4a96b
......@@ -3,9 +3,7 @@
<form name="crm-system-status" crm-ui-id-scope>
<div>
<h1>{{ts('Status Messages')}}</h1>
</div>
<h1 crm-ui-title>{{ts('CiviCRM System Status (%1)', {1: _.where(statuses, {is_visible: 1}).length})}}</h1>
<div id="crm-status-list" crm-ui-tab-set>
<div
......
/// crmUi: Sundry UI helpers
(function (angular, $, _) {
var uidCount = 0;
var uidCount = 0,
pageTitle = 'CiviCRM';
angular.module('crmUi', [])
......@@ -975,6 +976,33 @@
}
};
})
// Sets the one and only page title - uses CMS title if available
// WARNING: Use only once per route!
// Example: <h1 crm-ui-title>{{ts('Hello')}}</h1>
.directive('crmUiTitle', function($timeout) {
return {
link: function(scope, $el, attrs) {
function update() {
$timeout(function() {
var newTitle = $el.html();
document.title = $('title').html().replace(pageTitle, newTitle);
// If the CMS has already added title markup to the page, use it
$('h1').not('.crm-container h1').each(function() {
if (_.trim($(this).html()) === _.trim(pageTitle)) {
$(this).html(newTitle);
$el.hide();
}
});
pageTitle = newTitle;
});
}
scope.$watch(function() {return $el.html();}, update);
}
}
})
.run(function($rootScope, $location) {
/// Example: <button ng-click="goto('home')">Go home!</button>
$rootScope.goto = function(path) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment