base2 updates

4 views
Skip to first unread message

Dean Edwards

unread,
Sep 24, 2009, 8:50:07 PM9/24/09
to base...@googlegroups.com
Hi all,

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:

http://dean.edwards.name/jsb/


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

doekman

unread,
Sep 27, 2009, 6:58:08 AM9/27/09
to base2-js
Looking good. I'm glad you're continuing the development of base2.

I haven't really looked at the changes too much, but is is promising.

Mathieu Pillard

unread,
Oct 9, 2009, 7:28:26 AM10/9/09
to base2-js
Hi,

I did some quick testing today. Tested the various matchesSelector()
related bugs, seems they were indeed fixed, good job!

I did found something strange though: it looks like I can't bind
iframes anymore, at least with IE 8/FF 3.5 Here is a testcase:
http://www.virgule.info/tmp/base2_iframe.html

Any idea what's going on ?

Dean Edwards

unread,
Oct 10, 2009, 3:44:45 PM10/10/09
to base...@googlegroups.com

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

kangax

unread,
Oct 10, 2009, 5:23:03 PM10/10/09
to base2-js
Do you still support 5.0? I thought it was 5.5.

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.

Unfortunately, there were 210 (!!!) users of Safari 1.3.2 and 150 of
Safari 2.0.4.

This is why we still didn't drop Safari 2.0.4 from Prototype.js. We
don't support 1.x, although it seems to be possible (BBC Glow.js guys
are doing it :))

--
kangax

Mathieu Pillard

unread,
Oct 10, 2009, 6:54:13 PM10/10/09
to base2-js
> 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.

Yeah, I think it should be an acceptable solution. I didn't even know
base2 worked with IE < 6.

Dean Edwards

unread,
Oct 11, 2009, 9:57:43 AM10/11/09
to base...@googlegroups.com

OK. I'll put it back (except for IE5.0). This also applies to OBJECT,
APPLET and EMBED tags.

-dean

Dean Edwards

unread,
Oct 11, 2009, 10:17:44 AM10/11/09
to base...@googlegroups.com
On 10/10/2009 22:23, kangax wrote:
> Do you still support 5.0? I thought it was 5.5.

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

Mathieu Pillard

unread,
Oct 12, 2009, 2:49:05 PM10/12/09
to base2-js
Just spotted another potential issue, but I don't know if its really
relevant since I didn't do any testing, just wanted to make sure you
knew : getBoundingClientRect() uses getBoxObjectFor(), but this method
is going away in Firefox 3.6. See https://bugzilla.mozilla.org/show_bug.cgi?id=340571
and the corresponding mootools bug (since they are currently using
it) : https://mootools.lighthouseapp.com/projects/2706-mootools/tickets/155

Dean Edwards

unread,
Oct 12, 2009, 3:35:27 PM10/12/09
to base...@googlegroups.com

It only uses getBoxObjectFor() in older versions of Firefox where
getBoundingClientRect() is not available.

-dean

kangax

unread,
Oct 12, 2009, 4:46:43 PM10/12/09
to base2-js
On Oct 11, 10:17 am, Dean Edwards <dean.edwa...@gmail.com> wrote:
> On 10/10/2009 22:23, kangax wrote:
>
> > Do you still support 5.0? I thought it was 5.5.
>
> 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).

Interesting. How do you deal with something like missing
`Object.prototype.hasOwnProperty` in Safari 2.x? If you "patch" it by
adding it to `Object.prototype` it doesn't become DontEnum (as specs
dictate), and is instead treated as user-defined property (with all
the consequences, such as leaking in for-in).

>
> 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.

Makes sense.

>
> 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

Oh cool. I'm glad to hear that :)

> 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

Fair enough. Harmless is sniffing is harmless :)

> 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. :(

I haven't worked with it extensively. Will take a look at your
implementation when I have a chance.

--
kangax

Dean Edwards

unread,
Oct 13, 2009, 10:04:50 AM10/13/09
to base...@googlegroups.com
On 12/10/2009 21:46, kangax wrote:
> Interesting. How do you deal with something like missing
> `Object.prototype.hasOwnProperty` in Safari 2.x? If you "patch" it by
> adding it to `Object.prototype` it doesn't become DontEnum (as specs
> dictate), and is instead treated as user-defined property (with all
> the consequences, such as leaking in for-in).

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

Reply all
Reply to author
Forward
0 new messages