Activate your free membership today | Log-in

Tuesday, May 13th, 2008

Timelapse CSS

Category: Fun, CSS


Matthew Buchanan had a little fun and created a Timelapse CSS example that lets you walk through the process of how a browser would put together a page if it was a human artist:

When building website templates, I’m constantly switching between a view of my CSS code and a view of the page I’m working on in a browser. At my most fevered I’m switching from one to the other after every couple of amendments, to ensure my additional rules are having the intended effect. Over time, were I to record this incremental buildup, it would paint a reasonably good picture of my approach to converting a design comp to a CSS layout.

With this in mind, I thought it might be useful to try to capture the process automatically and then play it back. I’ve seen this done using a collection of manual screen captures, but that didn’t seem a particularly elegant or easily reproducible solution.

As a proof of concept I cobbled together a (stylistically unsound) function to traverse the stylesheets of the current page (in reverse order) and remove a property from each rule every tenth of a second.

JAVASCRIPT:
  1.  
  2. function timelapseRemoveCss() {
  3.     var interval=0;
  4.     for(var i=document.styleSheets.length-1;i>=0;i--){
  5.         rules=document.styleSheets[i].cssRules;
  6.         for(var j=rules.length-1;j>=0;j--){
  7.             var attributes=rules[j].style.length;
  8.             for(var k=0;k<attributes ;k++){
  9.                 interval+=100;
  10.                 var timeout = "document.styleSheets["
  11.                     +i+"].cssRules["+j+"].style"
  12.                     +".removeProperty(document"
  13.                     +".styleSheets["+i+"].cssRules["
  14.                     +j+"].style["+0+"])";
  15.                 setTimeout(timeout,interval);
  16.             }
  17.         }
  18.     }
  19. }
  20.  

Posted by Dion Almaer at 11:08 am
1 Comment

+++++
5 rating from 4 votes

What’s in a window.name?

Category: Security

Sometimes it is interesting to see that knowledge from the 10,000 B.C. period of web development can be used in new ways to create - to play it safely - interesting ideas.

Each window in a browser has a name property which became pretty much useless when we stopped using pop-up windows and tried to make them communicate with each other by name.

Thomas Frank, however wrote a small library that uses window.name to store session variables without having to resort to cookies and his research seems to prove that you can store up to two megabytes of data in window.name. As this property is available across page reloads it is a sort of session, but as the comments show the security aspects of it are just scary:

There is a cross domain flag in sessvars, but although it defaults to false, this just sees to that you don't get any other sites window.name garbage inside your sessvars by mistake. The actual data you set will be available for other scripts on other domains to look at – and also to anyone able to type javascript:alert(window.name) in the browser's address bar

Posted by Chris Heilmann at 10:06 am
4 Comments

+++--
3.7 rating from 6 votes

inputEx: JSON form builder

Category: Showcase, JSON

inputEx is "a javascript framework to build fields and forms" created by Eric Abouaf. The framework uses a JSON format to describe a form, such as:

JAVASCRIPT:
  1.  
  2. {
  3.         "fields" : [
  4.                 {
  5.                         "type" : "group",
  6.                         "inputParams" : {
  7.                                 "fields" : [
  8.  
  9.                                 ],
  10.                                 "name" : "",
  11.                                 "tooltipIcon" : false,
  12.                                 "value" : {
  13.  
  14.                                 },
  15.                                 "optionsLabel" : "Options"
  16.                         }
  17.                 }
  18.         ],
  19.         "optionsLabel" : "Options"
  20. }
  21.  

which you can build with the help of the builder application.

Check out the getting started guide and if you like to build an application that looks like:

JAVASCRIPT:
  1.  
  2.    init: function() {
  3.       this.buildTree();
  4.       this.initContextMenu();
  5.       this.buildForm();
  6.       this.initEvents();
  7.       this.queryData();
  8.    }
  9.  

rather than HTML, then this could be the tool for you!

inputEx

Posted by Dion Almaer at 7:35 am
4 Comments

++---
2.4 rating from 10 votes

Persevere: JSON Storage / Application Server

Category: Dojo, Showcase, JSON

Kris Zyp of Sitepen has released Persevere:

An open source set of tools for persistence and distributed computing using intuitive standards-based JSON interfaces of HTTP REST, JSON-RPC, JSONPath, and HTTP Channels. The core of the Persevere project is the Persevere Server. The Persevere server includes a Persevere JavaScript client, but the standards-based interface is intended to be used with any framework or client.

