diff --git a/Repositories/otago_eprints3/otago_eprints/cfg/cfg.d/eprint_render.pl b/Repositories/otago_eprints3/otago_eprints/cfg/cfg.d/eprint_render.pl index 5eb7ba6..f5b29a2 100755 --- a/Repositories/otago_eprints3/otago_eprints/cfg/cfg.d/eprint_render.pl +++ b/Repositories/otago_eprints3/otago_eprints/cfg/cfg.d/eprint_render.pl @@ -109,25 +109,34 @@ # Strip the front off the URL to get just the document path. my $doc_url = $doc->get_url; $doc_url =~ m|^http://[^/]+(/.+)$|; - my $docpath = $1; + my $javascript = "javascript:urchinTracker( '$1' );"; + + my $the_node; # NJS 2008-07-10 # Find the first element in the DocumentFragment and add the - # onclick attribute to it. Note that the DOM documentation says - # the NodeList is indexed from 0, but item(0) gives the wrong - # element (?!?!). + # onclick attribute to it. # # Need to check if it's defined, in case render_icon_link returns # nothing (probably because of document security restrictions). - if ( defined ( $rendered_icon->getElementsByTagName( 'a' )->item( 1 ) ) ) + # + # NJS 2008-07-15: Added test for GDOME. GDOME doesn't have + # the getElementsByTagName method, and XML::DOM and XML::LibXML + # don't have the findnodes method. D'oh! + # DOM 2 + if ( $EPrints::SystemSettings::conf->{enable_gdome} ) { - $rendered_icon->getElementsByTagName( 'a' )->item( 1 )->setAttribute( - 'onclick', - "javascript:urchinTracker( '" . - $docpath . - "' );" - ); + my @nodes = $rendered_icon->findnodes( './/a' ); + $the_node = $nodes[0]; } + else + # DOM 1 + # Note that the DOM 1 documentation says the NodeList is indexed + # from 0, but item(0) gives the wrong element (?!?!). + { + $the_node = $rendered_icon->getElementsByTagName( 'a' )->item( 1 ); + } + $the_node->setAttribute( 'onclick', $javascript ) if ( defined ( $the_node ) ); $doctd->appendChild( $rendered_icon ); ## END NJS 2008-07-10 @@ -150,15 +159,18 @@ # # Need to check if it's defined, in case render_icon_link returns # nothing (probably because of document security restrictions). - if ( defined ( $rendered_cite->getElementsByTagName( 'a' )->item( 1 ) ) ) + # DOM 2 + if ( $EPrints::SystemSettings::conf->{enable_gdome} ) { - $rendered_cite->getElementsByTagName( 'a' )->item( 1 )->setAttribute( - 'onclick', - "javascript:urchinTracker( '" . - $docpath . - "' );" - ); + my @nodes = $rendered_cite->findnodes( './/a' ); + $the_node = $nodes[0]; } + else + # DOM 1 + { + $the_node = $rendered_cite->getElementsByTagName( 'a' )->item( 1 ); + } + $the_node->setAttribute( 'onclick', $javascript ) if ( defined ( $the_node ) ); $doctd->appendChild( $rendered_cite ); ## END NJS 2007-07-30