Stormrose/twine — pull request #1 by videlais (2013-04-05 21:41:25+00:00)
Title: Adding Passage.update(content) and Tale.add(title, tags, content)

Here is Passage.update(content) and Tale.add(title, tags, content).

The first overwrites an individual Passage.text, Passage.initialText, and the actual
content of the passage in the storeArea div. (Best used in conjunction
with Tale.get(title) to both "get" and verify that a particular passage exists.)

The second adds a new Passage to the current Tale. If the tag is
"script," it calls eval() on the text. If the tag is "stylesheet," it
adds or overwrites the existing styles in use.

(I added the minified code to Responsive, Jonah, and Sugarcane.)

Passage.prototype.update = function(content)
{
this.initialText = this.text = content;
var passages = $("storeArea").children;
for(var i = 0; i < passages.length; i++)
{
if(passages[i].hasAttribute("tiddler"))
{
if(passages[i].getAttribute("tiddler") === this.title)
{
if(passages[i].innerText)
passages[i].innerText = content;
else
passages[i].textContent = content;
}
}
}
};

Tale.prototype.add = function(title,tags,content) {
var pTitle = unescape(encodeURIComponent(title));
var el = insertElement($("storeArea"),"div",pTitle,"",content);
el.setAttribute("tiddler",pTitle);
el.setAttribute("tags",tags);
el.setAttribute("modifer","twee");
var newP = new Passage(pTitle,$(pTitle));
this.passages[title] = newP;
if(tags === "stylesheet")
{ addStyle(newP.text); }
else if(tags === "script")
{
try {
eval(newP.text);
}
catch(e) {
alert("There is a technical problem with this story (" + newP.title + ":
" + e.message + "). You may be able to continue reading, but all parts
of the story may not work properly.");
}
}
};