Created
December 17, 2009 01:30
-
-
Save Maciek416/258425 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * This code searches for all the <script type="application/processing" target="canvasid"> | |
| * in your page and loads each script in the target canvas with the proper id. | |
| * It is useful to smooth the process of adding Processing code in your page and starting | |
| * the Processing.js engine. | |
| */ | |
| if ( window.addEventListener ) { | |
| window.addEventListener("load", function() { | |
| var scripts = document.getElementsByTagName("script"); | |
| for ( var i = 0; i < scripts.length; i++ ) { | |
| if ( scripts[i].type == "application/processing" ) { | |
| var src = scripts[i].getAttribute("target"); | |
| console.log("i=",i,"src = ",src); | |
| var canvas = scripts[i].nextSibling; | |
| if ( src && src.indexOf("#") > -1 ) { | |
| canvas = document.getElementById( src.substr( src.indexOf("#") + 1 ) ); | |
| console.log("i=",i,"canvas=",canvas); | |
| } else { | |
| while ( canvas && canvas.nodeName.toUpperCase() != "CANVAS" ) | |
| canvas = canvas.nextSibling; | |
| } | |
| if ( canvas ) { | |
| Processing(canvas, scripts[i].text); | |
| } | |
| } | |
| } | |
| }, false); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment