Monday, April 5th, 2010
Prototype 1.7 RC Sizzles…
<p>Andrew Dupont and the the Prototype team have announced the first RC of Prototype 1.7 which changes the selector engine to Sizzle, a new event API, has new layout/dimensions API, and more.Element#on
Element#on is a new way to access the Prototype event API. It provides first-class support for event delegation and simplifies event handler removal.
E.g.
-
-
$("messages").on("click", function(event) {
-
// simple version
-
});
-
-
// can also pass in a selector which means
-
$("messages").on("click", "a.comment_link", function(event, element) {
-
// ...
-
});
-
-
// instead of
-
$("messages").observe("click", function(event) {
-
var element = event.findElement("a.comment_link");
-
if (element) {
-
// ...
-
}
-
});
-
Element.Layout
The second major feature in 1.7 is Element.Layout, a class for pixel-perfect measurement of element dimensions and offsets.
Now you don't have to decide between properties like offsetWidth (which return numbers, but not the numbers you want) or retrieving computed styles (which have their own set of quirks and require a call to parseInt).
JAVASCRIPT:
// Simple case $('troz').measure('width'); //-> 150 $('troz').measure('border-top'); //-> 5 // Offsets, too: $('troz').measure('top'); //-> 226 // More complex case var layout = $('troz').getLayout(); layout.get('width'); //-> 150 layout.get('height'); //-> 500 layout.get('padding-left'); //-> 10 layout.get('margin-left'); //-> 25 layout.get('border-top'); //-> 5 layout.get('border-bottom'); //-> 5 layout.get('padding-box-width'); //-> 170 layout.get('border-box-height'); //-> 510Other fixes
The JSON interface slated for ECMAScript 5 is already being implemented in major browsers. It uses many of the same method names as Prototype's existing JSON implementation, but with different behavior, so we rewrote ours to be ES5-compliant and to fall back to the native JSON support where possible. A few other methods, like Object.keys, received similar treatment.
Related Content:











Great work guys! (who needs Microsoft anyway?). getLayout() is potentially huge
“Microsoft” was not even mentioned and you start bashing.
I wonder why Sizzle is the default. Weren’t there talks about making NWMatcher the default for Prototype 1.7. Will people be able to build this release with NWMatcher instead?
Veej the below was taken from PrototypeJS.org post about 1.7
“So Sizzle is the new default. But there’s more to it than that. In moving to Sizzle, we’ve modularized the selector engine entirely. If you want to use Diego Perini’s NWMatcher library in place of Sizzle, you can. Just check out the source code and build like so:
rake dist SELECTOR_ENGINE=nwmatcher”
Great work ! I really like the new on() method. Like Veej, I wonder why they didn’t use NWMatcher as default engine, as in all the tests I’ve seen, it is faster than Proto+Sizzle.
Is it THAT hard to delete/disable accounts in wordpress? for example “linkszxc”?
@Veej, I’m pretty sure Sizzle is the default engine since NWMatcher isn’t Caja compliant.
An heads-up for the build process.
If you want to compile the unit tests correctly and run them using NWMatcher as selector engine you have to do:
rake test:build SELECTOR_ENGINE=nwmatcher
some failing tests are a result of unit tests that haven’t been corrected by Prototype developers to reflect elements in document order
Hope this helps NWMatcher supporters out there :-)