For all of you interested in a solid introduction to and what to expect when using Prototype and script.aculo.us, I’m doing a talk on Spending the weekends at home again at QCon London, on Friday, March 16.
Head over to the QCon site for more info about the conference.
Slowly but surely, Ruby and Rails is getting some momentum here in “enterprise-software” infested Austria, so we need a Stammtisch to discuss things. If you’re in Vienna on January 31, drop by and have some beer & ruby fun.
Now, if script.aculo.us only had an API documentation like the new one for Prototype. The wiki is great, but a more complete, up-to-date and coherent resource would be even better. Well, let’s see about that… 😉
Of course thanks to the contributors. And yeah, I know that there are quite a bunch of tickets and patches pending—let’s get this one out first and get all that love in the next version. 🙂
NOTE: This is not the version included in Rails 1.2.1.—. You can use this version with Rails 1.2.1, just download and overwrite the files provided by Rails! The next Rails release will include this, of course. 🙂
Thanks to the heroic efforts of foremost Justin Palmer and the rest of the Prototype core team we now present complete API docs, one of the things that has been missing from this great library.
On the JavaScript side of things, Prototype has seen lots of updates lately, and this new improved version is part of the Rails release candidate, so don’t miss it.
Thanks to Tobie Langel for this niceness. Additionally, next to the string based style strings, you can also use the style definitions you know from .setStyle() in Prototype:
Effects should now also play faster, provided your browser and computer is fast enough, as the maximum frames per second setting is now at 60fps vs. 25fps in earlier releases.
Also, some issues are addressed in the included new beta of Prototype, mainly Opera 9 issues and a using Safari with HTTP authorization; plus of course lots of other fixes and new cool stuff.
Next to all sorts of cool new stuff within the framework, It also includes all the latest Prototype and script.aculo.us features (both Prototype 1.5.0_rc2 and script.aculo.us 1.7.0 beta 1 is part of it). So be sure to get a glimpse of the future right now… 🙂
script.aculo.us 1.7 beta 1 is out now (see below!)—and the big new thing is Effect.Morph which allows for CSS style-based effects, and its companion, the Effect.Transform shortcut to set up complex animations in a snap (while I’ve been thinking of adding this for some time now, there’s some inspiration coming from Bernie’s Better Animation Class).
new Effect.Morph('error_message',{ style:'border-width:3px; font-size:15pt; color:#f00'});
This will start an effect to morph the div element with id error_message smoothly from whatever border-width currently is set, whatever font-size is set (note the currently set font-size must have the same unit, in this case pt), and whatever color is set to the given new values. Because Effect.Morph queries the original values with Prototype’s Element.getStyle API, it doesn’t matter whether these styles are set inline or in an external stylesheet definition. Of course the effect supports all usual options, like duration or transition.
It internally uses a new addition to the String API in script.aculo.us 1.7, that is String.prototype.parseStyle. This method is smart about how to parse CSS style properties correctly. For example, it will automatically parse a ‘border-width’ property to be split up in ‘border-left-width’, ‘border-top-width’ and so on. This allows you to use styles freely as you do in everyday CSS files.
But! Prototype and script.aculo.us are about making development easier, having less stuff to type and think about, and handle common cases with the utmost niceness:
.morph() ia automatically available for all elements. It takes an optional second argument, an object that’s given to the generated Effect.Morph. You can use this to chain morph effects, like this:
Effect.Transform is a helper that doesn’t generate a normal effect, but stores a more complex set of Effect.Morph effects to be generated when called upon.
Let’s see an example of how this works:
1234567891011121314
// define the Effect.Transform and store for latervar transformation = new Effect.Transform([ { 'div.morphing': // divs with CSS class 'morphing''font-size:20px;padding-left:40em;opacity:0.5' }, { 'error_message': // or '#error_message''width:480px;border-width:10px;' + 'border-right-width:20px;' +'margin:20px;margin-bottom:-20px;' +'font-size:30px;' +'background:#954' }],{ duration: 1.3 });// sometime latertransformation.play();
Effect.Transform takes an array of tracks, which are defined in a ‘identifier or CSS selector’: ‘style’ syntax, and generates Effect.Morph effects when you call the play() method. You can also add additional tracks later on, which the addTracks() method.
Notably, you can use DOM object ids or CSS selectors to choose which elements should be acted upon—which means that at any given time you call play(), Effect.Transform will automatically choose the correct elements for the effects, given on these rules. Also, you can an Effect.Transform when none of the referenced elements are already rendered—as long as they are there when you actually call play().
If you need a complex one-shot effect, you can also do this:
new Effect.Morph('error_message',{ style:'background:#f00; color:#fff;'+'border: 20px solid #f88; font-size:2em', duration:0.8});// same thing with Element morph is$('error_message').morph('background:#f00; color:#fff;'+'border: 20px solid #f88; font-size:2em',{duration:0.8});
The aerogel-weight mobile JavaScript framework, which also works great for Safari and Chrome extensions. The jQuery-compatible API makes it easy to pick up, and it's just 5k to 7k in size!