client/js/router.js
author rougeronj
Wed, 03 Jun 2015 17:27:46 +0200
changeset 471 e0c7be5dc02c
child 473 6649d2d75a87
permissions -rw-r--r--
Add a router to handle fragment identifier Set up a listener of the router in the scene to update it Start Backbone.history (eventlistener of the router) when all the project is loaded Include router.js to all the test file

(function(root) {
    "use strict";
    
    var Backbone = root.Backbone;
    
    var Router = root.Rkns.Router = Backbone.Router.extend({
        routes: {
            '': 'index',
            '*params': 'setParams'
        },
        
        index: function(){
            this.params = {};
        },
        setParams: function (parameters) {
            var _this = this;
            this.params = {};
            
            parameters.split('&').forEach(function(param){
                _this.params[param.split('=')[0]] = param.split('=')[1] || null;
                _this.trigger(param.split('=')[0], param.split('=')[1]);
            });
            
        }  
    });

})(window);