Skip to content

Instantly share code, notes, and snippets.

@rob-gordon
Last active September 15, 2017 18:23
Show Gist options
  • Select an option

  • Save rob-gordon/4ea006f6e37a7a2d0d15bb7e09a5a226 to your computer and use it in GitHub Desktop.

Select an option

Save rob-gordon/4ea006f6e37a7a2d0d15bb7e09a5a226 to your computer and use it in GitHub Desktop.
clean dom-based routing es 6
/* ========================================================================
* Based on http://goo.gl/EUTi53 by Paul Irish
* ======================================================================== */
(function($) {
var Routes = {
common: {
init: () => {},
finalize: () => {}
},
home: {
init: () => {},
finalize: () => {}
},
about_us: {
init: () => {}
}
};
var UTIL = {
fire: function(func, funcname, args) {
var fire;
var namespace = Routes;
funcname = funcname === undefined ? "init" : funcname;
fire = func !== "";
fire = fire && namespace[func];
fire = fire && typeof namespace[func][funcname] === "function";
if (fire) {
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(classnm, "finalize");
}
);
UTIL.fire("common", "finalize");
}
};
$(document).ready(UTIL.loadEvents);
})(jQuery);
@rob-gordon
Copy link
Author

Make not related to jQuery, and make "more ES6"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment