Sha256: e6f9c457396043f03b31783ffda4beac511d5606e29c2c7bb6d13a845cb68620

Contents?: true

Size: 1.19 KB

Versions: 44

Compression:

Stored size: 1.19 KB

Contents

var Router = (function () {

    "use strict";

    var routes = [];

    function addRoute(route, handler) {

        routes.push({parts: route.split('/'), handler: handler});
    }

    function load(route) {
        window.location.hash = route;
    }

    function start() {

        var path = window.location.hash.substr(1),
            parts = path.split('/'),
            partsLength = parts.length;

        for (var i = 0; i < routes.length; i++) {
            var route = routes[i];
            if (route.parts.length === partsLength) {
                var params = [];
                for (var j = 0; j < partsLength; j++) {
                    if (route.parts[j].substr(0, 1) === ':') {
                        params.push(parts[j]);
                    } else if (route.parts[j] !== parts[j]) {
                        break;
                    }
                }
                if (j === partsLength) {
                    route.handler.apply(undefined, params);
                    return;
                }
            }
        }
    }

    window.onhashchange = start;

    return {
        addRoute: addRoute,
        load: load,
        start: start
    };

}());

module.exports = Router;

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
nutella_framework-0.7.3 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.7.2 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.7.1 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.7.0 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.21 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.20 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.19 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.18 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.17 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.16 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.15 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.13 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.12 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.11 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.10 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.9 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.8 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.7 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.6 framework_components/roomcast-channel-creator/src/app/components/Router.js
nutella_framework-0.6.5 framework_components/roomcast-channel-creator/src/app/components/Router.js