Tuesday, July 19, 2005

Javascript citations, redux

Following on from yesterday’s experiment: I decided that yes, the automatically-added link citations were cute enough to keep. Not cute enough to turn on by default, though.

So I’ve added a little extra Javascript here to scan each post for autocitable links and, if any are found, to add a link down in the byline to toggle link citations. Give it a go: it’s fun. Unless you have Javascript turned off, in which case you’ll be unobtrusively none the wiser.

Nitty-gritty: function make_autocitation_link in file blogger-tools.js. Pass it two IDs: the ID of the <div> or other container to which you want citations added; the ID of an <span> or other container to which to add the “add citations” link. In my case here, the first is the <div> containing the post body; the second, an empty <span> in the byline.

Possible customisations: the citation_add_link and citation_remove_link variables contain the text for the “add citations” and “remove citations” links. The citation_pre and citation_post variables contain optional text to be added before and after the link.

And some mild tweaking: I excluded image links—links which contain only an image, for example the maps here and here—from autocitation; the results were more ugly than useful. And I’m toying with also excluding links to other pages here: it all starts getting a bit too self-referential, and to be quite honest nobody ever talks about me anyway…