( Please read this before considering using it)
Description
The MJSLIB main module contains general purpose stuff which are used all along other modules of this collection. Part of this will probably be very useful for your coding too, hence this page of documentation.Javascript runtime
Event Handlers
Dealing with events is a pain because of differences between browsers. The main module offer a mecanism which works everywhere the same way:
mjs_setEventCallback(evname,name,obj,code)
This function binds the given event 'evname' within the DOM element 'obj' to the function 'func'. The event name need to be expressed in the standardized way, not with the "on" prefix that is used in few browsers, and from the inline HTML event binding (ex: "click" is a good event name, not "onclick").
The second parameter is a name that you will have to choose and associate with this binding; it will be used to make sure the same event is not bound twice inadvertently.
Your callback function will receive an unique parameter: the element that triggered the event (a button for "click", a form for "submit", etc.). This is the element you passed to the registration function (parameter 'obj'). Your callback will have to return a boolean value. When returning false, the default handing of the event will be bypassed. This is something especially useful when dealing with "submit" event, when you want to prevent a form to be submitted for example.
Array Class
Few browsers, such as IE, implement the String class partially. The main module adds the methods "push", "pop" and "shift" when they are missing. A few non-strandard Array methods are also added:list1.append(list2)
list.remove(item)
Null, undefined => valued
mjs_valued(expr)
New features
Logging (LOG* functions)
Logging messages from various places of your code is a key element for troubleshooting problems. You'll see detailed information in the debugging section of this collection.sprintf collection
I did not believe that JavaScript lack the amazing sprintf() function. This is such a miss... Anyway, I reimplemented it and it should behaves more or less the same way than your libc favorite function. Also, there is this "alertf(fmt,p1,...)" function which is just an alert with formatted parameters. You probably gonna like it!String utilities
strcmp(str1,str2) strcasecmp(str1,str2)
strlc=mjs_lc(str) struc=mjs_uc(str)