I'm preparing some big updates for base2.
I recently checked in a lot of code. I'll summarise the changes here:
1. All googlecode bugs have been resolved
2. There is a new package: jsb
3. There is a new module in base2.dom (ElementView)
4. base2.DOM has been renamed to base2.dom (lowercase package names)
5. base2.JavaScript has been renamed to base2.js
6. the Selectors API has been re-written
7. ViewCSS has been re-written (more accurate getComputedStyle)
8. Improvements to get/set/has/removeAttribute
The main focus of this update is to provide a *more consistent* set of
results across browser platforms.
In Detail:
1. All googlecode bugs have been resolved
=========================================
Only the defects have been fixed.
2. There is a new package: jsb
==============================
JSB == JavaScript Behaviors
This is a new package to make using the base2.dom API a bit easier.
It allows the developer to create Rules defining the behavior of
elements by CSS selector. I've written 80% of the documentation, you can
read it here:
3. There is a new module in base2.dom (ElementView)
===================================================
For bound elements, this module provides the getBoundingClientRect() method.
As a static object it provides:
* ElementView.getBoundingClientRect(element)
* ElementView.getOffsetFromBody(element)
4. base2.DOM has been renamed to base2.dom
==========================================
I'm moving to lowercase package names. The "DOM" package is now
accessible as a pseudonym of "dom". You do not need to immediately
change your code but the "DOM" name is deprecated.
5. base2.JavaScript has been renamed to base2.js
================================================
I'm moving to lowercase package names. The "JavaScript" package is now
accessible as a pseudonym of "js". You do not need to immediately change
your code but the "JavaScript" name is deprecated.
Let's face it, "JavaScript" is horrible to type.
6. the Selectors API has been re-written
========================================
The interface of the Selector object has changed slightly. There is no
longer a static "parse" method. You should use the instance method
"toDOMQuery" instead. Hopefully, nobody will know what I'm talking about. :)
What this means is that the new selector engine is now faster and more
accurate. It was already pretty fast (according to neutral testers). The
one area that has been improved dramatically is that matchesSelector()
is now very very fast. I promised this before but this time I mean it. :)
7. ViewCSS has been re-written
==============================
getComputedStyle() has been filled out so that you get pretty consistent
results across platforms. I can now parse colours on all platforms.
backgroundPosition, opacity, clip, etc (other edge cases) are calculated
correctly.
8. Improvements to get/set/has/removeAttribute
==============================================
You now get consistent results across platforms.
The de facto standard for getAttribute is to return null if the
attribute is not specified (should be an empty string). This is
*contrary* to the specification. base2 adopts the de facto standard.
Summary
=======
As mentioned previously, the main focus of this update is to provide a
*more consistent* set of results across browser platforms. I will
probably not add to the base2/base2.dom APIs much in the future. In
base2/base2.dom I am trying to provide some core JavaScript/DOM
functionality and provide it in a consistent way. Future DOM
functionality will be provided through JSB and plugins to JSB.
HTML5
=====
I'm pretty serious about JSB. It has some excellent advantages when it
comes to extending HTML. I'm a member of the WHATWG and somewhat
committed to ensuring that HTML5 is a success. As part of that endeavour
I am building an HTML5 support library. It is entirely built on top of
JSB (which is turn built on top of base2/base2.dom). It is a good
showcase for JSB which is in turn a good showcase for base2. There is
very little browser-sniffing/feature detection in JSB. Which means that
I got the abstractions in base2 right. :) I will send all base2
subscribers an invite to the HTML5 googlegroup where you can get a sneak
peek of this library.
Download
========
You can find all the builds here:
http://base2.googlecode.com/svn/trunk/lib/
Please feel free to comment or ask questions about this release.
-dean
Binding iframes throws an error in IE5.0 so I turned it off. I can turn
it back on again and just prevent binding iframes in IE5.0. Shall I do
that? It does mean that you will get different behavior in different
browsers but it is such an edge case that it probably doesn't matter.
-dean
OK. I'll put it back (except for IE5.0). This also applies to OBJECT,
APPLET and EMBED tags.
-dean
base2.DOM supports:
Safari 2+
FF 1+
IE5.5+
Opera 8+
By including an additional file, base2-legacy.js, you get extended
support for:
Safari 1.x
Firefox < 1
IE5.0
The legacy file is only 2KB gzipped and it will work with other JS libs
too. It basically just patches the language and some DOM methods (e.g.
textContent is provided for old Mozilla platforms).
If you can support IE6 then it is really easy to support IE5.5 as they
are virtually the same. If you can support IE5.5 then just by including
the legacy file you will get support for IE5.0. This applies to any JS
project.
> FWIW, my employer site (aimed mainly at educational organizations)
> got only 3 IE5.5 users for the last month (out of ~236,000), and 0
> IE5.0.
Different sites have different stats. The BBC dropped jQuery because it
didn't support IE5.5. They must have a significant number of IE5.5 users
to do that.
The structure of base2 makes it really easy for me to remove support for
legacy browsers. There is no branching in function bodies. It's not
quite so easy now that I've switched to feature detection but it's still
very easy.
BTW, I took out most of the browser-sniffing from base2.DOM (there has
never been any in the core). Your nagging paid off. ;) I think I should
point out that base2 builds its own UA string and it is pretty accurate.
There is still some platform detection in base2.DOM but it is mostly
harmless. It doesn't branch on major functionality, it is there for
enhancements, speed improvements and things that you can't feature
detect (e.g. fixes to the event system). I still use platform detection
in my getBoundingClientRect calculations. All browsers get this right
now and I found it easier to test and debug by patching the older broken
versions. getBoundingClientRect is horrendously complicated no matter
how you do it. :(
-dean
It only uses getBoxObjectFor() in older versions of Firefox where
getBoundingClientRect() is not available.
-dean
I don't patch anything on Object.prototype. You can write JavaScript
without using hasOwnProperty. Most of the need for that is abstracted
into base2's extend() and forEach() methods anyway.
-dean