Commit 23f75008 authored by Robert Knight's avatar Robert Knight

Merge pull request #3187 from hypothesis/replace-page-router

Replace node page router
parents aa0413b3 302ce020
......@@ -9,14 +9,10 @@ if (settings.raven) {
window.$ = window.jQuery = require('jquery');
require('bootstrap');
var page = require('page');
var page = require('./page');
var AdminUsersController = require('./admin-users');
page('/admin/users', function() {
new AdminUsersController(document.body, window);
});
document.addEventListener('DOMContentLoaded', function () {
page.start();
});
'use strict';
function page(path, callback) {
if (window.location.pathname === path) {
document.addEventListener('DOMContentLoaded', callback, false);
}
}
module.exports = page;
......@@ -6,7 +6,7 @@ if (settings.raven) {
require('./raven').init(settings.raven);
}
var page = require('page');
var page = require('./page');
var CreateGroupFormController = require('./create-group-form');
var DropdownMenuController = require('./dropdown-menu');
......@@ -38,7 +38,3 @@ page('/register', function() {
page('/forgot_password', function() {
new FormSelectOnFocusController(document.body);
});
document.addEventListener('DOMContentLoaded', function () {
page.start({click: false});
});
'use strict';
var page = require('../page');
// helper to dispatch a native event to an element
function sendEvent(element, eventType) {
// createEvent() used instead of Event constructor
// for PhantomJS compatibility
var event = document.createEvent('Event');
event.initEvent(eventType, true /* bubbles */, true /* cancelable */);
element.dispatchEvent(event);
return event;
}
describe('page', function () {
it('it adds the callback when the url path matches', function () {
var spy = sinon.spy();
page(document.location.pathname, spy);
sendEvent(document, 'DOMContentLoaded');
assert.calledOnce(spy);
});
it('it skips adding the callback when the url path does not match', function () {
var spy = sinon.spy();
page(document.location.pathname + '-foo', spy);
sendEvent(document, 'DOMContentLoaded');
assert.notCalled(spy);
});
});
......@@ -50,7 +50,6 @@
"mkdirp": "^0.5.1",
"ng-tags-input": "2.2.0",
"node-uuid": "^1.4.3",
"page": "^1.6.4",
"postcss": "^5.0.6",
"query-string": "^3.0.1",
"raf": "^3.1.0",
......
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