This one’s a bit long, please bear with me. Could you point me to some possible solution to this?
- I want to render passage 2 inside passage 1.
- I want to generate a clickable link within passage 2 through a function.
- The function cannot listen to passage events for the “make link clickable” part.
In Snowman 2.0.3, I want a function that inserts a link in the passage content. The text part can be as simple as this:
window.insertLink = function( text ) { return "<a>" + text + "</a>" }
And then, to use it in a passage:
<%= insertLink( "This is a link!" ) %>
How to make this link clickable? With this forum’s help, I came to this solution. It uses click()
and unbind()
, and listens to the passage displayed event to work.
window.insertLink = function( text, target ) {
// THIS PART MAKES THE GAME CLICKABLE
$(document).on('sm.passage.shown', function () {
$("#reveal-"+target).unbind().click(function () {
// HERE WE PUT WHATEVER THE LINK DOES WHEN CLICKED
} )
});
// THIS PART PRINTS THE LINK TEXT
var link;
link = '<a id="reveal-'+target+'" href="javascript:void(0)">'+text+'</a>';
return link;
}
This is a simplified version of what I had in The good people.
Where’s the problem? Here: it listens to the passage displayed event. In the code, this is .on('sm.passage.shown'...
In Snowman, when you display a passage through standard Twine links or a story.show()
function, a sequence of events is fired.
But if passage display ends, and all events fire, and after that you render another passage inside that with story.render()
, there is no event to listen to. If the new passage has my insertLink() function, the part that makes the link clickable won’t work.
So. Do you think there’s any simple solution to this? Or perhaps it would take a new Snowman feature?
Thanks!