There are a number of people who question the whole idea of putting
together "a library" as a one-size fits all. I'm sure some of them will
weigh in. IMHO, if one is going to do a library, one should do it as
'modular' as possible, with a tiny core and then make it easy to include
just the APIs that one needs.
Comments on code:
Lose this in its entirety. Browser sniffing is obsolete and
untrustworthy at best, and failing in "interesting" ways at worst.
Browser : {
isIE: !!(window.attachEvent && !window.opera),
isIE6: !!(window.attachEvent && !window.opera && !
window.XMLHttpRequest),
isOpera: !!window.opera,
isSafari: navigator.userAgent.toLowerCase().indexOf
('safari') > -1,
isGecko: navigator.userAgent.indexOf('Gecko') > -1 &&
navigator.userAgent.indexOf('KHTML') == -1,
isDOM: !!document.getElementById
},
And loose this function too.
Firstly, the name $ for a function is just a bad name. (Common, but
still bad.)
$ : function(id){
return document.getElementById(id);
},
What does this function even do?
Poorly named. This function is actually
getElementByIdAndIfItDoesNotExistThenCreateIt.
IMO, any function that begins with "get___" should not have any side
effects. If a value is not found, then return something like 'null' or
'undefined'
In addition, you are not getting HTML. In fact, this function has /
nothing/ to do with HTML. It does, however, return an element node,
which may at one point been created with HTML.
getHTML : function(tagName, id){
if(id != null){
var obj = this.$(id);
if(obj) return obj;
}
var obj = document.createElement(tagName);
if(id != null) obj.id = id;
return obj;
},
Again, a poorly named function. See notes on HTML above.
Secondly, this function can be written without try/catch. Between the
performance issues of try/catch and its lack of universal support, its
use should be kept to a minimum.
removeHTML : function(id){
var obj = this.$(id);
if(obj) try{ obj.parentNode.removeChild(obj); }catch(e){}
},
The 'util.getQueryString' function:
Check the c.l.js archives for 'serialize forms' and the 'Code Worth
Recommending' project. Your code does not handle checkboxes, radio
buttons or multi-select combo boxes.
Your 'addEvent' code is broken.
Read:
<
http://www.quirksmode.org/blog/archives/2005/08/addevent_consid.html>
<
http://www.quirksmode.org/blog/archives/2005/09/addevent_recodi.html>
I didn't look into any of the tooltip code or Ajax code.
There is no consensus about augment Native (as opposed to host) objects
like String, Number and Arrays. Some do it freely, others avoid doing it
under any circumstance. Do you understand the side effects of doing so,
and how it might impact someone who is using this library?
Lastly, your code does no feature detection to determine what host
methods do or do not exist, and thus may fail in a very ungraceful way.
Yes, there are browsers in use that do not support try/catch and
Search the c.l.js archives for 'Code Worth Recommending Project' and read
about isHostMethod and family.