-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
199 lines (167 loc) · 7.66 KB
/
test.php
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html>
<html lang="ru" class="h-100">
<head>
<title>Тест</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.3.1/dist/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
#card_cont {
min-height: 300px;
transition: transform 0.5s;
}
.front {
transform: rotateY(0deg);
}
.back {
transform: rotateY(180deg);
}
.flipped {
transform: rotateY(180deg);
}
</style>
</head>
<body class="bg-light d-flex flex-column h-100">
<?php include ('inc/header.php')?>
<div class="container">
<h2 class="text-center mb-xl-5" id="cardsName"></h2>
<div id="cards"></div>
</div>
<!-- Подключение модального окна -->
<div class="modal fade" id="explanationModal" tabindex="-1" role="dialog" aria-labelledby="explanationModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="explanationModalLabel">Пояснение</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<h2>Пояснение</h2>
<div id="explanationText"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть</button>
</div>
</div>
</div>
</div>
<?php include ('inc/footer.php')?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<script>
let url = window.location.href;
let id = url.split('/').pop();
$.ajax({
url: '/collections/get_cards/' + id,
type: 'post',
dataType: 'json',
success: function(data) {
// Обработка полученных данных
let currentCardIndex = 0;
let cards = data;
let cardsName = cards[0].id;
let cardCount = cards.length;
let cardsNameContainer = $('#cardsName');
let cardContainer = $('#cards');
let explanationContainer = $('#explanationText');
let cardTemplate = '' +
'<div class="row mb-3">' +
'<div class="btn-group justify-content-center">' +
'<a href="/collections/training/" class="btn btn-outline-primary col-1">Тренажер</a>' +
'<button type="button" class="btn btn-outline-primary exp-btn col-1" data-toggle="modal" data-target="#explanationModal">Пояснение</button>' +
'<a href="/collections/" class="btn btn-outline-primary col-1">Закончить</a>' +
'</div>' +
'</div>' +
'<div class="row">' +
'<div class="card-group justify-content-center">' +
'<div class="card btn col-1 border-right-0 border-primary justify-content-center prev-card">←</div>' +
'<div class="card col-6 border-right-0 border-primary align-items-center justify-content-center" id="card_cont">' +
'<div class="front">' +
'<h2>{formula}</h2>' +
'</div>' +
'<div class="back visually-hidden">' +
'<h3>{description}</h3>' +
'</div>' +
'</div>' +
'<div class="card btn col-1 border-primary justify-content-center next-card">→</div>' +
'</div>' +
'</div>'
;
let explanationTemplate = '<p>{explanationText}</p>';
let cardsNameTemplate = '<p>'+cardsName+'</p>';
cardsNameContainer.html(cardsNameTemplate);
function showCard(index) {
let card = cards[index];
let formula = card.formula;
let description = card.description;
let nav = '<ul class="pagination justify-content-center mt-3">';
for (let i = 0; i < cardCount; i++) {
nav += '<li class="page-item' + (i === currentCardIndex? ' active' : '') + '"><a class="page-link" href="#" data-index="' + i + '">' + (i+1) + '</a></li>';
}
nav += '</ul>';
let html = cardTemplate.replace('{formula}', formula).replace('{description}', description).replace('{CardIndex}', index+1).replace('{CardCount}', cards.length);
cardContainer.html(html);
cardContainer.append(nav);
let card_class = document.querySelector('#card_cont');
let front = document.querySelector('.front');
let back = document.querySelector('.back');
cardContainer.on('click', '.card', function() {
card_class.classList.toggle('flipped');
front.classList.toggle('visually-hidden');
back.classList.toggle('visually-hidden');
});
// Отображение формулы в нужном виде
MathJax.Hub.Config({
showMathMenu: false,
tex2jax: {
inlineMath: [ ['$','$'], ['\\(','\\)'] ]
}
});
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
}
function showPrevCard() {
currentCardIndex--;
if (currentCardIndex < 0) {
currentCardIndex = cardCount - 1;
}
showCard(currentCardIndex);
}
function showNextCard() {
currentCardIndex++;
if (currentCardIndex >= cardCount) {
currentCardIndex = 0;
}
showCard(currentCardIndex);
}
function prepareExplanation(index){
let card = cards[index];
let explanation = card.explanation;
let html = explanationTemplate.replace('{explanationText}', explanation);
explanationContainer.html(html);
}
function showExplanation(){
prepareExplanation(currentCardIndex);
}
showCard(currentCardIndex);
cardContainer.on('click', '.page-link', function(event) {
event.preventDefault();
let index = $(this).data('index');
currentCardIndex = index;
showCard(index);
});
cardContainer.on('click', '.prev-card', showPrevCard);
cardContainer.on('click', '.next-card', showNextCard);
cardContainer.on('click', '.exp-btn', showExplanation)
},
error: function(xhr, status, error) {
// Вывод ошибки в консоль
console.log('Error:', error);
}
});
</script>
</body>
</html>