front_idill/extern/fajran-tuiojs/examples/processingjs/init.js
author bastiena
Thu, 12 Apr 2012 13:09:46 +0200
changeset 27 6c08d4d7219e
parent 26 858e90c7cbaa
permissions -rw-r--r--
Middleware : GPL License added. Front Processing : GPL License added. Front IDILL : extern altered to send TUIO cursors from Middleware to Front. implemented as a plugin.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     1
/*
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     2
* This code searches for all the <script type="application/processing" target="canvasid">
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     3
* in your page and loads each script in the target canvas with the proper id.
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     4
* It is useful to smooth the process of adding Processing code in your page and starting
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     5
* the Processing.js engine.
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     6
*/
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     7
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     8
if (window.addEventListener) {
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
     9
  window.addEventListener("load", function() {
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    10
    var scripts = document.getElementsByTagName("script");
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    11
    var canvasArray = Array.prototype.slice.call(document.getElementsByTagName("canvas"));
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    12
    var canvas;
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    13
    for (var i = 0, j = 0; i < scripts.length; i++) {
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    14
      if (scripts[i].type == "application/processing") {
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    15
        var src = scripts[i].getAttribute("target");
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    16
        if (src && src.indexOf("#") > -1) {
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    17
          canvas = document.getElementById(src.substr(src.indexOf("#") + 1));
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    18
          if (canvas) {
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    19
            new Processing(canvas, scripts[i].text);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    20
            for (var k = 0; k< canvasArray.length; k++)
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    21
            {
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    22
              if (canvasArray[k] === canvas) {
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    23
                // remove the canvas from the array so we dont override it in the else
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    24
                canvasArray.splice(k,1);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    25
              }
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    26
            }
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    27
          }
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    28
        } else {
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    29
          if (canvasArray.length >= j) {
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    30
            new Processing(canvasArray[j], scripts[i].text);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    31
          }
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    32
          j++;
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    33
        }
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    34
      }
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    35
    }
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    36
  }, false);
858e90c7cbaa Front IDILL :
bastiena
parents:
diff changeset
    37
}