Commit 2014c98d authored by Robert Knight's avatar Robert Knight

Fix client-side router on site

The JS for the group share page failed to load
because of an incorrect comparison of the result
of String.match() against a number and also
because of an attempt to load Bootstrap
unnecessarily on this pages.

This commit fixes the issue and prepares us for
adding new pages in future by:

 * Adding a client-side micro-router to simplify running
   page-specific JS

 * Only loading the Bootstrap components on pages that
   actually need it.

Fixes #2867
parent 315cfc6e
function ShareGroupFormController(element) { function ShareGroupFormController(element) {
if (!element.querySelector('.is-member-of-group')) {
return;
}
var shareLink = element.querySelector('.js-share-link'); var shareLink = element.querySelector('.js-share-link');
shareLink.focus(); shareLink.focus();
shareLink.select(); shareLink.select();
......
...@@ -3,32 +3,31 @@ if (window.RAVEN_CONFIG) { ...@@ -3,32 +3,31 @@ if (window.RAVEN_CONFIG) {
require('./raven').init(window.RAVEN_CONFIG); require('./raven').init(window.RAVEN_CONFIG);
} }
var page = require('page');
var CreateGroupFormController = require('./create-group-form'); var CreateGroupFormController = require('./create-group-form');
var DropdownMenuController = require('./dropdown-menu'); var DropdownMenuController = require('./dropdown-menu');
var InstallerController = require('./installer-controller'); var InstallerController = require('./installer-controller');
var ShareGroupFormController = require('./share-group-form'); var ShareGroupFormController = require('./share-group-form');
// load our customized version of Bootstrap which // setup components
// provides a few basic UI components (eg. modal dialogs) new DropdownMenuController(document);
require('../styles/vendor/bootstrap/bootstrap');
function setupGroupsController(path) { page('/', function () {
if (path === '/groups/new') { // load our customized version of Bootstrap which
// provides a few basic UI components (eg. modal dialogs)
require('../styles/vendor/bootstrap/bootstrap');
new InstallerController(document.body);
});
page('/groups/new', function () {
new CreateGroupFormController(document.body); new CreateGroupFormController(document.body);
} else if (document.querySelector('.is-member-of-group')) { });
page('/groups/:id/:name', function () {
new ShareGroupFormController(document.body); new ShareGroupFormController(document.body);
} });
}
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
// setup components page.start();
new DropdownMenuController(document);
// setup route
var route = document.location.pathname;
if (route === '/') {
new InstallerController(document.body);
} else if (route.match('^/groups') === 0) {
setupGroupsController(route);
}
}); });
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
"js-polyfills": "^0.1.11", "js-polyfills": "^0.1.11",
"ng-tags-input": "2.2.0", "ng-tags-input": "2.2.0",
"node-uuid": "^1.4.3", "node-uuid": "^1.4.3",
"page": "^1.6.4",
"postcss": "^5.0.6", "postcss": "^5.0.6",
"raf": "^3.1.0", "raf": "^3.1.0",
"raven-js": "^2.0.2", "raven-js": "^2.0.2",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment