(not sure if this should be here or the subreddit; feel free to let me know to move it.)
I'd like an answer to this, too. I'm not sure if asking for something like this (a feature or functionality rather than a straight-up answerable question) is in line with the rules of this forum.
You'll need some CSS to make it look pretty, but here's a start:
Macro.add('typeme', {
tags : null,
handler : function () {
var $text = $(document.createElement('textarea'));
var $wrapper = $(document.createElement('div'));
// simple error checking
if (this.args.length !== 1) {
return this.error('incorrect number of arguments');
} if (typeof this.args[0] != 'string') {
return this.error('argument should be a string');
}
// get message parameters
var message = this.args[0],
shown = '',
length = message.length,
i = 0,
id = 'typeme-output-' + message.replace(/[^A-Za-z0-9]/g, ''),
cls = 'macro-' + this.name,
content = this.payload[0].contents;
$text
.wiki(shown)
.attr({
id : id,
readonly : true
})
.addClass(cls)
.appendTo(this.output);
// listener
$(document).on('keydown', '#' + id, function (e) {
if (i < length) {
shown = shown + message.charAt(i);
$('#' + id).empty().wiki(shown);
}
if (i === length) {
$wrapper
.wiki(content)
.addClass(cls)
.insertAfter('#' + id);
}
i++;
});
}
});
Syntax:
<<typeme 'message to type out'>>
STUFF TO SHOW/CODE TO RUN ONCE MESSAGE IS COMPLETED (e.g. a [[Continue]] link)
<</typeme>>
Things to note:
- The text area generated by the macro must have focus for the typing to work.
- You can have multiples in the same passage; i.e. they shouldn't interfere with each other unless they both have the exact same message, which might cause problems.
- You can pass variables as the string argument (e.g. <<typeme $message>><</typeme>>).
- The content that is generated on completion is evaluated only on completion (so if it contains code, that code won't fire until the message is completed), and is appended beneath the text area as a div, so you may need to be careful with your white space. I made it a div because that seemed easier at the time.