add helper command

This commit is contained in:
Cade Scroggins
2016-02-01 10:20:01 -08:00
parent 78c21a283b
commit 88cb8cc14b
+25 -2
View File
@@ -43,9 +43,8 @@
.wrapper { .wrapper {
position: relative; position: relative;
top: 40%; top: 25%;
padding: 1rem; padding: 1rem;
transform: translateY(-50%);
} }
.time { .time {
@@ -67,6 +66,12 @@
color: #fff; color: #fff;
font-size: 1.1rem; font-size: 1.1rem;
} }
.help {
width: 300px;
margin: 1rem auto 0;
text-align: left;
}
</style> </style>
<!-- markup --> <!-- markup -->
@@ -76,6 +81,8 @@
<form class="search" id="js-search" autocomplete="off"> <form class="search" id="js-search" autocomplete="off">
<input class="search__text" id="js-search-text" type="search" autofocus> <input class="search__text" id="js-search-text" type="search" autofocus>
</form> </form>
<pre class="help" id="js-help"></pre>
</div> </div>
<!-- script --> <!-- script -->
@@ -104,6 +111,7 @@
var Commander = { var Commander = {
searchForm: document.getElementById('js-search'), searchForm: document.getElementById('js-search'),
searchText: document.getElementById('js-search-text'), searchText: document.getElementById('js-search-text'),
searchHelp: document.getElementById('js-help'),
init: function(commands) { init: function(commands) {
Commander.commands = commands; Commander.commands = commands;
@@ -112,6 +120,16 @@
search: function(e) { search: function(e) {
var q = Commander.searchText.value; var q = Commander.searchText.value;
if (q === '?') {
var helpMessage = '';
Commander.commands.forEach(function(command) {
helpMessage += command.key + ': ' + command.url + '\n';
});
Commander.searchHelp.innerHTML = helpMessage;
} else {
Commander.location = 'https://www.google.com/search?q=' + q; Commander.location = 'https://www.google.com/search?q=' + q;
Commander.commands.forEach(function(command) { Commander.commands.forEach(function(command) {
@@ -119,11 +137,16 @@
}); });
window.location.href = Commander.location; window.location.href = Commander.location;
}
Commander.searchText.value = '';
e.preventDefault(); e.preventDefault();
} }
}; };
Clock.init(); Clock.init();
// add commands here
Commander.init([ Commander.init([
{ key: 'i', url: 'https://inbox.google.com' }, { key: 'i', url: 'https://inbox.google.com' },
{ key: 'k', url: 'https://keep.google.com' }, { key: 'k', url: 'https://keep.google.com' },