Last active
January 3, 2016 22:19
-
-
Save videlais/8527604 to your computer and use it in GitHub Desktop.
Highlighting 'visited' links in Twine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
The first thing we are doing here is to create a new | |
display function, oldDisplay, as a reference to the | |
the normal History.display function. | |
(Note: History.display does most of the heavy lifting | |
in Twine. When a link is clicked, it is what | |
grabs the content of the passage from HTML and | |
adds it to the screen as text.) | |
*/ | |
History.prototype.oldDisplay = History.prototype.display; | |
/* | |
Once we have saved a reference to the History.display function, | |
we can overwrite it like the following. | |
*/ | |
History.prototype.display = function(name, source, type, callback) { | |
/* | |
We need to make sure the 'source' element is not null here. | |
Because, when this is called for the Start passage, it will be. | |
(Start doesn't have a 'source'; it isn't called | |
by any other passage.) | |
*/ | |
if(source != null) { | |
/* | |
Source is the element that did the calling. | |
In other words, an 'a' element when the user clicks on it. | |
By using its style property, we can change | |
its CSS properties. | |
*/ | |
source.style.color = "green"; | |
source.style.fontSize = "larger"; | |
} | |
/* | |
The final step is to call the oldDisplay within the same function | |
scope as it would have normally run in before we interrupted the process. | |
This is done using the 'apply' and 'this' keywords, telling the code | |
to run from the current this (History.display) scope and to apply the same | |
to History.oldDisplay using the same arguments passed to the current function scope. | |
*/ | |
this.oldDisplay.apply(this, arguments); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment