aboutsummaryrefslogtreecommitdiff
path: root/public/javascripts/url.js
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2017-01-30 14:04:20 +0100
committerNoah Loomans <noahloomans@gmail.com>2017-01-30 14:04:20 +0100
commit25fbba2084a23fb62ab0e7fdf2dd47eadc28a967 (patch)
tree532293fef971164b21e3227955ff532668f850a1 /public/javascripts/url.js
parentacbdba98a7ab37e76c856cc751b78e2a974036b9 (diff)
Fix bugs in url update
- Document title doesn't update - Page crashes when going back to front page
Diffstat (limited to 'public/javascripts/url.js')
-rw-r--r--public/javascripts/url.js27
1 files changed, 24 insertions, 3 deletions
diff --git a/public/javascripts/url.js b/public/javascripts/url.js
index a5877c6..b856285 100644
--- a/public/javascripts/url.js
+++ b/public/javascripts/url.js
@@ -4,10 +4,31 @@ const EventEmitter = require('events')
const self = new EventEmitter()
+self._getPageTitle = function (selectedItem) {
+ if (selectedItem == null) {
+ return `Metis Rooster`
+ } else {
+ return `Metis Rooster - ${selectedItem.value}`
+ }
+}
+
+self._getPageURL = function (selectedItem) {
+ return `/${selectedItem.type}/${selectedItem.value}`
+}
+
+self.push = function (selectedItem, push) {
+ if (push == null) push = true
+ const pageTitle = self._getPageTitle(selectedItem)
+ const pageURL = self._getPageURL(selectedItem)
+ if (push) {
+ window.history.pushState(selectedItem, pageTitle, pageURL)
+ } else {
+ window.history.replaceState(selectedItem, pageTitle, pageURL)
+ }
+}
+
self.update = function (selectedItem) {
- const pageTitle = `Metis Rooster - ${selectedItem.value}`
- const pageUrl = `/${selectedItem.type}/${selectedItem.value}`
- window.history.pushState(selectedItem, pageTitle, pageUrl)
+ document.title = self._getPageTitle(selectedItem)
}
self.hasSelectedItem = function () {