jQuery in Zotero

40 views
Skip to first unread message

Alf Eaton

unread,
Nov 29, 2007, 12:34:37 PM11/29/07
to zotero-dev
I've been doing some work to allow Zotero translators to use jQuery.

The benefits of this are a) ease of writing translators and b)
portability. The second of these is the most important: ideally
Zotero's translators would run in Firefox, WebKit (which doesn't have
E4X, eg Safari, KHTML) and Rhino (which doesn't have XPath).

Getting this working was helped immensely by the recent posting of a
couple of new builds of Greasemonkey (based on work that's been around
for a while, incidentally) that allow user scripts to import jQuery or
other Javascript libraries.

The jquery.diff patch to Zotero at <http://alf.hubmed.org/zotero/
jquery.diff> loads jquery.js from the chrome folder (if you place the
latest jquery.js in chrome/content/zotero/), sets up a few environment
variables and evals it in the sandbox, so that the $jq function is
available to translators. It also adds one utility function ('unique')
to Zotero.Utilities.

The scrapers.diff patch to scrapers.sql at <http://alf.hubmed.org/
zotero/scrapers.diff> replaces the Amazon translator with a jQuery-
fied version. You'll need to run 'Reset Translators and Styles' from
Zotero's preferences to use it.

I still have a couple of things to work out, like whether it's safe to
set 'document' to the sandboxed, XPCNativeWrapper document so that
jQuery can access it, but otherwise - it works!

Alf Eaton

unread,
Nov 30, 2007, 7:52:18 AM11/30/07
to zotero-dev
On Nov 29, 5:34 pm, Alf Eaton <eaton....@googlemail.com> wrote:
> I've been doing some work to allow Zotero translators to use jQuery.

As an example of how this can be useful, here's the COinS detector
rewritten to use jQuery:

-----

function detectWeb(doc, url) {
var coins = $jq("span.Z3988[@title*='ctx_ver=']", doc); // span
element with class of "Z3988" and title attribute containing
"ctx_ver="
switch(coins.length){
case 0: return false;
case 1: var item = new Zotero.Item;
Zotero.Utilities.parseContextObject($jq(coins[0]).attr("title"),
item); return item.itemType;
default: return "multiple";
}
}

-----

Bruce D'Arcus

unread,
Nov 30, 2007, 9:16:45 AM11/30/07
to zoter...@googlegroups.com
Alf Eaton wrote:
> On Nov 29, 5:34 pm, Alf Eaton <eaton....@googlemail.com> wrote:
>> I've been doing some work to allow Zotero translators to use jQuery.
>
> As an example of how this can be useful, here's the COinS detector
> rewritten to use jQuery:

Just wanted to offer congrats on this work Alf. Would obviously be great
to see a shareable collection of translators that can work both in
different browsers, and on servers.

Nice job!

Bruce

Alf Eaton

unread,
Nov 30, 2007, 12:40:33 PM11/30/07
to zotero-dev
On Nov 30, 2:16 pm, Bruce D'Arcus <bdar...@gmail.com> wrote:

> Would obviously be great to see a shareable collection of translators that can work both in different browsers, and on servers.

Speaking of which, is there any work in progress for moving the
translators out of the database and into Greasemonkey-like user script
files?

Bruce D'Arcus

unread,
Nov 30, 2007, 1:47:29 PM11/30/07
to zoter...@googlegroups.com

This would be nice. It's the same issue when the CSL files were stuck in
the SQL code. It's good to see them now liberated!

Bruce

Daniel Cohen

unread,
Nov 30, 2007, 1:58:01 PM11/30/07
to zoter...@googlegroups.com
>
> Alf Eaton wrote:
>>
>>> Would obviously be great to see a shareable collection of
>>> translators that can work both in different browsers, and on
>>> servers.
>>
>> Speaking of which, is there any work in progress for moving the
>> translators out of the database and into Greasemonkey-like user
>> script files?

>>
> On Nov 30, 2007, at 1:47 PM, Bruce D'Arcus wrote:
> This would be nice. It's the same issue when the CSL files were
> stuck in
> the SQL code. It's good to see them now liberated!
>
> Bruce

Alf,

Like Bruce, I'm incredibly impressed with your work on this.

Since recently launching the CSL repository we're taking a breather on
other repos until we finish up some critical infrastructural work for
the server. But we're planning on doing this soonish--as Bruce notes,
the repo has *really* helped out with the CSL development.

jQuery has a lot to recommend it, e.g., its compactness and
portability. But in terms of standards, XPath has been widely adopted
(including in the latest version of WebKit) and E4X is an ECMA
standard. And--perhaps this is nearsighted--but at the end of the day
Zotero is a Firefox tool and we have committed a lot of resources to
that and for obvious reasons worry a little bit about switching the
translator architecture from using standards with native support in
Firefox to a third-party JS-based library.

But certainly we'll keep on eye on this and hope the translator repo
will be helpful to you and others (and out soon).

Dan

Bruce D'Arcus

unread,
Feb 11, 2008, 9:12:03 AM2/11/08
to zoter...@googlegroups.com
Just a followup to this ...

On Nov 30, 2007 1:58 PM, Daniel Cohen <dco...@gmu.edu> wrote:

...

> jQuery has a lot to recommend it, e.g., its compactness and
> portability. But in terms of standards, XPath has been widely adopted
> (including in the latest version of WebKit) and E4X is an ECMA
> standard. And--perhaps this is nearsighted--but at the end of the day
> Zotero is a Firefox tool and we have committed a lot of resources to
> that and for obvious reasons worry a little bit about switching the
> translator architecture from using standards with native support in
> Firefox to a third-party JS-based library.

This might be relevant:

<http://ejohn.org/blog/xpath-overnight/>

Bruce

Reply all
Reply to author
Forward
0 new messages