forked from Vazkii/br101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbr101.js
80 lines (67 loc) · 1.55 KB
/
br101.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
const min = 0;
const max = 5;
var current = 0;
var openExplanation = -1;
var animationsEnabled = true;
$('.btn').click(function() {
if(!animationsEnabled)
return;
var next = $(this).attr('id') == 'btn-next';
if(next ? (current == max) : (current == min))
return;
animationsEnabled = false;
$('#inst' + current).fadeOut(function() {
current += (next ? 1 : -1);
$('#step-counter').fadeOut(150, function() {
$(this).text(current);
$(this).fadeIn(150);
});
$('#inst' + current).fadeIn(function() {
animationsEnabled = true;
});
});
});
$('.why').click(function() {
if(!animationsEnabled)
return;
var id = $(this).attr('id').substring(3);
var div = $('#why-expl' + id);
var lastOpen = openExplanation;
openExplanation = id;
if(lastOpen != -1) {
var lastOpenDiv = $('#why-expl' + lastOpen);
if(lastOpenDiv.attr('id') == div.attr('id')) {
closeDiv(div);
openExplanation = -1;
return;
}
closeDiv(lastOpenDiv, function() {
openDiv(div);
});
} else openDiv(div);
});
function openDiv(div) {
animationsEnabled = false;
var height = div.css('height');
div.css('height', '0px');
div.css('display', 'inline');
div.animate({ height: height }, function() {
div.fadeIn(function() {
animationsEnabled = true;
});
});
}
function closeDiv(div, func) {
animationsEnabled = false;
var height = div.css('height');
var height = div.css('height');
div.animate({ height: '0px' }, function() {
div.css({
display: 'none',
height: height,
});
animationsEnabled = true;
});
if(func != null)
func();
}