1
0
Fork 0
fgdata/webgui/topics/SubtopicViewmodel.js
Torsten Dreyer 4d94d42ff6 Phi: hash based single page navigation and Map tuning
with this patch, navigation with the browsers forward/backward buttons
is supported within topics and subtopics as well as deep linking into
topics using hashed urls like /gui/#Map or /gui/#Environment/Weather

Also, slightly rename map overlay layers
2015-03-04 12:16:17 +01:00

34 lines
948 B
JavaScript

(function(factory) {
if (typeof define === "function" && define.amd) {
// AMD. Register as an anonymous module.
define(['knockout'], factory);
} else {
// Browser globals
factory(ko);
}
}(function(ko) {
function SubtopicViewModel(topics, prefix, params) {
var self = this;
self.topics = topics;
self.selectedTopic = ko.observable();
self.selectedComponent = ko.pureComputed(function() {
return prefix + "/" + self.selectedTopic();
});
self.selectTopic = function(topic) {
location.hash = prefix + "/" + topic;
self.selectedTopic(topic);
}
var topic = (params && params.topic) ? ko.unwrap(params.topic) : self.topics[0];
if( self.topics.indexOf(topic) == -1 )
topic = self.topics[0];
self.selectTopic(topic);
}
return SubtopicViewModel;
}));