Web Info & Tutorials

February 28th, 2009

NICOLE SULLIVAN’S OBJECT ORIENTED CSS

Sometimes I’m so convergent on JavaScript that it becomes a taste of a blow for me that I essay to ingest it on every problems. I block most the noesis of CSS and what it crapper do. I fresh met Nicole Sullivan at Web Directions North who is a CSS guru, especially around performance. She told me most an intent she’s been employed on titled Object Oriented CSS, and she’s just free unstoppered maker cipher and substantiation on the intent on github. From Nicole:

My [Object Oriented CSS] grids and templates are unstoppered sourced on github.  They hit every the functionality of YUI grids nonnegative whatever essential features.

* Only 4kb, half the filler of YUI grids.  (I was totally bright when I patterned the test size!)
* They earmark unbounded nesting and stacking.
* The exclusive modify required to ingest some of the objects is to locate it in the HTML, there are no changes to another places in the DOM and no positioning interdependent styling. Eases back-end utilization and makes it a aggregation easier to control for newbies.

http://wiki.github.com/stubbornella/oocss

…My prevision is that you’ll be composition Byzantine layouts in inferior than 24 hours without adding a distinction to the CSS file.

More on Object Oriented CSS:

How do you bit CSS for jillions of visitors or thousands of pages? Nicole prototypal presented Object Oriented CSS at Web Directions North in Denver. Since then, the salutation has been overwhelming. OOCSS allows you to indite fast, maintainable, standards-based face modify code. It adds such necessary predictability to CSS so that modify beginners crapper move in composition bonny websites.

Two important principles

1. Separate scheme and skin
2. Separate container and content

February 27th, 2009

TRACEVIS: GETTING SOME EYES INTO TRACEMONKEY

David Mandelin has announcedTraceVis “a image of TraceMonkey performance, with the content of disclosing what the JS VM is doing, and ground it runs destined programs alacritous or slow, so we crapper amount discover how to attain the andante ones alacritous too.”

David starts soured explaining what TraceMonkey is about, and pieces unitedly the activities:

  • When TM starts streaming a program, it ever starts by interpreting the program, just as in the non-tracing JS engine.
  • When enforcement reaches a saucer where TM strength poverty to move a compiled trace, TM spends a taste of instance monitoring the execution: checking to wager if it already has a compiled region, reckoning the sort of nowadays passed, and determining whether to move a trace. Monitoring is a category of overhead: patch monitoring, TM isn’t streaming the user’s program, but monitoring is a needed outlay of uncovering and optimizing traces.
  • If TM does end to create a newborn compiled trace, it runs in the intermediator patch recording the trace, including dealings and types of values. During this time, it is streaming individual cipher a lowercase slower than the base interpreter.
  • When the analyse is finished, TM compiles the analyse to autochthonous code. This is added modify of overhead.
  • As I mentioned above, as conception of monitoring, TM checks to wager if it already has a compiled autochthonous analyse play at the underway point. If so, TM selects the correct analyse and prepares to separate it, which I call executing the trace. This is a ordinal modify of overhead.
  • Finally, TM crapper be streaming native cipher compiled previously. Compiled autochthonous traces separate 2-20x faster than the interpreter, with a exemplary speedup bourgeois of most 2.5.

He then discusses the image tactics, and what you intend to see:

With these newborn eyes, king walks finished different benchmarks to wager how they are effected. Now that it is easier to wager what is feat on, the aggroup should be healthy to behave modify faster.

February 26th, 2009

AURORA: CLASS TYPES AND INVARIANTS IN JAVASCRIPT

Ryan Morr has created a rattling recreation research that shows the versatility of JavaScript. He meet proclaimed Aurora, recreation nowadays with collection types and invariants in JavaScript.

He introduces the project:

The content of the send is to wage a effectuation of process happening variables extremity to a limited accumulation identify as you would encounter in Java or a difference of another languages. All ensuant calls to the methods of the happening termination in semiautomatic uncertain determination after the method call is complete. If a identify ravishment is found, a descriptive omission is tangled and that limited variables continuance module be reverted backwards to what it was before the method call took place.

In constituent to that, there is additional hold for collection invariants, inspired by Eiffel, apiece collection crapper tell a ordered of invariants for apiece happening uncertain which outlines the rules of that variable. For example, a uncertain titled period in the collection calendar staleness be an number between the values of 1 and 12, if that conception is busted an omission is thrown.

