User Tools

Site Tools


This is an old revision of the document!

Adding New Behaviors

Just as you can tag a passage stylesheet to have its contents treated as CSS style rules, you can use the script tag to include custom JavaScript in your story. All passages with this tag are executed when the page loads, which you can use as an opportunity to do two things:

  • Perform some initialization. This passage asks readers what their names are when they first open the story:

    prompt(“Hi! What's your name?”);

    This example is not particularly useful, but if you are integrating extra JavaScript code into your story, this can be a useful way to do some initialization.
  • Modify how your story will work. To do this properly requires careful inspection of the Twee API, which is outside the scope of this document. As an example, however, this passage forces only one passage to be displayed at a time in the Jonah story template:
History.prototype.originalDisplay = History.prototype.display;

History.prototype.display = function (title, link, render)
	if ((render != 'quietly') && (render != 'offscreen'))
	this.originalDisplay.apply(this, arguments);

The execution order of passages tagged script is not guaranteed.

adding_new_behaviors.1384320952.txt.gz · Last modified: 2017/10/09 20:36 (external edit)