global.js - This simple object provides really common stuff (like browser capabilities) that we ended up using in many different places. You'll need this script in addition to the standard prototype.js, in order to use any of the scripts below. One nice new class in this script is the Utils class, which defines an extended parseDate function that supports lots'o'date formats.
msg.js - A set of simple messaging functions available through a global "Msg" object, where the message target should be a reference to a field on the page (such as a message display). Has support for informational, warning, and error messages.
Our approach was to create a Sprintf object that implemented the parsing and formatting functions, and then provide the following global functions:
- sprintf(fmt, args...) - Invoke with your favorite C format string and a set of variable parameters and you should get back what you expect. Example:sprintf('%.2f', 42.359) returns '42.35'
- safe_sprintf(fmt, args...) - Identical to the above, but space characters are replaced with . Example:safe_sprintf('%-10s', 'Hello') returns 'Hello     '
- snprintf(max_len, fmt, args...) - Cut off your sprintf to fit a max desired size. Example:snprintf(5, '%s', 'Hello, World!') returns 'Hello'
- safe_snprintf(max_len, fmt, args...) - Identical to safe_sprintf except that it honors your max length.
string.js - Just your garden-variety set of string functions from a C-programmer's point-of-view. Things like trim, rtrim, empty, isdigit, isalnum and so on. The source should be pretty self-explanatory.
timer.js - A set of simple timing routines (via a Timer class) that allow user-defined actions to occur either on a single timer or a recurring timer. Also has some nice derived classes that do handy things like display a countdown in the browser status bar (irritating, I know, but sometimes useful).
validate.js - Provides a Validate class with the following handy-dandy validation routines built into it: required field, simple email validation, telephone number validation, age validation, password strength validation, field length validation, extended date validation, integer/floating point numeric validation, etc. user-defined actions to occur either on a single timer or a recurring timer. Also has some nice derived classes that do handy things like display a countdown in the browser status bar (irritating, I know, but sometimes useful).
munge-links.js - Ah, support for the "standard" rel=external modifier in anchor elements. Since no browser *actually supports this yet* we have to munge all the A elements after page load time to set the target to "_blank" manually. And why, might you ask? So your pages will conform to the XHTML standard, of course!