JavaScript from Null: Cross-Browser Event Binding


In chapter five of this series, we jumped into the muddy world of event listeners. In that episode, we only got our feet wet; however, today, we’ll take things a step further as we implement a far more efficient solution. Along the way, we’ll learn a plethora of new techniques.

As with every JavaScript from Null screencast, it’s not essential that you view the previous entries in the series before watching.

Catch Up


Chapter 6: Cross-Browser Event Binding

Premium Members: Download this Video ( Must be logged in)

Our Final Code

var addEvent = (function( window, document ) {
	if ( document.addEventListener ) {
		return function( elem, type, cb ) {
			if ( elem && !elem.length ) {
				elem.addEventListener(type, cb, false );
			}
			else if ( elem && elem.length ) {
				var len = elem.length;
				for ( var i = 0; i < len; i++ ) {
					addEvent( elem[i], type, cb );
				}
			}
		};
	}
	else if ( document.attachEvent ) {
		return function ( elem, type, cb ) {
			if ( elem && !elem.length ) {
				elem.attachEvent( 'on' + type, function() { return cb.call(elem) } );
			}
			else if ( elem.length ) {
				var len = elem.length;
				for ( var i = 0; i < len; i++ ) {
					addEvent( elem[i], type, cb );
				}
			}
		};
	}
})( this, document );

// Example Usage
var lis = document.getElementsByTagName('li');
addEvent( lis, 'click', function() {
	this.style.border = '1px solid red';

});

Found Footage: Sharp says ‘sushi please’ on iPad

Lots of visual content, quick transactions, and hungry customers: that’s what Sharp has in mind with this proof of concept sushi menu application for iPad. Rather than putting diners through the chore of tracking down their favorite rolls and sashimi in a multipage laminated paper menu, the app puts dishes front and center.

The iPad app isn’t for sale yet, although the DigInfo report quotes Sharp saying it may be commercialized if there’s interest; it might also be ported to Sharp-built devices. If it does get rolled out, it would be included as an integrated piece of Sharp’s POS system for restaurants, including billing and order management tools. We’ve seen systems like this tested before, but as far as we’ve heard, no one’s actually using iPads in real-life restaurants and at least one Australian tapas joint has already gotten on the bandwagon. If you’ve seen a virtual menu in action, let us know in the comments.

[via Guy Kawasaki]

TUAWFound Footage: Sharp says ‘sushi please’ on iPad originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 17:00:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

FTC makes ruling in iTunes review case

The Federal Trade Commission, of all things, has laid down a ruling in the strange case of Reverb Communications’ iTunes reviews. We didn’t get to this story the first time around, but a PR firm named Reverb Communications (disclaimer: I’ve attended their press events here in LA) was accused a while back of asking its staff to leave positive iTunes reviews on some of their clients’ App Store titles. This wasn’t just a request to have the staff try out and review client games — they had an “internal user reviews” process, in which employees of the firm were paid specifically to leave positive reviews — “not over the top” were their words — on iTunes and online message boards.

Now, the Federal Trade Commission, ruling under the recent regulations for endorsements online, has decided to settle the case. No money is changing hands, but Reverb and its executive have been asked to remove all of the reviews posted. You can read more about the agreement on the FTC’s website. The FTC says that anyone endorsing a product online “should disclose the material connection the reviewer shares with the seller of the product or service,” and that Reverb didn’t do that.

For its part, Reverb and executive Tracy Snitker would like to brush the accusations off. “Rather than continuing to spend time and money arguing, and laying off employees to fight what we believed was a frivolous matter, we settled this case and ended the discussion,” she told the New York Times. But this ruling seems more important than that — it’s the FTC’s first enforcement of the Internet review guidelines, and so we’ll have to see what kinds of precedents this case sets.

TUAWFTC makes ruling in iTunes review case originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 18:00:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

Overclocked, liquid-cooled Mac Pro trades noise for speed

