Hey there !
I'm using Chapel's <<message>> macro
// message macro, by chapel (with help from T.M. Edwards); for sugarcube 2
// version 1.0.0
// see the documentation: https://github.com/ChapelR/custom-macros-for-sugarcube-2#message-macro
//intialize namespace
setup.messageMacro = {};
// default text option:
setup.messageMacro.default = 'Help';
// <<message>> macro
Macro.add('message', {
tags : null,
handler : function () {
var message = this.payload[0].contents;
var $wrapper = $(document.createElement('span'));
var $link = $(document.createElement(this.args.includes('btn') ? 'button' : 'a'));
var $content = $(document.createElement('span'));
$link
.wiki(this.args.length > 0 && this.args[0] !== 'btn' ? this.args[0] : setup.messageMacro.default)
.ariaClick(function () {
if ($wrapper.hasClass('open')) {
$content
.css('display', 'none')
.empty();
}
else {
$content
.css('display', 'block')
.wiki(message);
}
$wrapper.toggleClass('open');
});
$wrapper
.attr('id', 'macro-' + this.name + '-' + this.args.join('').replace(/[^A-Za-z0-9]/g, ''))
.addClass('message-text')
.append($link)
.append($content)
.appendTo(this.output);
}
});
Which works perfectly well. "This macro displays a link or, optionally, a button. The link or button can be clicked to display a message immediately below it in the passage text, and clicked again to collapse the message."
I have, however, an issue with it. I'm using that macro in my StoryCapion passage. Which means the macro loads again and again.
Whenever I change passage within the story, the unfolded text re-folds itself within the link, and the player has to click the link again to display it. Would there be a way to solve this ? I was thinking of adding a boolean variable, something like <<set $opened to true>> whenever it would be opened, and <<set $opened to false>> whenever it would be closed, and it wouldn't close whenever $opened is true.
But I have no idea how to include that within the javascript part of the code...
Thanks a lot !