Last active
September 15, 2017 18:23
-
-
Save rob-gordon/4ea006f6e37a7a2d0d15bb7e09a5a226 to your computer and use it in GitHub Desktop.
clean dom-based routing es 6
This file contains hidden or 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
| /* ======================================================================== | |
| * 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); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make not related to jQuery, and make "more ES6"