2014-08-01 22:50:23 -04:00
|
|
|
(function () {
|
|
|
|
var Router = Backbone.Router.extend({
|
|
|
|
routes: {
|
|
|
|
"": "home", // #home
|
|
|
|
"explore/:section": "explore", // #explore/active
|
|
|
|
"maps/:id": "maps" // #maps/7
|
|
|
|
},
|
2014-08-06 10:09:01 -04:00
|
|
|
home: function () {
|
|
|
|
|
|
|
|
document.title = 'My Maps | Metamaps';
|
|
|
|
$('#cards').show();
|
|
|
|
},
|
2014-08-01 22:50:23 -04:00
|
|
|
explore: function (section) {
|
2014-08-06 10:09:01 -04:00
|
|
|
|
|
|
|
var capitalize = section.charAt(0).toUpperCase() + section.slice(1);
|
|
|
|
|
|
|
|
document.title = 'Explore ' + capitalize + ' Maps | Metamaps';
|
|
|
|
//$('#cards').hide();
|
2014-08-01 22:50:23 -04:00
|
|
|
},
|
|
|
|
maps: function (id) {
|
2014-08-06 10:09:01 -04:00
|
|
|
|
|
|
|
document.title = 'Map ' + id + ' | Metamaps';
|
|
|
|
$('#cards').hide();
|
2014-08-01 22:50:23 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Metamaps.Router = new Router();
|
|
|
|
Metamaps.Router.init = function () {
|
2014-08-06 10:09:01 -04:00
|
|
|
Backbone.history.start({
|
2014-08-01 22:50:23 -04:00
|
|
|
pushState: true,
|
2014-08-06 10:09:01 -04:00
|
|
|
root: '/'
|
2014-08-01 22:50:23 -04:00
|
|
|
});
|
|
|
|
console.log('router started');
|
|
|
|
$(document).on("click", "a:not([data-bypass])", function (evt) {
|
|
|
|
var href = {
|
|
|
|
prop: $(this).prop("href"),
|
|
|
|
attr: $(this).attr("href")
|
|
|
|
};
|
|
|
|
var root = location.protocol + "//" + location.host + Backbone.history.options.root;
|
2014-08-06 10:09:01 -04:00
|
|
|
|
|
|
|
if (href.prop && href.prop === root) href.attr = ""
|
|
|
|
|
2014-08-01 22:50:23 -04:00
|
|
|
if (href.prop && href.prop.slice(0, root.length) === root) {
|
|
|
|
evt.preventDefault();
|
|
|
|
Backbone.history.navigate(href.attr, true);
|
|
|
|
}
|
2014-08-06 10:09:01 -04:00
|
|
|
});
|
2014-08-01 22:50:23 -04:00
|
|
|
}
|
2014-08-02 13:49:51 -04:00
|
|
|
})();
|