1
0
mirror of https://github.com/flarum/core.git synced 2025-10-14 00:15:51 +02:00

Massive JavaScript cleanup

- Use JSX for templates
- Docblock/comment everything
- Mostly passes ESLint (still some work to do)
- Lots of renaming, refactoring, etc.

CSS hasn't been updated yet.
This commit is contained in:
Toby Zerner
2015-07-15 14:00:11 +09:30
parent 4480e0a83f
commit ab6c03c0cc
220 changed files with 9785 additions and 5919 deletions

View File

@@ -1,65 +1,61 @@
import ScrollListener from 'flarum/utils/scroll-listener';
import History from 'flarum/utils/history';
import Pane from 'flarum/utils/pane';
import Drawer from 'flarum/utils/drawer';
import mapRoutes from 'flarum/utils/map-routes';
/*global FastClick*/
import BackButton from 'flarum/components/back-button';
import HeaderPrimary from 'flarum/components/header-primary';
import HeaderSecondary from 'flarum/components/header-secondary';
import FooterPrimary from 'flarum/components/footer-primary';
import FooterSecondary from 'flarum/components/footer-secondary';
import Composer from 'flarum/components/composer';
import Modal from 'flarum/components/modal';
import Alerts from 'flarum/components/alerts';
import SearchBox from 'flarum/components/search-box';
import ScrollListener from 'flarum/utils/ScrollListener';
import Pane from 'flarum/utils/Pane';
import Drawer from 'flarum/utils/Drawer';
import mapRoutes from 'flarum/utils/mapRoutes';
export default function(app) {
var id = id => document.getElementById(id);
app.history = new History();
app.pane = new Pane(id('page'));
app.search = new SearchBox();
app.drawer = new Drawer();
app.cache = {};
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();
m.mount(id('back-control'), BackButton.component({ className: 'back-control', drawer: true }));
m.mount(id('back-button'), BackButton.component());
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());
$('.global-content').click(e => {
if ($('body').hasClass('drawer-open')) {
e.preventDefault();
$('body').removeClass('drawer-open');
}
});
app.pane = new Pane(document.getElementById('page'));
app.drawer = new Drawer();
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());
m.route.mode = 'pathname';
m.route(document.getElementById('content'), '/', mapRoutes(app.routes));
m.endComputation();
// 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.
$('#home-link').click(e => {
if (e.ctrlKey || e.metaKey || e.which === 2) return;
e.preventDefault();
app.history.home();
});
m.mount(id('header-primary'), HeaderPrimary.component());
m.mount(id('header-secondary'), HeaderSecondary.component());
m.mount(id('footer-primary'), FooterPrimary.component());
m.mount(id('footer-secondary'), FooterSecondary.component());
app.composer = m.mount(id('composer'), Composer.component());
app.modal = m.mount(id('modal'), Modal.component());
app.alerts = m.mount(id('alerts'), Alerts.component());
m.route.mode = 'pathname';
m.route(id('content'), '/', mapRoutes(app.routes));
m.endComputation();
// Add a class to the body which indicates that the page has been scrolled
// down.
new ScrollListener(top => $('body').toggleClass('scrolled', top > 0)).start();
$(function() {
FastClick.attach(document.body);
});
// Initialize FastClick, which makes links and buttons much more responsive on
// touch devices.
$(() => FastClick.attach(document.body));
app.booted = true;
}