szurubooru/client/js/views/users_header_view.js
rr- 76882b59ef client/router: introduce own router
I'm tired of page.js lack of documentation around finer quirks, and
being forced to read its crap code. Refactored into classes, removed
unused cruft.
2016-06-12 21:43:20 +02:00

35 lines
959 B
JavaScript

'use strict';
const router = require('../router.js');
const keyboard = require('../util/keyboard.js');
const misc = require('../util/misc.js');
const views = require('../util/views.js');
class UsersHeaderView {
constructor() {
this._template = views.getTemplate('users-header');
}
render(ctx) {
const target = ctx.target;
const source = this._template(ctx);
const form = source.querySelector('form');
keyboard.bind('q', () => {
form.querySelector('input').focus();
});
form.addEventListener('submit', e => {
e.preventDefault();
const searchTextInput = form.querySelector('[name=search-text]');
const text = searchTextInput.value;
searchTextInput.blur();
router.show('/users/' + misc.formatSearchQuery({text: text}));
});
views.showView(target, source);
}
}
module.exports = UsersHeaderView;