//------------------------------------------------------------------------ // Name: LW_Debug_Debugger // Desc: Works with the PHP LW_Debug_Debugger class to display debugging // information. //------------------------------------------------------------------------ LW_Debug_Debugger = { debug_items: Array(), // The debug items. queries: Array(), // The queries array. database_resources: Array(), // The database resources array. resources: Array(), // The resources array. execution_time: "", // The execution time of the page. //---------------------------------------------------------------------- // Name: addSystemSetting() // Desc: Adds a setting. //---------------------------------------------------------------------- addSystemSetting: function( category, setting, value ) { // Add the setting. LW_Debug_Debugger.system_settings[category].push( { setting: setting, value: value } ); }, //---------------------------------------------------------------------- // Name: addItem() // Desc: Adds a debug item. //---------------------------------------------------------------------- addItem: function( message, error_code, file, line, php_class, php_function, type ) { // Add the debug item. LW_Debug_Debugger.debug_items.push( { message: message, error_code: error_code, file: file, line: line, php_class: php_class, php_function: php_function, type: type, args: Array() } ); }, //---------------------------------------------------------------------- // Name: addFunctionArg() // Desc: Adds a function's argument. //---------------------------------------------------------------------- addFunctionArg: function( id, arg ) { // Get the debug item. var debug_item = LW_Debug_Debugger.debug_items[id]; // Add the function argument. debug_item.args.push( arg ); }, //---------------------------------------------------------------------- // Name: addQuery() // Desc: Adds a query. //---------------------------------------------------------------------- addQuery: function( query, file, line ) { // Add the debug item. LW_Debug_Debugger.queries.push( { query: query, file: file, line: line } ); }, //---------------------------------------------------------------------- // Name: addDBResource() // Desc: Adds a database resource. //---------------------------------------------------------------------- addDBResource: function( host, name ) { // Add the database resource. LW_Debug_Debugger.database_resources.push( { host: host, name: name } ); }, //---------------------------------------------------------------------- // Name: addResource() // Desc: Adds a resource. //---------------------------------------------------------------------- addResource: function( class_name, id ) { // Add the resource. LW_Debug_Debugger.resources.push( { class_name: class_name, id: id } ); }, //---------------------------------------------------------------------- // Name: showDebugInfo() // Desc: Pops up a window with the debug information. //---------------------------------------------------------------------- showDebugInfo: function() { var window_html = ""; var debug_window = null; var last_resource_class = ""; // Start getting the debug HTML. window_html += ""; window_html += "Debug Information"; window_html += ""; window_html += ""; //////////////////////////////////////// // Execution Information window_html += "

Execution Information

"; window_html += "
"; window_html += "Page Execution Time:
" + LW_Debug_Debugger.execution_time + " Seconds

"; window_html += "Number of Debug Items: " + LW_Debug_Debugger.debug_items.length + "
"; window_html += "Number of Queries: " + LW_Debug_Debugger.queries.length + "
"; window_html += "Number of Resources: " + LW_Debug_Debugger.resources.length + "
"; window_html += "
"; //////////////////////////////////////// // Debug items. window_html += "

Debug Information

"; // Loop through each debug item. formatted_debug_items = LW_Debug_Debugger.formatDebugItems(); for ( var i = 0; i < formatted_debug_items.length; i++ ) { // Get the debug item. var debug_item = formatted_debug_items[i]; window_html += "

Item #" + (i + 1) + "

"; window_html += "
"; window_html += debug_item; window_html += "
"; } // Next debug item. //////////////////////////////////////// // Database queries. window_html += "

Database Queries (" + LW_Debug_Debugger.queries.length + ")

"; // Loop through each query. for ( var i = 0; i < LW_Debug_Debugger.queries.length; i++ ) { // Get the query. var query = LW_Debug_Debugger.queries[i]; // Show the query. window_html += "

Query #" + (i + 1) + "

"; window_html += "
"; window_html += '"' + query.query + '"
'; window_html += "File: " + query.file + "
"; window_html += "Line: " + query.line + "
"; window_html += "
"; } // Next query. //////////////////////////////////////// // Resource information. window_html += "

Resource Information (" + LW_Debug_Debugger.resources.length + ")

"; // Loop through each DB resource. for ( var i = 0; i < LW_Debug_Debugger.database_resources.length; i++ ) { // Get the DB resource. var resource = LW_Debug_Debugger.database_resources[i]; // Show the DB resource. window_html += "

DB #" + (i + 1) + "

"; window_html += "
"; window_html += "DB Host: " + resource.host + "
"; window_html += "DB Name: " + resource.name + "
"; window_html += "
"; } // Next DB resource. // Loop through each resource. for ( var i = 0, n = 0; i < LW_Debug_Debugger.resources.length; i++, n++ ) { // Get the resource. var resource = LW_Debug_Debugger.resources[i]; // If we haven't encountered this resource yet. if ( last_resource_class != resource.class_name ) { // Reset n. n = 0; // Store this new resource's class name. last_resource_class = resource.class_name; } // Show the resource. window_html += "

