diff --git a/xwords4/wasm/main.c b/xwords4/wasm/main.c index f5741ffe1..929b0b939 100644 --- a/xwords4/wasm/main.c +++ b/xwords4/wasm/main.c @@ -78,6 +78,13 @@ EM_JS(void, call_dialog, (const char* str, const char** but_strs, nbDialog(UTF8ToString(str), buttons, proc, closure); } ); +EM_JS(void, call_get_string, (const char* msg, const char* dflt, + AlertProc proc, void* closure), { + let jsMgs = UTF8ToString(msg); + let jsDflt = UTF8ToString(dflt); + nbGetString( jsMgs, jsDflt, proc, closure ); + } ); + EM_JS(void, call_haveDevID, (void* closure, const char* devid), { onHaveDevID(closure, UTF8ToString(devid)); }); diff --git a/xwords4/wasm/shell_minimal.html b/xwords4/wasm/shell_minimal.html index ccba0e1fe..826221ec3 100644 --- a/xwords4/wasm/shell_minimal.html +++ b/xwords4/wasm/shell_minimal.html @@ -67,6 +67,11 @@ padding: 10px; } + textarea.stringedit { + rows: 1; + resize: none; + } + diff --git a/xwords4/wasm/xwutils.js b/xwords4/wasm/xwutils.js index c7a529cc7..23b98bb51 100644 --- a/xwords4/wasm/xwutils.js +++ b/xwords4/wasm/xwutils.js @@ -87,17 +87,23 @@ function mqttSend( topic, ptr ) { return canSend; } -function nbDialog(msg, buttons, proc, closure) { +function newDlgWMsg(msg) { let container = document.getElementById('nbalert'); let dlg = document.createElement('div'); dlg.classList.add('nbalert'); - dlg.style.zIndex = 10000; + dlg.style.zIndex = 10000 + container.childElementCount; container.appendChild( dlg ); let txtDiv = document.createElement('div'); - dlg.appendChild( txtDiv ); txtDiv.textContent = msg + dlg.appendChild( txtDiv ); + + return dlg; +} + +function nbDialog(msg, buttons, proc, closure) { + let dlg = newDlgWMsg( msg ); let span = document.createElement('div'); span.classList.add('buttonRow'); @@ -107,13 +113,39 @@ function nbDialog(msg, buttons, proc, closure) { button.onclick = function() { Module.ccall('onDlgButton', null, ['number', 'number', 'string'], [proc, closure, buttonTxt]); - container.removeChild(dlg); + dlg.parentNode.removeChild(dlg); }; span.appendChild( button ); } dlg.appendChild( span ); } +function nbGetString(msg, dflt, proc, closure) { + let dlg = newDlgWMsg( msg ); + + let tarea = document.createElement('textarea'); + tarea.classList.add('stringedit'); + tarea.value = dflt; + dlg.appendChild( tarea ); + + dismissed = function(str) { + dlg.parentNode.removeChild(dlg); + Module.ccall('onDlgButton', null, ['number', 'number', 'string'], + [proc, closure, str]); + } + + let buttons = document.createElement('div'); + dlg.appendChild(buttons); + let cancel = document.createElement('button'); + cancel.textContent = "Cancel"; + buttons.appendChild(cancel); + cancel.onclick = function() { dismissed(null);} + let ok = document.createElement('button'); + ok.textContent = 'OK'; + buttons.appendChild(ok); + ok.onclick = function() { dismissed(tarea.value);} +} + for ( let one of ['paho-mqtt.js'] ) { let script = document.createElement('script'); script.src = one