Recent Code News
Recently, word came through the twitter-nets that JS1k, a 1 kilobyte JavaScript competition, was accepting entries. Now, I haven’t done anything “fancy” in a while, but I used to do that kind of stuff all the time (you know, before I was married).
So I asked myself, “Ben, can you do something extra fancy in exactly 1024 bytes of JavaScript?”
While I generally try to avoid Firefox these days (using Chrome instead), I still like to test my code in multiple versions of all the major browsers to ensure that behavior is generally consistent. For a while, I was using MultiFirefox, which is a great utility, but I found using it to be far less streamlined than I would like.
Fortunately, I stumbled upon an article this weekend that explained how to launch Firefox with an arbitrary profile via command-line parameter (which is probably what MultiFirefox does internally). Unfortunately, because OS X aliases don’t work like Windows shortcuts, it’s a bit cumbersome to have to open the Terminal and type a command every time you want to launch Firefox… so I wrote a relatively simple AppleScript that greatly streamlines the process.
Basically, once configured, you never again have to choose which profile goes with which version of Firefox. Just run the launcher and it handles everything! If you’re curious, check out the instructions for Multi-Firefox Launcher now, and let me know what you think.
Next Wednesday, June 2, I’ll be talking jQuery plugin development at Boston jQuery Meetup #4, in the awesome Bocoup Loft event space.
I’m going to talk about code organization and best practices as it relates to creating modular, reusable code, aka “plugins.” I’ll focus on code maintainability, organization and generalization, and touch on performance and size optimization, in the context of jQuery plugin development. And as if that weren’t enough, I’ll even step through the creation of a jQuery plugin, taking it from concept to completion, before your very eyes.
So, if you use jQuery, or even just JavaScript, and want some free pizza and beer, along with ninety minutes of examples, explanations and Q&A, sign up now, and I’ll see you next week!
Even though I initially released jQuery BBQ in late 2009, the plugin has actually been many years in the making. While it started out as a little snippet of code that almost every web developer, at one point or another, has written, over time it evolved into something much larger.. and much tastier.
In this article, I’ll not only explain how jQuery BBQ came to be, but I’ll also give you some things to think about, in case you’re considering writing a jQuery plugin.
The jQuery special events API is a fairly flexible system by which you can specify bind and unbind hooks as well as default actions for custom events. In using this API, you can create custom events that do more than just execute bound event handlers when triggered—these “special” events can modify the event object passed to event handlers, trigger other entirely different events, or execute complex setup and teardown code when event handlers are bound to or unbound from elements.
I don’t write many book reviews, but when Packt Publishing contacted me recently asking if I would like to review the newly released jQuery 1.4 Reference Guide, I agreed. Even though I prefer online documentation, many people prefer theirs printed out, so I figured that I’d review the book for them. Also, I’m bringing the copy that Packt sent me into the office today for my coworkers to use.
I want to clear up a common misconception. It’s my belief that developers mistakenly call JavaScript Object literals “JSON Objects” because their syntax is identical to what is described in the JSON specification, but what the specification fails to mention explicitly is that since JSON is a “data-interchange language,” it’s only actually JSON when it’s used in a string context.
When I initially started releasing jQuery plugins, I asked a number of my peers how I should license them. I was already using a Creative Commons license for my photography and text, but I had read that it wasn’t recommended for software. The most common suggestion was to use the MIT license, which I really liked because it is concise, establishes that I own the copyright, that the software in question is free, and that no warranty is provided.
You might not be thinking about this now, but it’s never a bad idea to state somewhere that this hard work, that you’re doing free of charge because you love open source, is provided as-is, without any kind of warranty. I’m not saying that anyone is going to hold you liable and take you to court because your code broke in production due to some wacky bug, costing them thousands of dollars.. but you’re better safe than sorry, right?
Either way, the MIT license allows people to pretty much use your code however they want, in a free or commercial product, as long as they keep your copyright notice intact.
So, that’s it, right? Well, that’s actually only half the story…
I never really expected to categorize a post as both “code” and “music,” but you know those “there’s an app for that” iPhone commercials? Well, apparently, “there’s a Ben Alman jQuery plugin for that.”
After I had gone to sleep last night, Jonathan Neal, author of the jQuery SWFObject plugin, jQuery sIFR plugin, CMS.txt and the creator of the yayQuery podcast theme song posted a new track into IRC…
Recently, Elijah Manor and Ralph Whitbeck asked me if I’d like to be a guest on the Official jQuery Podcast. Of course, I agreed.. and last week, Episode 6 was recorded.
First, let me just say that it was a lot of fun! We had a lot of laughs, and not all at Elijah’s expense (but mostly), and actually talked about some useful, jQuery-related stuff.
We talked about plugin development, code organization and one of my contributions to jQuery 1.4 core. We also discussed some general suggestions for developers who want to contribute to the jQuery project, but aren’t sure how to get involved, and I gave a rundown on a handful of my plugins, what they’re called, what they do, etc.
In addition to the actual “useful” stuff, we heard a few of my tunes, I explained where the nickname “Cowboy” came from, and oh yeah, we talked about the hottest new John Resig-related internet meme!
If you haven’t heard The Official jQuery Podcast, Episode 6 yet, what are you waiting for? Check it out now on the jQuery Blog, and let me know what you think!
Recently, Cody Lindley asked me to take a look at his new book, jQuery Enlightenment, and write up my thoughts. Now, I’ve never written a book review before, but since I’ve spent a lot of time helping novice jQuery users understand programming and design concepts as they relate to both jQuery and JavaScript, I saw this as a good opportunity for me to weigh in on a book written for exactly those people.
If you’ve tried out jQuery 1.4, you might have noticed that, among other things, the $.param method has seen some significant improvements.
I’d like to take a few moments to explain how request params parsing works, and how things have changed in jQuery 1.4.
I recently encountered an odd behavior in WebKit while testing jQuery BBQ on a page that lived in an Iframe. What I initially thought might be a bug in jQuery BBQ actually appears to be a bug in Webkit, so I set up an example page that shows how location.hash browser history breaks in an Iframe, in WebKit, Safari, and Chrome.
Recently, Katherine Senzee at Acquia contacted me to ask if I would consider dual-licensing my jQuery BBQ plugin as both MIT and GPL, because they wanted to include it in the upcoming Drupal 7 admin interface.
The idea is for the admin interface to appear as a modal window on top of the current page, with fully function back/forward button functionality, while maintaining the context of the current page. This is, of course, a great idea.. and one that jQuery BBQ makes easy!
A while back, I coded up a very basic nextUntil method, but it felt a bit simplistic. I felt that I could code a slightly more “general” solution that actually sorted correctly.. so here’s the result:
jQuery Untils provides three very simple, but very useful methods: nextUntil, prevUntil, and parentsUntil. These methods are based on their nextAll, prevAll, and parents counterparts, except that they allow you to stop when a certain selector is reached. Elements are returned in “traversal order”.
Note that these methods take a less naïve approach than others bearing the same names, and are designed to actually return elements in traversal order, despite the element ordering flaws inherent in the jQuery 1.3.2 selector engine. A ticket and patch have been submitted to the jQuery team for hopeful inclusion in the 1.4 release.
Check out the documentation and examples at the plugin page, and let me know what you think in the comments!
More Recent Code News
- BBEdit Invisibles colors: Update! 11-12-2009
- Is this a Firefox remote XMLHttpRequest bug? 11-09-2009
- CSS: With HTTP requests, less is more! 11-04-2009
- jQuery BBQ plugin v1.0.2, JavaScript Debug on GitHub 10-12-2009
- jQuery urlInternal plugin v1.0 10-08-2009
- Gyazo.. on your own server 10-07-2009
- jQuery BBQ plugin v1.0 10-05-2009
- On contributing to jQuery, and new plugins too... 09-30-2009
- Chrome, browser history, bugginess 09-24-2009
- jQuery Conference '09 09-13-2009