input.js | |
---|---|
Effects to request viewer input. | var input_thanks,
input_save_to,
input_jump_to,
input_options = [],
input_value = 'Default',
input_choice = false,
input_autocomplete; |
Request viewer input as a single-line text box. The Usage:
Auto-complete is also possible, but you must include your own copy of jQuery UI. This way, Cacophony avoids conflicts with existing sites should we provide our own. Usage: | function input_text (data) {
cacophony.input = true;
input_thanks = data.thanks;
input_save_to = data.save_to;
input_jump_to = data.jump_to;
if (! data.value) {
data.value = '';
}
if (data.autocomplete) {
input_autocomplete = data.autocomplete;
autocomplete = 'onfocus="$(this).autocomplete ({source: input_autocomplete})"';
} else {
autocomplete = '';
}
cacophony.html (
'<div style="width: ' + Math.round (cacophony.width * .6) + 'px; height: ' + Math.round (cacophony.height * .35) + 'px; background-color: rgba(255, 255, 255, .7); padding: 20px; text-align: left; border-radius: 10px">' +
'<form onsubmit="return input_save (this)" style="display: inline">' +
'<p>' + data.msg + '</p>' +
'<p><input type="text" id="input-field" name="input-field" value="' + data.value + '" ' + autocomplete + ' style="border: 1px solid #666; width: 70%; height: 20px" />' +
' <input type="submit" value="Submit" /> <a href="#" onclick="return input_cancel ()">Cancel</a></p>' +
'</form></div>');
} |
Request viewer input as a multiline text box. The Usage: | function input_textarea (data) {
cacophony.input = true;
input_thanks = data.thanks;
input_save_to = data.save_to;
input_jump_to = data.jump_to;
if (! data.value) {
data.value = '';
}
cacophony.html (
'<div style="width: ' + Math.round (cacophony.width * .6) + 'px; height: ' + Math.round (cacophony.height * .35) + 'px; background-color: rgba(255, 255, 255, .7); padding: 20px; text-align: left; border-radius: 10px">' +
'<form onsubmit="return input_save (this)" style="display: inline">' +
'<p>' + data.msg + '</p>' +
'<p><textarea id="input-field" name="input-field" style="border: 1px solid #666; width: 100%; height: 60px">' + data.value + '</textarea></p>' +
'<p><input type="submit" value="Submit" /> <a href="#" onclick="return input_cancel ()">Cancel</a></p>' +
'</form></div>');
} |
Request viewer input as a set of choices, each of which specify
a beat number to jump to via Usage: | function input_branching (data) {
input_options = data.options;
input_save_to = data.save_to;
cacophony.html (data.msg);
var opts = '';
for (var i = 0; i < input_options.length; i++) {
opts += '<p><a href="#" onclick="return input_choose (' + i + ')">' + input_options[i].choice + '</a></p>';
}
cacophony.html (
'<div style="width: ' + Math.round (cacophony.width * .6) + 'px; height: ' + Math.round (cacophony.height * .35) + 'px; background-color: rgba(255, 255, 255, .7); padding: 20px; text-align: left; border-radius: 10px">' +
'<p>' + data.msg + '</p>' +
opts +
'</div>');
} |
Handles the input for | function input_save () {
cacophony.input = false;
input_value = $('#input-field').get (0).value;
$.post (input_save_to, { input: input_value });
cacophony.html (
'<div style="width: ' + Math.round (cacophony.width * .6) + 'px; height: ' + Math.round (cacophony.height * .35) + 'px; background-color: rgba(255, 255, 255, .7); padding: 20px; text-align: left; border-radius: 10px">' +
'<p style="width: 100%">' + input_thanks + '</p>' +
'</div>');
setTimeout ('cacophony.html ();', 3000);
if (input_jump_to) {
cacophony.jumpTo (input_jump_to);
input_jump_to = false;
}
return false;
}
function input_cancel () {
cacophony.input = false;
input_value = false;
cacophony.html ();
if (input_jump_to) {
cacophony.jumpTo (input_jump_to);
input_jump_to = false;
}
return false;
} |
Handles the choice selection for | function input_choose (n) {
input_choice = n + 1;
if (input_save_to) {
$.post (input_save_to, { choice: input_choice });
}
cacophony.html ();
cacophony.jumpTo (input_options[n].jump_to);
} |
Register all effects. | _e['input_text'] = input_text;
_e['input_textarea'] = input_textarea;
_e['input_branching'] = input_branching;
|