forked from e621ng/e621ng
[Home] Rework the search form to use the extra buttons (#881)
This commit is contained in:
parent
8136799546
commit
f6e9f44aef
46
app/javascript/src/javascripts/home.js
Normal file
46
app/javascript/src/javascripts/home.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import Page from "./utility/page";
|
||||||
|
|
||||||
|
const Home = {};
|
||||||
|
|
||||||
|
Home.init = function () {
|
||||||
|
|
||||||
|
const $form = $("#home-search-form");
|
||||||
|
const $tags = $("#tags");
|
||||||
|
console.log("init");
|
||||||
|
|
||||||
|
let isEmpty = !$tags.val();
|
||||||
|
let wasEmpty = isEmpty;
|
||||||
|
if (isEmpty) $form.addClass("empty");
|
||||||
|
console.log("input", isEmpty, wasEmpty);
|
||||||
|
|
||||||
|
$tags.on("input", () => {
|
||||||
|
wasEmpty = isEmpty;
|
||||||
|
isEmpty = !$tags.val();
|
||||||
|
console.log("input", isEmpty, wasEmpty);
|
||||||
|
|
||||||
|
if (isEmpty && !wasEmpty) $form.addClass("empty");
|
||||||
|
else if (!isEmpty && wasEmpty) $form.removeClass("empty");
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".home-buttons a").on("click", (event) => {
|
||||||
|
if (isEmpty) return; // Act like regular links
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
const extraTags = $(event.currentTarget).attr("tags");
|
||||||
|
if (extraTags) {
|
||||||
|
$tags.val((index, value) => {
|
||||||
|
return value + " " + extraTags;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$form.trigger("submit");
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
$(() => {
|
||||||
|
if (!Page.matches("static", "home")) return;
|
||||||
|
Home.init();
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Home;
|
@ -75,6 +75,10 @@ body.c-static.a-home {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#home-search-form:not(.empty) .home-buttons a span::before {
|
||||||
|
content: "Search ";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Footer
|
// Footer
|
||||||
.home-footer-top {
|
.home-footer-top {
|
||||||
|
@ -4,21 +4,26 @@
|
|||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
||||||
<section class="home-section">
|
<section class="home-section">
|
||||||
<%= form_tag(posts_path, method: "get", class: "home-search") do %>
|
<%= form_tag(posts_path, method: "get", id: "home-search-form") do %>
|
||||||
<%= text_field_tag("tags", "", autofocus: "autofocus", placeholder: "Search posts by tag", data: { shortcut: "q", autocomplete: "tag-query" }) %>
|
|
||||||
<%= tag.button(tag.i(class: "fa-solid fa-magnifying-glass"), type: "submit") %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div class="home-buttons">
|
<!-- Primary Searchbar -->
|
||||||
<a href="/posts">
|
<div class="home-search">
|
||||||
<i class="fas fa-splotch"></i>
|
<%= text_field_tag("tags", "", autofocus: "autofocus", placeholder: "Search posts by tag", data: { shortcut: "q", autocomplete: "tag-query" }) %>
|
||||||
Latest
|
<%= tag.button(tag.i(class: "fa-solid fa-magnifying-glass"), type: "submit") %>
|
||||||
</a>
|
</div>
|
||||||
<a href="/popular">
|
|
||||||
<i class="fas fa-fire-alt"></i>
|
<!-- Secondary search buttons -->
|
||||||
Popular
|
<div class="home-buttons">
|
||||||
</a>
|
<a href="<%= posts_path %>" tags="">
|
||||||
</div>
|
<i class="fas fa-splotch"></i>
|
||||||
|
<span>Latest</span>
|
||||||
|
</a>
|
||||||
|
<a href="<%= posts_path(tags: "order:rank") %>" tags="order:rank">
|
||||||
|
<i class="fas fa-fire-alt"></i>
|
||||||
|
<span>Popular</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<% if news_update = NewsUpdate.recent %>
|
<% if news_update = NewsUpdate.recent %>
|
||||||
|
Loading…
Reference in New Issue
Block a user