Saturday, April 19, 2014

Hroute.js

Tiny helper to catch hash changes

Demo : http://jsfiddle.net/hasantayyar/Wq7PC/2/embedded/result/

hroute({
        '': function(){
            content.innerHTML = "default page";
        },
        'about': function(){
            content.innerHTML = "about page";
        },
        '^video\/(.*)': function(params){
            content.innerHTML = '<iframe width="100%" height="315" '+
            'src="https://www.youtube.com/embed/'+params[1]+
            '" frameborder="0" allowfullscreen></iframe>';
        } 
    },{
    default: function(){
        console.log("404/notfound/default action"); 
    }, 
    beforeAction: function(){
        console.log("before action");
    }
});

No comments: