Revision b75a5717
Added by koszko over 1 year ago
html/DOM_helpers.js | ||
---|---|---|
85 | 85 |
return result_object; |
86 | 86 |
} |
87 | 87 |
#EXPORT clone_template |
88 |
|
|
89 |
function Showable(on_show_cb, on_hide_cb) { |
|
90 |
this.shown = false; |
|
91 |
|
|
92 |
/* |
|
93 |
* Wrap the requested callback into one that only executes it if showable is |
|
94 |
* not shown. |
|
95 |
*/ |
|
96 |
this.when_hidden = cb => { |
|
97 |
const wrapped_cb = (...args) => { |
|
98 |
if (!this.shown) |
|
99 |
return cb(...args); |
|
100 |
} |
|
101 |
return wrapped_cb; |
|
102 |
} |
|
103 |
|
|
104 |
this.show = () => { |
|
105 |
if (this.shown) |
|
106 |
return false; |
|
107 |
|
|
108 |
this.shown = true; |
|
109 |
|
|
110 |
try { |
|
111 |
on_show_cb(); |
|
112 |
} catch(e) { |
|
113 |
console.error(e); |
|
114 |
} |
|
115 |
|
|
116 |
return true; |
|
117 |
} |
|
118 |
|
|
119 |
this.hide = () => { |
|
120 |
if (!this.shown) |
|
121 |
return false; |
|
122 |
|
|
123 |
this.shown = false; |
|
124 |
|
|
125 |
try { |
|
126 |
on_hide_cb(); |
|
127 |
} catch(e) { |
|
128 |
console.error(e); |
|
129 |
} |
|
130 |
|
|
131 |
return true; |
|
132 |
} |
|
133 |
} |
|
134 |
#EXPORT Showable |
Also available in: Unified diff
add a repo querying HTML interface