Wednesday, March 28, 2007

Rules For JavaScript Library Authors

Dean Edwards wrote a nice article on "Rules For JavaScript Library Authors".
His main points are:
1) Be unobtrusive:
My HTML doesn’t want to know about your JavaScript

2) Object.prototype is verboten!
This is so important that it needs a rule all to itself. Objects are the basic building blocks of JavaScript functionality. Don’t mess with them

3) Do Not Over-extend
The less you extend JavaScript’s built-in objects the better. Don’t get me wrong. Native JavaScript objects are a little sparse on useful methods. You will feel obliged to add one or two of your own. But “one or two” is not enough for the creative (library) programmer. Stop! Just add what you need. The less you extend JavaScript’s built-in objects the less you will clash with other libraries.

4) Follow Standards
As a library writer you are defining patterns of JavaScript code. Patterns are signs of weakness in programming languages. Remember, JavaScript and the DOM are continually being specified. If you are going to “fix” something then look to see if it has not already been fixed. Consider available solutions. If you follow standards, then follow them closely (e.g. don’t skip a parameter on a forEach method).

5) Or Follow The Leader
Mozilla leads the way in JavaScript. The creator of the language, Brendan Eich, continues to develop it. New language features are available in Mozilla browsers before any other. If you are going to add language features to JavaScript then look to Mozilla standards first. For example, if you want to extend Array to allow an enumeration method, then call that method forEach instead of each. If you do provide missing language features then follow existing standards closely.

6) Be Flexible
What if I want to modify behaviour without changing the source code of your library? How easy is that? Not easy enough. Make it easier.

7) Manage Memory
People care about memory leaks. Do your job

8) Eliminate Browser Sniffing
It seems that browser vendors will forever compete by adding new features. As a library author you must keep up with the latest fashions. It is not good enough to browse Ajaxian occasionally. You must slavishly read every blog to find the next hack. Browser sniffing can be addictive

9) Small is Better
JavaScript libraries have come of age. Some of them now power premier sites. But we are not all on 2MBit DSL lines. So keep your library small. Better yet, provide a build page that allows me to efficiently build my library according to my needs.

10) The Tenth Rule
Good ol’ tenth rule. You can always rely on the tenth rule. The tenth rule is: be predictable. I should be able to guess what your methods do. And if I don’t know what a method is called then I should be able to guess that too.

11) Bonus Rules
* Documentation. Annoying but true.
* The more namespacing you use, the less likely I am to remember your phone number.
* Remember that potentially millions of people will be executing your code.

The article is a must read for web 2.0 programmers.

The full article:
Rules For JavaScript Library

Control.Modal: Great CSS Modal Windows and Lightboxes in one package

Ryan Johnson has created Control.Modal (CSS modal window based on the Prototype library).

It weighs in at around 8K and hit a sweet spot for some functionality. The Prototype
window class was overkill, and he needed more than just a lightbox

Example and source code can be found here: Control.Modal

Monday, March 19, 2007

Efficient looping in Javascript

Hi Guys,
I read a great article that talk about the Efficient looping in Javascript.
If you are a big fan of Javascript Libraries like Prototype and Mootools, this article will show you the performance problems of some of these Libraries Iterating like:
Native For-Loop
Native For-In-Loop
Prototype Each-Loop


Efficient looping in Javascript

Cross Browser Keyboard Support

First here is an excellant article on keystroke detection keystroke detection

Here is the code in order to support Cross Browser Keyboard:

document.onkeydown = function(e) {handleKeys(e)}
document.onkeypress = function(e) {handleKeys(e)}
var nonChar = false;

function handleKeys(e) {
var char;
var evt = (e) ? e : window.event; //IE reports window.event not arg
if (evt.type == "keydown") {
char = evt.keycode;
if (char < 16 || // non printables
(char > 16 && char < 32) || // avoid shift
(char > 32 && char < 41) || // navigation keys
char == 46) { // Delete Key (Add to these if you need)
handleNonChar(char); // function to handle non Characters
nonChar = true;
} else
nonChar = false;
} else { // This is keypress
if (nonChar) return; // Already Handled on keydown
char = (evt.charCode) ?
evt.charCode : evt.keyCode;
if (char > 31 && char < 256) // safari and opera
handleChar(char); //
if (e) // Non IE
Event.stop(evt); // Using prototype
else if (evt.keyCode == 8) // Catch IE backspace
evt.returnValue = false; // and stop it!

CSS+Javascript Fancy menu

If you are looking for cool javascript+CSS menu, you can found one right here on link below:

I found it when I was surfing and looking for cool javascript and CSS stuff.

Sunday, March 11, 2007

Cache Manager plug-in for ASP.NET

Hi Guys,
Steven Smith wrote Cache Manager for an ASP.NET application.
"Cache Manager is an ASP.NET plug-in which can be added to any ASP.NET website with no code, no recompile, a single DLL, and a single entry in web.config. It allows web administrators to monitor and manage the ASP.NET Cache object for their ASP.NET applications."

More information and download:
Cache Manager

Hope it will be useful :-)

Compressed versions of Prototype

John-David Dalton Compressed some prototype version like:
1.4, 1.5rc0, 1.5rc1, 1.5 final.
His package can be download from:
Compressed prototype

He managed to get it down to 14.4kb.

Wednesday, March 7, 2007

ASP.NET JavaScript IntelliSense

A new release of Visual Studio “Orcas” shows off the intellisense features nicely, including:
1) Proactive Completion List: No more waiting for ‘.’
2) Keywords in Completion List: fun your way to function
3) ASP.NET AJAX Concepts in Completion List: Direct support for Atlas
4) IntelliSense from Script Libraries for ASPX Pages: Now you can see objects that exist in other external script files.

This comes along with the release of an updated Ajax Control Toolkit.

more information: