topical media & game development

talk show tell print

lib-present-graphic-canvas-init.js / js



  /*
   * 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 ( document.addEventListener ) {
   document.addEventListener("DOMContentLoaded", function() {
    var scripts = document.getElementsByTagName("script");
    
    for ( var i = 0; i < scripts.length; i++ ) {
     if ( scripts[i].type == "application/processing" ) {
      var src = scripts[i].src, canvas = scripts[i].nextSibling;
   
      if ( src && src.indexOf("#") ) {
       canvas = document.getElementById( src.substr( src.indexOf("#") + 1 ) );
      } else {
       while ( canvas && canvas.nodeName.toUpperCase() != "CANVAS" )
        canvas = canvas.nextSibling;
      }
  
      canvas = document.getElementsById("canvas");
      if ( canvas ) {
       Processing(canvas, scripts[i].textContent);
      }
     }
    }
   }, false);
  }
  


(C) Æliens 27/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.