I wonder if it’s only a matter of time before Apple decides to go to a liquid-cooled solution rather than keeping with bigger and faster fans. In any case, one technically adept person over at Asetek didn’t want to wait for that day. He went about not only water cooling an older 8-core Mac Pro, but overclocked it as well. The result was a much quieter system, with the same speed as a newer Mac Pro and at lower cost.

I haven’t noticed a Mac Pro to be all that noisy, but the quieter the system the better, especially when it’s on or under your desk. What this guy didn’t explain, though, was how much time and money it cost to outfit the older Mac Pro with water cooling. Would the time, effort and cost there still make it a worthwhile mod? Check out his full video after the jump.

TUAWOverclocked, liquid-cooled Mac Pro trades noise for speed originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 19:00:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

App Store approval limbo boxes in Briefs

There are plenty of hurdles between a good idea and App Store success; even after your killer app hits the virtual shelves, the challenges of discoverability and competitors sandbagging your app with Astroturfed bad reviews add up to plenty of headaches. Still, once past the biggest stumbling block — Apple giving a thumbs up or thumbs down — things should get easier, right?

Unfortunately, some intriguing apps end up in approval limbo, the stranded state between all-clear and no-thanks that’s reserved for some of the most innovative and paradigm-busting apps; the apps that make Apple go “Hmm…” and force the app approval team to exercise the pocket veto. Without a clear rejection (telling the dev what can be fixed), there’s nothing to do but wait.

The most high-profile limbo case is Google Voice, which as far as we know is still being reviewed by Apple’s team more than a year after it was submitted. The latest is Briefs, a well-regarded app prototyping tool which may be running afoul of the no-interpreted-code ban in section 3.3.2 of Apple’s developer agreement, despite the assertion that Briefs doesn’t work in a way that’s forbidden by Apple’s rules. Even though developer Rob Rhyne made a cogent case to Apple’s team on the merits, and even with some high-level support from contacts made at WWDC, Briefs remains unapproved and unrejected.

Rather than wait indefinitely with his 1.0 growing stale, Rhyne has decided to offer the existing version as open source, which iPhone developers can compile and install on their testing devices. Rob’s colleague Jeff Lamarche at Martian Craft voices his frustration here.

In many ways, this could be an App Store success story: developer dedication and innovation, open lines of communication between indies and Apple, an open source tool that can improve app development for scores of coders. The only problem is that darned silent treatment, and the missing timeline for escalation. If an app can’t make it on the store, it seems the least Apple ought to do is say so and say why.

TUAWApp Store approval limbo boxes in Briefs originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 15:00:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

Paul Allen’s company sues Apple, Google

Microsoft co-founder Paul Allen has formally sued Apple, Google and several others over the use of technologies for which he holds the patents.

The Wall Street Journal was unable to reach any of the parties involved for comment, but notes that Allen has been going after companies, many of them high-profile, that he believes are using software that was developed in his Silicon Valley laboratory several years ago.

The suit identifies four specific patents. Each appears to be a huge part of how contemporary e-commerce and Internet search tools work. For example, one addresses how websites suggest products based upon customers’ recent searches. Another lets those reading a news story quickly find related stores, while the two others let ads and news items, among other things, flash on a computer screen adjacent to what the user is directly looking at. No specific dollar amount was identified.

Allen’s spokesman, David Postaman, told the Journal, “Paul thinks this is important, not just to him but to the researchers at Interval who created this technology.” Others named in the suit include Ebay, Facebook, Netflix and Aol (Note: TUAW is owned by Aol).

We’ll keep an eye on this story and post any updates.

TUAWPaul Allen’s company sues Apple, Google originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 15:15:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

Mac 101: Keep all your service info close to hand

More Mac 101, our series of tips and tricks for novice Mac users.

As reliable and fantastic as your Mac is, chances are it will occasionally need service. When you’re speaking with a representative on the phone or standing at the Genius Bar with your lovely, you’ll be asked to provide some basic information, like the model, OS and so on.

