Skip to content

Commit 339cc8e

Browse files
committed
router doesn't require jQuery. use default params
1 parent 3425386 commit 339cc8e

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

assets/scripts/main.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import 'bootstrap/dist/js/umd/popover.js';
2121
// rename this variable, you will also need to rename the namespace below.
2222
const routes = {
2323
// All pages
24-
'common': Common,
24+
common: Common,
2525
// Home page
26-
'home': Home,
26+
home: Home,
2727
// About us page, note the change from about-us to about_us.
28-
'about_us': About
28+
about_us: About
2929
};
3030

3131
// Load Events

assets/scripts/util/router.js

+7-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import $ from 'jquery';
2-
31
/* ========================================================================
42
* DOM-based Routing
53
* Based on http://goo.gl/EUTi53 by Paul Irish
@@ -15,14 +13,10 @@ export default class Router {
1513
this.routes = routes;
1614
}
1715

18-
fire(func, funcname, args) {
19-
funcname = (funcname === undefined) ? 'init' : funcname;
20-
let fire = func !== '';
21-
fire = fire && this.routes[func];
22-
fire = fire && typeof this.routes[func][funcname] === 'function';
23-
16+
fire(route, fn = 'init', args) {
17+
let fire = route !== '' && this.routes[route] && typeof this.routes[route][fn] === 'function';
2418
if (fire) {
25-
this.routes[func][funcname](args);
19+
this.routes[route][fn](args);
2620
}
2721
}
2822

@@ -31,13 +25,10 @@ export default class Router {
3125
this.fire('common');
3226

3327
// Fire page-specific init JS, and then finalize JS
34-
$.each(
35-
document.body.className.replace(/-/g, '_').split(/\s+/),
36-
(i, className) => {
37-
this.fire(className);
38-
this.fire(className, 'finalize');
39-
}
40-
);
28+
document.body.className.replace(/-/g, '_').split(/\s+/).forEach((className) => {
29+
this.fire(className);
30+
this.fire(className, 'finalize');
31+
});
4132

4233
// Fire common finalize JS
4334
this.fire('common', 'finalize');

0 commit comments

Comments
 (0)