Commit 8cc87e4a authored by Robert Knight's avatar Robert Knight

Re-enable client-side handling of the Via link

This avoids a redirect in the common case that JS is
available and has loaded.

 * Refactor the controller setup for the home route
   to be consistent with how it is handled for other pages.
parent 85ba902e
...@@ -29,6 +29,16 @@ function showSupportedInstallers(rootElement) { ...@@ -29,6 +29,16 @@ function showSupportedInstallers(rootElement) {
showIf('.js-install-any', offerChromeInstall || offerBookmarkletInstall); showIf('.js-install-any', offerChromeInstall || offerBookmarkletInstall);
} }
module.exports = { function InstallerController(element) {
showSupportedInstallers: showSupportedInstallers, showSupportedInstallers(element);
};
// setup Via link form
var proxyForm = document.querySelector('.js-proxy-form');
proxyForm.addEventListener('submit', function (event) {
event.preventDefault();
var url = proxyForm.elements['url'].value;
window.location.href = 'https://via.hypothes.is/' + url;
});
}
module.exports = InstallerController;
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 ShareGroupFormController = require('./share-group-form'); var ShareGroupFormController = require('./share-group-form');
var installerController = require('./installer-controller');
// load our customized version of Bootstrap which // load our customized version of Bootstrap which
// provides a few basic UI components (eg. modal dialogs) // provides a few basic UI components (eg. modal dialogs)
require('../styles/vendor/bootstrap/bootstrap'); require('../styles/vendor/bootstrap/bootstrap');
...@@ -23,7 +22,7 @@ document.addEventListener('DOMContentLoaded', function () { ...@@ -23,7 +22,7 @@ document.addEventListener('DOMContentLoaded', function () {
// setup route // setup route
var route = document.location.pathname; var route = document.location.pathname;
if (route.match('^/(new-homepage)?$')) { if (route.match('^/(new-homepage)?$')) {
installerController.showSupportedInstallers(document); new InstallerController(document.body);
} else if (route.match('^/groups') === 0) { } else if (route.match('^/groups') === 0) {
setupGroupsController(route); setupGroupsController(route);
} }
......
...@@ -11,7 +11,8 @@ describe('installer page', function () { ...@@ -11,7 +11,8 @@ describe('installer page', function () {
rootElement.innerHTML = rootElement.innerHTML =
'<button class="extension js-install-chrome is-hidden"></button>' + '<button class="extension js-install-chrome is-hidden"></button>' +
'<button class="bookmarklet js-install-bookmarklet is-hidden"></button>' + '<button class="bookmarklet js-install-bookmarklet is-hidden"></button>' +
'<input class="link">'; '<input class="link">' +
'<form class="js-proxy-form"><input name="url"></form>'
extensionBtn = rootElement.querySelector('.extension'); extensionBtn = rootElement.querySelector('.extension');
bookmarkletBtn = rootElement.querySelector('.bookmarklet'); bookmarkletBtn = rootElement.querySelector('.bookmarklet');
linkField = rootElement.querySelector('.link'); linkField = rootElement.querySelector('.link');
...@@ -23,11 +24,10 @@ describe('installer page', function () { ...@@ -23,11 +24,10 @@ describe('installer page', function () {
}); });
function createController(userAgentInfo) { function createController(userAgentInfo) {
var controller = proxyquire('../installer-controller', { var Controller = proxyquire('../installer-controller', {
'./ua-detect': userAgentInfo './ua-detect': userAgentInfo
}); });
controller.showSupportedInstallers(rootElement); return new Controller(rootElement);
return controller;
} }
function isHidden(el) { function isHidden(el) {
......
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