Showing posts with label work. Show all posts
Showing posts with label work. Show all posts

Sunday, March 7, 2010

jQuery Plugins

In reference to this

It may not look like it from my other blog entries, but I really am a programmer.

Lately I've been working a lot with CouchDB as both a database and an application server. As part of getting up to speed, I've jumped into JavaScript. Somewhere along the way I found jQuery and ended up writing a plugin.

Since I'm such a perfectionist and because I'd armed myself with some knowledge of JavaScript's good parts, I wasn't 100% satisfied with the way some jQuery plugins were written.

Below is my take on a jQuery plugin template. You can see it in action in my autoExpandingList plugin (demo). I'll probably put it on GitHub eventually, but for now it's on jsbin (great tool, by the way).


/**
* jQuery.PLUGINNAME
*
* @author YOUR NAME
*
* NOTES/DESCRIPTION
*
*/
"use strict";
(function ($) {

$.fn.pluginName = $.fn.pluginName || (function () {

var defaults = {
//Default configuration
};

// Utility functions that you use inside your plugin that
// don't rely on per-invocation closures should go here.
// This is also a good place to keep track of any global
// state information that your individual plugin instances
// may want to make use of.
// This is your plugin function, what people will call
// with $("li").pluginName(...);
return function (settings) {

// Settings are cached per selector/invocation,
// not per affected element. This is a bit of a memory optimization.
// If you need/want your settings to be per element,
// just move this line to inside the each() below.
settings = $.extend({}, defaults, settings);

this.each(function () {
//Cache 'this' because it may change with scope,
// depending on what you do below.
var that = this;

/* Insert your special sauce here.
* Perform your operations on 'this' or 'that'
*and it will affect each element in the selector.
*/
});

// This is important in jQuery land.
// It allows chaining. Even if you don't make use of chaining,
// people using your plugin may.
return this;
};
}());
}(jQuery)); //Pass in the jQuery object by name in case $ is used


Some other things that I found to make things better were JSLint (which the above template passes) and js-beautify (which was used to format the above).

js-beautify had a small bug where it would make things ugly if you were using an empty object literal ($.extend({}, defaults, settings)'), but a one-liner patch was all it took to clear that up and I've already submitted it and had it applied, so it's ready for you to use!

I've also been teaching myself Python, so maybe I'll have some posts on that in the future as well. And maybe some thoughts on CouchDB.

Saturday, March 6, 2010

Great Week

I've had a few things going on lately and this last week seems to have ended on a high note.

My project at work paid large dividends over Thursday and Friday. I was able to get a couple week's work done in only two days thanks to my design decisions early on in the project. I love it when a plan comes together.

In fitness land, I finally got in both of my midweek runs for my Sun Run training. This was week 4. I'm still disappointed that things kept getting in the way, but I'm very happy that I was able to fit them in this week. I'm already at that point in the training where I'm finding it difficult to hold myself back and not over do it. I'm hoping to expand my route next week to up the distance to 2.8km/1.7mi from 2.2km/1.4mi. It's a small increase, but it should be. I'll expand it the week after that again I think.

And then there's this other project that I've been working on. Let's call it Project With A View. The most recent meeting I had about it was a blast and was a great way to cap off the week.

Actually, that's not quite how I capped off the week. We found a babysitter for Arland and I went out for dinner with my wife. Sorry, Project With a View, the wife wins.

I'll see if I can write up a couple other entries to follow up on some things in the near future. Tie up some loose threads from previous entries.

Thursday, September 4, 2008

Job Change

...but not changing company. I'm still at Fortinet.

Now that I've finally figured out how to describe my job to non-technical people, I go and change teams. I'm moving from development (on the main product) to configuration management (covering all products).

Guess I better start working on how to explain that one to people. CM is such a niche, most IT people don't even seem to understand it. Hell, I probably don't even understand it entirely myself! Then there's the dirty looks I get from some developers. The kind I gave to developers moving to QA (yes, such strange people exist). Maybe it's the office, or maybe it's CM in general, but it's not seen as prestigious as being a hard-core C monkey. Maybe it's a mistake, maybe I'll move back to development after a year. Who knows.

Should be some moderately interesting times. Hopefully not in a bad way. With some luck, I'll have more energy for coding at the end of the day though. And that can't be a bad thing.