mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 22:04:23 +00:00
allow to launch show / hide manually
Useful when show/hide occurs in collection
This commit is contained in:
parent
ce365b2c41
commit
99632344a6
@ -101,3 +101,4 @@ Branch CRUD-Init
|
||||
- css: add an extra space around choices expanded widget
|
||||
- add Tabs parametric feature to easily render tabs panels
|
||||
- css: add a margin on the button "delete entry" in collection
|
||||
- module `show_hide`: add the possibility to launch a show hide manually and not on page loading. Useful when show/hide occurs in collection.
|
||||
|
@ -23,9 +23,14 @@ var ShowHide = function(options) {
|
||||
container = typeof options.container[Symbol.iterator] === "function" ? options.container : [ options.container ],
|
||||
is_shown = true,
|
||||
event_name = 'event_name' in options ? options.event_name : 'change',
|
||||
container_content = [];
|
||||
|
||||
window.addEventListener('load', function(event) {
|
||||
container_content = [],
|
||||
debug = 'debug' in options ? options.debug : false,
|
||||
load_event = 'load_event' in options ? options.load_event : 'load';
|
||||
|
||||
var bootstrap = function(event) {
|
||||
if (debug) {
|
||||
console.log('debug is activated on this show-hide', this);
|
||||
}
|
||||
// keep the content in memory
|
||||
for (let c of container.values()) {
|
||||
let contents = [];
|
||||
@ -39,6 +44,9 @@ var ShowHide = function(options) {
|
||||
for (let f of froms.values()) {
|
||||
let inputs = f.querySelectorAll('input');
|
||||
for (let input of inputs.values()) {
|
||||
if (debug) {
|
||||
console.log('attaching event to input', input);
|
||||
}
|
||||
input.addEventListener(event_name, function(e) {
|
||||
onChange(e);
|
||||
});
|
||||
@ -46,8 +54,8 @@ var ShowHide = function(options) {
|
||||
}
|
||||
|
||||
// first launch of the show/hide
|
||||
onChange(event);
|
||||
});
|
||||
onChange(event);
|
||||
};
|
||||
|
||||
|
||||
var onChange = function (event) {
|
||||
@ -77,6 +85,13 @@ var ShowHide = function(options) {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
if (load_event !== null) {
|
||||
window.addEventListener('load', bootstrap);
|
||||
} else {
|
||||
bootstrap(null);
|
||||
}
|
||||
};
|
||||
|
||||
export {ShowHide};
|
||||
|
Loading…
x
Reference in New Issue
Block a user