" + resource.class_name + " #" + (n + 1) + "

"; window_html += "
"; window_html += "ID: " + resource.id + "
"; window_html += "
"; } // Next resource. // Open a window for the output. debug_window = window.open( "", "DebugWindow", "menubar=yes,scrollbars=yes,status=yes,width=500,height=500" ); // Show the output. debug_window.document.open(); debug_window.document.write( window_html ); debug_window.document.close(); }, //---------------------------------------------------------------------- // Name: showDebugInfo() // Desc: Loops through each debug item and formats it ready for printing. //---------------------------------------------------------------------- formatDebugItems: function() { var formatted_items = Array(); // Loop through each debug item. for ( var i = 0; i < LW_Debug_Debugger.debug_items.length; i++ ) { var debug_item = LW_Debug_Debugger.debug_items[i]; formatted_items[i] = ""; // Error code. if ( debug_item.error_code != "" ) formatted_items[i] += "[ " + debug_item.error_code + " ] - "; // Message. if ( debug_item.message != "" ) formatted_items[i] += '"' + debug_item.message + '"
'; // File. if ( debug_item.file != "" ) formatted_items[i] += "File: " + debug_item.file + "
"; // Line. if ( debug_item.line != "" ) formatted_items[i] += "Line: " + debug_item.line + "
"; // Class. if ( debug_item.php_class != "" ) formatted_items[i] += "Class: " + debug_item.php_class + "
"; // Function. if ( debug_item.php_function != "" ) formatted_items[i] += "Function: " + debug_item.php_function + "
"; // Type. if ( debug_item.php_function != "" ) { // Type of function? if ( debug_item.type == "->" ) { formatted_items[i] += "Type: Class Function
"; } else if ( debug_item.type == "::" ) { formatted_items[i] += "Type: Static Function
"; } else { formatted_items[i] += "Type: Normal Function
"; } } // End type. // Prototype. if ( debug_item.php_function != "" ) { formatted_items[i] += "Prototype: "; // Any class? if ( debug_item.php_class != "" ) formatted_items[i] += debug_item.php_class; // Any type? if ( debug_item.type != "" ) formatted_items[i] += debug_item.type; // Put the function name. formatted_items[i] += debug_item.php_function + "( "; // Loop through the args. for ( var n = 0; n < debug_item.args.length; n++ ) { formatted_items[i] += debug_item.args[n]; if ( n != debug_item.args.length - 1 ) formatted_items[i] += ", "; } // Next arg. // End the function. formatted_items[i] += " )"; formatted_items[i] += "
"; } // End prototype. formatted_items[i] += "
"; } // Next debug item. // Return the formatted items. return formatted_items; } }; //------------------------------------------------------------------------ // Package: Structures // The various structures used by the system. // // Topic: Dependencies // - //------------------------------------------------------------------------ //------------------------------------------------------------------------ // Class: LW_Structure_Color // Handles a single color. //------------------------------------------------------------------------ //------------------------------------------------------------------------ // Constructor: LW_Structure_Color() // Class constructor. // // Parameters: // RGB - A six character string of Red, Green and Blue values, eg: "FF2345". // // OR // // R - Red value, 0 - 255. // G - Green value, 0 - 255. // B - Blue value, 0 - 255. //------------------------------------------------------------------------ function LW_Structure_Color() { // What type of argument was passed in? if ( arguments.length == 1 && (typeof arguments[0] == "string" || arguments[0] instanceof String) ) { this.R = parseInt( arguments[0].substring( 0, 2 ), 16 ); this.G = parseInt( arguments[0].substring( 2, 4 ), 16 ); this.B = parseInt( arguments[0].substring( 4, 6 ), 16 ); } // End if hex string. else if ( arguments.length == 3 ) { this.R = arguments[0]; this.G = arguments[1]; this.B = arguments[2]; } // End if numbers passed in. else { this.R = null; this.G = null; this.B = null; } // End if null passed in. } //------------------------------------------------------------------------ // Public Member Functions //------------------------------------------------------------------------ //------------------------------------------------------------------------ // Function: toHexString() // Returns the color as a string of hexidecimal values. //------------------------------------------------------------------------ LW_Structure_Color.prototype.toHexString = function() { var R = (this.R < 16) ? "0" + this.R.toString( 16 ) : this.R.toString( 16 ); var G = (this.G < 16) ? "0" + this.G.toString( 16 ) : this.G.toString( 16 ); var B = (this.B < 16) ? "0" + this.B.toString( 16 ) : this.B.toString( 16 ); return R + G + B; } //------------------------------------------------------------------------ // Class: LW_Structure_Dimensions // Handles a single set of dimensions. //------------------------------------------------------------------------ //------------------------------------------------------------------------ // Constructor: LW_Structure_Dimensions() // Class constructor. // // Parameters: // width - The width to store. // height - The height to store. // // OR // // element - A DOM element, in which case it will store the dimensions // of that element at the time this structure was created. //------------------------------------------------------------------------ function LW_Structure_Dimensions() { // What type of arguments passed in? if ( arguments.length == 2 ) { // Store the passed in parameters. this.width = arguments[0]; this.height = arguments[1]; } // End if a width and height. else if ( arguments.length == 1 ) { var element = arguments[0]; // Get the element's dimensions. this.width = LW_DOM_Library.getWidth( element ); this.height = LW_DOM_Library.getHeight( element ); } // End if element passed in. } //------------------------------------------------------------------------ // Class: LW_Structure_Position // Handles a single position. For positioning objects relative to its // containing element. //------------------------------------------------------------------------ //------------------------------------------------------------------------ // Constructor: LW_Structure_Position() // Class constructor. // // Parameters: // top - The value from the top of the containing element. // right - The value from the right of the containing element. // bottom - The value from the bottom of the containing element. // left - The value from the left of the containing element. //------------------------------------------------------------------------ function LW_Structure_Position( top, right, bottom, left ) { // Store the passed in parameters. this.top = top; this.right = right; this.bottom = bottom; this.left = left; } //------------------------------------------------------------------------ // Class: LW_Structure_Point // Handles a single point. //------------------------------------------------------------------------ //------------------------------------------------------------------------ // Constructor: LW_Structure_Point() // Class constructor. // // Parameters: // X - The X value of the point. // Y - The Y value of the point. //------------------------------------------------------------------------ function LW_Structure_Point( X, Y ) { // Store the passed in parameters. this.X = X; this.Y = Y; } //------------------------------------------------------------------------ // Class: LW_Structure_Region // Handles a single region. //------------------------------------------------------------------------ //------------------------------------------------------------------------ // Constructor: LW_Structure_Region() // Class constructor. // // Parameters: // min_point - The of the top left corner. // max_point - The of the bottom right corner. // // OR // // element - A DOM element, in which case the region will be the // containing region of the element. //------------------------------------------------------------------------ function LW_Structure_Region() { // What was passed in? if ( arguments.length == 2 ) { // Store the passed in parameters. this.min_point = arguments[0]; this.max_point = arguments[1]; } // End if points passed in. else if ( arguments.length == 1 ) { var element = arguments[0]; // Get the element's position for the region's min point. this.min_point = LW_DOM_Library.getXY( element ); // Get the max point for the region. this.max_point = new LW_Structure_Point( (this.min_point.X + element.offsetWidth), (this.min_point.Y + element.offsetHeight) ); } // End if HTML element passed in. } //------------------------------------------------------------------------ // Public Member Functions //------------------------------------------------------------------------ //------------------------------------------------------------------------ // Function: intersectRegion() // Used to test if two objects are intersecting // each other. // // Parameters: // region - The that you'd like to test for // intersection against this object. // in_test - (Optional) If this is set to true, the region passed in // must be fully contained by this object. // epsilon - (Optional) This is the allowable mistake that can happen // between the tests, eg: if this is 1, then if the region // is 1 pixel away from intersecting, this function will // still return true. //------------------------------------------------------------------------ LW_Structure_Region.prototype.intersectRegion = function( region, in_test, epsilon ) { // Get the epsilon. epsilon = (epsilon) ? epsilon : 0; // Only do this if we are testing if it's completely contained. if ( in_test ) { var contained = true; // Is the region completely contained in this region? if ( region.min_point.X < (this.min_point.X + epsilon) || region.min_point.X > (this.max_point.X + epsilon) ) contained = false; else if ( region.min_point.Y < (this.min_point.Y + epsilon) || region.min_point.Y > (this.max_point.Y + epsilon) ) contained = false; else if ( region.max_point.X < (this.min_point.X + epsilon) || region.max_point.X > (this.max_point.X + epsilon) ) contained = false; else if ( region.max_point.Y < (this.min_point.Y + epsilon) || region.max_point.Y > (this.max_point.Y + epsilon) ) contained = false; // Return. return contained; } // End if completely contained test. else { // Perform the intersection test. return ((this.min_point.X + epsilon) <= region.max_point.X) && ((this.min_point.Y + epsilon) <= region.max_point.Y) && ((this.max_point.X + epsilon) >= region.min_point.X) && ((this.max_point.Y + epsilon) >= region.min_point.Y); } // End normal touching test. } //------------------------------------------------------------------------ // Function: containsPoint() // Used to test if there is an object within the // bounds of this region. // // Parameters: // point - The object. //------------------------------------------------------------------------ LW_Structure_Region.prototype.containsPoint = function( point ) { var contained = true; // Is the point completely contained in this region? if ( this.min_point.X > point.X || this.max_point.X < point.X ) contained = false; if ( this.min_point.Y > point.Y || this.max_point.Y < point.Y ) contained = false; // Return. return contained; } // First, before we do anything, load the Yahoo! UI DOM library. document.writeln("