It works perfectly when doing this...
Yet I have an issue. (Again.)
I am using Chapel's <<message>> macro. And it doesn't work within...
Here's the 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);
}
});
(function () {
var state = [];
prehistory['handle-messages'] = function () {
state = [];
$('.message-text').each( function () {
var $self = $(this);
if ($self.hasClass('open')) {
state.push($self.attr('id'))
}
});
};
$(document).on(':passageend', function () {
state.forEach( function (id) {
$('#' + id + ' a').trigger('click');
});
});
}());
Here's what I tested out :
[img[$Helmet[0]]]
[img[$Helmet[1]]]
<<display "scriptImage">>
<<message "Test">>
[img[$Helmet[0]]]
[img[$Helmet[1]]]
<<display "scriptImage">>
<</message>>
Here's what's inside "scriptImage"
<<script>>
$(document).one(':passagerender', function (ev) {
const content = $(ev.content);
content
.find('img[src="images/helmet0.jpg"]')
.attr('title', 'Your starting helmet.');
content
.find('img[src="images/helmet1.jpg"]')
.attr('title', 'A better helmet. +3 strength, +1 endurance.');
});
<</script>>
The <<script>> works for 2 first images.
But when in the <<message>> macro, the image displays, but not the text...
Again, thanks for your incredible help.