From 339cc8e01e6171f7f6e1a385052c650ce3beda4c Mon Sep 17 00:00:00 2001 From: QWp6t Date: Sat, 16 Jul 2016 10:02:03 -0700 Subject: [PATCH] router doesn't require jQuery. use default params --- assets/scripts/main.js | 6 +++--- assets/scripts/util/router.js | 23 +++++++---------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/assets/scripts/main.js b/assets/scripts/main.js index bd72382..52c84d0 100644 --- a/assets/scripts/main.js +++ b/assets/scripts/main.js @@ -21,11 +21,11 @@ import 'bootstrap/dist/js/umd/popover.js'; // rename this variable, you will also need to rename the namespace below. const routes = { // All pages - 'common': Common, + common: Common, // Home page - 'home': Home, + home: Home, // About us page, note the change from about-us to about_us. - 'about_us': About + about_us: About }; // Load Events diff --git a/assets/scripts/util/router.js b/assets/scripts/util/router.js index c564633..7da8cb4 100644 --- a/assets/scripts/util/router.js +++ b/assets/scripts/util/router.js @@ -1,5 +1,3 @@ -import $ from 'jquery'; - /* ======================================================================== * DOM-based Routing * Based on http://goo.gl/EUTi53 by Paul Irish @@ -15,14 +13,10 @@ export default class Router { this.routes = routes; } - fire(func, funcname, args) { - funcname = (funcname === undefined) ? 'init' : funcname; - let fire = func !== ''; - fire = fire && this.routes[func]; - fire = fire && typeof this.routes[func][funcname] === 'function'; - + fire(route, fn = 'init', args) { + let fire = route !== '' && this.routes[route] && typeof this.routes[route][fn] === 'function'; if (fire) { - this.routes[func][funcname](args); + this.routes[route][fn](args); } } @@ -31,13 +25,10 @@ export default class Router { this.fire('common'); // Fire page-specific init JS, and then finalize JS - $.each( - document.body.className.replace(/-/g, '_').split(/\s+/), - (i, className) => { - this.fire(className); - this.fire(className, 'finalize'); - } - ); + document.body.className.replace(/-/g, '_').split(/\s+/).forEach((className) => { + this.fire(className); + this.fire(className, 'finalize'); + }); // Fire common finalize JS this.fire('common', 'finalize');