/** util.js: (C) 2009 Rackspace Hosting, All Rights Reserved This file defines a single object in global scope: trc.util The util object contains internal objects which contain useful utility properties and methods. trc.util.browser: contains methods for browser detection. trc.util.dom: contains methods for manipulating the DOM. trc.util.text: contains methods and properties useful when working with plain text. trc.util.net: contains methods for creating HTTP requests. trc.util.yui : contains methods for working with the YUI toolkit. All methods/properties prepended with an underscore (_) are meant for internal use. **/ // // Define TRC // if (!window.trc) { trc= new Object(); } trc.util = new Object(); trc.util.browser = { // // Returns the current version of IE, or -1 if it's not an IE // browser. This is one of the recommended ways of detecting IE // see: // // http://msdn.microsoft.com/en-us/library/ms537509%28VS.85%29.aspx // detectIEVersion : function() { var rv = -1; // Return value assumes failure. if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); } return rv; }, // // A list of functions to execute on init. // _initFuns : new Array(), // // Has the init function event been set? // _initFunSet: false, // // Function called when the DOM has loaded. It launches all init // functions. // _onInit : function() { // // Sort by order... // this._initFuns.sort(function(a, b){ return a.order - b.order; }); for (var i=0;i -1) && (ieVersion < 7)) { element.className = name; } else { element.setAttribute ("class",name); } } }; trc.util.text = { // // Useful RegExps // blank : new RegExp ("^\\s*$"), /* A blank string */ indent : new RegExp ("^\\s+"), /* Line indent */ lines : new RegExp ("$","m"), /* All lines */ linechars : new RegExp ("(\n|\r)"), /* EOL line characters */ tabs : new RegExp ("\t","g"), /* All tabs */ // // We need this because microsoft browsers before IE 7, connot // display pre-formatted text correctly win unix style line // endings. // unix2dos : function(txt /* String */) { //if already DOS... if (txt.search(/\r\n/) != -1) { return txt; } return txt.replace (/\n/g, "\r\n"); }, // // Useful to normalize text. // dos2unix : function(txt /* String */) { //if already unix... if (txt.search(/\r\n/) == -1) { return txt; } return txt.replace(/\r/g, ""); }, // // Create a string with a character repeated x times. // repString : function (length, /* integer, size of the string to create */ ch /* string, The character to set the string to */ ) { var ret = new String(); for (var i=0;idep. // _deps : new Object(), // // An array of callback functions, these should be called when all // dependecies are loaded. // _callbacks : new Array(), // // The init function simply calls the YUI loader... // _init : function() { var yuiUtil = this; // // It takes safari a while to load the YUI Loader if it hasn't // loaded yet keep trying at 1/4 second intervals // if (!window.YAHOO) { window.setTimeout (function() { yuiUtil._init(); }, 250); return; } // // Collect requirements... // var required = new Array(); for (var req in this._deps) { required.push (req); } // // Load YUI dependecies... // var loader = new YAHOO.util.YUILoader({ require: required, loadOptional: true, filter: "RAW", onSuccess: function() { yuiUtil._depsLoaded(); }, timeout: 10000, combine: true }); loader.insert(); }, // // Called after all dependecies have been loaded // _depsLoaded : function() { // // Dependecies are loaded let everyone know. // for (var i=0;i