diff options
Diffstat (limited to 'html/dialog.js')
-rw-r--r-- | html/dialog.js | 41 |
1 files changed, 6 insertions, 35 deletions
diff --git a/html/dialog.js b/html/dialog.js index a4e275f..fbea657 100644 --- a/html/dialog.js +++ b/html/dialog.js @@ -41,17 +41,14 @@ * proprietary program, I am not going to enforce this in court. */ -#FROM html/DOM_helpers.js IMPORT clone_template +#FROM html/DOM_helpers.js IMPORT clone_template, Showable function make(on_dialog_show, on_dialog_hide) { const dialog_context = clone_template("dialog"); - Object.assign(dialog_context, { - on_dialog_show, - on_dialog_hide, - shown: false, - queue: [], - }); + dialog_context.queue = []; + + Showable.call(dialog_context, on_dialog_show, on_dialog_hide); for (const [id, val] of [["yes", true], ["no", false], ["ok", undefined]]) { const but = dialog_context[`${id}_but`]; @@ -74,12 +71,7 @@ function close_dialog(dialog_context, event) if (dialog_context.queue.length > 0) { process_queue_item(dialog_context); } else { - dialog_context.shown = false; - try { - dialog_context.on_dialog_hide(); - } catch(e) { - console.error(e); - } + dialog_context.hide(); } resolve(event ? event.target.haketilo_dialog_result : undefined); @@ -104,15 +96,8 @@ async function show_dialog(dialog_context, shown_buts_id, msg) const result_prom = new Promise(cb => resolve = cb); dialog_context.queue.push([shown_buts_id, msg, resolve]); - if (!dialog_context.shown) { + if (dialog_context.show()) process_queue_item(dialog_context); - dialog_context.shown = true; - try { - dialog_context.on_dialog_show(); - } catch(e) { - console.error(e); - } - } return await result_prom; } @@ -129,17 +114,3 @@ const ask = (ctx, ...msg) => show_dialog(ctx, "ask_buts", msg); const loader = (ctx, ...msg) => show_dialog(ctx, null, msg); #EXPORT loader - -/* - * Wrapper the requested callback into one that only executes it if dialog is - * not shown. - */ -function when_hidden(ctx, cb) -{ - function wrapped_cb(...args) { - if (!ctx.shown) - return cb(...args); - } - return wrapped_cb; -} -#EXPORT when_hidden |