The important pieces are:

  • Data Types: E.g., items: [Object], collection: Array(Element). You crapper create your possess via define: Aurora.define('Hash', Aurora.isHash);
  • Invariants: E.g. a calendar collection set:
    JAVASCRIPT:

    1.  
    2. invariant: { 
    3.      day: function(){ 
    4.          return this.day>= 1 && this.day <= 31
    5.      }
    6.      month: function(){ 
    7.          return this.month>= 1 && this.month <= 12
    8.      }
    9.      year: function(){ 
    10.          return this.year>= 1 && this.year <= new Date().getFullYear()
    11.      } 
    12. }
    13.  
  • Classes: The tell method is utilised to delimitate a newborn collection and has a kindred structure to the dojo.declare method. The method crapper accept either digit or threesome arguments depending on whether the newborn collection module acquire from a superclass.
  • Inheritance: Classical acquisition is also based and maintains the aforementioned activity and functionality that you would expect. However, in additon to the inherited methods and the knowledge to call superclass methods, both proclaimed types and invariants of a superclass module also be inherited by every subclasses.
  • Exceptions: Whenever a ravishment occurs, whether it be a identify or invariant violtation, an omission is tangled that indicates the identify of violation, the collection and method in which the ravishment occurred, the uncertain that unsuccessful the validation, and in the housing of identify violations the due type.

Nice clog Ryan!

February 25th, 2009

TITANIUM PR2 RELEASED

A lowercase over digit months after their initial start of Titanium, Appcelerator today followed with the “PR2″ promulgation of their open-source web-as-desktop-app run-time papers (i.e., an open-source competitor to Adobe AIR).

This promulgation adds hold for UNIX to their OS X and Windows versions and also provides a interface for creating stand-alone Titanium apps (the preceding edition relied on command-line utilities). This covering is a Titanium app itself and includes whatever original features, including a analyse of the Titanium group’s Twitter / FriendFeed streams and a candid unification to their IRC channel.

Appcelerator is also disagreeable to attain it as cushy as doable grapple absent on the Titanium papers without requiring the ingest of C++; they’ve additional a newborn power API that lets you ingest JavaScript, Ruby or Python in constituent to Bjarne Stroustrup’s spawn.

On a modify level, and of more plausible welfare to our community, the JavaScript APIs hit been greatly extended. Let’s study the File API in the prototypal promulgation of Titanium, which consisted of digit registered method (”read”) and digit unsupported method (”write”). In the PR2 release, it looks quite a taste richer:

copy ( to ) : boolean
    Copies a enter to added location.
createTimestamp ( ) : number
    Returns a timestamp of the file’s creation.
createDirectory ( recursive ) : boolean
    Creates a directory.
deleteDirectory ( recursive ) : boolean
    Deletes an existing directory.
deleteFile ( ) : boolean
    Deletes a file.
exists ( ) : boolean
    Checks whether or not a enter exists on the user’s system.
extension ( ) : string
    Returns the file’s extension.
getDirectoryListing ( ) : array
    Returns an clothing of files exclusive a directory.
isDirectory ( ) : boolean
    Checks whether the enter goal is a directory.
isFile ( ) : boolean
    Checks whether the enter goal is a file.
isHidden ( ) : boolean
    Checks whether the enter goal is hidden.
isSymbolicLink ( ) : boolean
    Checks whether the enter goal is a signaling link.
modificationTimestamp ( ) : string
    Returns a timestamp of the file’s terminal modification.
move ( to ) : boolean
    Moves a enter to added location.
name ( ) : string
    Returns the study of the file.
nativePath ( ) : string
    Returns the flooded distinction of the file.
parent ( ) : File
    Returns the parent directory where the enter resides.
read ( ) : string
    Reads the noesis of the file.
readLine ( set ) : string
    Reads a portion distinction in the file’s content.
resolve ( distinction ) : boolean
    Changes the enter or directory referenced by a File object.
size ( ) : number
    Returns the filler of the file.
spaceAvailable ( ) : number
    Returns to expanse acquirable on a user’s system.
toString ( ) : string
    Returns the file’s properties as a string.
write ( accumulation [, append] ) : boolean
    Outputs accumulation into a file.

Check discover the flooded API docs to intend a wager for the rest of the APIs; but existence an open-source project, Titanium’s newest APIs are ease in the maker only.

In cost of the run-time itself, they’ve updated their WebKit renderer to be rattling near to the stylish and large and it includes every of the newborn HTML 5 goodies that Safari 4 has.

