forked from tillbiskup/dokuwiki-bibtex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
69 lines (59 loc) · 2.04 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* Page behaviours
*
* This class adds various behaviours to the rendered page
*/
dw_bibtex = {
/**
* initialize page behaviours
*/
init: function(){
jQuery('span.bibtex_citekey').mouseover(dw_bibtex.bibtexReferenceDisplay);
},
/**
* Create/get a insitu popup used by the footnotes
*
* @param target - the DOM element at which the popup should be aligned at
* @param popup_id - the ID of the (new) DOM popup
* @return the Popup jQuery object
*/
insituPopup: function(target, popup_id) {
// get or create the popup div
var $bibtexdiv = jQuery('#' + popup_id);
// popup doesn't exist, yet -> create it
if($bibtexdiv.length === 0){
$bibtexdiv = jQuery(document.createElement('div'))
.attr('id', popup_id)
.addClass('insitu-bibtexref JSbibtexref')
.mouseleave(function () {jQuery(this).hide();});
jQuery('.dokuwiki:first').append($bibtexdiv);
}
// position() does not support hidden elements
$bibtexdiv.show().position({
my: 'left top',
at: 'left center',
of: target
}).hide();
return $bibtexdiv;
},
/**
* Display an insitu bibtex reference popup
*
* @author Andreas Gohr <[email protected]>
* @author Chris Smith <[email protected]>
* @author Till Biskup <[email protected]>
*/
bibtexReferenceDisplay: function () {
var content = jQuery(jQuery(this)).html();
if (content === null){
return;
}
// strip the leading content anchors and their comma separators
content = content.replace(/(^.*<span>)+\s*/gi, '');
// prefix ids on any elements with "insitu__" to ensure they remain unique
content = content.replace(/\bid=(['"])([^"']+)\1/gi,'id="insitu__$2');
// now put the content into the wrapper
dw_bibtex.insituPopup(this, 'insitu__bibtex').html(content).show();
}
};
jQuery(dw_bibtex.init);