1 /** 2 * This file is part of the smilText parser implemented in JavaScript, 3 * 4 * Copyright (C) 2003-2009 Stichting CWI, 5 * Science Park 123, 1098 XG Amsterdam, The Netherlands. 6 * 7 * smilText parser in JavaScript is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU Lesser General Public License as published by 9 * the Free Software Foundation; either version 2.1 of the License, or 10 * (at your option) any later version. 11 * 12 * smilText parser in JavaScript is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public License 18 * along with smilText parser in JavaScript; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 /** 23 @name cwi.util 24 @namespace Hold some general-purpose functions. 25 @version 1.0 26 @author <a href="mailto:rlaiola@cwi.nl">Rodrigo Laiola Guimaraes</a> 27 */ 28 Namespace("cwi.util"); 29 30 31 32 33 34 /** 35 * Trim a given string. 36 * @param {string} str string to be trimmed 37 * @return {string} 38 */ 39 cwi.util.trim = function (str) 40 { 41 var trimmed = str.replace(/^\s+|\s+$/g, '') ; 42 return trimmed; 43 }; 44 45 /** 46 * Get a property value based on the current style. 47 * @param {string} id the element id 48 * @param {string} styleProp the style property 49 * @return {string} 50 */ 51 cwi.util.getStyleByElemId = function (el,styleProp) 52 { 53 var x = document.getElementById(el); 54 if (x.currentStyle) 55 var y = x.currentStyle[styleProp]; 56 else if (window.getComputedStyle) 57 var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp); 58 return y; 59 } 60 61 /** 62 * Get a property value based on the current style. 63 * @param {Object} el the HTML element 64 * @param {string} styleProp the style property 65 * @return {string} 66 */ 67 cwi.util.getStyleByElem = function(el,styleProp) 68 { 69 var x = el; 70 if (x.currentStyle) 71 var y = x.currentStyle[styleProp]; 72 else if (window.getComputedStyle) 73 var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp); 74 return y; 75 } 76