From 3b75f01ccd5e8efc72d9d9aed65941625a57458e Mon Sep 17 00:00:00 2001 From: Nils Schneider Date: Sun, 5 Apr 2015 23:44:43 +0200 Subject: [PATCH] set document.title on router events --- lib/gui.js | 6 ++++-- lib/title.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 lib/title.js diff --git a/lib/gui.js b/lib/gui.js index 5c5376e..2439a99 100644 --- a/lib/gui.js +++ b/lib/gui.js @@ -1,8 +1,8 @@ define([ "chroma-js", "map", "sidebar", "tabs", "container", "meshstats", "linklist", "nodelist", "simplenodelist", "infobox/main", - "proportions", "forcegraph" ], + "proportions", "forcegraph", "title" ], function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Linklist, - Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph) { + Nodelist, SimpleNodelist, Infobox, Proportions, ForceGraph, Title) { return function (config, router) { var self = this var dataTargets = [] @@ -59,6 +59,7 @@ function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Linklist, } contentDiv.appendChild(buttonToggle) + var title = new Title(config) var infobox = new Infobox(config, sidebar, router) var tabs = new Tabs() var overview = new Container() @@ -86,6 +87,7 @@ function (chroma, Map, Sidebar, Tabs, Container, Meshstats, Linklist, tabs.add("Verbindungen", linklist) tabs.add("Statistiken", statistics) + router.addTarget(title) router.addTarget(infobox) addContent(Map) diff --git a/lib/title.js b/lib/title.js new file mode 100644 index 0000000..d285cbe --- /dev/null +++ b/lib/title.js @@ -0,0 +1,31 @@ +define(function () { + return function (config) { + function setTitle(d) { + var title = [config.siteName] + + if (d !== undefined) + title.push(d) + + document.title = title.join(": ") + } + + this.resetView = function () { + setTitle() + } + + this.gotoNode = function (d) { + if (d) + setTitle(d.nodeinfo.hostname) + } + + this.gotoLink = function (d) { + if (d) + setTitle(d.source.node.nodeinfo.hostname + " – " + d.target.node.nodeinfo.hostname) + } + + this.destroy = function () { + } + + return this + } +})