/*! p5.dom.js v0.1.5 November 7, 2014 */ /** *

The web is much more than just canvas and p5.dom makes it easy to interact * with other HTML5 objects, including text, hyperlink, image, input, video, * audio, and webcam.

*

There is a set of creation methods, DOM manipulation methods, and * an extended p5.Element that supports a range of HTML elements. See the * * beyond the canvas tutorial for a full overview of how this addon works. * *

Methods and properties shown in black are part of the p5.js core, items in * blue are part of the p5.dom library. You will need to include an extra file * in order to access the blue functions. See the * using a library * section for information on how to include this library. p5.dom comes with * p5 complete or you can download the single file * * here.

*

See tutorial: beyond the canvas] * for more info on how to use this libary. * * @module p5.dom * @submodule p5.dom * @for p5.dom * @main */ var p5DOM = (function(){ // ============================================================================= // p5 additions // ============================================================================= /** * Searches the page for an element with given ID and returns it as * a p5.Element. The DOM node itself can be accessed with .elt. * Returns null if none found. * * @method getElement * @param {String} id id of element to search for * @return {Object/p5.Element|Null} p5.Element containing node found */ p5.prototype.getElement = function (e) { var res = document.getElementById(e); if (res) { return new p5.Element(res); } else { return null; } }; /** * Searches the page for elements with given class and returns an * array of p5.Elements. The DOM nodes themselves can be accessed * with .elt. Returns an empty array if none found. * * @method getElements * @param {String} class class name of elements to search for * @return {Array} array of p5.Element wrapped nodes found */ p5.prototype.getElements = function (e) { var arr = []; var res = document.getElementsByClassName(e); if (res) { for (var j = 0; j < res.length; j++) { var obj = new p5.Element(res[j]); arr.push(obj); } } return arr; }; /** * Removes all elements created by p5, except any canvas / graphics * elements created by createCanvas or createGraphics. * Event handlers are removed, and element is removed from the DOM. * @method removeElements * @example *

* function setup() { * createCanvas(100, 100); * createDiv('this is some text'); * createP('this is a paragraph'); * } * function mousePressed() { * removeElements(); // this will remove the div and p, not canvas * } *
* */ p5.prototype.removeElements = function (e) { for (var i=0; i