That’s the easy stuff we know off the top of our heads. Other specifics, like serial number, the kind of processor, the date of purchase and so on are harder to remember. Fortunately, Apple has produced some cheat sheets that you can print, fill out and store away until they’re needed.

There are three documents available: “My Mac Hardware,” “My Mac OS X Software and my Apple ID,” and “My Internet Connection.” Print them, fill them out and keep them stashed somewhere safe. It’ll only take a minute and when you need them, you’ll be glad they’re there.

TUAWMac 101: Keep all your service info close to hand originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 16:00:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

Last day for Bodega half-off sales on Mac apps

Update: If it wasn’t clear originally — you have to download the Bodega client first, and purchase the apps through its store. Some readers were confused by the link to the 1Password site, which was for illustration purposes only — the discount on the Mac client is specific to Bodega.

Today’s the last day to grab some deals from Bodega. The would-be app store for Mac OS X software is offering a 50 percent discount on the following applications through the end of the day:

This is a great deal on some really awesome software for your Mac. A good many of us love 1Password, and Sandvox is a great WYSIWYG web editor that’s won an Apple Design Award.

To take advantage of the sale, you need to purchase the software through Bodega, which is a free download.

TUAWLast day for Bodega half-off sales on Mac apps originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 14:00:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

Angry Birds fever continues

Angry Birds

Here’s one Angry Birds fan who took things to a whole new level. An industrious fan decided to recreate one of her favorite iPhone games using balls, clay, eggs, slingshots and cardboard boxes for a sort of “live” version of the popular iPhone/iPad game. I sure hope that’s not a wick on the top of the big black bird … or do I?

Meanwhile, everyone’s talking about the previously-reported rumors of an Angry Birds movie. Variety recently spoke with Mikael Hed, CEO of Rovio, creator of Angry Birds, where he talked about the success of the game and a short word on a probable sequel.

Add to all of this that Angry Birds is slated to hit the Sony PSP, PS3 and the Nintendo DS. Is it possible we’ll get sick of all this Angry Birds-ness before it’s allowed to become as big as Hed hopes? The title is certainly primes for moving in more directions, so long as Hed gets the ball rolling quickly.

TUAWAngry Birds fever continues originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 12:00:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

In Brief: September 1 Apple event

As preparations begin in San Francisco (check out the Yerba Buena Center’s new look) for the September 1 press event, here’s a brief review of what’s likely and unlikely to go down.

iPods are a given, and likely to be the thrust of the event. Apple has refreshed the line every year in September since the iPod‘s introduction. We’re guessing a more iPhone 4-like touch with a camera and possibly a retina display, perhaps on a higher-end model.

Also expected is a new iTunes rental option for TV episodes. As of this writing, TV shows are available for purchase at US$1.99 each. Bloomberg has suggested that Apple will add a rental option for $0.99 a pop, with new episodes becoming available just 24 hours after their original air time.

The wildcard is a new Apple TV (or iTV) running specialized apps on the iOS. It certainly doesn’t fit the music theme implied by the invite, but who knows. Perhaps Steve has one more thing up his black sleeve. In any case, visit TUAW on the 1st for our complete coverage.

TUAWIn Brief: September 1 Apple event originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 13:00:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

Hands on with Safari-based Gmail phone calls

Now that the inconvenient duplicate emails are a thing of the past, TUAW had a chance this morning to put Gmail’s new calling feature to the test. With Gmail phone calls, you can place free US-to-US calls directly from your browser or pay a low fee for international access. Calls use the Google Voice service backbone (and technology from the Gizmo5 acquisition), integrating voice features with desktop applications.

The installation is straightforward, and it begins with downloading the Google Talk video chat plugin if you don’t already have it. Grab the installer from your Gmail homepage, quit your browser, install, and then re-launch Safari. Navigate back to your Gmail account and you’ll be ready to place outgoing calls. To begin, click the Call phone button at the left of the Gmail web page.

TUAWHands on with Safari-based Gmail phone calls originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 13:30:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

TUAW’s Daily App: Zentomino HD

