accept direct urls / slight css refactor
This commit is contained in:
+13
-9
@@ -10,10 +10,6 @@
|
|||||||
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js" async></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js" async></script>
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
* {
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
body {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
@@ -41,6 +37,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
|
box-sizing: border-box;
|
||||||
width: 90%;
|
width: 90%;
|
||||||
max-width: 310px;
|
max-width: 310px;
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
@@ -57,10 +54,12 @@
|
|||||||
border: 0;
|
border: 0;
|
||||||
outline: 0;
|
outline: 0;
|
||||||
-webkit-appearance: none;
|
-webkit-appearance: none;
|
||||||
|
-moz-appearance: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
aside {
|
aside {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
|
box-sizing: border-box;
|
||||||
left: 0;
|
left: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 190px;
|
max-width: 190px;
|
||||||
@@ -151,6 +150,7 @@
|
|||||||
var searchForm = document.getElementById('js-search-form');
|
var searchForm = document.getElementById('js-search-form');
|
||||||
var searchInput = document.getElementById('js-search-input');
|
var searchInput = document.getElementById('js-search-input');
|
||||||
var searchHelp = document.getElementById('js-help');
|
var searchHelp = document.getElementById('js-help');
|
||||||
|
var urlRegex = /(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/;
|
||||||
|
|
||||||
opts.commands.forEach(function(command) {
|
opts.commands.forEach(function(command) {
|
||||||
var li = document.createElement('li');
|
var li = document.createElement('li');
|
||||||
@@ -160,20 +160,19 @@
|
|||||||
|
|
||||||
key.innerHTML = command.key + ': ';
|
key.innerHTML = command.key + ': ';
|
||||||
name.innerHTML = command.name;
|
name.innerHTML = command.name;
|
||||||
|
|
||||||
link.href = command.url;
|
link.href = command.url;
|
||||||
|
|
||||||
link.appendChild(key);
|
link.appendChild(key);
|
||||||
link.appendChild(name);
|
link.appendChild(name);
|
||||||
|
|
||||||
li.appendChild(link);
|
li.appendChild(link);
|
||||||
|
|
||||||
searchHelp.appendChild(li);
|
searchHelp.appendChild(li);
|
||||||
});
|
});
|
||||||
|
|
||||||
searchForm.addEventListener('submit', function(event) {
|
searchForm.addEventListener('submit', function(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
var q = searchInput.value
|
var q = searchInput.value.trim();
|
||||||
|
var redirect = '';
|
||||||
|
|
||||||
if (q === '' || q === '?') {
|
if (q === '' || q === '?') {
|
||||||
sidebar.setAttribute('data-toggled', true);
|
sidebar.setAttribute('data-toggled', true);
|
||||||
@@ -181,7 +180,12 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var redirect = opts.defaultCommand + encodeURIComponent(q);
|
if (q.match(new RegExp(urlRegex))) {
|
||||||
|
redirect = q;
|
||||||
|
} else {
|
||||||
|
redirect = opts.defaultCommand + encodeURIComponent(q);
|
||||||
|
}
|
||||||
|
|
||||||
q = q.split(opts.delimiter);
|
q = q.split(opts.delimiter);
|
||||||
|
|
||||||
opts.commands.forEach(function(command) {
|
opts.commands.forEach(function(command) {
|
||||||
|
|||||||
Reference in New Issue
Block a user