router doesn't require jQuery. use default params

This commit is contained in:
QWp6t
2016-07-16 10:02:03 -07:00
parent 34253864fa
commit 339cc8e01e
2 changed files with 10 additions and 19 deletions

View File

@@ -21,11 +21,11 @@ import 'bootstrap/dist/js/umd/popover.js';
// rename this variable, you will also need to rename the namespace below. // rename this variable, you will also need to rename the namespace below.
const routes = { const routes = {
// All pages // All pages
'common': Common, common: Common,
// Home page // Home page
'home': Home, home: Home,
// About us page, note the change from about-us to about_us. // About us page, note the change from about-us to about_us.
'about_us': About about_us: About
}; };
// Load Events // Load Events

View File

@@ -1,5 +1,3 @@
import $ from 'jquery';
/* ======================================================================== /* ========================================================================
* DOM-based Routing * DOM-based Routing
* Based on http://goo.gl/EUTi53 by Paul Irish * Based on http://goo.gl/EUTi53 by Paul Irish
@@ -15,14 +13,10 @@ export default class Router {
this.routes = routes; this.routes = routes;
} }
fire(func, funcname, args) { fire(route, fn = 'init', args) {
funcname = (funcname === undefined) ? 'init' : funcname; let fire = route !== '' && this.routes[route] && typeof this.routes[route][fn] === 'function';
let fire = func !== '';
fire = fire && this.routes[func];
fire = fire && typeof this.routes[func][funcname] === 'function';
if (fire) { if (fire) {
this.routes[func][funcname](args); this.routes[route][fn](args);
} }
} }
@@ -31,13 +25,10 @@ export default class Router {
this.fire('common'); this.fire('common');
// Fire page-specific init JS, and then finalize JS // Fire page-specific init JS, and then finalize JS
$.each( document.body.className.replace(/-/g, '_').split(/\s+/).forEach((className) => {
document.body.className.replace(/-/g, '_').split(/\s+/), this.fire(className);
(i, className) => { this.fire(className, 'finalize');
this.fire(className); });
this.fire(className, 'finalize');
}
);
// Fire common finalize JS // Fire common finalize JS
this.fire('common', 'finalize'); this.fire('common', 'finalize');