Activate your free membership today | Log-in

Thursday, October 16th, 2008

Another look at JavaScript inheritance

Category: JavaScript

Stoyan Stefanov of Yahoo! has published a nice article on JavaScript's class-less objects.

This is published on JavaRanch, so it talks to the Java community, and uses that lense to explain the differences.

He delves into:

  • Constructor functions
  • Function objects and prototype property
  • Inheritance via the prototype
  • Inheritance by copying properties
  • Crockford's beget object:
    JAVASCRIPT:
    1.  
    2. function begetObject(o) {
    3.   function F() {}
    4.   F.prototype = o;
    5.   return new F();
    6. }
    7.  
  • YUI's extend()

Posted by Dion Almaer at 12:44 pm
1 Comment

++++-
4 rating from 5 votes

Jack: Mocking JavaScript the good way

Category: Testing

Jack is a new JavaScript mocking framework coming out of Bekk in Norway. A lot of the RSpec talent is there too, so they know their testing!

Jack features:

  • Set expectations for number of calls and argument constraints
  • Specify mock implementations for specific expectation scenarios
  • Create mock objects with a list of stub functions
  • Reports expectation failures to test frameworks. Currently integrated with JSSpec and Scriptaculous TestRunner

Examples show it off:

JAVASCRIPT:
  1.  
  2. // Expect one call to function
  3. jack(function(){
  4.    jack.expect("jQuery.post").exactly("1 time");
  5.    storeSomething();
  6. });
  7.  
  8. // Expect argument values
  9. jack(function(){
  10.    jack.expect("jQuery.post")
  11.       .exactly("1 time")
  12.       .withArguments("http://example.com/service");
  13.  
  14.    storeSomething();
  15. });
  16.  
  17. // Set other argument constraints
  18. jack(function(){
  19.    jack.expect("jQuery.post")
  20.       .exactly("1 time")
  21.       .whereArgument(0).isOneOf("/serviceOne","/serviceTwo");
  22.  
  23.    storeSomething();
  24. });
  25.  
  26. // Creating a mock object to run expectations against
  27. jack(function(){
  28.    var mockObject = jack.create("mockObject", ['functionOne','functionTwo']);
  29.  
  30.    jack.expect("mockObject.functionOne")
  31.       .exactly("1 time")
  32.       .whereArgument(0).is("something");
  33.  
  34.    mockObject.functionOne("something");
  35. });
  36.  

Posted by Dion Almaer at 9:37 am
Comment here

++---
2.9 rating from 10 votes

Google Chrome History Issue

Category: Browsers, Google

Amongst the reactions to Google's release of Chrome was the developer's howl of pain at the thought of another major browser on which to do compatibility testing. Google's generally asserts that Safari compatibility results should be the same as Chrome's, but Nathan Hammond stumbled across a divergence that he finds troubling and which Google shows no inclination to fix. Says Nathan:

There exists a bug in Google Chrome that breaks most history managers. Most all current history managers rely upon form-based storage to repopulate their history stack after navigating away from and returning to the present document object, but Chrome doesn't refill form fields when that happens. The result of that is that Google Chrome is currently incompatible with websites using the current generation of history management plugins, and, if their issue tracker has anything to say about it, will remain that way. The bug was closed as "wontfix" due to a misunderstanding. However, it still needs to be addressed to meet the goal of Chrome as I heard at The Ajax Experience 2008: a goal of not fracturing the web and creating yet another browser we developers have to test in and code around.

Nathan elaborates on his blog.

Posted by Ben Galbraith at 9:00 am
4 Comments

+++--
3.9 rating from 16 votes

OSGI and JavaScript; Frameworks and building blocks for Ajax apps

Category: Dojo

Bill Higgins of IBM Rational has written up some thoughts on componentization and packaging for Ajax applications based on work that his team did on the Rational Jazz platform.

Some of what he built was:

  • A nice component model based on OSGi bundles and the Dojo module system
  • Request-time “building” of many fine-grained JavaScript files into monolithic files for faster download based on the introspected relationships between the files - i.e. no developer effort required for fast code loading other than writing good code
  • Making a subset of the Eclipse extension registry available in the web page and queryable via JavaScript APIs modeled off of the org.eclipse.core.runtime extension registry Java APIs, allowing for open-ended extensibility using the Eclipse extensibility model
  • A simple framework for demarcating UI states that made the back button, history, and page titles work seamlessly within the Ajax page, even when a user gesture resulted in crossing a component boundary (e.g. loading and displaying a new virtual “page” from a different component)
  • Dynamic, transparent loading of missing code in response to a user gesture that required it

