From 0de8fbee36cf18ea98dba85a7fc629db7e6ca769 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Mon, 10 Apr 2017 17:23:03 +0200 Subject: [PATCH] latin: support default sample text option Read ?q= parameter during setup. --- latinsample.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/latinsample.js b/latinsample.js index f4a6a6d..c17242a 100644 --- a/latinsample.js +++ b/latinsample.js @@ -33,16 +33,27 @@ function appendsample() { } }; +function getrequest(name) { + // find GET variable in page request + var match = new RegExp('[?&]'+name+'=([^&]*)'); + var param = match.exec(window.location.search); + return param ? decodeURIComponent(param[1]) : ''; +} + function prependinput(target) { var form = document.createElement('FORM'); form.id = 'search'; form.className = 'aside'; + form.onsubmit = function () { return false }; var input = document.createElement('INPUT'); input.oninput = appendsample; input.placeholder = 'Sample'; input.type = 'search'; input.name = 'q'; + if (input.value = getrequest('q')) { + input.oninput(); + } form.appendChild(input); target.parentNode.insertBefore(form, target); -- 2.30.0