From b75a5717a084c9e5a727c2e960f2b910abcb5ace Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Tue, 25 Jan 2022 09:37:34 +0100 Subject: add a repo querying HTML interface --- html/DOM_helpers.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'html/DOM_helpers.js') diff --git a/html/DOM_helpers.js b/html/DOM_helpers.js index 88092e5..9e64956 100644 --- a/html/DOM_helpers.js +++ b/html/DOM_helpers.js @@ -85,3 +85,50 @@ function clone_template(template_id) return result_object; } #EXPORT clone_template + +function Showable(on_show_cb, on_hide_cb) { + this.shown = false; + + /* + * Wrap the requested callback into one that only executes it if showable is + * not shown. + */ + this.when_hidden = cb => { + const wrapped_cb = (...args) => { + if (!this.shown) + return cb(...args); + } + return wrapped_cb; + } + + this.show = () => { + if (this.shown) + return false; + + this.shown = true; + + try { + on_show_cb(); + } catch(e) { + console.error(e); + } + + return true; + } + + this.hide = () => { + if (!this.shown) + return false; + + this.shown = false; + + try { + on_hide_cb(); + } catch(e) { + console.error(e); + } + + return true; + } +} +#EXPORT Showable -- cgit v1.2.3