Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use two different divs for mobile and desktop instead of a JS solution #1284

Merged
merged 3 commits into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions queryads.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,24 @@
<div class="col-md-12">
<div class="box">
<div class="box-body">
<div class="form-group">
<div class="input-group">
<input id="domain" type="text" class="form-control" placeholder="Domain to look for (example.com or sub.example.com)">
<!-- Domain Input <992px -->
<div class="visible-xs-block visible-sm-block">
<div class="input-group-block">
<input id="domain_1" type="url" class="form-control" placeholder="Domain to look for (example.com or sub.example.com)" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off" style="margin-bottom: 5px">
<input id="quiet" type="hidden" value="no">
<div class="text-center" style="display: block; width: 100%">
<button type="button" id="btnSearch_1" class="btn btn-default">Search partial match</button>
<button type="button" id="btnSearchExact_1" class="btn btn-default">Search exact match</button>
</div>
</div>
</div>
<!-- Domain Input >=992px -->
<div class="visible-md-block visible-lg-block">
<div class="input-group">
<input id="domain_2" type="url" class="form-control" placeholder="Domain to look for (example.com or sub.example.com)" autocomplete="off" spellcheck="false" autocapitalize="none" autocorrect="off">
<span class="input-group-btn">
<button type="button" id="btnSearch" class="btn btn-default">Search partial match</button>
<button type="button" id="btnSearchExact" class="btn btn-default">Search exact match</button>
<button type="button" id="btnSearch_2" class="btn btn-default">Search partial match</button>
<button type="button" id="btnSearchExact_2" class="btn btn-default">Search exact match</button>
</span>
</div>
</div>
Expand Down
44 changes: 13 additions & 31 deletions scripts/pi-hole/js/queryads.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function quietfilter(ta, data) {

function eventsource() {
var ta = $("#output");
var domain = $("#domain").val().trim();
// process with the current visible domain input field
var domain = $("input[id^='domain']:visible").val().trim();
var q = $("#quiet");

if (domain.length === 0) {
Expand All @@ -38,7 +39,7 @@ function eventsource() {
if (typeof EventSource !== "function") {
$.ajax({
method: "GET",
url: "scripts/pi-hole/php/queryads.php?domain=" + domain.toLowerCase() + exact + "&IE",
url: "scripts/pi-hole/php/queryads.php?domain=" + domain.toLowerCase() + "&" + exact + "&IE",
async: false
}).done(function (data) {
ta.show();
Expand Down Expand Up @@ -86,41 +87,22 @@ function eventsource() {
exact = "";
}

// Handle enter button
$(document).keypress(function (e) {
if (e.which === 13 && $("#domain").is(":focus")) {
// Handle enter key
$("#domain_1, #domain_2").keypress(function (e) {
if (e.which === 13) {
// Enter was pressed, and the input has focus
exact = "";
eventsource();
}
});
// Handle button
$("#btnSearch").on("click", function () {

// Handle search buttons
$("button[id^='btnSearch']").on("click", function () {
exact = "";
eventsource();
});
// Handle exact button
$("#btnSearchExact").on("click", function () {
exact = "exact";
eventsource();
});

// Wrap form-group's buttons to next line when viewed on a small screen
$(window).on("resize", function () {
if ($(window).width() < 992) {
$(".form-group.input-group").removeClass("input-group").addClass("input-group-block");
$(".form-group.input-group-block > input").css("margin-bottom", "5px");
$(".form-group.input-group-block > .input-group-btn")
.removeClass("input-group-btn")
.addClass("btn-block text-center");
} else {
$(".form-group.input-group-block").removeClass("input-group-block").addClass("input-group");
$(".form-group.input-group > input").css("margin-bottom", "");
$(".form-group.input-group > .btn-block.text-center")
.removeClass("btn-block text-center")
.addClass("input-group-btn");
if (this.id.match("^btnSearchExact")) {
exact = "exact";
}
});
$(function () {
$(window).trigger("resize");

eventsource();
});