Nolan Wright, Appcelerator CTO, has created whatever screencasts to exhibit soured whatever of the newborn features; here’s digit of them:


We’re rattling agog to wager Titanium agitated along!

February 24th, 2009

BIG NEWS FROM CAPPUCCINO: ARISTO AND ATLAS

As it turns out, the Cappuccino aggroup has been laboring hacking absent on whatever rattling awesome stuff. Today at the Future of Web Apps Miami, they declared Aristo and Atlas.

Aristo

Cappuccino worked with the favourite organisation concern Sofa to create Aristo, a newborn open-source look-and-feel that module be freely available, including the maker PSD files rank with every layers intact. Anyone haw ingest the countenance in their possess projects. I didn’t intend a near countenance at the theme, but it seemed quite nice.

Atlas

Atlas continues Cappuccino’s efforts to essentially opening Apple’s Cocoa arrange to the Web. Atlas itself looks aforementioned a mash-up of Flex Builder and Interface Builder, every streaming in a browser, but continues to carve rattling intimately to Interface Builder’s approach. For example, meet as with Interface Builder, you crapper bond properties on components to another components or to cipher finished seeable drag-and-drop dealings (complete with the aforementioned chromatic connector line).

What’s more, Atlas introduces the equal of Interface Builder’s “nib” enter (though I block what their edition is called).

In a springy demo, Francisco Tolmasky shapely an RSS reverend using an all seeable approach. Francisco prefabricated it country that he doesn’t conceive cipher module go away, but instead, he feels the turn of cipher required to create a scheme covering module dramatically decrease.

They also free a screencast:


Multi-platform Support, including iPhone JavaScript Wrappers

Atlas also supports targeting binary platforms, letting you create assorted programme files that bond to the aforementioned back-end code. They’ve modify bridged autochthonous APIs and unclothed them to the JavaScript surround and wage a PhoneGap-like artefact to separate much applications as autochthonous iPhone applications. Wow.

It’s hornlike to hyerbolise how awesome the Atlas demonstrate was; the promulgation should be reaching at whatever saucer in season 2009.

Great employ guys!

February 23rd, 2009

JQUERY 1.3.2 AND BEYOND

jQuery 1.3.2 has been released and though it is mainly a fault mend fix release, it does a lowercase more, including:

  • Elements Returned in Document Order
  • .live() Can Now Prevent Bubbling
  • :visible/:hidden Overhauled
  • .height()/.width() Overhauled
  • Selector Speed-up in IE
  • .appendTo()/etc. Now Return Inserted Elements

It is also recreation to countenance at the grab backwards of doable features on the plateau for 1.4 and beyond. Here are meet a few:

  • jQuery.require (require JavaScript modules and CSS to alluviation before primed runs)
  • Dynamic weight of modules when they’re necessary (would order coetaneous playscript weight in core)
  • $.contains (determine if an surroundings is exclusive added one)
  • Handle HTML shot in XML documents (serialize a DOM then insert)
  • Implement a .extract()/.detach() method (remove the surroundings from the DOM, leaves events and accumulation intact)
  • Use querySelectorAll for element-rooted queries
  • Piggy-back on a bicentric accumulation cache, if digit exists.
  • Allowing a duty as the “setter” discussion for .css() — same we hit in .attr() — and maybe for .val(), .html(), and .text() as well.
  • Offset: Faster Initialization, ingest parseFloat, boundingClientRect check
  • Events: Have img.load analyse for .complete in IE, Multiple protection with namespaces, Event scoping, .live() improvements
  • Ajax: Use JSON API if acquirable to parse JSON, Dynamic weight of stylesheets
  • Effects: Synchronized animations, fadeTo exhibit also exhibit the element, if it’s hidden
February 22nd, 2009

CROSS-BROWSER INLINE-BLOCK

Ryan Doherty has digit of those rattling pleasant articles that achievement you finished how to do something that should be cushy in CSS but isn’t, until you undergo how: Cross Browser Inline Block.

By the modify of it every you module hit this:

HTML:

  1.  
  2.     li {
  3.         width: 200px;
  4.         min-height: 250px;
  5.         border: 1px solidified #000;
  6.         display: -moz-inline-stack;
  7.         display: inline-block;
  8.         vertical-align: top;
  9.         margin: 5px;
  10.         zoom: 1;
  11.         *display: inline;
  12.         _height: 250px;
  13.     }
  14. </style>
  15.  
  16.         <div>
  17.             <h4>This is awesome</h4>
  18.             <img src=“http://farm4.static.flickr.com/3623/3279671785_d1f2e665b6_s.jpg”
  19.             alt=“lobster” width=“75″ height=“75″/>
  20.         </div>
  21. </li>
  22.  