The Persevere Server is an object storage engine and application server
(running on Java/Rhino) that provides persistent data storage of dynamic
JSON data in an interactive server side JavaScript environment. It is
currently in beta, and boasts a very solid feature set that should
interest JavaScript, Dojo and Ajax developers:

  • Create, read, update, and delete access to persistent data through
    a standard JSON HTTP/REST web interface
  • Dynamic object persistence - expando objects, arrays, and
    JavaScript functions can be stored, for extensive JavaScript persistence
    support
  • Remote execution of JavaScript methods on the server through
    JSON-RPC for a consistent client/server language platform
  • Flexible and fast indexed query capability through JSONPath
  • Comet-based data monitoring capabilities through HTTP Channels
    with Bayeux transport plugin/negotiation support
  • Data-centric capability-based object level security with user
    management, Persevere is designed to be accessed securely through Ajax
    with public-facing sites
  • Comprehensive referencing capabilities using JSON referencing,
    including circular, multiple, lazy, non-lazy, cross-data source, and
    cross-site referencing for a wide variety of object structures
  • Data integrity and validation through JSON Schema
  • Class-based data hierarchy - typed objects can have methods,
    inheritance, class-based querying
  • Pluggable data source architectures - SQL tables, XML files,
    remote web services can be used as data stores
  • Service discovery through Service Mapping Description

You can check out a live Persevere data grid demo that auto-syncs the grid using JS such as this:

JAVASCRIPT:
  1.  
  2. var persevereStores = dojox.data.PersevereStore.getStores(); // persevere stores are auto-generated
  3. customerStore = persevereStores.Customer; // and get the Customer store
  4. dataModel = new dojox.grid._data.DojoData(null,null,{/*rowsPerPage:12,*/store:customerStore,query:"",clientSort:true});
  5.  
  6. addItem = function() {
  7.         // need to specify the parent because the customerStore is hierarchical and the grid model will
  8.         // call newItem without any info who the parent
  9.         //customerStore.parentId="0.examples.customers";
  10.         grid.addRow({firstName: "firstName", lastName: "lastName",created:dojo.date.stamp.toISOString(new Date,{zulu:true})});
  11. }
  12.  

Posted by Dion Almaer at 3:46 am
Comment here

++++-
4 rating from 13 votes

Monday, May 12th, 2008

OpenKM: Open Source Document Management

Category: Showcase, GWT

OpenKM is a multi-platform application for document management based on GWT, JBoss, and Jackrabbit (the content repository API).

Version 2.0 has been released, which you can test drive to see the application-style interface. The new features in 2.0 include: the previsualization of multimedia elements as images and videos, an improved an rewritten administration interface, a centralized management of templates, an exclusive area to allow users to store their private documentation, a tool for massive import and output data from ZIP files, searches by date ranks as well as translations to more languages.

However, one of the more relevant functions to mention is the indexing of the most common types of files: text, Office, Office 2007, OpenOffice, PDF, HTML, XML, MP3, JPEG, etc.

OpenKM

Posted by Dion Almaer at 11:10 am
4 Comments

++++-
4.4 rating from 9 votes

CSS Child Selector Performance

Category: Browsers, CSS, Performance

Are child selectors slower than more simple brethren? This is a question that Jon Sykes sought out data for after he read the work of Jim Barraud.

His conclusion?

The skinny is that child selectors are a major performance issue.

This seemed to make sense, but to me I needed some sort of proof rather than just being told it's that way by someone, so over the last two days I've tried two approaches to see if I can replicate the issue.

The first one was rather a half-assed idea that afterwards seems fundamentally flawed as a benchmark.

So I took a new approach which does seem to return some valid and rather interesting findings, particularly regarding Safari and Firefox 3 and how they react to child selectors and performance.

The tests show that there is slow down using child selectors over direct class name declarations in IE6, IE7 and Safari 3. Safari 3 being the most impacted by child selectors. Firefox 2 has some impact, and Firefox 3 doesn’t seem to be impacted at all.

That said, this is a very extreme test, it is not often you’d have 20,000 class definitions in a single page or that all of them would use 4 levels of child selector.

CSS Child Selector Performance

Posted by Dion Almaer at 10:44 am
13 Comments

++++-
4.8 rating from 8 votes

Live Chess with Comet

Category: Games, Comet

Piotr Dachtera took his 64pola.pl, and created a scalable version using Comet. Dylan reports it as "a Jetty-powered Comet app that uses dojox.cometd on the client-side. It’s a solid implementation that shows chess moves in real-time, and to date is the best all-around Comet game I’ve seen that is live to the world."

Mathieu Nouzareth then commented that Cafe.com, a Flash based gaming platform also uses Jetty and Comet techniques (compared to AMF etc).

Posted by Dion Almaer at 9:44 am
3 Comments

++++-
4.6 rating from 10 votes

