mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 06:14: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
|
- css: add an extra space around choices expanded widget
|
||||||
- add Tabs parametric feature to easily render tabs panels
|
- add Tabs parametric feature to easily render tabs panels
|
||||||
- css: add a margin on the button "delete entry" in collection
|
- 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 ],
|
container = typeof options.container[Symbol.iterator] === "function" ? options.container : [ options.container ],
|
||||||
is_shown = true,
|
is_shown = true,
|
||||||
event_name = 'event_name' in options ? options.event_name : 'change',
|
event_name = 'event_name' in options ? options.event_name : 'change',
|
||||||
container_content = [];
|
container_content = [],
|
||||||
|
debug = 'debug' in options ? options.debug : false,
|
||||||
|
load_event = 'load_event' in options ? options.load_event : 'load';
|
||||||
|
|
||||||
window.addEventListener('load', function(event) {
|
var bootstrap = function(event) {
|
||||||
|
if (debug) {
|
||||||
|
console.log('debug is activated on this show-hide', this);
|
||||||
|
}
|
||||||
// keep the content in memory
|
// keep the content in memory
|
||||||
for (let c of container.values()) {
|
for (let c of container.values()) {
|
||||||
let contents = [];
|
let contents = [];
|
||||||
@ -39,6 +44,9 @@ var ShowHide = function(options) {
|
|||||||
for (let f of froms.values()) {
|
for (let f of froms.values()) {
|
||||||
let inputs = f.querySelectorAll('input');
|
let inputs = f.querySelectorAll('input');
|
||||||
for (let input of inputs.values()) {
|
for (let input of inputs.values()) {
|
||||||
|
if (debug) {
|
||||||
|
console.log('attaching event to input', input);
|
||||||
|
}
|
||||||
input.addEventListener(event_name, function(e) {
|
input.addEventListener(event_name, function(e) {
|
||||||
onChange(e);
|
onChange(e);
|
||||||
});
|
});
|
||||||
@ -47,7 +55,7 @@ var ShowHide = function(options) {
|
|||||||
|
|
||||||
// first launch of the show/hide
|
// first launch of the show/hide
|
||||||
onChange(event);
|
onChange(event);
|
||||||
});
|
};
|
||||||
|
|
||||||
|
|
||||||
var onChange = function (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};
|
export {ShowHide};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user