which gets you the mass reliably in some browsers:

Along the artefact you module see most more IE grapheme hacks, recreation with hasLayout, ingest XUL stacks to support Firefox 2 along, and more. Very pleasant employ Ryan.

February 20th, 2009

WINDOWS IPHONE SIMULATOR

There’s no artefact to emulate the iPhone on Windows, but Shaun designer has the incoming prizewinning thing: taking a Windows physique of WebKit and embedding it exclusive an iPhone-like Chrome. It’s not perfect, but it’s as near as Windows users are feat to intend for now–and is rattling accessible for checking how your place module probable countenance (modulo type issues).

He’s exclusive proven it on Vista, however.

February 20th, 2009

COMPARISON OF JAVASCRIPT INHERITANCE MECHANISMS; PROPOSAL

Andrea Giammarchi took the happening to compare the JavaScript acquisition mechanisms in base2, Dojo, jsClass, MooTools, Prototype, and YUI and illustrates the aforementioned scenario with every of those frameworks. Handy indeed!

He concludes with a proposal:

WebReflection Proposal
After an psychotherapy aforementioned this one, how could I resile my “all the prizewinning from others without troubles” proposal?
These are my considerations:

* The fastest artefact to ingest a parent method is an definitive call

* The prizewinning artefact to action above travel is via a unification healthy to vanish definitive dependencies (read: MyParentClassName instead of this.constructor.superclass). In this artefact methods could be easily transported from a image to added digit without problems (less module practice and inferior cipher to maintain)

* The this.parent() resolution is the cleanest digit and mostly speech more near to our construct of “Object Oriented JavaScript”. It is portable, it is meaningful, it is shorter than an definitive call with or without a unification but it is not that alacritous to execute.

* Using prizewinning practices to store every we need, create a hurried wrapper, partitioning unseeable methods problems, module not alter us to autochthonous or YUI performances, but at small in a beatific scenario: alacritous sufficiency to indorse performances over cipher elegance and readability

So here we are with my proposal:

* Concept: parent in image but denaturized runtime for organisation determine exclusive if needed (read: exclusive for overrides). This module allows us to call parent direct in the constructor, as example, so we won’t hit threefold calls for apiece instance. At the aforementioned time, this feat lets us call explicitly a parent method from those whose were not inherited.

* Troubles: performances are the prizewinning but ease farther from autochthonous one.

Here’s the practice of his planned library:

JavaScript:

  1.  
  2. function WRClass(name){
  3.     this.name = name;
  4. };
  5. WRClass.prototype.toString = function(){
  6.     return this.name;
  7. };
  8. WRClass.prototype.toLocaleString = function(){
  9.     return “locale: “ + this.toString();
  10. };
  11. function WRSub(name, age){
  12.     this.parent(name);
  13.     this.age = age;
  14. };
  15. wr.extend(WRSub, WRClass, {
  16.     toString:function(){
  17.         return this.parent() + “: “ + this.age;
  18.     }
  19. });
  20. var me = new WRSub(“Andrea”, 30);
  21. alert(me);                   // Andrea: 30
  22. alert(me.toLocaleString())// locale: Andrea: 30
  23.  
  24. // last, but not least
  25. WRSub.prototype.explicitParentToString = function(){
  26.     return this.parent.prototype.toString.call(this);
  27.     // instead of
  28.     return this.constructor.superclass.toString.call(this);
  29. };
  30. alert(me.explicitParentToString()); // Andrea
  31.  

And, wager the journal place linked above for the maker cipher to his implementation.

February 19th, 2009

SPROCKETS: BUILD TIME JAVASCRIPT DEPENDANCY MANAGEMENT

Sprockets is a physique instance Ruby agency that reads in your JavaScript files, preprocesses and concatenates:

It takes some sort of maker files and preprocesses them line-by-line in visit to physique a azygos concatenation. Specially formatted lines behave as directives to the Sprockets preprocessor, informing it to visit the table of added enter or accumulation prototypal or to wage a ordered of quality files (such as images or stylesheets) to the writing root. Sprockets attempts to fit required dependencies by intelligent a ordered of directories titled the alluviation path.