Everything you wanted to know about String performance

Category: JavaScript, Performance

Tom Trenka has detailed a great analysis of JavaScript performance across the various browsers. This is important work, and it reminded me of the JVM days where people tried to use pools and such... to find out that they were bad for performance as newer VM technology came out. When you try to be too tricky you can end up in a bad state as new versions try to optimize the common task, and not your trick.

Eugene Lazutkin had a great explanation on Strings in languages:

Many modern languages (especially functional languages) employ “the immutable object” paradigm, which solves a lot of problems including the memory conservation, the cache localization, addressing concurrency concerns, and so on. The idea is simple: if object is immutable, it can be represented by a reference (a pointer, a handle), and passing a reference is the same as passing an object by value — if object is immutable, its value cannot be changed => a pointer pointing to this object can be dereferenced producing the same original value. It means we can replicate pointers without replicating objects. And all of them would point to the same object. What do we do when we need to change the object? One popular solution is to use Copy-on-write (COW). Under COW principle we have a pointer to the object (a reference, a handle), we clone the object it points to, we change the value of the pointer so now it points to the cloned object, and proceed with our mutating algorithm. All other references are still the same.

JavaScript performs all of “the immutable object” things for strings, but it doesn’t do COW on strings because it uses even simpler trick: there is no way to modify a string. All strings are immutable by virtue of the language specification and the standard library it comes with. For example: str.replace(”a”, “b”) doesn’t modify str at all, it returns a new string with the replacement executed. Or not. If the pattern was not found I suspect it’ll return a pointer to the original string. Every “mutating” operation for strings actually returns a new object leaving the original string unchanged: replace, concat, slice, substr, split, and even exotic anchor, big, bold, and so on.

Tom then went on to detail the rounds that he went through:

  • Round 1: Measuring Native Operations.
  • Round 2: Comparing types of buffering techniques.
  • Round 3: Applying Results to dojox.string.Builder.

