1 /* 2 SpiderGL Computer Graphics Library 3 Copyright (c) 2010, Marco Di Benedetto - Visual Computing Lab, ISTI - CNR 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions are met: 8 * Redistributions of source code must retain the above copyright 9 notice, this list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above copyright 11 notice, this list of conditions and the following disclaimer in the 12 documentation and/or other materials provided with the distribution. 13 * Neither the name of SpiderGL nor the 14 names of its contributors may be used to endorse or promote products 15 derived from this software without specific prior written permission. 16 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 DISCLAIMED. IN NO EVENT SHALL PAUL BRUNT BE LIABLE FOR ANY 21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** 30 * @fileOverview DOM 31 */ 32 33 /** 34 * The SpiderGL.DOM namespace. 35 * 36 * @namespace The SpiderGL.DOM namespace. 37 */ 38 SpiderGL.DOM = { }; 39 40 /** 41 * Gets a document element object by id. 42 * 43 * The returned element object is retrieved by a direct call to document.getElementById(id). 44 * 45 * @param {string} id The element id. 46 * @return {Element} The document element. 47 */ 48 SpiderGL.DOM.getElementById = function (elementId) { 49 return document.getElementById(elementId); 50 } 51 52 /** 53 * Gets the text of a document element. 54 * 55 * The returned text is retrieved by concatenating the text content of internal element nodes. 56 * 57 * @param {string} id The element id. 58 * @return {string} The text contained in the document element. 59 */ 60 SpiderGL.DOM.getElementText = function (elementId) { 61 var elem = document.getElementById(elementId); 62 if (!elem) return null; 63 64 var str = ""; 65 elem = elem.firstChild; 66 while (elem) { 67 if (elem.nodeType == 3) { 68 str += elem.textContent; 69 } 70 elem = elem.nextSibling; 71 } 72 73 return str; 74 } 75 76