He then goes on to explain the architecture of reusable building blocks, and a realization:

My recent realization (which seems obvious in hindsight) is that the useful functionality provided by frameworks and libraries need not be mutually exclusive. For instance, in our Ajax framework’s dynamic build system, rather than requiring applications to run within our framework to enjoy this capability, we could have created a simple callable library to perform dynamic optimization on a set of files, and then created a framework that simply used this same library.

Over the past month or so we’ve been refactoring our Ajax framework to extract the useful building blocks into simple callable libraries and making the framework proper smaller by delegating to these libraries. We’ve done this in the hopes that our code will be useful to other IBM teams but as a result of the exercise, we’ve gained a deeper knowledge of our software and the software’s quality has improved as we’ve decoupled the framework aspects from the building blocks aspects.

Going forward, it’s my intention that our team will generally start with building blocks first and then consider if we should provide some higher-level framework that uses these building blocks. I only wish we had taken this approach from the beginning but you know, live and learn.

Any kind of heavy packaging systems haven't done hugely well in the Ajax community as a-whole, but there is a huge problem with components and being able to reuse them. The fact that someone builds a great jQuery plugin, that then gets ported to Prototype and Dojo and .... is frustrating (one example, it happens N times, with the original framework changing).

Posted by Dion Almaer at 7:23 am
5 Comments

++++-
4.4 rating from 9 votes

Wednesday, October 15th, 2008

FancyUpload for Flash 10 to fix your uploader

Category: Adobe

This is the week of the plugin. First we had the launch of Silverlight 2, and then, quickly on the back of that we get Adobe Flash 10 at the same time as the entire Creative Suite 4 (which has great Flash authoring tools of course).

One of the security features in Flash 10 is the requirement for the user to act on a Flash movie to be able to access certain APIs. This has caused some Flash upload components to break (ones that use a hidden Flash movie, such as SWFUpload Flickrs FancyUpoad). The solution is quite simple, you need to make the button that launches the upload a Flash control itself (versus an HTML button for example).

Harald Kirschner has jumped on it and created a FancyUpload for Flash 10.

You can check out the showcase and do a view source to see that the link is not a link :)

What else is in Flash 10? Here are the top features that Adobe mentions:

3D effects

Create more intuitive, engaging interfaces using built-in support for 3D effects. Get started quickly without being a 3D master by designing in 2D and easily transforming and animating in 3D. Fast, extremely lightweight, and simple-to-use APIs, along with 3D tools in Adobe® Flash® CS4 Professional software, make motion that was previously accessible only to expert users via ActionScript® language or custom third-party libraries available to everyone.

Custom filters and effects

Create high-performance, real-time effects for cinematic experiences that quickly engage users. With new Adobe Pixel Bender™, the same technology behind many filters and effects in Adobe After Effects® software, these dynamic and interactive effects can be used both in production with After Effects CS4 and live with Flash Player 10. The Pixel Bender just-in- time (JIT) compiler can also be used to process other types of data, such as sound or mathematical functions, asynchronously in a separate thread.

Advanced text support

Take advantage of a new, flexible text layout engine that brings print-quality publishing to the web, building on more than 25 years of Adobe expertise in typography. Gain more control over text layout using an extensible library of ActionScript 3.0 text components to flow text and sophisticated typographic elements such as ligatures across multiple columns, around inline images, bidirectionally, vertically, or chained together. Create multilingual rich Internet applications (RIAs) using device fonts that can now be anti-aliased, rotated, and styled, or build your own unique text components.

Dynamic sound generation

Use enhanced sound APIs to dynamically generate audio and create new types of audio applications such as music mixers and sequencers, real-time audio for games, and even audio visualizers. Work with loaded MP3 audio at a lower level by extracting audio data and supplying it to the sound buffer. Process, filter, and mix audio in real time through the Pixel Bender JIT compiler to extend creative freedom beyond the visual experience.

Drawing API

Perform runtime drawing more easily with restyleable properties, 3D APIs, and a new way of drawing sophisticated shapes without having to code them line by line. Developers can tweak parts of curves, change styling, replace parts, and use custom filters and effects, delivering improved throughput, creative control, and greater productivity. Enhancements to the Drawing API add the z dimension, real perspective, textured meshes in 3D space, a retained graphics model, read/write rendering, and triangle drawing with UV coordinates, while adding memory and improving performance.

