-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathpldoc.js
83 lines (73 loc) · 1.83 KB
/
pldoc.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* This file is part of the SWI-Prolog PlDoc package for online
documentation browsing. It defines JavaScript to issue HTTP requests
on the Prolog server that do not create a new page and handling
footnotes.
Author: Jan Wielemaker & Michiel Hildebrand
Copying: Public domain
*/
function HTTPrequest(url)
{ $.get(url,
{
});
}
function selectAndCopy(el, clean) {
let text = el.innerText;
if ( clean )
text = text.replace(/[-+?@:]/g, "");
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(el);
selection.removeAllRanges();
selection.addRange(range);
navigator.clipboard.writeText(text);
}
function selectAndCopyPred(ev) {
const el = ev.target;
if ( el.tagName == "VAR" )
selectAndCopy(el.closest("a"), true)
else
selectAndCopy(el, false)
}
function copyCode() {
$("code.copy").click(function(ev) {
selectAndCopy(ev.target)
});
}
function copyMode() {
$("dt.pubdef a, multidef a").each(function() {
const el = $(this);
if ( !el.hasClass("source") ) {
el.addClass("copy")
.click(selectAndCopyPred);
}
});
}
function setupFootnotes() {
const footnoteactivator = $('.fn');
footnoteactivator.mouseenter(function() {
window.clearTimeout(this.footnoteid);
var fn = $(this).find('span.fn-text');
if ( fn ) {
fn.removeClass('fn-text');
fn.addClass('fnp');
}
$(this).find('span.fnp').show(100);
});
footnoteactivator.mouseleave(function() {
const t = $(this).find('span.fnp');
if(this.footnoteid !== null)
{ window.clearTimeout(this.footnoteid);
}
this.footnoteid = window.setTimeout(
function() {
t.hide(100);
}, 2000);
});
}
/* Improve footnote interaction. Contributed by Anne Ogborn.
*/
$(function(){
copyCode();
copyMode();
setupFootnotes();
});