mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 09:35:23 -04:00
Web: Fix Window_OpenKeyboard not updating text/placeholder when input element is already being shown
This commit is contained in:
parent
483d489d99
commit
93d47a9e0c
@ -592,7 +592,8 @@ mergeInto(LibraryManager.library, {
|
|||||||
alert(UTF8ToString(title) + "\n\n" + UTF8ToString(msg));
|
alert(UTF8ToString(title) + "\n\n" + UTF8ToString(msg));
|
||||||
},
|
},
|
||||||
interop_OpenKeyboard: function(text, type, placeholder) {
|
interop_OpenKeyboard: function(text, type, placeholder) {
|
||||||
var elem = window.cc_inputElem;
|
var elem = window.cc_inputElem;
|
||||||
|
var shown = true;
|
||||||
if (!elem) {
|
if (!elem) {
|
||||||
if (type == 1) {
|
if (type == 1) {
|
||||||
elem = document.createElement('input');
|
elem = document.createElement('input');
|
||||||
@ -600,11 +601,15 @@ mergeInto(LibraryManager.library, {
|
|||||||
} else {
|
} else {
|
||||||
elem = document.createElement('textarea');
|
elem = document.createElement('textarea');
|
||||||
}
|
}
|
||||||
elem.setAttribute('style', 'position:absolute; left:0; bottom:0; margin: 0px; width: 100%');
|
shown = false;
|
||||||
elem.setAttribute('placeholder', UTF8ToString(placeholder));
|
}
|
||||||
elem.value = UTF8ToString(text);
|
|
||||||
|
elem.setAttribute('style', 'position:absolute; left:0; bottom:0; margin: 0px; width: 100%');
|
||||||
|
elem.setAttribute('placeholder', UTF8ToString(placeholder));
|
||||||
|
elem.value = UTF8ToString(text);
|
||||||
|
|
||||||
// stop event propogation, because we don't want the game trying to handle these events
|
if (!shown) {
|
||||||
|
// stop event propagation, because we don't want the game trying to handle these events
|
||||||
elem.addEventListener('touchstart', function(ev) { ev.stopPropagation(); }, false);
|
elem.addEventListener('touchstart', function(ev) { ev.stopPropagation(); }, false);
|
||||||
elem.addEventListener('touchmove', function(ev) { ev.stopPropagation(); }, false);
|
elem.addEventListener('touchmove', function(ev) { ev.stopPropagation(); }, false);
|
||||||
elem.addEventListener('mousedown', function(ev) { ev.stopPropagation(); }, false);
|
elem.addEventListener('mousedown', function(ev) { ev.stopPropagation(); }, false);
|
||||||
@ -622,15 +627,17 @@ mergeInto(LibraryManager.library, {
|
|||||||
window.cc_container.appendChild(window.cc_divElem);
|
window.cc_container.appendChild(window.cc_divElem);
|
||||||
window.cc_container.appendChild(elem);
|
window.cc_container.appendChild(elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// force on-screen keyboard to be shown
|
||||||
elem.focus();
|
elem.focus();
|
||||||
elem.click();
|
elem.click();
|
||||||
},
|
},
|
||||||
// NOTE: When pressing 'Go' on the on-screen keyboard, some web browsers add \n to value
|
|
||||||
interop_SetKeyboardText: function(text) {
|
interop_SetKeyboardText: function(text) {
|
||||||
if (!window.cc_inputElem) return;
|
if (!window.cc_inputElem) return;
|
||||||
var str = UTF8ToString(text);
|
var str = UTF8ToString(text);
|
||||||
var cur = window.cc_inputElem.value;
|
var cur = window.cc_inputElem.value;
|
||||||
|
|
||||||
|
// when pressing 'Go' on the on-screen keyboard, some web browsers add \n to value
|
||||||
if (cur.length && cur[cur.length - 1] == '\n') { cur = cur.substring(0, cur.length - 1); }
|
if (cur.length && cur[cur.length - 1] == '\n') { cur = cur.substring(0, cur.length - 1); }
|
||||||
if (str != cur) window.cc_inputElem.value = str;
|
if (str != cur) window.cc_inputElem.value = str;
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user