2015-07-15 12:30:11 +08:00
|
|
|
/*global FastClick*/
|
|
|
|
|
|
|
|
import ScrollListener from 'flarum/utils/ScrollListener';
|
|
|
|
import Pane from 'flarum/utils/Pane';
|
|
|
|
import Drawer from 'flarum/utils/Drawer';
|
|
|
|
import mapRoutes from 'flarum/utils/mapRoutes';
|
|
|
|
|
|
|
|
import Navigation from 'flarum/components/Navigation';
|
|
|
|
import HeaderPrimary from 'flarum/components/HeaderPrimary';
|
|
|
|
import HeaderSecondary from 'flarum/components/HeaderSecondary';
|
|
|
|
import FooterPrimary from 'flarum/components/FooterPrimary';
|
|
|
|
import FooterSecondary from 'flarum/components/FooterSecondary';
|
|
|
|
import Composer from 'flarum/components/Composer';
|
|
|
|
import ModalManager from 'flarum/components/ModalManager';
|
|
|
|
import Alerts from 'flarum/components/Alerts';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The `boot` initializer boots up the forum app. It initializes some app
|
|
|
|
* globals, mounts components to the page, and begins routing.
|
|
|
|
*
|
|
|
|
* @param {ForumApp} app
|
|
|
|
*/
|
|
|
|
export default function boot(app) {
|
|
|
|
m.startComputation();
|
2015-04-25 20:58:39 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
m.mount(document.getElementById('page-navigation'), Navigation.component({className: 'back-control', drawer: true}));
|
|
|
|
m.mount(document.getElementById('header-navigation'), Navigation.component());
|
|
|
|
m.mount(document.getElementById('header-primary'), HeaderPrimary.component());
|
|
|
|
m.mount(document.getElementById('header-secondary'), HeaderSecondary.component());
|
|
|
|
m.mount(document.getElementById('footer-primary'), FooterPrimary.component());
|
|
|
|
m.mount(document.getElementById('footer-secondary'), FooterSecondary.component());
|
2015-04-25 20:58:39 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
app.pane = new Pane(document.getElementById('page'));
|
2015-06-24 10:14:53 +08:00
|
|
|
app.drawer = new Drawer();
|
2015-07-15 12:30:11 +08:00
|
|
|
app.composer = m.mount(document.getElementById('composer'), Composer.component());
|
|
|
|
app.modal = m.mount(document.getElementById('modal'), ModalManager.component());
|
|
|
|
app.alerts = m.mount(document.getElementById('alerts'), Alerts.component());
|
2015-06-18 16:11:37 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
m.route.mode = 'pathname';
|
|
|
|
m.route(document.getElementById('content'), '/', mapRoutes(app.routes));
|
2015-04-25 20:58:39 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
m.endComputation();
|
2015-05-11 09:33:40 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
// Route the home link back home when clicked. We do not want it to register
|
|
|
|
// if the user is opening it in a new tab, however.
|
2015-06-25 06:44:51 +08:00
|
|
|
$('#home-link').click(e => {
|
|
|
|
if (e.ctrlKey || e.metaKey || e.which === 2) return;
|
|
|
|
e.preventDefault();
|
|
|
|
app.history.home();
|
|
|
|
});
|
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
// Add a class to the body which indicates that the page has been scrolled
|
|
|
|
// down.
|
2015-04-25 20:58:39 +08:00
|
|
|
new ScrollListener(top => $('body').toggleClass('scrolled', top > 0)).start();
|
2015-06-18 16:11:37 +08:00
|
|
|
|
2015-07-15 12:30:11 +08:00
|
|
|
// Initialize FastClick, which makes links and buttons much more responsive on
|
|
|
|
// touch devices.
|
|
|
|
$(() => FastClick.attach(document.body));
|
2015-06-24 10:14:53 +08:00
|
|
|
|
2015-06-18 16:11:37 +08:00
|
|
|
app.booted = true;
|
2015-04-25 20:58:39 +08:00
|
|
|
}
|