User Tools

Site Tools



This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
adding_new_behaviors [2013/11/13 00:35]
klembot created
adding_new_behaviors [2017/10/09 20:39] (current)
Line 1: Line 1:
-===== Adding New Behaviors ===== +#redirect [[script]]
- +
-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: +
- +
-<​code>​ +
-History.prototype.originalDisplay = History.prototype.display;​ +
- +
-History.prototype.display = function (title, link, render) +
- if ((render != '​quietly'​) && (render != '​offscreen'​)) +
- removeChildren($('​passages'​));​ +
-  +
- this.originalDisplay.apply(this,​ arguments);​ +
-}; +
-</​code>​ +
- +
-The execution order of passages tagged ''​script''​ is not guaranteed.+
adding_new_behaviors.txt · Last modified: 2017/10/09 20:39 (external edit)