show form input when you click the clock

This commit is contained in:
Cade Scroggins
2017-07-29 23:14:33 -07:00
parent d87006fce8
commit 6e86d155c2
+33 -14
View File
@@ -143,6 +143,7 @@
margin-top: -.06em; margin-top: -.06em;
font-size: 6rem; font-size: 6rem;
letter-spacing: .05em; letter-spacing: .05em;
cursor: pointer;
} }
#search-form { #search-form {
@@ -402,10 +403,12 @@
}; };
class Clock { class Clock {
constructor({ delimiter }) { constructor(options) {
this._el = $.el('#clock'); this._el = $.el('#clock');
this._delimiter = delimiter; this._delimiter = options.delimiter;
this._form = options.form;
this._setTime = this._setTime.bind(this); this._setTime = this._setTime.bind(this);
this._registerEvents();
this._start(); this._start();
} }
@@ -413,6 +416,10 @@
return ('0' + num.toString()).slice(-2); return ('0' + num.toString()).slice(-2);
} }
_registerEvents() {
this._el.addEventListener('click', this._form.show);
}
_setTime() { _setTime() {
const date = new Date(); const date = new Date();
const hours = this._pad(date.getHours()); const hours = this._pad(date.getHours());
@@ -881,7 +888,17 @@
this._loadQueryParam(); this._loadQueryParam();
} }
hide() {
$.bodyClassRemove('form')
}
show() {
$.bodyClassAdd('form');
this._inputEl.focus();
}
_bindMethods() { _bindMethods() {
this.show = this.show.bind(this);
this._clearPreview = this._clearPreview.bind(this); this._clearPreview = this._clearPreview.bind(this);
this._handleKeydown = this._handleKeydown.bind(this); this._handleKeydown = this._handleKeydown.bind(this);
this._handleInput = this._handleInput.bind(this); this._handleInput = this._handleInput.bind(this);
@@ -915,8 +932,7 @@
case '?': if (!$.bodyClassHas('form')) this._help.toggle(); return; case '?': if (!$.bodyClassHas('form')) this._help.toggle(); return;
} }
$.bodyClassAdd('form'); this.show();
this._inputEl.focus();
} }
_handleInput() { _handleInput() {
@@ -924,7 +940,7 @@
const { isKey } = this._queryParser.parse(newQuery); const { isKey } = this._queryParser.parse(newQuery);
this._inputElVal = newQuery; this._inputElVal = newQuery;
this._setBackgroundFromQuery(newQuery); this._setBackgroundFromQuery(newQuery);
if (!newQuery) $.bodyClassRemove('form'); if (!newQuery) this.hide();
else if (this._instantRedirect && isKey) this._submitWithValue(newQuery); else if (this._instantRedirect && isKey) this._submitWithValue(newQuery);
else if (this._suggester) this._suggester.suggest(newQuery); else if (this._suggester) this._suggester.suggest(newQuery);
} }
@@ -1016,16 +1032,19 @@
}); });
}; };
const getForm = () => {
return new Form({
colors: CONFIG.colors,
help: getHelp(),
instantRedirect: CONFIG.instantRedirect,
newTab: CONFIG.newTab,
queryParser: getQueryParser(),
suggester: CONFIG.suggestions ? getSuggester() : false,
});
};
new Clock({ new Clock({
delimiter: CONFIG.clockDelimiter, delimiter: CONFIG.clockDelimiter,
}); form: getForm(),
new Form({
colors: CONFIG.colors,
help: getHelp(),
instantRedirect: CONFIG.instantRedirect,
newTab: CONFIG.newTab,
queryParser: getQueryParser(),
suggester: CONFIG.suggestions ? getSuggester() : false,
}); });
</script> </script>