Skip to content

Commit

Permalink
set and unset window title for details
Browse files Browse the repository at this point in the history
fixes #42
  • Loading branch information
davkal committed May 29, 2015
1 parent d82edf4 commit 215a1b4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
17 changes: 17 additions & 0 deletions client/app/scripts/components/node-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ const React = require('react');

const NodeDetailsTable = require('./node-details-table');
const NodeColorMixin = require('../mixins/node-color-mixin');
const TitleUtils = require('../utils/title-utils');

const NodeDetails = React.createClass({

mixins: [
NodeColorMixin
],

componentDidMount: function() {
this.updateTitle();
},

componentWillUnmount: function() {
TitleUtils.resetTitle();
},

render: function() {
const node = this.props.details;

Expand Down Expand Up @@ -36,6 +45,14 @@ const NodeDetails = React.createClass({
</div>
</div>
);
},

componentDidUpdate: function() {
this.updateTitle();
},

updateTitle: function() {
TitleUtils.setTitle(this.props.details && this.props.details.label_major);
}

});
Expand Down
20 changes: 20 additions & 0 deletions client/app/scripts/utils/title-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

const PREFIX = 'Weave Scope';
const SEPARATOR = ' - ';

function setDocumentTitle(title) {
if (title) {
document.title = [PREFIX, title].join(SEPARATOR);
} else {
document.title = PREFIX;
}
}

function resetDocumentTitle() {
setDocumentTitle(null);
}

module.exports = {
resetTitle: resetDocumentTitle,
setTitle: setDocumentTitle
};

0 comments on commit 215a1b4

Please sign in to comment.