Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/* ========================================================================
* DOM-based Routing
* Based on http://goo.gl/EUTi53 by Paul Irish
* ======================================================================== */
(function ($) {
var Whitespace = {
common: {
init: function () {
// Run everywhere.
},
finalize: function () {
// Run everywhere. Loaded last.
}
},
home: {
init: function () {
// Run on page with body class `home`.
}
},
code_snippets: {
init: function () {
// Run on page with body class `code-snippets` (change - to _)
}
}
};
var util = {
fire: function (func, funcname, args) {
var namespace = Whitespace;
funcname = (funcname === undefined) ? 'init' : funcname;
if (func !== '' && namespace[func] && typeof namespace[func][funcname] === 'function') {
namespace[func][funcname](args);
}
},
loadEvents: function () {
util.fire('common');
$.each(document.body.className.replace(/-/g, '_').split(/\s+/), function (i, classnm) {
util.fire(classnm);
});
util.fire('common', 'finalize');
}
};
$(document).ready(util.loadEvents);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.