Hardware acceleration

Use the hardware processing power of the graphics card to paint SWF files into the browser and accelerate compositing calculations of bitmaps, filters, blend modes, and video overlays faster than would be performed in software.

Vector data type

Use the new typed array class for better performance, efficiency, and error checking of data.

Dynamic Streaming

Show exceptional video with streams that automatically adjust to changing network conditions. Leverage new quality-of-service metrics to provide a better streaming experience.

Speex audio codec

Take advantage of the new, high-fidelity and open source Speex voice codec, which offers a low-latency alternative for voice encoding. Flash Player also supports ADPCM, HE-AAC, MP3, and Nellymoser audio.

File upload and download APIs

Bring users into the experience by letting them load and save files from your web application. New file reference runtime access allows local processing of data without roundtripping to the server.

Posted by Dion Almaer at 4:06 pm
10 Comments

++++-
4 rating from 10 votes

Say Goodbye to alert()

Category: JavaScript

Blackbird, G. Scott Olson's JavaScript logging library, truly has a catchy slogan. The slogan "Say hello to Blackbird and 'goodbye' to alert()" definitely captures what the Blackbird library aims to do; make logging messages in JavaScript extremely easy. And setup is very easy. By incorporating the following lines of code, you've now added the ability to set checkpoints which will display specific data you're interested in:

HTML:
  1.  
  2.     <script type="text/javascript" src="/PATH/TO/blackbird.js"></script>
  3.     <link type="text/css" rel="Stylesheet" href="/PATH/TO/blackbird.css" />
  4.     ...
  5.   </head>
  6. </html>
  7.  

From there, its a simple matter of using Blackbird's methods to send results to the console:

JAVASCRIPT:
  1.  
  2. log.debug( 'this is a debug message' );
  3. log.info( 'this is an info message' );
  4. log.warn( 'this is a warning message' );
  5. log.error( 'this is an error message' );
  6.  

The nice thing is that each of these public methods uniquely displays the data to make it easy to determine the type of message being sent:

Blackbird has been tested in:

  • Internet Explorer 6+
  • Firefox 2+
  • Safari 2+
  • Opera 9.5

Brian Dillard was one of the first to announce this release and has also done a nice writeup of Blackbird.

Posted by Rey Bango at 2:25 pm
17 Comments

+++--
3 rating from 27 votes

Non-Euclidean Browser UI

Category: Browsers, UI

The video above by Ron Brinkmann is his mockup of a non-euclidean browser UI which looks a touch like the magnifying glass tool on the iPhone, and aims to give you your data in a readable way, while still showing the larger context:

The reason why I think an interface like this can be superior in many ways is that it allows you to specify an area of interest where you get full, detailed information yet you can still see the full document/page/object at the same time. Which means that one is able to avoid the zoom(in/out)-scroll-zoom(in/out)-scroll paradigm that you often get stuck in when using, for example, the iphone. In many ways it gives the user an analogue to the way peripheral vision works in the ‘real world’. You have an area of interest that you can focus on but then you’re also aware of the surroundings and glean information from that as well.

(The mockup I did above just shows a single point-of-interest but it’s certainly expandable to multiple points if you’ve got a touchscreen or other such device. And there’s all sort of little refinements you’d want to implement if you really wanted to make it swank - drag&drop from one place to another might want to keep the source area zoomed but also follow the dragged object with a zoom-region until you get to the appropriate destination. This all gets even sexier once eye-tracking becomes more available - the area you’re looking at would bubble up to full resolution but you’d still be able to quickly scan the entire page and re-target the area of interest. Somebody get busy on this, okay?)

In his post, Ron then shows other subtle examples, such as mapping this to peripheral vision.

Posted by Dion Almaer at 6:16 am
1 Comment

++---
2.5 rating from 32 votes

Using JavaScript to make things work

Category: JavaScript, jQuery

An interesting top 12 list has been published, on using Javascript to fix 12 common browser headaches:

  1. Setting Equal Heights (jQuery example: $("#col1, #col2").equalizeCols();)
  2. IE6 PNG Alpha Transperancy support
  3. Changing CSS Classes in JavaScript
  4. Browser selectors in CSS ($('html').addClass($.browser);)
  5. min-/max- height & width support
  6. Center Elements Vertically / Horizontally
  7. Display Q tags in Internet Explorer
  8. Increase the size of click targets and get more call-to-action conversions
  9. Lazy loader
  10. bgiframe: Helps ease the pain when having to deal with IE z-index issues.
  11. ieFixButtons: fixes the buggy behavior of the
  12. Fix Overflow

