Nothing Insightful

Month

March 2011

7 posts

Play
Mar 27, 201126 notes
#Apple #iOS #iPad #Real Racing #Firemint
Mar 21, 20119 notes
#iPad #iPad 2 #Real Racing #VW #GTI #Comparison
Aristo 1.1 Released

I woke up on Saturday morning to find about 2,000 new visitors to my blog and 22 email notifications of new Twitter and Tumblr followers. It turns out Aristo made it to the front page of Hacker News for the second time in it’s short lifespan, and in turn was tweeted about by some popular Twitter users.

HN users had some great suggestions in the comments section, and most of those have been implemented and are now live on the GitHub repo and demo page. The list of changes include:

  • Styled basic input and textarea fields.
  • Button hover effects now fade with CSS3 transitions (Webkit, Firefox & Chrome).
  • Put user-select:none; on buttons to give them a more native feel.
  • Prevented empty button links from sending you to the top of a page (confusing when in a modal).
  • Fixed auto-complete versus slider z-index bug by hard coding z-index. This may cause other problems, so be on the lookout.
  • Fixed background bleed through bug for the progress bar.

I hope this keeps you satisfied for a while :)

image

image

 

image

Mar 20, 201120 notes
#Aristo #jQuery #jQuery UI #css3 #theme #github
Audi A3 Concept

Audi has officially released details on an A3 concept sedan following it’s earlier picture leak. Powered by a whopping 300kW, 5 cylinder engine and nearing A4 length, it poses some serious questions about model cannibalisation. If this goes into production, what will happen to both the A4 and the RS3? The silly sequence of A4 (add a few inches) A6 (add a few inches) A8 seems to become more ridiculous with the addition of an A3 sedan.

Regardless of Audi’s confused direction, I’m still very interested.

(Via AusMotive)

image

image

image

image

image

Mar 14, 201111 notes
#audi #a3 #concept #concept car #geneva #car #rs3
Play
Mar 9, 201118 notes
#Tron #Tron Legacy #Lightcycle
Linking JavaScript Objects to HTML Elements

Alternative Title: The jQuery $.data() Function is Awesome

image

The Workflow creation tool I’ve been working on and blogging about (design & code pattern) would have been impossible without forcing myself to learn object oriented (OO) JavaScript. It was a pretty steep learning curve for a designer, and I soon came across the common pitfalls of writing OO code. The factory pattern structure I linked to above took care of most of the problems like: pushing pseudo-class objects to an array, easy find methods without the use of hash tables, and deleting objects non-destructively.

One thing that took me a while to wrap my head around: How do you form a relationship between the “back end” object instances and the HTML/DOM objects you output from these?

Say you have the classic Person object example:

var collection = [];

var Person = function(params) {
    this.name = null;
    this.age = null;
    $.extend(this, params);
    collection.push(this);
}

image

When I came across the problem of being able to link back to the object itself, the first (and laziest) solution that jumped to mind was searching using an instance’s unique ID. Creating the objects initially gives you the chance to ensure the HTML and back end instance shared the same ID. At a later point when you need to find the instance, you can loop through your objects with class manager shorthand findBy() function:

Manager.prototype.findBy = function(p, v) {
    for(var i = 0, len = this.objs.length; i < len; i++) { 
        if(this.objs[i][p] === v) {
            return this.objs[i];
        }
    }
};

MyManager.findBy(“id”, 999);

This made a lot of sense initially:

  • HTML attributes can only be strings.
  • Make the HTML element and the back end object share an ID
  • Loop through and match the object when required

image

An Example

JSFiddle Example

In this example, we have to get the ID from the HTML element, convert it to an integer and then finally: loop through all the instances until it finds a match.

    // get the ID value
    var theID = parseInt($(this).attr(“objectID”), 10);

    // silly loop to find the object
    $(collection).each(function(i, item) {
        if (item.id === theID) {
            item.birthday();
        }
    });

But why bother looping? Maybe a hash table would be better suited to your scenario, but for me I wanted something more dynamic.

image

The Better Way

JSFiddle Example

The jQuery $.data() method is awesome. On face value it’s like the native $.attr() method but doesn’t restrict you to a string value. What this incredibly long-winded post boils down to is the realisation that you can bind your HTML elements directly to their back end objects via the use of the data attribute. No (visible) loops.

// set the data attribute originally
$(obj).data(“personObject”, self); 

// call birthday on the object directly
var theObject = $(this).data(“personObject”);
theObject.birthday();

You don’t even have to declare a reference to the object, you could just as easily chain up your calls. A word of warning though: this can get a bit confusing if you’re using a chaining library like jQuery, especially if your object prototype functions share names like “remove()”. ■

Mar 9, 201114 notes
#JavaScript #OOP #OO #HTML #HTML5 #jQuery #Prototype
Mar 6, 20115,075 notes
#bafta #movies #social network #inception #kings speech #black swan #awards
Next page →
2012 2013
  • January 4
  • February
  • March
  • April 2
  • May
  • June 2
  • July
  • August
  • September
  • October
  • November
  • December
2011 2012 2013
  • January 2
  • February 3
  • March 7
  • April 7
  • May 3
  • June 3
  • July 4
  • August 1
  • September 5
  • October
  • November 5
  • December
2010 2011 2012
  • January 6
  • February 2
  • March 7
  • April 4
  • May 4
  • June 6
  • July 5
  • August 7
  • September 5
  • October 4
  • November 5
  • December 3
2010 2011
  • January 13
  • February 8
  • March 6
  • April 4
  • May 6
  • June 7
  • July 11
  • August 5
  • September 3
  • October 3
  • November 3
  • December 2