« Show or hide components » : différence entre les versions
essaie d'utiliser le blockquote pour formater des code |
|||
| Ligne 34 : | Ligne 34 : | ||
The script should detect button clicks and act accordingly. | The script should detect button clicks and act accordingly. | ||
init = function(sheet) { | |||
init = function(sheet) { | |||
if (sheet.id() === "main") { | if (sheet.id() === "main") { | ||
initMain(sheet); | initMain(sheet); | ||
} | } | ||
}; | |||
}; | const initMain = function(sheet) { | ||
const initMain = function(sheet) { | |||
// initialize the main sheet | // initialize the main sheet | ||
initContentVisibility(sheet,"content_to_hide_id", "hide_button_id", "show_button_id"); | initContentVisibility(sheet,"content_to_hide_id", "hide_button_id", "show_button_id"); | ||
}; | |||
}; | const initContentVisibility = function(sheet, extra_id, hide_button_id, show_button_id){ | ||
const initContentVisibility = function(sheet, extra_id, hide_button_id, show_button_id){ | |||
// Get the button. | // Get the button. | ||
let hideButton = sheet.get(hide_button_id); | let hideButton = sheet.get(hide_button_id); | ||
let showButton = sheet.get(show_button_id); | let showButton = sheet.get(show_button_id); | ||
let content = sheet.get(extra_id); | let content = sheet.get(extra_id); | ||
// hide the content, show show_button and hide hide_button. | // hide the content, show show_button and hide hide_button. | ||
const hideContent = function() { | const hideContent = function() { | ||
log("hide click"); | log("hide click"); | ||
hideButton.hide(); | hideButton.hide(); | ||
showButton.show(); | showButton.show(); | ||
content.hide(); | content.hide(); | ||
}; | }; | ||
// show the contente, hide show_button and show hide_button. | // show the contente, hide show_button and show hide_button. | ||
const showContent = function() { | const showContent = function() { | ||
log("show click"); | log("show click"); | ||
hideButton.show(); | hideButton.show(); | ||
showButton.hide(); | showButton.hide(); | ||
content.show(); | content.show(); | ||
}; | }; | ||
// show | // show | ||
hideButton.on('click', hideContent); | hideButton.on('click', hideContent); | ||
// hide | // hide | ||
showButton.on('click', showContent); | showButton.on('click', showContent); | ||
}; | |||
}; | |||
Version du 31 août 2025 à 20:30
Hide / Show Components
Components can be hidden using Bootstrap classes:
- d-none: Hide elements
- invisible: Visibility
This allows you to hide parts of a character sheet in order to keep it more compact and readable.
Creating a collapsible container
When your character sheet contains large amounts of text, it can be useful to hide some of it to keep the sheet clear. This is especially useful for Repeater views, which may contain a lot of text.
image repeater expanded and repeater collapsed
To do this, you will need to use scripting.
Define the content to hide
Place the content you want to hide inside a Column component, itself inside a Row component. This way, you can easily hide or display the content.
To test, add or remove the d-none class from the Row component. Its child elements should show or hide accordingly.
Prepare the buttons
To control the hidden content, create two buttons:
- a Show button
- a Hide button
These two buttons will alternate to control the content display.
- If the content is visible by default → apply d-none to the "Show" button.
- If the content is hidden by default → apply d-none to the "Hide" button.
Script
The script should detect button clicks and act accordingly.
init = function(sheet) {
if (sheet.id() === "main") {
initMain(sheet);
}
};
const initMain = function(sheet) {
// initialize the main sheet
initContentVisibility(sheet,"content_to_hide_id", "hide_button_id", "show_button_id");
};
const initContentVisibility = function(sheet, extra_id, hide_button_id, show_button_id){
// Get the button.
let hideButton = sheet.get(hide_button_id);
let showButton = sheet.get(show_button_id);
let content = sheet.get(extra_id);
// hide the content, show show_button and hide hide_button.
const hideContent = function() {
log("hide click");
hideButton.hide();
showButton.show();
content.hide();
};
// show the contente, hide show_button and show hide_button.
const showContent = function() {
log("show click");
hideButton.show();
showButton.hide();
content.show();
};
// show
hideButton.on('click', hideContent);
// hide
showButton.on('click', showContent);
};