{% load i18n %}
{% load ifsetting %}
{% ifsetting ENDORSEMENT_ENABLED %}
{% endifsetting %}
var tag = this;
function getRoutes(){
/* returns a list of all the possible routes for this tag */
return _.map(tag.tags.router.tags.route, 'opts.path');
}
function excludeEditor(routes){
/* exclude "editor" routes which are not really directly addressable */
var exported_routes = _.reject(routes, function(r){return _.includes(r, '*')});
/* Sometimes we have a situation such as 'results..', when this occurs we need to route to 'results' not 'results..' */
exported_routes = _.map(exported_routes, function(r){
if (r.substring(r.length-2) === '..'){
return r.substring(0, r.length-2)
}
return r;
})
return exported_routes;
}
tag.on('mount', function(){
(function setGlobalRoutes(w){
w.routeToTag = {
next: function(){
var routes = excludeEditor(getRoutes());
var currentPage = _.replace(location.hash, '#', '');
var currentRouteIndex = _.indexOf(routes, currentPage);
var routeTo = routes[currentRouteIndex+1] || routes[0];
route(routeTo);
}
}
})(window);
})