Created
March 21, 2018 22:13
-
-
Save craigsimps/fbb0c576f78da1d6e2de295114eb3357 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
/* ======================================================================== | |
* 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