Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagemath.github.io
Path: blob/master/calctut/calctut-res/calctut.js
2467 views
1
var calctut = {
2
pages: ["index.html", "limits.html", "continuity.html", "onesided.html", "inflimits.html", "slantasymp.html", "tangent.html", "derivative.html", "differentiability.html", "diffrules.html"],
3
titles: ["Introduction", "Limits", "Continuity", "One-Sided Limits", "Limits at Infinity", "Supplement: Slant Asymptotes", "Tangent Lines", "The Definition of the Derivative", "Differentiability", "Differentiation Rules"],
4
id: null,
5
index: -1,
6
start: -1,
7
end: -1,
8
lines: false,
9
fsize: 0,
10
twoyears: null,
11
redir: null,
12
13
initCalc: function() {
14
calctut.pages[-1] = "review.html";
15
calctut.titles[-1] = "Review";
16
calctut.id = [];
17
for(var i = 0; i < calctut.pages.length; i ++) {
18
calctut.id[i] = calctut.pages[i].substring(0, calctut.pages[i].lastIndexOf("."));
19
}
20
if(calctut.index == -1) {
21
calctut.refreshIndex();
22
}
23
calctut.updateTitle();
24
calctut.twoyears = new Date();
25
calctut.twoyears.setFullYear(calctut.twoyears.getFullYear()+2);
26
},
27
28
refreshIndex: function() {
29
var curpage = location.href.substring(location.href.lastIndexOf("\/")+1);
30
for(var i = 0; i < calctut.pages.length; i ++) {
31
if(curpage == calctut.pages[i]) {
32
calctut.index = i;
33
}
34
}
35
},
36
37
updateTitle: function() {
38
document.title = "Sage Calculus Tutorial - "+calctut.titles[calctut.index];
39
},
40
41
pageLoad: function() {
42
calctut.checkCookie();
43
calctut.writeCookieLastVisited();
44
calctut.updateLineNumbers();
45
if(calctut.fsize && calctut.fsize !== 0) {
46
var sign = Math.abs(calctut.fsize)/calctut.fsize;
47
for(var i = 0; i < Math.abs(calctut.fsize); i ++) {
48
changeFontSize(sign, sign*2, false);
49
}
50
}
51
calctut.goToCurrentNav();
52
calctut.hideExplanations();
53
calctut.populateDropdown();
54
},
55
56
checkCookie: function() {
57
var namestart, nameend;
58
var arr = ["lines", "fsize"];
59
var value;
60
for(var i = 0; i < arr.length; i ++) {
61
var index = document.cookie.indexOf(arr[i]);
62
if(index != -1) {
63
namestart = (document.cookie.indexOf("=", index) + 1);
64
nameend = document.cookie.indexOf(";", index);
65
if(nameend == -1) {
66
nameend = document.cookie.length;
67
}
68
value = document.cookie.substring(namestart, nameend);
69
switch (i) {
70
case 0:
71
calctut.lines = value == "true";
72
break;
73
case 1:
74
calctut.fsize = value;
75
break;
76
default:
77
break;
78
}
79
}
80
}
81
},
82
83
writeCookieLines: function() {
84
document.cookie = "lines="+calctut.lines+"; expires="+calctut.twoyears.toString();
85
},
86
87
writeCookieFSize: function() {
88
if(calctut.fsize > 5) {
89
calctut.fsize = 5;
90
} else if(calctut.fsize < -2) {
91
calctut.fsize = -2;
92
}
93
document.cookie = "fsize="+calctut.fsize+"; expires="+calctut.twoyears.toString();
94
},
95
96
writeCookieLastVisited: function() {
97
document.cookie = "lastvisited="+calctut.pages[calctut.index]+"; expires="+calctut.twoyears.toString();
98
},
99
100
goToCurrentNav: function() {
101
return;
102
/*
103
var pos = calctut.end-calctut.index;
104
if(calctut.index < 0) {
105
pos = 1;
106
}
107
navbarjs.initSlide(pos, true);
108
navbarjs.currentTab = pos;
109
*/
110
},
111
112
hideExplanations: function() {
113
for(var i = 1; true; i ++) {
114
d = document.getElementById("explain"+i);
115
if(!d) {
116
break;
117
}
118
d.style.display = 'none';
119
}
120
},
121
122
populateDropdown: function() {
123
var select = document.getElementById("tutgoto");
124
var x = new Option();
125
x.text = "Go to...";
126
x.value = "-1";
127
var y = new Option();
128
y.text = "Review";
129
y.value = "-1";
130
//Even though select.add(x, null); would be standards-compliant, IE doesn't support it. Hm...
131
//One more reason to use Firefox, I guess.
132
try {
133
select.add(x, null);
134
select.add(y, null);
135
} catch(err) {
136
select.add(x);
137
select.add(y);
138
}
139
for(var i = 0; i < calctut.pages.length; i ++) {
140
var opt = new Option();
141
if(i > 0) {
142
var num = i+"";
143
if(num.length == 1)
144
num = "0"+num;
145
opt.text = num+"-"+calctut.titles[i];
146
} else {
147
opt.text = calctut.titles[i];
148
}
149
opt.value = ""+i;
150
try {
151
select.add(opt, null);
152
} catch(err) {
153
select.add(opt);
154
}
155
}
156
select.selectedIndex = calctut.index+2;
157
},
158
159
toggleLineNumbers: function() {
160
calctut.lines = !calctut.lines;
161
calctut.writeCookieLines();
162
calctut.updateLineNumbers();
163
},
164
165
fontPlus: function() {
166
calctut.fsize ++;
167
calctut.writeCookieFSize();
168
},
169
170
fontMinus: function() {
171
calctut.fsize --;
172
calctut.writeCookieFSize();
173
},
174
175
updateLineNumbers: function() {
176
var pres = document.getElementsByTagName('pre');
177
var tutcodes = new Array();
178
for(var i = 0; i < pres.length; i ++) {
179
if(pres[i].className == 'tutcode')
180
tutcodes.push(pres[i]);
181
}
182
for(var i = 0; i < tutcodes.length; i ++) {
183
var s = tutcodes[i].innerHTML.split('\n');
184
var html = '';
185
for(var a = 0; a < s.length; a ++) {
186
if(s[a] == '' && a+1 == s.length) {
187
break;
188
}
189
if(calctut.lines) {
190
s[a] = (a+1)+') '+s[a];
191
} else if(s[a].indexOf(")") == (a+1).toString().length) {
192
s[a] = s[a].substring((a+1).toString().length+2);
193
} else {
194
i = -1;
195
break;
196
}
197
html += s[a]+'\r\n';
198
}
199
if(i == -1) {
200
break;
201
}
202
tutcodes[i].innerHTML = html;
203
}
204
},
205
206
dropdownSelect: function () {
207
var select = document.getElementById("tutgoto");
208
if(select.selectedIndex > 0) {
209
document.location.href = calctut.pages[select.selectedIndex-2];
210
}
211
},
212
213
generateNav: function() {
214
if(calctut.id == null) {
215
calctut.initCalc();
216
}
217
calctut.start = calctut.index;
218
calctut.end = calctut.index;
219
if(calctut.index+1 < calctut.pages.length) {
220
document.write("<li id=\""+calctut.id[calctut.index+1]+"\"><a href=\""+calctut.pages[calctut.index+1]+"\" title=\"\">Next ("+calctut.titles[calctut.index+1]+")<\/a><\/li>");
221
calctut.end = calctut.index+1;
222
}
223
if(calctut.index >= -1)
224
document.write("<li id=\""+calctut.id[calctut.index]+"\"><a href=\""+calctut.pages[calctut.index]+"\" title=\"\">"+calctut.titles[calctut.index]+"<\/a><\/li>");
225
if(calctut.index >= 0) {
226
document.write("<li id=\""+calctut.id[calctut.index-1]+"\"><a href=\""+calctut.pages[calctut.index-1]+"\" title=\"\">Previous ("+calctut.titles[calctut.index-1]+")<\/a><\/li>");
227
calctut.start = calctut.index-1;
228
}
229
},
230
231
toggle: function(no) {
232
var disp = document.getElementById("explain"+no).style.display == 'none';
233
if(disp) {
234
document.getElementById("explain"+no).style.display = '';
235
} else {
236
document.getElementById("explain"+no).style.display = 'none';
237
}
238
},
239
240
ansToggle: function(no, text) {
241
var ans = document.getElementById("answer"+no);
242
if(ans.innerHTML == "Toggle answer") {
243
ans.innerHTML = text;
244
}
245
else {
246
ans.innerHTML = "Toggle answer";
247
}
248
},
249
250
writePreviousPage: function() {
251
if(calctut.index-1 >= 0) {
252
document.write("<td><a class=\"noresize\" href=\""+calctut.pages[calctut.index-1]+"\">Previous ("+calctut.titles[calctut.index-1]+")<\/a><\/td>");
253
} else {
254
document.write("<td>&nbsp;<\/td>");
255
}
256
},
257
258
writeNextPage: function() {
259
if(calctut.index+1 < calctut.pages.length) {
260
document.write("<td><a class=\"noresize\" href=\""+calctut.pages[calctut.index+1]+"\">Next ("+calctut.titles[calctut.index+1]+")<\/a><\/td>");
261
} else {
262
document.write("<td>&nbsp;<\/td>");
263
}
264
},
265
266
doLastVisited: function() {
267
calctut.initCalc();
268
var namestart, nameend, address, title = "";
269
var index = document.cookie.indexOf("lastvisited");
270
if(index != -1) {
271
namestart = (document.cookie.indexOf("=", index) + 1);
272
nameend = document.cookie.indexOf(";", index);
273
if(nameend == -1)
274
nameend = document.cookie.length;
275
address = document.cookie.substring(namestart, nameend);
276
} else {
277
address = calctut.pages[0];
278
}
279
for(var i = -1; i < calctut.pages.length; i ++) {
280
if(calctut.pages[i] == address) {
281
title = calctut.titles[i];
282
}
283
}
284
document.write("<br /><br />Redirecting to <em>"+title+"<\/em>");
285
calctut.redir = address;
286
},
287
288
redirect: function() {
289
document.location.href = calctut.redir;
290
}
291
};
292
293
294