mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
[show/hide] add events to module
This commit is contained in:
parent
99632344a6
commit
d46ee72fb1
@ -102,3 +102,4 @@ Branch CRUD-Init
|
|||||||
- 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.
|
- module `show_hide`: add the possibility to launch a show hide manually and not on page loading. Useful when show/hide occurs in collection.
|
||||||
|
- module `show_hide`: add events to module
|
||||||
|
@ -25,7 +25,8 @@ var ShowHide = function(options) {
|
|||||||
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,
|
debug = 'debug' in options ? options.debug : false,
|
||||||
load_event = 'load_event' in options ? options.load_event : 'load';
|
load_event = 'load_event' in options ? options.load_event : 'load',
|
||||||
|
id = 'uid' in options ? options.id : Math.random();
|
||||||
|
|
||||||
var bootstrap = function(event) {
|
var bootstrap = function(event) {
|
||||||
if (debug) {
|
if (debug) {
|
||||||
@ -59,26 +60,19 @@ var ShowHide = function(options) {
|
|||||||
|
|
||||||
|
|
||||||
var onChange = function (event) {
|
var onChange = function (event) {
|
||||||
var result = test(froms, event);
|
var result = test(froms, event), me;
|
||||||
|
|
||||||
if (result === true) {
|
if (result === true) {
|
||||||
if (is_shown === false) {
|
if (is_shown === false) {
|
||||||
for (let i of container_content.keys()) {
|
forceShow();
|
||||||
var contents = container_content[i];
|
me = new CustomEvent('show-hide-show', { detail: { id: id, container: container, froms: froms } });
|
||||||
for (let el of contents.values()) {
|
window.dispatchEvent(me);
|
||||||
container[i].appendChild(el);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is_shown = true;
|
|
||||||
}
|
}
|
||||||
} else if (result === false) {
|
} else if (result === false) {
|
||||||
if (is_shown) {
|
if (is_shown) {
|
||||||
for (let contents of container_content.values()) {
|
forceHide();
|
||||||
for (let el of contents.values()) {
|
me = new CustomEvent('show-hide-hide', { detail: { id: id, container: container, froms: froms } });
|
||||||
el.remove();
|
window.dispatchEvent(me);
|
||||||
}
|
|
||||||
}
|
|
||||||
is_shown = false;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw "the result of test is not a boolean";
|
throw "the result of test is not a boolean";
|
||||||
@ -86,12 +80,47 @@ var ShowHide = function(options) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var forceHide = function() {
|
||||||
|
if (debug) {
|
||||||
|
console.log('force hide');
|
||||||
|
}
|
||||||
|
for (let contents of container_content.values()) {
|
||||||
|
for (let el of contents.values()) {
|
||||||
|
el.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is_shown = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
var forceShow = function() {
|
||||||
|
if (debug) {
|
||||||
|
console.log('show');
|
||||||
|
}
|
||||||
|
for (let i of container_content.keys()) {
|
||||||
|
var contents = container_content[i];
|
||||||
|
for (let el of contents.values()) {
|
||||||
|
container[i].appendChild(el);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
is_shown = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
var forceCompute = function(event) {
|
||||||
|
onChange(event);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
if (load_event !== null) {
|
if (load_event !== null) {
|
||||||
window.addEventListener('load', bootstrap);
|
window.addEventListener('load', bootstrap);
|
||||||
} else {
|
} else {
|
||||||
bootstrap(null);
|
bootstrap(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
forceHide: forceHide,
|
||||||
|
forceShow: forceShow,
|
||||||
|
forceCompute: forceCompute,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export {ShowHide};
|
export {ShowHide};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user