Patching Milans jQuery Plugin Pattern for jQuery 1.6

I recently wrote some code with Milan Adamovsky’s jQuery plugin pattern. A nice pattern for writing plugins that does a lot of cool stuff for you.

However, I discovered that with a jQuery version higher than 1.4 everything broke. I could no longer use jQuery at all if the plugin was loaded. I got the very suspect error:
Uncaught TypeError: Cannot call method 'find' of undefined in jquery.min.js:16

After some digging I found out that what the pattern does is to extend jQuerys init method like this:

$.fn.extend({
  init: function (selector, context) {
    return jQuery.fn._plugin = new jQuery.fn.jQueryInit(selector, context);
  }
});

The problem is that jQuery changed the method signature for the init method from this:
init: function( selector, context ) {

to this:
init: function( selector, context, rootjQuery ) {

The solution is to patch the pattern so it gives init all it’s arguments and everything is fine:

$.fn.extend({
  init: function (selector, context, rootjQuery) {
    return jQuery.fn._plugin = new jQuery.fn.jQueryInit(selector, context, rootjQuery);
  }
});

The best thing is that this patch actually works for jQuery 1.4 as well since javascript silently ignores extra arguments.

Ludvig Widman

Comment

Posted:
212 days ago
Tags:

Lenovo Thinkpad X1 on Linux

Today I got my Thinkpad X1 and immediately installed Ubuntu 11.04. So far it feels like a really nice laptop. The keyboard is perfect, it’s light and having a trackpoint is a nice bonus. On the downside the fan is a bit loud and the screen very glossy. The Ctrl key is in the wrong place (Fn is at the very left), but this can be changed in BIOS.

It’s always interesting to see what works and what does not, so heres a list of things that works right away and things that needs some work:

Things that works right away
  • Wifi
  • Audio
  • Backlight adjustment
  • Keyboard backlight
  • Trackpad and Trackpoint
  • Suspend
  • Webcam
  • Memory card reader
  • Two finger scrolling and side scrolling on trackpad
  • External Monitors (but only one external and the internal)

Stuff that needs some work

Linux support is over all very good and most things works right away.

Ludvig Widman

Comment [3]

Posted:
241 days ago
Tags:

Avocado, Sambal Badjak and Cheese Sandwich

I love sandwiches. This is one of my latest creations:

Actually, it’s my third attempt since the previous two got eaten before I bothered to pick up the camera.

Its a brown bread with butter, aged Prästost, Sambal Badjak, Avocado, pepper and sea salt.

Ludvig Widman

Comment

Posted:
339 days ago
Tags:

Finally on App Store: Light List – the fast shopping list

A while back I tried to find a good shopping list for iPhone. I wanted one that starts quickly and with a database of common items. After a long search with no luck I decided to create one myself.

It’s called Light List and lightweight is exactly what it is. There’s nothing unnecessary included and that’s the way I will keep it. To avoid the feature bloat that so many other shopping lists have I will not add any feature that makes it slower.

In the app there is a list of over 400 common items that makes it faster to add stuff to the list. This database is currently available in Swedish or English. The app sorts searches by how often the items are added so the most used things is faster to add.

You can read more about Light List at the website I made for it.

Ludvig Widman

Comment

Posted:
442 days ago
Tags:

Digital clock with date and weather

This is a project I started both to learn more about electronics and because I needed a clock for the workshop. The resulting clock I built has a 4-digit time display with yellow 7-segment LED-displays and a LCD that shows the current date, week and weather. The clock is powered by an Arduino connected to a server that sends updates to it every five minutes.

Each of the 7-segment displays is connected to a shift register so that I can control all 32 LEDs with only 3 pins on the Arduino. Each shift register has 8 outputs and they can be daisy chained so only one of them has to be directly connected to the Arduino.

I found this tutorial that describes how to do this. Since I wired my displays the easiest way possible (just connect everything and figure out which pin controls what later) I had to rewrite the character map but otherwise the code in the tutorial was very helpful.

I also connected an LCD to the Ardiuno so I could display some more information like date, week and weather. This information is sent to the Arduino over USB. To do this I created a small python script that uses serial to communicate with the arduino and pywapi to get weather data. The script also sends the current date and time to both avoid handling dates in the Arduino code and avoiding clock skew. Since the server that the clock is connected to uses ntpd the clock always shows the right time.

Ludvig Widman

Comment

Posted:
504 days ago

« Older