There are a few surprises here, and Tom later concludes:

  • Native string operations in all browsers have been optimized to the point where borrowing techniques from other languages (such as passing around a single buffer for use by many methods) is for the most part unneeded.
  • Array.join still seems to be the fastest method with Internet Explorer; either += or String.prototype.concat.apply(”", arguments) work best for all other browsers.
  • Firefox has definite issues with accessing argument members via dynamic/variables

Erik Arvidsson reminds us of the reason to use push(): IE6 and it’s really bad GC.

I look forward to the IE 8 / FF 3 results too.

Posted by Dion Almaer at 8:34 am
Comment here

++++-
4.9 rating from 11 votes

Friday, May 9th, 2008

Exclusive Mastering Dojo Chapters

Category: Dojo, Books

Craig Riecke, Rawld Gill, and Alex Russell, along with the Pragmatic Programmers themselves have been kind enough to give the Ajaxian community some exclusive extracts from the Mastering Dojo beta book.

What do we have on the docket?

First, we have details on the Dojo DOM Apis. Specifically, the author takes us through a challenge involving interview questions and manipulating the DOM for them. We end up seeing code that uses dojo.query, and class addition such as:

JAVASCRIPT:
  1.  
  2. function layout1(){
  3.   dojo.addClass(dojo.query("form> p")[0], "formTitle");
  4.   dojo.query("div.questions p").forEach(function(node, i) {
  5.     dojo.addClass(node, (i % 2) ? "lightBand" : "darkBand");
  6.   });
  7. }
  8.  

It then delves into the intricacies of dojo.query and beyond.

Secondly, we have Ajax the Dojo way which takes us on a trip down dojo.data and dojox.Grid lane... two differentiating features that Dojo comes with. The chapter builds a wishlist system using these features.

There is a lot lot more in the book, which the table of contents covers for you. There are 400 pages of material here that cover the huge variety that exists within the Dojo community.

Thanks to the authors and the editor for sharing this with us.

Posted by Dion Almaer at 7:10 pm
3 Comments

++++-
4.1 rating from 34 votes

oEmbed makes embedding third party videos and images a breeze

Category: Announcements, Standards

Flickr, Viddler, Qik, Pownce and Revision3 are the first services to support oEmbed, an easy way to allow embeding media from a certain URL in a third party site.

From the oEmbed site:

oEmbed is a format for allowing an embedded representation of a URL on third party sites. The simple API allows a website to display embedded content (such as photos or videos) when a user posts a link to that resource, without having to parse the resource directly.

This means that if you for example find a nice photo on flickr, you can take the URL and easily turn it into embed-able data:

Original URL: http://flickr.com/photos/codepo8/2475016321/

oEmbed URL: http://flickr.com/services/oembed?url=http://flickr.com/photos/codepo8/2475016321/

Result:

XML:
  1. <oembed>
  2.   <version>1.0</version>
  3.   <type>photo</type>
  4.   <title>? too much myspace error</title>
  5.   <author_name>codepo8</author_name>
  6.   <author_url>http://www.flickr.com/photos/codepo8/</author_url>
  7.   <cache_age>3600</cache_age>
  8.   <provider_name>Flickr</provider_name>
  9.   <provider_url>http://www.flickr.com/</provider_url>
  10.   <width>500</width>
  11.   <height>375</height>
  12.   <url>
  13.     http://farm4.static.flickr.com/3128/2475016321_982666ec95.jpg
  14.   </url>
  15. </oembed>

You can define the output format and the maximum width and height with URL parameters:

oEmbed URL:

http://flickr.com/services/oembed?url=http://flickr.com/photos/codepo8/2475016321/&format=json&maxwidth=200

Result:

JAVASCRIPT:
  1. {
  2.   version: '1.0',
  3.   type: 'photo',
  4.   title: '? too much myspace error',
  5.   author_name: 'codepo8',
  6.   author_url: 'http://www.flickr.com/photos/codepo8/',
  7.   cache_age: '3600',
  8.   provider_name: 'Flickr',
  9.   provider_url: 'http://www.flickr.com/',
  10.   width: '100',
  11.   height: '75',
  12.   url: 'http://farm4.static.flickr.com/3128/2475016321_982666ec95_t.jpg'
  13. }

Supported formats for responses so far are photo, video, link and rich.

Posted by Chris Heilmann at 6:33 am
8 Comments

++++-
4.5 rating from 6 votes

Processing.js: Port of the Processing language to JavaScript and Canvas

Category: JavaScript, Canvas

Processing.js

John Resig has completed 7 months of work to produce a port of Processing, the "programming language and integrated development environment (IDE) built for the electronic arts and visual design communities", which aims to teach the basics of computer programming in a visual context, and to serve as the foundation for electronic sketchbooks. One of the stated aims of Processing is to act as a tool to get non-programmers started with programming, through the instant gratification of visual feedback."

Processing.js uses Canvas and obviously JavaScript to get the job down in the browser.

John talks about the two pieces of the puzzle:

The Processing Language

The first portion of the project was writing a parser to dynamically convert code written in the Processing language, to JavaScript. This involves a lot of gnarly regular expressions chewing up the code, spitting it out in a format that the browser understands.

The language includes a number of interesting aspects, many of which are covered in the basic demos. Here's a brief selection of language features that are handled:

  • Types and type casting - Type information is generally discarded, but becomes important in variable declaration and in casting (which is generally handled well).
  • Classes - The full class system is supported (can be instantiated, etc. just fine).
  • Method overloading and multiple constructors - Within classes you can have multiple method (or constructor) definitions - with the appropriate methods being called, based upon their signature length.
  • Inheritance - Even classical-style inheritance is supported.

Note: There's one feature of Processing that's pretty much impossible to support: variable name overloading. In Processing you can have variables and functions that have the same name (e.g. float size = 0; float size(){}). In order to support this there would have to be considerable overhead - and it's generally not a good practice to begin with.

The Processing API

The second portion of the project is the full 2d Processing API. This includes all sorts of different methods:

  • Shapes drawing
  • Canvas manipulation
  • Pixel utilities
  • Image drawing
  • Math functions
  • Keyboard and mouse access
  • Objects (point, arrays, random number generators)
  • Color manipulation
  • Font selection and text drawing
  • Buffers

Congratulations to John, and I look forward to seeing some fantastic visualizations in the browser thanks to this work.

Posted by Dion Almaer at 12:54 am
8 Comments

++++-
4.6 rating from 35 votes

Thursday, May 8th, 2008

Ajax Pioneer Week: Alex Russell of Dojo

Category: JavaScript, Dojo, Interview

Last, but never least, is Alex Russell of the Dojo Toolkit and SitePen. In Alex's five minutes of video footage for our JavaOne talk, he explained how Dojo enables you to built fantastic, responsive applications for everyone. The everyone piece revolves around accessibility too, which is core to Dojo thanks to work from Becky Gibson and others on the team.

The Dojo grid and charting packages are very rich these days, and continue to get better. Alex also noted in a separate discussion how there are subtle advantages to the charting package such as being able to print the darn things out nicely. Other flashier products may not allow that minor feature.


Previously on Ajax Pioneer Week...

Posted by Dion Almaer at 11:51 am
3 Comments

+++--
3.7 rating from 25 votes

Growl for Windows and a Web Notification API

Category: