Tag: JavaScript

A fitVids vanilla JavaScript do-over

FitVids.js is a jQuery plugin used to create fluid videos. It helps makes video embeds from YouTube, Vimeo and a number of other sources display nicely on responsive sites. FitVids calculates the ratio of a video, wraps it in a div and sets the padding to enforce a ratio. A typical 4:3 YouTube embed starts as: <iframe width=”420″ […]

Code

IE friendly console.log

Internet Explorer makes me sad every time I open it to cross-browser test during development and it crashes on console.log. A simple check OR define option can kill console in the IE developer toolbar, so I decided to write a more robust cross-browser compatible console.log.

Code

Vendor prefixes, polyfills and former clients

Jeremy Keith’s recent post Polyfills and products asked an interesting question about handing polyfilled code to clients: [Short term client projects] makes it very tricky to include a polyfill in our deliverables. We’d need to figure out a way of also including a timeline for revisiting that polyfill and evaluating when it’s time to drop […]

Code

Open site redesign using a pattern library

As I’ve mentioned previously, I’m in the process of redesigning this web site. It’s very much a work in progress. Pattern Library As a first step I’m building a pattern library and I’ve decided to open source the repo during the build process. I’m using Pattern Lab for the purpose.

Code

Optimising the Typekit Code

The Typekit kit editor provides two versions of the embed code, the default version blocks rendering and the asynchronous version which can produce a flash of unstyled content (FOUC). In the case of Typekit, I prefer the FOUC over slowing down rendering. The asynchronous code also offers the advantage of your site staying online should […]

Code

Avoiding the FOUC

For several years I’ve used Paul Irish’s technique for avoiding the FOUC caused by JavaScript kicking in. I’ve recently changed to a slightly improved version.

Code

The Developer’s Guide To Conflict-Free JavaScript And CSS In WordPress

Imagine you’re playing the latest hash-tag game on Twitter when you see this friendly tweet: You might want to check your #WP site. It includes two copies of jQuery. Nothing’s broken, but loading time will be slower. Continue reading at Smashing Magazine.

Code

HTML5: I couldn’t (quite) do it

I found it difficult to use pure and semantic HTML5 when dealing with current versions of Internet Explorer. I really tried to adopt the commonly advocated view that it’s okay to require website visitors have JavaScript enabled but settled on a different option I could actually live with.

Code

JavaScript Localisation in WordPress

I was asked on Twitter recently if it’s possible to pass WordPress data to JavaScript, wp_localize_script() is the tool to do it with.

Code

JavaScript the WordPress Way / Part 2

In Part 1 we introduced the wp_register_script and wp_enqueue_script functions developed to avoid JavaScript conflicts.

In this section we’ll deal with a more complicated example. We’ll also take what we’ve learnt about including JavaScript and apply it to our CSS.

Code