-
Notifications
You must be signed in to change notification settings - Fork 1
/
trails.js
108 lines (90 loc) · 3.43 KB
/
trails.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// put this on the web page, and set trail = true
var doc_id = "aata";
var topsection = document.getElementsByTagName('section')[0];
var thefocus = topsection.id;
var recenthistory = '';
var onpage = false;
var timecounter = 0;
var dataurlbase = "https://track.aimath.org/" + doc_id + "/u3au3a?";
dataurlbase = dataurlbase.concat(doc_id).concat("&");
dataurlbase = dataurlbase.concat("per").concat("=").concat(aa_id).concat("&");
dataurlbase = dataurlbase.concat("ut_id").concat("=").concat(ut_id).concat("&");
function timeTracker() {
if (onpage) {
timecounter++;
recenthistory = recenthistory.concat(thefocus).concat('.');
if (timecounter % 10 == 0) {
dataurl = dataurlbase.concat(recenthistory.slice(0, -1)); //trailing "."
$.get(dataurl);
recenthistory = '';
}
}
}
theTimer = setInterval(timeTracker, 1000);
$('body').focusout(function() {
onpage = false;
if (recenthistory != '') {
dataurl = dataurlbase.concat(recenthistory.slice(0, -1)); //trailing "."
$.get(dataurl);
recenthistory = '';
}
timecounter = 0;
});
$('body').focusin(function() {
onpage = true;
});
// the hidden proof knowls have knowl="", which is like the a does not have knowl as an attribute
$('a').on('click', function() {
console.log("clicked on an a", this);
if(this.classList.contains('active')) {
thefocus = this.closest('section').id;
} else if (this.hasAttribute("knowl")) {
if($(this).attr("id")) {
thefocus = this.id
}
// ***** maybe this case is obsolete?
else if (kid = this.getAttribute('knowl-id')) {
thefocus = kid
}
else if (kid = this.getAttribute('refid')) {
// ***** check. want hk-proof-80 --> proof-80
// ***** also check that closing it goes back to the correct focus.
// ***** (currenty, closing an know return focus to the enclosing section. Is that always correct?)
thefocus = kid.slice(3)
}
// ***** check on the knowl="" case, and probably rearrange these options
else if (kid = this.getAttribute('knowl')) {
full_kid = kid
trimmed_kid = full_kid.replace(/.*\//, "");
trimmed_kid = trimmed_kid.replace(/\..*/, "");
// ****** add intormation about parents, because this might not be the
// only instance of this knowl on that page
closest_p = this.closest('[id]');
console.log("was clicked", this);
console.log("closest('p')", closest_p);
parent_pid = closest_p.id;
thefocus = parent_pid + "_" + trimmed_kid
}
else {
thefocus = 'Unknown'
}
} else if ($(this).attr("id")) {
// ***** shouldn't this come earlier, and not recheck for id inside of knowl?
thefocus = this.id;
};
// ***** is it good that we put "click-"+section when closing a knowl
recenthistory = recenthistory.concat('click-').concat(thefocus).concat('.');
});
setTimeout(function(){
$('body').attr('tabindex',-1).focus()},
100);
// instead of waiting 2 seconds, it would be better to trigger on sage cell completing setup
setTimeout(function(){
var allbuttons = document.getElementsByTagName('button');
$('button.sagecell_evalButton').on('click', function() {
article_id = this.closest('div.sagecell-sage').id;
thefocus = article_id;
recenthistory = recenthistory.concat('click-').concat(article_id).concat('.');
});
},
2000);