improved error handling with preproc (empty status & server only runs when build successful); added 1 example: selectionFlower; added <IE9 alert to template

This commit is contained in:
fjenett
2011-06-04 10:38:43 +00:00
parent dbddec591a
commit c3dbecf291
5 changed files with 146 additions and 18 deletions
@@ -0,0 +1,50 @@
/**
* This code will be embedded into the HTML page as "normal"
* JavaScript code through a <script> tag. This allows one to
* interact with the page as any normal JavaScript code can.
*/
var mySketchInstance;
// called once the page has fully loaded
window.onload = function () {
getSketchInstance();
}
// this is called (repeatedly) to find the sketch
function getSketchInstance() {
var s = Processing.getInstanceById("selectionFlower");
if ( s == undefined )
return setTimeout(getSketchInstance, 200); // try again a bit later
mySketchInstance = s;
monitorSelection();
}
// this code gets called all the time (every 1/5 sec) to check
// if the selection changed
function monitorSelection ( ) {
var txt = undefined;
if (window.getSelection) {
txt = window.getSelection().toString();
} else if (document.getSelection) {
txt = document.getSelection().toString();
} else if (document.selection) {
txt = document.selection.createRange().text;
}
if ( txt !== undefined && txt != "" )
{
mySketchInstance.setSelectionText(txt); // set the text in the sketch
console.log( txt );
}
setTimeout(monitorSelection, 1000/5);
}