It is created by Sam Stephenson, and he tells us ground you haw be fascinated to ingest it:

  • Extract reusable cipher and deal it crossways binary scheme sites or applications.
  • Speed up your locate by automatically concatenating JavaScript into digit file.
  • Organize your JavaScript maker cipher into binary commented files and directories.
  • Use bleeding-edge support and accumulation cipher in your application.
  • Sprockets is documentation-friendly

The preprocessor uses a require/provide ornament (Dojo has dojo.require(), dojo.provide() and crapper do physique instance and runtime work):

require

Use the visit directive to verify Sprockets that added JavaScript maker enter should be inserted into the series before continuing to preprocess the underway maker file. If the given maker enter has already been required, Sprockets ignores the directive.

The info of a visit directive determines how Sprockets looks for the interdependent maker file. If you locate the study of the maker enter in seek brackets:

//= visit <prototype>

Sprockets module see your alluviation path, in order, for a enter titled prototype.js, and begin preprocessing the prototypal correct it finds. (An nonachievement module be upraised if a matched enter can’t be found.) If you locate the study of the maker enter in quotes:

//= visit "date_helper"

Sprockets module not see the alluviation path, but module instead countenance for a enter titled date_helper.js in the aforementioned directory as the underway maker file. In general, it is a beatific intent to ingest quotes to intend to attendant files, and seek brackets to intend to packages, libraries, or third-party cipher that haw springy in a assorted location.

You crapper intend to files in subdirectories with the visit directive. For example:

//= visit <behavior/hover_observer>

Sprockets module see the alluviation line for a enter titled hover_observer.js in a directory titled behavior.

provide

Sometimes it is needed to allow related stylesheets, images, or modify HTML files with a JavaScript plugin. Sprockets lets you take that a JavaScript maker enter depends on a ordered of assets, and offers a turn for copying every interdependent assets into the writing root.

The wage directive tells Sprockets that the underway maker enter depends on the ordered of assets in the titled directory. For example, feature you hit a plugin with the mass directory structure:

plugins/color_picker/assets/images/color_picker/arrow.png
plugins/color_picker/assets/images/color_picker/circle.png
plugins/color_picker/assets/images/color_picker/hue.png
plugins/color_picker/assets/images/color_picker/saturation_and_brightness.png
plugins/color_picker/assets/stylesheets/color_picker.css
plugins/color_picker/src/color.js
plugins/color_picker/src/color_picker.js

Assume plugins/color_picker/src/ is in your Sprockets alluviation path. plugins/color_picker/src/color_picker.js strength countenance same this:

//= visit "color"
//= wage "../assets"

When <color_picker> is required in your application, its wage directive module verify Sprockets that every files in the plugins/color_picker/assets/ directory should be derived into the scheme server’s writing root.

Build instance unceasing replacement

You haw requirement to parameterize and append constants into your maker code. Sprockets lets you delimitate much constants in a primary enter titled constants.yml that lives in your alluviation path. This enter is formatted as a YAML hash.

Continuing the color_picker example, adopt plugins/color_picker/src/constants.yml contains the following:

JAVASCRIPT:

  1.  
  2. COLOR_PICKER_VERSION: 1.0.0
  3. COLOR_PICKER_AUTHOR: Sam businessman <sam @example.org>
  4.  

The constants are given in a azygos place, and you crapper today append them into your maker cipher without repetition:

JAVASCRIPT:

  1.  
  2. /* Color Picker plugin, edition <%= COLOR_PICKER_VERSION %>
  3. * (c) 2009 <%= COLOR_PICKER_AUTHOR %>
  4. * Distributed low the cost of an MIT-style authorise */
  5.  
  6. var ColorPicker = {
  7.   VERSION: ‘<%= COLOR_PICKER_VERSION %>’,
  8.   …
  9. };
  10.  

The resulting concatenated production module hit the unceasing values substituted in place:

JAVASCRIPT:

  1.  
  2. /* Color Picker plugin, edition 1.0.0
  3. * (c) 2009 Sam businessman </sam><sam @example.org>
  4. * Distributed low the cost of an MIT-style authorise */
  5.  
  6. var ColorPicker = {
  7.   VERSION: ‘1.0.0′,
  8.   …
  9. };
  10.  

Constants deal a orbicular namespace, so you crapper intend to constants circumscribed anywhere in your alluviation path. If a unceasing is not found, Sprockets raises an nonachievement and halts boost preprocessing.