add randomize button

This commit is contained in:
Hunternif 2019-04-07 22:32:39 +07:00
parent a62a175768
commit 0808fa850f
2 changed files with 15 additions and 0 deletions

View file

@ -4,6 +4,8 @@
%><wbr/><%
%><input class='mousetrap' type='submit' value='Search'/><%
%><wbr/><%
%><button id="random-button" style="padding:0.2em; margin-right:0.25em; margin-bottom:0.25em;"><i class="fa fa-random"></button><%
%><wbr/><%
%><% if (ctx.enableSafety) { %><%
%><input data-safety=safe type='button' class='mousetrap safety safety-safe <%- ctx.settings.listPosts.safe ? '' : 'disabled' %>'/><%
%><input data-safety=sketchy type='button' class='mousetrap safety safety-sketchy <%- ctx.settings.listPosts.sketchy ? '' : 'disabled' %>'/><%

View file

@ -145,6 +145,7 @@ class PostsHeaderView extends events.EventTarget {
'click', e => this._evtSafetyButtonClick(e));
}
this._formNode.addEventListener('submit', e => this._evtFormSubmit(e));
this._randomButtonNode.addEventListener('click', e => this._evtRandomButtonClick(e));
this._bulkEditors = [];
if (this._bulkEditTagsNode) {
@ -191,6 +192,10 @@ class PostsHeaderView extends events.EventTarget {
return this._hostNode.querySelector('form [name=search-text]');
}
get _randomButtonNode() {
return this._hostNode.querySelector('#random-button');
}
get _bulkEditTagsNode() {
return this._hostNode.querySelector('.bulk-edit-tags');
}
@ -242,6 +247,14 @@ class PostsHeaderView extends events.EventTarget {
e.preventDefault();
this._navigate();
}
_evtRandomButtonClick(e) {
if (!this._queryInputNode.value.includes('sort:random')) {
this._queryInputNode.value += ' sort:random';
} else {
location.reload();
}
this._navigate();
}
_navigate() {
this._autoCompleteControl.hide();