Dead simple jQuery pagination plugin [UPDATED]

This is an extremely simple jQuery plugin for paginating over lists of items. It uses the jQuery.slice() function to reveal the appropriate section of the list, which means it should work fine with dynamic or sortable lists.

/**
 * jQuery UI paginatio plugin
 * Copyright (c) 2009 Christopher Beer
 * Date: 04/15/09
 *
 * @projectDescription Simple jQuery pagination plugin
 *
 * @author Chris Beer - chris@ratherinsane.com
 * @version 0.1
 *
 * @example $('ui.dropdown').paginate( );
 *
 * Depends:
 *	ui.core.js
 */

(function($) {
	$.widget("ui.paginate", {
		_init: function() {
			var self = this, o = this.options;
			this.$container = $(this.element);
			this.nav();
			this.page(0);
		},
		page: function(i) {
			o = this.options;
			max = Math.ceil(this.length() / o.itemsPerPage) - 1;
			min = 0;
			this.pg = Math.max(Math.min(i, max), min);
			if (this.pg == max) {
				o.pager.find("." + o.next).addClass('disabled');
			} else {
				o.pager.find("." + o.next).removeClass('disabled');
			}
			if (this.pg == min) {
				o.pager.find("." + o.prev).addClass('disabled');
			} else {
				o.pager.find("." + o.prev).removeClass('disabled');
			}
			this.$container.children().hide().slice(this.pg * o.itemsPerPage,
					(this.pg + 1) * o.itemsPerPage).show();
			return this.pg;
		},
		next: function() {
			o = this.options;
			return this.page(this.pg + 1);
		},
		prev: function() {
			return this.page(this.pg - 1);
		},
		nav: function() {
			var self = this, o = this.options;
			if (o.pager === null) {
				o.pager = $('
'); o.pager.insertBefore(this.element); } var pagerNav = $('« PrevNext »'); $(o.pager).append(pagerNav); nextbut = o.pager.find("." + o.next); prevbut = o.pager.find("." + o.prev); nextbut.click( function() { self.next(); return false; }); prevbut.click( function() { self.prev(); return false; }); }, length: function() { return this.$container.children().length; }, itemsPerPage: function(i) { if (i != undefined) { this.options.itemsPerPage = i; } return this.options.itemsPerPage; } }); $.extend($.ui.paginate, { version : '1.6rc6', getters : 'nav length', defaults : { itemsPerPage : 5, pager : null, prev : 'prev', next : 'next' } }); })(jQuery);
---- Update: There was an off-by-one error in the original code -- max = Math.floor([...]); should be max = Math.ceil([...])-1;

Open Source Archives Hosting

At a recent conference, someone mentioned their desire to see some kind of digital-library-as-a-service model for people looking to enter the digital domain. This model seems like the perfect way to help people overcome the technical obstacles faced by smaller institutions who would rather focus on mission-based work (offering their content) rather than worry about technical infrastructure. I was then shocked at the relative absence of existing players — is it that the technology is too new, too small a market, etc? Figuring I have extra capacity on my server to offer, and a little free time on my hands, I’d like to announce the availability of some open source archives application hosting on my servers for OmekaCollectiveAccess, and Scriblio. We can offer a wide range of services, from the most basic server management and maintenance tasks, to help installing and configuring the archives applications, to full scale ingest workflow processes and plugin authoring. Initially, the basic services will be offered free, but if server resources grow scarce, an at-cost model may be pursued. Right now, though, it is simply a good way to put surplus resources to good use.

Trackback for Annotations

One of the “Web 2.0″ features people always want in a repository interface is the ability to annotate or comment upon the record. Unfortunately, the commenting environment in many systems is very basic and make it difficult to create the kinds of annotations that could be truly useful.

To help overcome the environmental challenges and constraints, what if you could make comments in your personal content management system (like, say, a blog) and have that recorded within the repository?

There’s an obvious mechanism here, already employed by many blogging systems: Trackback

A trackback is one of three types of linkbacks, methods for Web authors to request notification when somebody links to one of their documents. This enables authors to keep track of who is linking, and so referring, to their articles [http://en.wikipedia.org/wiki/Trackback].

In a repository that already employs linked data, adding a trackback is fairly easy and an obvious way of providing (tech savvy) users the ability to comment and curate collections, while creating a reference in the repository itself. Implementing trackbacks is as simple as adding this in the header:

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
    xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description
rdf:about="http://path/to/this page/pid/wgbh%3A131#this"
dc:identifier="http://path/to/this page/pid/wgbh%3A131#this"
dc:title="Interview with Robert McFarlane, 1996 (Part 1)"
trackback:ping="http://path/to/action/trackback/pid/wgbh:131">
</rdf:Description>
</rdf:RDF>

Visualizing Media Archives: A Case Study

Beer, C., Michael, C., and Todorovic, M. 2009. Visualizing Media Archives: A Case Study. Code4Lib Journal 6 (March 2009)
The WGBH Media Library and Archives is piloting an online media archive for scholarly research. In conversation with users, we have discovered they want to quickly pinpoint items relevant to their work and get an overview of collections and their relationships to other materials. To demonstrate the size and complexity of our collection to users in a meaningful way, WGBH is employing data visualization techniques to provide an interactive, graphical representation of the various relationships between items. This article discusses the techniques employed in implementing our relationship map, emphasizes the cataloging techniques required for this effort, and offers code and examples to spark discussion about ways to improve or extend this effort.

HSB Color to RGB

Here is a quick utility function for PHP to calculating the RGB hex for a given HSB color vector. It is based, in part, this article by Chris Jackson:

function hsbColor($h, $s, $b)
   {
       if(0 > $h || 360 < $h) { throw new Exception('Out of Range');}
       if(0 > $s || 1 < $s) { throw new Exception('Out of Range');}
       if(0 > $b || 1 < $b) { throw new Exception('Out of Range');}

       if($s == 0) {
            return sprintf("#%'02x%'02x%'02x", $b*255, $b*255, $b*255);
       }

       $hi = floor($h/60) % 6;
       $f = ($h/60) - floor($h/60);

       $p = 255 * $b * (1-$s);
       $q = 255 * $b * (1 - $f * $s);
       $t = 255 * $b * (1 - (1 - $f) * $s);

       $b = (int)($b * 255);
       switch($hi) {
        case 0:
            return sprintf("#%'02x%'02x%'02x", $b, $t, $p);
            break;
        case 1:
            return sprintf("#%'02x%'02x%'02x", $q, $b, $p);
            break;
        case 2:
            return sprintf("#%'02x%'02x%'02x", $p, $b, $t);
            break;
        case 3:
            return sprintf("#%'02x%'02x%'02x", $p, $q, $b);
            break;
        case 4:
            return sprintf("#%'02x%'02x%'02x", $t, $p, $b);
            break;
        case 5:
            return sprintf("#%'02x%'02x%'02x", $b, $p, $q);
            break;
       }

    }