Skip to content

Instantly share code, notes, and snippets.

@lgrz
Created September 2, 2010 07:52
Show Gist options
  • Save lgrz/562018 to your computer and use it in GitHub Desktop.
Save lgrz/562018 to your computer and use it in GitHub Desktop.
/*
* ShortCut
* Mini routing for jQuery
*/
(function($){
$.shortCut = function(settings){
var defaults = {
controller: false,
init: false,
element: $('body'),
attr: 'id'
};
settings = $.extend(defaults, settings);
if(!settings.controller || !settings.element.length){
return;
}
if(!$.isPlainObject(settings.controller)) {
return;
}
// Run the init function (called on every page load if set)
var init = settings.controller[settings.init];
if($.isFunction(init)){
init();
}
var key = settings.element.attr(settings.attr);
var func = settings.controller[key];
if(!$.isFunction(func)){
return;
}
func();
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment