mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-24 00:23:50 +00:00
[show/hide] add events to module
This commit is contained in:
@@ -25,7 +25,8 @@ var ShowHide = function(options) {
|
||||
event_name = 'event_name' in options ? options.event_name : 'change',
|
||||
container_content = [],
|
||||
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) {
|
||||
if (debug) {
|
||||
@@ -59,26 +60,19 @@ var ShowHide = function(options) {
|
||||
|
||||
|
||||
var onChange = function (event) {
|
||||
var result = test(froms, event);
|
||||
var result = test(froms, event), me;
|
||||
|
||||
if (result === true) {
|
||||
if (is_shown === false) {
|
||||
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;
|
||||
forceShow();
|
||||
me = new CustomEvent('show-hide-show', { detail: { id: id, container: container, froms: froms } });
|
||||
window.dispatchEvent(me);
|
||||
}
|
||||
} else if (result === false) {
|
||||
if (is_shown) {
|
||||
for (let contents of container_content.values()) {
|
||||
for (let el of contents.values()) {
|
||||
el.remove();
|
||||
}
|
||||
}
|
||||
is_shown = false;
|
||||
forceHide();
|
||||
me = new CustomEvent('show-hide-hide', { detail: { id: id, container: container, froms: froms } });
|
||||
window.dispatchEvent(me);
|
||||
}
|
||||
} else {
|
||||
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) {
|
||||
window.addEventListener('load', bootstrap);
|
||||
} else {
|
||||
bootstrap(null);
|
||||
}
|
||||
|
||||
return {
|
||||
forceHide: forceHide,
|
||||
forceShow: forceShow,
|
||||
forceCompute: forceCompute,
|
||||
};
|
||||
};
|
||||
|
||||
export {ShowHide};
|
||||
|
Reference in New Issue
Block a user