Web Info & Tutorials

November 9th, 2007

PROTOSCRIPTY SAME GAME

Gary Haran wanted to see how well the latest versions of Prototype and Script.aculo.us worked, so he created a game, Same Name.

The 179 lines of JavaScript has fun with animations and sound.

Same Game

November 9th, 2007

NO MORE “CLICK TO ACTIVATE”, NO MORE SWFOBJECT / UFO?

Pete LePage has posted on the IE blog about the change to component activation in IE. Microsoft licensed the silliness from Eolas, which now means that you don’t have to click to activate a component anymore.

Previously, people were getting around that by using SWFObject or UFO, but shortly you will be able to just embed away. Here is the timeline:

IE Click to Activate

So you’re probably wondering when we are going to release this update? The first chance will be with an optional preview release, called the Internet Explorer Automatic Component Activation Preview, available in December 2007 via the Microsoft Download Center. Additionally this change will be made part of the next pre-release versions of Windows Vista SP1 and Windows XP SP3. After giving people enough time to prepare for this change, we’ll roll this behavior into the IE Cumulative Update in April 2008, and all customers who install the update will get the change.

If you have a custom application using WebOC or MSHTML, there may be some changes that affect your application. For example:

  • If your application uses the DOCHOSTUI flag to opt-in to the current “Click To Activate” behavior, that behavior will continue to be respected and your application will require “Click To Activate”
  • If you application uses the registry key FEATURE_ENABLE_ACTIVEX_INACTIVATE_MODE to opt-in to the current “Click To Activate” behavior, this registry key will no long be respected. If you wish to continue to use the “Click to Activate” behavior, please use the DOCHOSTUI flag.

In the coming weeks, we’ll be updating the MSDN article with descriptions of the new behavior. Keep an eye out here for when the preview goes live. 

November 9th, 2007

PSEUDO-CUSTOM EVENTS IN PROTOTYPE 1.6

Andrew Dupont has written a tutorial on how to normalize proprietary browser events using Prototype's new custom events feature.

The piece is interesting as it talks about how the Prototype core team originally went down the wrong path trying to boil the ocean with great features that were a bit too much. And then:

we refocused, trimmed the fat, and added a whole bunch of features to the event system while still excluding thie kitchen sink. We picked some low-hanging fruit; for instance, we normalized the event object so that properties like target exist in all browsers, and we ensured events fire in the scope of the element in IE (so that this refers to the proper thing).

But we also added cross-browser support for custom events. Now developers can fire their own events alongside native browser events and can listen for both types with the same API. Custom events will make Prototype add-ons at least 50% more righteous, allowing for even more control than the standard callback pattern. Imagine TableKit firing an event when a cell gets edited, or PWC firing an event when a dialog is resized.

Since the 1.6 RC1 release, several people have asked whether we have any plans to add native support for mouseenter, mouseleave, or mousewheel. I think we ought not, lest the event codebase become an unholy thicket of special-casing. That’s the sort of environment where bugs thrive.

But, as Sam points out, the addition of custom events makes it easy for third parties to add their own support for proprietary browser events. To demonstrate, today we’ll write 20 lines of code to add sane, cross-browser support for mouse wheel events.

I’m calling these pseudo-custom events because they serve the same purpose as standard browser events: they report on certain occurrences in the UI. Here we’re using custom events to act as uniform façades to inconsistently-implemented events. Together we’ll write some code to generate mouse:wheel events. At the end of this article, you’ll know enough to be able to write code to generate mouse:enter and mouse:leave events document-wide.

This leads you into the example itself which takes you through a number of iterations before ending up with:

JAVASCRIPT:
  1.  
  2. (function() {
  3.   function wheel(event) {
  4.     var realDelta;
  5.  
  6.     // normalize the delta
  7.     if (event.wheelDelta) // IE & Opera
  8.       realDelta = event.wheelDelta / 120;
  9.     else if (event.detail) // W3C
  10.       realDelta = -event.detail / 3;
  11.  
  12.     if (!realDelta) return;
  13.  
  14.     var customEvent = event.element().fire("mouse:wheel", {
  15.      delta: realDelta });
  16.     if (customEvent.stopped) event.stop();
  17.   }
  18.  
  19.  document.observe("mousewheel",     wheel);
  20.  document.observe("DOMMouseScroll", wheel);
  21. })();
  22.  
November 9th, 2007

JAVASCRIPT 2: NEWS AND OPINION

Brendan has been conversation most ES4 for a daylong instance now, and we hit been a lowercase astonied at how lowercase grouping had been stipendiary tending to it. But, of course, it is same an election. People cut it until it gets near and then they countenance at the issues “oh move a minute. that man would do WHAT?”.

This has advance to the discharge of interest, and blog-fare. To closing up the week, we desired to unification to Brendan’s stylish thoughts on ES4 programme and opinion which includes a newborn known incompatibilities document:

Some programme on module size: the planned ECMAScript 4th edition (ES4) grammar is a taste more than twice as bounteous as ES3’s, reckoning individual structure (concrete productions, nonfigurative structure tree convexity types).

This is not discover of distinction presented the octad eld since ES3, which came inferior than threesome eld after ES1. Much of ES4 has been matured and shipped in ES3-based languages: AS3 in Flash, JS1.6 and 1.7 in Firefox, Opera’s extensions including clothing destructuring. And we’re existence bounteous with grammar conveniences, which desugar to a small set language.

On the sympathy front, we hit a newborn writing on known incompatibilities between ES3 (ECMA-262 Edition 3 the spec, not real-world activity of ES3 implementations in browsers — state well) and ES4.

Neither a unseeable and unripe deciding proposal, nor generalized objections from a eld in the group, should prevent a accepted in progress. ES4 should be suspended or forsaken exclusive on theoretical demerits, demonstrated specifically. There are sufficiency implementors employed unitedly to attain a standard, and ES4 as it has evolved has ever been the due progeny standard. To country it supported on generalized fears and opinions prejudges both the test accepted and the mart for it. The market, not Ecma TC39-TG1, should end ES4’s fate.

It should be country by today that the eld of TG1, who souvenir ES4, poverty to ready the assemble from splitting, or otherwise risking clashing forks of ES3. Everyone loses in that scenario.

We wouldn’t hit spent every the instance in the wiki and at meetings if we all, including me, didn’t poverty a win-win outcome for every players. And I personally advisable to Chris in March that Microsoft could be a bounteous succeeder by championship ES4 and activity it in IE.

Is it ease doable for everyone to win? I hit to feature I’m not as constructive as I utilised to be. If we every impact on testable sympathy via the meaning implementation, then I’m somewhat more hopeful. But it module verify a meliorate attitude than rejection of ES4 “in full [and] in part” to intend somewhere.

November 9th, 2007

HOW WELL DO YOU KNOW PROTOTYPE?

With all of the news about Prototype this week, it's time to do a quick check to see if you, the Prototype developer, actually know your stuff.

Juiry Zaytsev takes us through a comparison of the right & wrong ways of doing certain tasks in Prototype:

I've been developing with prototype for almost a year now and have been spending a lot of time on the IRC channel. It's hard to explain what kind of nonsense people are asking sometimes. It seems to me that most of the time prototype is used at 15%, not more. I'm not surprised anymore to see Ajax.Request used with document.getElementById on one line

Juriy created two posts that offer insight into how to properly right Prototype code to handle various scenarios. For example:

The wrong way:

$('footer').style.height = '100px';
$('footer').style.background = '#ffc';

The right way:

$('footer').setStyle({
height: '100px',
background: '#ffc'
})

The two posts can be found below:

How well do you know prototype Part 1
How well do you know prototype Part 2