diff options
| author | rr- | 2016-08-28 18:53:06 +0200 |
|---|---|---|
| committer | rr- | 2016-08-28 23:40:28 +0200 |
| commit | cf1d15354df5e9062c4c8a24e24bd283214d06ca (patch) | |
| tree | c47a9711ffe7954c711e257d4f6b808565b538ff /client/js/util | |
| parent | e83e1b06a1159ba66d2d8bf560d038ea3c7a07b3 (diff) | |
client/paging: avoid redrawing header navigation
Diffstat (limited to 'client/js/util')
| -rw-r--r-- | client/js/util/search.js | 17 | ||||
| -rw-r--r-- | client/js/util/views.js | 41 |
2 files changed, 39 insertions, 19 deletions
diff --git a/client/js/util/search.js b/client/js/util/search.js new file mode 100644 index 0000000..ba5c2f7 --- /dev/null +++ b/client/js/util/search.js @@ -0,0 +1,17 @@ +'use strict'; + +const misc = require('./misc.js'); +const keyboard = require('../util/keyboard.js'); +const views = require('./views.js'); + +function searchInputNodeFocusHelper(inputNode) { + keyboard.bind('q', () => { + inputNode.focus(); + inputNode.setSelectionRange( + inputNode.value.length, inputNode.value.length); + }); +} + +module.exports = misc.arrayToObject([ + searchInputNodeFocusHelper, +], func => func.name); diff --git a/client/js/util/views.js b/client/js/util/views.js index f340a00..c25a505 100644 --- a/client/js/util/views.js +++ b/client/js/util/views.js @@ -248,6 +248,25 @@ function makeVoidElement(name, attributes) { return `<${_serializeElement(name, attributes)}/>`; } +function emptyContent(target) { + while (target.lastChild) { + target.removeChild(target.lastChild); + } +} + +function replaceContent(target, source) { + emptyContent(target); + if (source instanceof NodeList) { + for (let child of [...source]) { + target.appendChild(child); + } + } else if (source instanceof Node) { + target.appendChild(source); + } else if (source !== null) { + throw `Invalid view source: ${source}`; + } +} + function showMessage(target, message, className) { if (!message) { message = 'Unknown message'; @@ -283,9 +302,7 @@ function showInfo(target, message) { function clearMessages(target) { const messagesHolder = target.querySelector('.messages'); /* TODO: animate that */ - while (messagesHolder.lastChild) { - messagesHolder.removeChild(messagesHolder.lastChild); - } + emptyContent(messagesHolder); } function htmlToDom(html) { @@ -394,25 +411,10 @@ function enableForm(form) { } } -function replaceContent(target, source) { - while (target.lastChild) { - target.removeChild(target.lastChild); - } - if (source instanceof NodeList) { - for (let child of [...source]) { - target.appendChild(child); - } - } else if (source instanceof Node) { - target.appendChild(source); - } else if (source !== null) { - throw `Invalid view source: ${source}`; - } -} - function syncScrollPosition() { window.requestAnimationFrame( () => { - if (history.state.hasOwnProperty('scrollX')) { + if (history.state && history.state.hasOwnProperty('scrollX')) { window.scrollTo(history.state.scrollX, history.state.scrollY); } else { window.scrollTo(0, 0); @@ -488,6 +490,7 @@ document.addEventListener('click', e => { module.exports = misc.arrayToObject([ htmlToDom, getTemplate, + emptyContent, replaceContent, enableForm, disableForm, |