AJAX & JavaScript
Peter Michaux
Douglas Crockford's articles on JavaScript (and his posts at the Yahoo! User Interface Blog) have helped me greatly to understand the more exotic and subtle features of the language, along with the patterns that exploit those features.
Now I've discovered a similar collection of articles by Peter Michaux. They often riff on Crockford's ideas, sometimes offering a fresh perspective and sometimes explaining things in a more accessible way. Well worth a read for aspiring JavaScript ninjas.
Simulating HTML5's placeholder attribute with jQuery
I recently discussed the placeholder attribute in HTML5. Today, I needed exactly such a behavior for a site I'm working on, so I knocked together a reusable, unobtrusive solution with jQuery.
target="_blank" for XHTML Strict
For better or for worse, it's a widespread convention for offsite links to open in a new window. This is usually achieved by setting the attribute target="_blank" on the link in question.
Of course, the target attribute is illegal in XHTML Strict—so this bit of functionality of will invalidate your pages.
I whipped up a simple fix to this problem. Here's the demo and download page.
Three essential Firefox extensions for web developers
Firefox is beloved by web developers for its compliance with W3C standards, its open-source nature, and its general awesomeness. But its vast library of genuinely useful extensions and Greasemonkey scripts is surely a big part of the attraction, too. Here are three that I couldn't live without.
Styling horizontal rules in Internet Explorer 6 & 7
Scott Klarr has a nice post about the difficulties of styling horizontal rules with CSS—owing mainly, of course, to problems in Internet Explorer.
In short, IE 6 and 7 insist on putting a border around horizontal rules, no matter how you set up your stylesheet.
Scott offers a simple but elegant solution which relies on jQuery. That's fine if you're already using jQuery in your project, but if you're not, it's hard to justify the extra payload to fix a simple cosmetic issue.
I've written a standalone version of Scott's script. At less than 350 bytes, it's a very lightweight solution, and it's easy to implement. Here's a demo page. As Scott's post explains, it simply replaces all <hr /> elements with <div class="iehrfix"></div> in the affected versions of IE.
A comprehensive JavaScript pad function
I wanted a JavaScript function for padding strings, but I couldn't find one that met my criteria. So, I wrote my own.
- Minified (850 bytes)
- Uncompressed
It behaves identically to PHP's str_pad() function, and has been unit tested in Firefox 3, Safari 3, Chrome, IE6, and IE7.
(more...)
JavaScript Standard Library 1.8+
I just came across Andrea Giammarchi's JavaScript Standard Library, a ≈2.7KB library which transparently adds JavaScript 1.6 methods (mostly the new Array stuff) to browsers which don't support them natively.
Surprisingly, this is the first library I've seen whose sole purpose is JavaScript version compatibility. Andrea says it provides "a quite totally standard environment", and offers some unit tests.
(more...)