As you will see, most of the solutions are jQuery plugins, but you could roll your own.

Posted by Dion Almaer at 5:31 am
Comment here

++---
2.9 rating from 24 votes

Firefox 3.1 beta: Geolocation, @font-face, Video and Audio, XHR++, and TraceMonkey

Category: Browsers, Firefox

Isn't it great that a browser point release these days adds so many features? We are starting to see this from Firefox, Opera, WebKit and others, and it is exciting!

The Firefox 3.1 beta 1 release has a slew of features that developers have been craving:

Geolocation

The labs team got Geode out there, and quickly we have seen the addition of the W3C Geolocation API added to the Firefox core. I can test Where Are You with a native implementation.

@font-face

WebKit lead with their @font-face implementation, and getting browser #2 to support it is huge. Now you can load up a font using same-origin rules via simple CSS:

CSS:
  1.  
  2. @font-face {
  3.   font-family: "Bitstream Vera Serif Bold";
  4.   src: url("http://developer.mozilla.org/@api/deki/files/2934/=VeraSeBd.ttf");
  5. }
  6.  

Video and Audio

We now have lots of examples testing out the video and audio tags with support for both OGG Theora and OGG Vorbis.

This is something that the Web really needs to work out. The codec game is far from Open, and with native support we get to do cool things such as integrating media with canvas, svg, and plain old HTML. Take a video, add transparency, and skew it a little.... and add an overlay message.

XHR Updates

XHR Progress Notification

We’ve added a better way to get progress notifications for XML HTTP Requests. We’ve implemented the W3C Draft Spec on progress events. In Firefox 3 the events available on the XHR object were progress, uploadprogress, load, abort and error. For 3.1 we now support the loadstart, progress, load, abort and error events. (uploadprogress is also supported, but is deprecated.)

There’s a great example of the new progress events by Olli Pettay. It’s very simple and does everything in a single script.

XHR Cross-site Access Control

We’ve implemented the draft specification for access-control for cross-site requests.  Web developers have long wanted to be able to get data from one site on another but same-origin restrictions on many types of requests prevent many developers from mashing up content.  This new access control mechanism offers the ability for servers, content and web clients to cooperate to make a lot of new things possible on an opt-in basis.  The spec is complex, and support is new, so if you’re interested reading the spec is probably the best thing to do.  It contains examples and uses cases.

Fast JavaScript VM

An early version of TraceMonkey is here:

Beta 1 does include TraceMonkey, our super-fast JavaScript engine, but it’s not turned on by default.  If you do want to turn it on, go to about:config, set javascript.options.jit.content to True, restart your browser and try it out.

This is an early beta, of course, so there will be issues. Please file bugs if you find sites that don’t work or cause crashes or hangs. The more testing we get, the better it will be when we turn it on.

Phew, good times for browsers == good times for Web developers.

UPDATE

More browser news, Flock 2.0 is out there, providing a very social browsing experience.

Posted by Dion Almaer at 12:01 am
Comment here

++++-
4.9 rating from 24 votes

Tuesday, October 14th, 2008

Open Web Podcast - Episode 5: Ryan Stewart of Adobe

Category: Adobe, OpenWebPodcast

Ryan Stewart of Adobe joined us for episode 5 of the Open Web Podcast. We really want to be pragmatic Open Web citizens, so thought it would be good to hear from Ryan and get his point of view on what Adobe, and he, are thinking with respect to the Web as a-whole.

You can download the podcast directly (OGG format too), or subscribe to the series, including via iTunes).

We had a really fun chat, which had us discussing:

  • Adobe's view of the Web
  • Silverlight, and Alex's quote of the show: "Microsoft can't write JavaScript." Ah, come on, what about Scott Isaacs!
  • Ctrl/Cmd-R is the "Make All" of the Web, and Flex
  • ECMAScript, ActionScript, and the path forward
  • Video: A huge Flash advantage. Where does the video tag fit in? John pointed us to the experimental vorbis support via haXe
  • AIR: Ryan talked about how he sees AIR fitting into the landscape, and how he personally would love to see Geolocation APIs added
  • Open Source: Ryan shares his insight on the experience Adobe has gotten from their Open Source projects (Tamarin, Flex, ...)

It was a real pleasure to have Ryan come into the lions den. He is very honest with what he does and doesn't know from within, and doesn't hold back on his own thoughts.

