Skip to content

Commit

Permalink
router doesn't require jQuery. use default params
Browse files Browse the repository at this point in the history
  • Loading branch information
QWp6t committed Jul 16, 2016
1 parent 3425386 commit 339cc8e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
6 changes: 3 additions & 3 deletions assets/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 7 additions & 16 deletions assets/scripts/util/router.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import $ from 'jquery';

/* ========================================================================
* DOM-based Routing
* Based on http://goo.gl/EUTi53 by Paul Irish
Expand All @@ -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);
}
}

Expand All @@ -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');
Expand Down

0 comments on commit 339cc8e

Please sign in to comment.