Wiki‎ > ‎

Quickdict


Purpose

QuickDict allows you to select text on the page of Philologic results, press a key on the keyboard ("D" by default) and perform a dictionary lookup.


Parts


philosubs

There is a function in philosubs, quickdicjs, that generates the code that is placed in the header of pages that are generated by Philo. This code does a couple things... it reads in the quickdict.js file from the lib directory of the installation, prints that out to the page for the browser to interpret. It also prints a little blurb telling you how to use it.


quickdict.js

This javascript file gets installed into the lib directory by default. You could include this in the normal manner with a script tag by copying it into your webspace, or just let philosubs take care of that by printing it in the HTML it generates.


External Resources

Which dictionary you want to link to is up to you. We provide 4 settings by default:

# Options: 1 = ARTFL one look dictionary function with morphological
# package. Obviously for French.
# 2 = Oxford English Dictionary.
# 3 = ARTFL Websters Dictionary
# 4 = onelook.com

You can easily set up your own resource by adding something like:

$dictURL = "http://yourhost.edu/cgi-bin/dictionary.cgi?word=";

If you are using POST, it won't work though. You could come up with some JS to submit using POST however.

Keep in mind that OED ain't free, so if you aren't a subscriber, that one won't work for you.


philo-db.cfg

Simply set $LINKDICT in philo-dg.cfg in the lib directory of your install to the number that corresponds with the resource you want to use.


Issues


dictOn not set throws js error

I amended this bit in philosubs:

                if ($LINKDICT) {
$navin =~ s/<body(.*?)>/<body\1 onkeypress="if \(dictOn\) checkKeyPressed\(event\);">/gi;
}

Previously, the subsitution was happening without checking $LINKDICT, which was bad because if there is no dictionary set, the dictOn javascript varaible does not get set, and there is an error when checking it. Now, it only gets subbed in if we are actually using the dictionary and the errors should go away.


Hacks


Conditionalizing the use of the QuickDict

You may not wish to display the dictionary use message and have the dictionary lookup function on every page on your database.... particularly, some of the results pages like bibliographic searches may not include a lot of interesting context that makes dictionary lookups appropriate. Therefore, you might want to check to see what the user is looking at before giving them the dictionary option.

For the Balzac database, we added the following code to quickdicjs:

sub quickdicjs {
local($output);
$dicopt = $_[0];

# For Balzac, we only want the pages that go through getobject or contextualize to use
# the dictionary

$myscript = $ENV{"SCRIPT_NAME"};

if (! ($myscript =~ /getobject\.pl$/ || $myscript =~ /contextualize\.pl/)) {
return;
}

Simple, but it does the trick. You could obviously add other conditions as you see fit. This could obviously be expanded to be a configurable option for which kinds of pages you want to use the QuickDict on.

Comments