mirror of
https://github.com/thelounge/thelounge
synced 2024-11-26 22:10:22 +00:00
Merge pull request #2258 from thelounge/xpaw/fix-2257
Unfocus input on touch devices to close the keyboard
This commit is contained in:
commit
de59dc7d9f
1 changed files with 16 additions and 19 deletions
|
@ -230,28 +230,20 @@ $(function() {
|
||||||
chat.find(".chan.active .chat").trigger("keepToBottom"); // fix growing
|
chat.find(".chan.active .chat").trigger("keepToBottom"); // fix growing
|
||||||
});
|
});
|
||||||
|
|
||||||
let focus = $.noop;
|
|
||||||
|
|
||||||
if (!("ontouchstart" in window || navigator.maxTouchPoints > 0)) {
|
|
||||||
focus = function() {
|
|
||||||
if (chat.find(".active").hasClass("chan")) {
|
|
||||||
input.trigger("focus");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i)) {
|
if (navigator.platform.match(/(Mac|iPhone|iPod|iPad)/i)) {
|
||||||
$(document.body).addClass("is-apple");
|
$(document.body).addClass("is-apple");
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#form").on("submit", function(e) {
|
$("#form").on("submit", function() {
|
||||||
e.preventDefault();
|
// Triggering click event opens the virtual keyboard on mobile
|
||||||
focus();
|
// This can only be called from another interactive event (e.g. button click)
|
||||||
|
input.trigger("click").trigger("focus");
|
||||||
|
|
||||||
const target = chat.data("id");
|
const target = chat.data("id");
|
||||||
const text = input.val();
|
const text = input.val();
|
||||||
|
|
||||||
if (text.length === 0) {
|
if (text.length === 0) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
input.val("");
|
input.val("");
|
||||||
|
@ -262,11 +254,13 @@ $(function() {
|
||||||
const cmd = args.shift().toLowerCase();
|
const cmd = args.shift().toLowerCase();
|
||||||
|
|
||||||
if (typeof utils.inputCommands[cmd] === "function" && utils.inputCommands[cmd](args)) {
|
if (typeof utils.inputCommands[cmd] === "function" && utils.inputCommands[cmd](args)) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.emit("input", {target, text});
|
socket.emit("input", {target, text});
|
||||||
|
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
$("button#set-nick").on("click", function() {
|
$("button#set-nick").on("click", function() {
|
||||||
|
@ -346,7 +340,7 @@ $(function() {
|
||||||
const target = self.data("target");
|
const target = self.data("target");
|
||||||
|
|
||||||
if (!target) {
|
if (!target) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a rather gross hack to account for sources that are in the
|
// This is a rather gross hack to account for sources that are in the
|
||||||
|
@ -435,6 +429,11 @@ $(function() {
|
||||||
|
|
||||||
if (chanChat.length > 0 && type !== "special") {
|
if (chanChat.length > 0 && type !== "special") {
|
||||||
chanChat.sticky();
|
chanChat.sticky();
|
||||||
|
|
||||||
|
// On touch devices unfocus (blur) the input to correctly close the virtual keyboard
|
||||||
|
// An explicit blur is required, as the keyboard may open back up if the focus remains
|
||||||
|
// See https://github.com/thelounge/thelounge/issues/2257
|
||||||
|
input.trigger("ontouchstart" in window ? "blur" : "focus");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chan.data("needsNamesRefresh") === true) {
|
if (chan.data("needsNamesRefresh") === true) {
|
||||||
|
@ -451,15 +450,13 @@ $(function() {
|
||||||
Changelog.requestIfNeeded();
|
Changelog.requestIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
focus();
|
|
||||||
|
|
||||||
// Pushes states to history web API when clicking elements with a data-target attribute.
|
// Pushes states to history web API when clicking elements with a data-target attribute.
|
||||||
// States are very trivial and only contain a single `clickTarget` property which
|
// States are very trivial and only contain a single `clickTarget` property which
|
||||||
// contains a CSS selector that targets elements which takes the user to a different view
|
// contains a CSS selector that targets elements which takes the user to a different view
|
||||||
// when clicked. The `popstate` event listener will trigger synthetic click events using that
|
// when clicked. The `popstate` event listener will trigger synthetic click events using that
|
||||||
// selector and thus take the user to a different view/state.
|
// selector and thus take the user to a different view/state.
|
||||||
if (data && data.pushState === false) {
|
if (data && data.pushState === false) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const state = {};
|
const state = {};
|
||||||
|
|
Loading…
Reference in a new issue