idmillington / undum

A client-side framework for narrative hypertext interactive fiction.
https://idmillington.github.com/undum
MIT License
336 stars 80 forks source link

Add new variants of System.prototype.write() #36

Closed sequitur closed 9 years ago

sequitur commented 9 years ago

Those two helper functions are variants of System.prototype.write, different only in that they pass different sets of JQuery function names to doWrite(). I found myself wanting ways of replacing content wholesale or adding nodes into an element in a way that was square with everything doWrite() does, so this is the easiest way to get that working in a modular way.

System.prototype.writeInto() calls doWrite() passing the name of the JQuery append() function. This means that unlike System.prototype.write(), when a selector is specified, new content is written as a new child node at the end of the matched element, rather than as a new sibling node after the matched element.

System.prototype.replaceWith() calls doWrite() passing the name of the JQuery replaceWith() function. The result is that either the matched element, or the entire situation is replaced with the given content. I wrote this to use it exclusively with a selector, and I'm not sure the latter is safe; maybe this should throw an error if it's called without a selector, or instead it should default to selecting the first/last child node of the situation?

idmillington commented 9 years ago

Excellent code + docs + explanation. Thank you. Merged.

sequitur commented 9 years ago

That was fast! Thank you.