There are lots of frantic action games available on the App Store, but sometimes all you want to do is get home, sit down with your iPad, and relax with a fun puzzle. Zentomino is a game that lets you do exactly that. It’s a very zen take on the “pentomino” puzzle game, requiring you to fit a certain set of shapes into a specific outline. The game’s about as relaxing as it gets. While the music is somewhat repetitive, you’re free to move as many pieces around as much as you want, and just pushing the big, colorful shapes around can be almost as entertaining as actually completing the puzzle. There’s not a lot of flair, but what’s there is intuitive and fun, and when you just want to sit on the couch and relax, that’s what you need.

Zentomino HD is the brand new iPad version of the game, and it’s available as an ad-supported app. The first set of puzzles is completely free, with others available through in-app purchase. The game’s also available for iPhone (either as a US$1.99 paid version, or a lite version with ads).

TUAWTUAW’s Daily App: Zentomino HD originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 08:00:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

Sega puts titles on sale for back-to-school, releases Phantasy Star II on iOS

Just in time for the days of, well, skipping out on video games and getting back to the books, Sega has decided to try and tempt you away from that schoolwork by dropping prices across the board on its iOS games. Golden Axe, Shining Force, Streets of Rage and Ecco the Dolphin are all on sale for just US$0.99, and the Super Monkey Ball and Sonic the Hedgehog games are on sale for just a few bucks as well.

Phantasy Star II is worth mentioning on its own. Sega just released the game on iOS today, and for my money (only $2.99 during this sale!), there’s no better Genesis-era RPG. Seriously, if you are a fan of the console RPG genre at all, this one’s a must buy. The story’s fun, the gameplay is excellent, and having the title on the App Store is a real treat. Shining Force is a great game, and Streets of Rage is a fun title to have around for just a buck, but if you buy one game during this sale (which lasts through September 1st — thanks, Sega!), I’d recommend Phantasy Star II.

TUAWSega puts titles on sale for back-to-school, releases Phantasy Star II on iOS originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 09:00:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

Remember the Milk for iPhone now free — with a catch

Remember the Milk (RTM) is a popular Web-based to-do list manager with an equally popular iOS app (here’s our review). This week, the app’s developers have announced that it’s now free for the iPhone… with a few caveats.

Until now, the iPhone app was only available to those who paid US$25 a year or $2.99/month for an RTM pro account. The free version includes everything in the full version with the following exceptions: It only syncs manually (and once every 24 hours at most) and it doesn’t support push notifications. If you depend on the app to nag you into action, you might want to move on or consider the pro upgrade. However, those comfortable with referring to the app as the day progresses are in for a treat. RTM for iPhone is a solid app that you’re sure to enjoy.

Those who’ve been putting off trying RTM for iPhone now have the perfect opportunity. Download and enjoy!

[Via Lifehacker]

TUAWRemember the Milk for iPhone now free — with a catch originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 09:30:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments

Dear Aunt TUAW: What’s in Apple’s guitar hole?

Dear Aunt TUAW,

Maybe I’m completely wrong, but I eventually demystified the Apple 9/1/2010 Press Invitation. I had a look at the press release image I found on www.fscklog.com (it’s a little bigger than yours) in Photoshop.

Instinctively the soundhole was very interesting to me, especially the “barely lit” part underneath the strings, where you can see the inside of the guitar back. Classic guitars typically have a label of the guitar maker there and in the image you can barely see something that could be a label.

I found it very interesting that the Apple creative crew was so picky in such a detail, so this again pulled my attraction. Of course, it would simply look odd, if you couldn’t see anything of the guitar’s inside from a front shot like this, so maybe there’s nothing special about it. I then inverted the image in Photoshop and there was a “label” clearly visible.

TUAWDear Aunt TUAW: What’s in Apple’s guitar hole? originally appeared on The Unofficial Apple Weblog (TUAW) on Fri, 27 Aug 2010 10:30:00 EST. Please see our terms for use of feeds.

Read | Permalink | Email this | Comments