aboutsummaryrefslogtreecommitdiff
path: root/html/DOM_helpers.js
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-01-25 09:37:34 +0100
committerWojtek Kosior <koszko@koszko.org>2022-01-25 09:37:34 +0100
commitb75a5717a084c9e5a727c2e960f2b910abcb5ace (patch)
treea9dcd00c428aeba011e9a445b96aacad962a1f3d /html/DOM_helpers.js
parent7218849ae2f43aee6b3462a30e07caf5bac3d22b (diff)
downloadbrowser-extension-b75a5717a084c9e5a727c2e960f2b910abcb5ace.tar.gz
browser-extension-b75a5717a084c9e5a727c2e960f2b910abcb5ace.zip
add a repo querying HTML interface
Diffstat (limited to 'html/DOM_helpers.js')
-rw-r--r--html/DOM_helpers.js47
1 files changed, 47 insertions, 0 deletions
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