Browse Source

added veryCompactAuthors and very short author+title as reference abbr. also added javascript highlighting of clicked citation

pull/2/head
Matthieu Guillaumin 13 years ago
parent
commit
352886011b
  1. 32
      bibtexbrowser.bibliography.php
  2. 10
      bibtexbrowser.php

32
bibtexbrowser.bibliography.php

@ -13,9 +13,9 @@ $DB = load_DB();
$citations = array();
// Function to create a link for a bibtex entry
function linkify($a) {
if ( empty($a) ) { return "<b>?</b>"; }
return '<a href="#' . $a . '">' . $a . '</a>' ;
function linkify($txt,$a) {
if ( empty($a) ) { return '<b><abbr title="'.$txt.'">?</abbr></b>'; }
return '<a href="#' . $a . '" class="bibreflink"><abbr title="'.$txt.'">' . $a . '</abbr></a>' ;
}
// Create citations from bibtex entries. One argument per bibtex entry.
@ -30,7 +30,8 @@ function cite() {
$bib = $DB->getEntryByKey($entry);
if ( empty($bib) ) {
$ref = array(); // empty ref for detection by linkify, while getting last with sort()
$refs[] = $ref;
$txt = "Unknown key &#171;$entry&#187;";
$refs[$txt] = $ref;
continue;
}
if (ABBRV_TYPE != 'index') {
@ -44,10 +45,14 @@ function cite() {
$citations[$entry] = $ref ;
}
}
$refs[] = $ref;
$txt = $bib->getVeryCompactedAuthors() . ", &#171;" . $bib->getTitle() . "&#187;, " . $bib->getYear() ;
$refs[$txt] = $ref;
}
asort( $refs );
$links = array();
foreach ( $refs as $txt => $ref ) {
$links[] = linkify($txt,$ref);
}
sort( $refs );
$links = array_map( 'linkify', $refs );
echo "[" . implode(",",$links) . "]" ;
}
@ -61,6 +66,19 @@ function make_bibliography() {
$_GET['keys'] = json_encode(array_flip($citations));
//print_r($_GET);
include( 'bibtexbrowser.php' );
?>
<script type="text/javascript" ><!--
updateCitation = function () { //detect hash change
var hash = window.location.hash.slice(1); //hash to string
$('.bibline').each(function() {$(this).removeClass("bibline-active");});
if (hash) {
$('[name='+hash+']').parents('.bibline').each(function() {$(this).addClass("bibline-active");});
}
};
$(window).bind('hashchange',updateCitation);
updateCitation();
--></script>
<?php
}
?>

10
bibtexbrowser.php

@ -1252,6 +1252,16 @@ class BibEntry {
return $this->formatAuthor($authors[0]) . $etal;
}
/**
* Returns a compacted string form of author names by throwing away
* all author names except for the first one and appending ", et al."
*/
function getVeryCompactedAuthors(){
$authors = $this->getRawAuthors();
$etal = count($authors) > 1 ? ', et al.' : '';
list($firstname, $lastname) = splitFullName($authors[0]);
return $lastname . $etal;
}
/** add the link to the homepage if it is defined in a string
* e.g. @string{hp_MartinMonperrus="http://www.monperrus.net/martin"}

Loading…
Cancel
Save