JavaScript Software
Here are some new projects from our Tooyen project. We have built a good amount of JavaScript modules for this project, and of course we believe in expanding knowledge rather than hoarding it. If these modules are useful--that's great! Feel free to sub-contract out to us any requests you have to make them better.
All these modules are built on the wonderful work done by Mr. Sam Stephenson in his prototype.js library. We consider his work to be truly outstanding and the first thing we did was to ensure that all of our modules look and smell as much like Sam's work as we could. We think that prototype.js should be the defacto "STL for JavaScript". Great stuff, Sam!
Please select from one of the loaded projects below:-
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.
-
sprintf.js - Here's something unusual--an implementation of "sprintf" for JavaScript. As old C programmers, we were appalled that our good friend "sprintf" was somehow missing from JavaScript itself. While the version we have isn't fully complete (some of the lesser-used sprintf format codes aren't supported), it works Pretty Good just as it is. And, of course, since it's Free Software, feel free to add the remaining features and/or rewrite the whole thing if you'd like. Just share your improvements with the rest of us, OK?
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!