Progressive Enhancement is Still Important

Jake Archibald makes a compelling case that progressive enhancement is still important, not because of users who’ve chosen to disable JavaScript, or because of outdated accessibility concerns, but because of graceful error handling and faster page rendering. He also dispels some myths, pointing out that building a progressively-enhanced application doesn’t have to require duplicating server-side logic and templating on the […]

Continue reading...

Attaching Uploads to Custom Post Types

I’m working on a plugin that implements a custom post type, and it doesn’t need the editor, but I do want to upload files. I setup the everything like you normally would, but I noticed that the files weren’t being attached to the post when they were uploaded. I couldn’t find anything online, so I dug through […]

Continue reading...

Progressive Enhancement with Backbone.js

I’m mostly focusing on back-end development these days, so I’m a bit behind the curve on a lot of the recent front-end practices, but I’ve been playing around with Backbone.js a bit, and one of the things that’s been nagging me is the hard dependency on JavaScript for the core functionality of the site. Looking around for some […]

Continue reading...

Reusing P2’s ajaxUrl Short-Circuits Other AJAX Requests

I just spent awhile tracking down some odd AJAX behavior that was puzzling me, so I thought I’d share the solution. I was working on a plugin to extend P2 and my AJAX requests were always responding with -1. After a lot of digging and some trial-and-error, I figured out that it was happening because I was […]

Continue reading...

Registering jQuery Event Handlers Before the Elements Exist

Update: I removed the link to the article because the site now contains malware. Dave Ward wrote an article Don’t let jQuery’s $(document).ready() slow you down that shows a few situations where execute the contents of a JavaScript file immediately, rather than wrapping it all inside jQuery( document ).ready(). The .live() method has been deprecated since he wrote the […]

Continue reading...

Why Hash-bang URLs are Bad

WebMonkey has a good article explaining why hash-bang URLS are a bad idea.  If you’re not familiar with them, they have  #! symbols at the beginning of the path, e.g. http://twitter.com/#!/username. They rely entirely on JavaScript to parse and therefore make the site inaccessible to browsers without  JavaScript (or those with it turned off by the user), assistive technologies […]

Continue reading...

Preventing Sites From Opening New Tabs/Windows

UPDATE: There’s now a Chrome extension called TheOne which does this, so you don’t need to create your own user script.   I wrote earlier about why it’s wrong for websites to force links to open in a new tab or window,  but it’ll probably be at least a few years before the majority of […]

Continue reading...

My First Shot at Adaptive Images

One of the first problems you run into when trying to build an adaptive layout is that images, unlike blocks of text, have fixed widths. Ideally we want to use small images on small screens and full sized ones on larger screens. The browser can resize the image on the fly, but the two problems […]

Continue reading...

Passing Multi-Dimensional Arrays from WordPress to JavaScript

On its own wp_localize_script() can’t handle multi-dimensional arrays, but you can get around that by encoding the child arrays in JSON. That doesn’t handle HTML content very well, though, so another way to do it is to use the l10n_print_after parameter. That’s kind of ugly, but it seems like the best way available right now. It […]

Continue reading...

admin-ajax.php Response Fails When Called from Domain Alias

I’m writing a WordPress plugin that uses AJAX and I had everything setup and working fine for awhile. I came back to the code a few hours later and all of the sudden I was getting a failed response, even though the code hadn’t changed. I got the correct JSON response when I loaded the […]

Continue reading...

Cross-Domain AJAX Requests

Browsers prevent standard AJAX calls across domains for security reasons, but you can make JSONP calls instead. If you’re using jQuery you just need to add ‘callback=?’ to the url: Then setup the request handler to prepend the callback parameter to the response and wrap it in quotes: If you’re using Firebug to monitor the […]

Continue reading...