What would you like to ask Adobe?

Posted by Dion Almaer at 8:45 am
Comment here

+++--
3.8 rating from 9 votes

Runtime Page Optimizer: Fix performance on the fly

Category: Performance

Steve Souders posted on Runtime Page Optimizer a tool that you can think of as a performance proxy. It sits on the server side, and cleans up content before it is sent back to the browser.

What can it do? Steve let us know:

RPO automatically implements many of the best practices from my book and YSlow, so the guys from Aptimize contacted me and showed me an early version. Here are the performance improvements RPO delivers:

  • minifies, combines and compresses JavaScript files
  • minifies, combines and compresses stylesheets
  • combines images into CSS sprites
  • inlines images inside the stylesheet
  • turns on gzip compression
  • sets far future Expires headers
  • loads scripts asynchronously

RPO reduces the number of HTTP requests as well as reducing the amount of data that is transmitted, resulting in a page that loads faster. In doing this the big question is, how much overhead does this add at runtime? RPO caches the resources it generates (combined scripts, combined stylesheets, sprites). The primary realtime cost is changing the HTML markup. Static pages, after they are massaged, are also cached. Dynamic HTML can be optimized without a significant slowdown, much less than what’s gained by adding these performance benefits.

Steve had another couple of interesting posts recently:

  • Say no to IE6 discusses how we need to do something to help upgrade IE6 users (to IE7 is fine!)
  • Raising the bar talks about results from Steve's UA Profiler tests and how new browsers are pushing forward

Posted by Dion Almaer at 8:11 am
6 Comments

++++-
4.4 rating from 16 votes

Bacon - a sizzling new YUI utility

Beware of what you ask for. After Stephen Woods asked on Twitter why there are just no Bacon utilities in the browser Dav Glass of the YUI team went right to it and created YUI Bacon.

YUI bacon is now the only JS solution to fry any HTML element with a few lines of code:

JAVASCRIPT:
  1. var foo = new YAHOO.util.Bacon('demo');
  2. var bar = new YAHOO.util.Bacon('demo2');

As always with Dav, the utility comes with a full API and documentation, features useful methods like fryBacon() and stopFryBacon() and there are several clever custom events (baconReady, baconDone, baconStart) to subscribe to.

If you dive deeper into the workings of bacon you also find hidden messages of what the future might hold: void cook() An override method for extending this class to maybe fry eggs too.

I am now waiting for jQuery cocktail sausage and protoype T-Bone.

Posted by Chris Heilmann at 6:36 am
8 Comments

++---
2.8 rating from 35 votes

Dojo 1.2: Squeezing it into 5.5kb

Category: Dojo

James Burke gave a great presentation in Boston on the Dojo build system, and how he is able to get the core down to 5.5k.

With Dojo 1.2, the build system can generate a 5.5KB gzipped (13KB ungzipped) dojo.js file, via the customBase layer option. Useful for iPhone development if you want to get under the 25KB uncompressed size limits for the Mobile Safari cache. That small dojo.js is basically just the loader and some bootstrap functions, but it allows you then to tune your build layers to meet the 25KB and dynamically load what you need as you go.

Also, the djConfig options afterOnLoad/require/addOnLoad allows loading Dojo after the page is loaded. Great for making progressively enhanced pages render even faster.

Posted by Dion Almaer at 6:17 am
Comment here

++++-
4 rating from 24 votes

MozAfterPaint: Being able to get a callback event on repaint

Category: Firefox, Mozilla

John Resig put together a nice usage of MozAfterPaint, the new Firefox event that will call back letting you know when a repaint operation has happened:

The event object contains two properties: .clientRects and .boundingClientRect, both of which refer to the result of the associated DOM methods.

In a nutshell, boundingClientRect gives you a single rectangle encompassing the entire area in which a paint operation could've taken place whereas clientRects gives you a number of rectangles, each encompassing an individual area that was drawn.

To test this I created a quick demo using CNN.com (only works in the latest Firefox nightlies).

John creating a simple tracking script that uses the new event to show where you have been.

kourge reminded us of the related Flash event showRedrawRegions.

Robert O'Callahan mentioned a use for the event when he discussed SVG bling that made it into the first 3.1 beta.

David Hyatt put in a WebKit patch to add support for CSS transitions on some SVG properties.

Posted by Dion Almaer at 5:02 am
6 Comments

++---
2.8 rating from 8 votes

Sensei: A beautiful Dojo application

Category: Dojo