Debugging

One hardly ever gets it right the first time.

Functions

Util.nodeId

Definition

Name
Util.nodeId
Syntax
String = Util.nodeId(Node node [, Boolean include_path ]);

Description

Identify node by looking for id, classname or nodename.

Parameters

node
Node node to identify
include_path
Boolean Optional, include node path in identification

Return values

String node identification based on best available id for node.

Examples

u.nodeId(u.qs("#content div"), 1);

returns

u.nodeId(u.qs("#content div"));

returns

Dependencies

JavaScript
  • try ... catch
Manipulator

Nothing

Util.bug

Definition

Name
Util.bug
Syntax
Void = Util.bug( String message [, Number corner [, String color ] ] );

Description

Simple development debugging function which outputs message to screen in overlay attached to a browser corner. Also outputs messages to console.log when available.

u.bug_force

Overlay is only injected in page if u.debugURL returns true. This can be overridden by setting u.bug_force = true; in your script.

u.bug_console_only

Overlay is injected in page as default. This can be overridden by setting u.bug_console_only = true; in your script.

u.bug_position

Default positioning of bug-message is absolute. This can be overridden by setting u.bug_position = fixed|relative|static in your script.

u.bug_bg

Default background color of bug-message is white. This can be overridden by setting u.bug_bg = #ff0000; (specifying whatever color you want) in your script.

u.bug_max_width

Default width of bug-message is auto. This can be overridden by setting u.bug_max_width = 123; (px will be added by u.bug) in your script.

Parameters

message
String message to output to screen/console.
corner
Integer Optional, corner. Default top left. If corner is not an Integer, parameter is assumed to contain color.
Options
0-3
Corner to attach message to, starting with top left corner continuing clockwise.
color
String Optional, text-color. Default black.

Return values

Void Outputs message to screen.

Examples

u.bug("hello world");

outputs "hello world" in top left corner, using black text-color.

u.bug("hello world", 0, "red");

outputs "hello world" in top left corner, using red text-color.

u.bug("hello world", 2);

outputs "hello world" in bottom right corner, using black text-color.

u.bug("hello world", "green");

outputs "hello world" in top left corner, using green text-color.

Dependencies

JavaScript
  • String.replace
  • typeof
  • isNaN
  • Node.innerHTML
Manipulator
  • Util.querySelector
  • Util.debugURL
  • Util.appendElement

Util.xInObject

Definition

Name
Util.xInObject
Syntax
Void = Util.xInObject( Object object [, JSON _options] );

Description

Output each index/value pair of object using Util.bug.

Parameters

object
Object object to output
_options
JSON Optional, JSON object with options for object debugging.
Options
return
return debugging information as string instead of sending it to u.bug. Default false.
objects
Explore nested objects by applying u.xInObject to nested objects (can cause infinite loops). Default false.

Return values

Void Object content is outputted to screen via Util.bug

Examples

u.xInObject(document.body);

Will output a looong list of all attributes, functions, constants, etc.

Dependencies

JavaScript
  • typeof
Manipulator
  • Util.debugURL
  • Util.nodeId

Util.exception

Definition

Name
Util.exception
Syntax
Void = Util.exception( String name, Object arguments, String exception );

Description

dependencies u.bug to generate standard exception output.

Parameters

name
String The name of function exception occured in
arguments
Object The arguments object from the function causing the exception
exception
String The exception message

Return values

Void

Examples

No examples

Dependencies

JavaScript
  • arguments.callee.caller
Manipulator

Util.bug

Util.xInObject

Util.debugURL

Definition

Name
Util.debugURL
Syntax
Boolean = Util.debugURL();

Description

Is the current url a test-url? Does it run on .local. The following functions only output to screen or console if site is running on valid test-urls.

To override the domain detection in other debugging functions, set u.bug_force = true; in your script

Parameters

No parameters

Return values

Boolean Debug url returns true, else false.

Examples

No examples

Dependencies

JavaScript
  • Sting.match
Manipulator

Nothing

Files

Main file

  • u-debug.js

Segment support files

  • none

Segment dependencies

desktop_edge
u-debug.js
desktop_ie11
u-debug.js
desktop
u-debug.js
desktop_ie10
u-debug.js
desktop_ie9
u-debug.js
desktop_light
u-debug.js
tablet
u-debug.js
tablet_light
u-debug.js
smartphone
u-debug.js
mobile
not tested
mobile_light
not tested
tv
u-debug.js
seo
not supported