Created
September 2, 2010 07:52
-
-
Save lgrz/562018 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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