-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
355 lines (316 loc) · 16.1 KB
/
index.html
File metadata and controls
355 lines (316 loc) · 16.1 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
<!DOCTYPE html>
<!-- Version 1.0.2 - Added manual update feature (June 2, 2025) -->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Python Practice - Learn Python Programming</title>
<meta name="description" content="Practice Python programming with interactive exercises for beginners and advanced learners">
<!--<link rel="stylesheet" href="css/enhanced-styles.css?v=1"> Updated to force cache refresh -->
<link rel="stylesheet" href="css/style.css">
<link rel="manifest" href="manifest.json">
<!-- Added auto-update notification system -->
<!-- Updated icon references to use local files instead of CDN -->
<link rel="apple-touch-icon" href="assets/icons/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="152x152" href="assets/icons/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="assets/icons/apple-touch-icon-180x180.png">
<link rel="icon" type="image/png" sizes="32x32" href="assets/icons/icon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="assets/icons/icon-16x16.png">
<link rel="shortcut icon" href="assets/icons/favicon.ico">
<!-- Fixed Google Fonts links with properly encoded ampersands -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Source+Code+Pro:wght@400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<!-- CodeMirror 5 CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/codemirror.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/addon/hint/show-hint.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/addon/lint/lint.min.css">
</head>
<body>
<header>
<h1><i class="fab fa-python"></i> Python Practice</h1>
<div class="auth-buttons">
<button id="login-btn" class="btn-auth" type="button"><i class="fas fa-sign-in-alt"></i> Login</button>
<button id="register-btn" class="btn-auth" type="button"><i class="fas fa-user-plus"></i> Register</button>
<button id="theme-toggle-btn" class="theme-btn" type="button" aria-label="Toggle dark/light mode"><i class="fas fa-moon"></i></button>
</div>
</header>
<div class="tabs">
<div class="tab active" data-tab="classic-editor">
<i class="fas fa-code"></i> Classic Editor
</div>
<div class="tab" data-tab="readme">
<i class="fas fa-book"></i> README
</div>
<div class="tab" data-tab="guide">
<i class="fas fa-map-signs"></i> Guide
</div>
</div>
<!-- Python Engine Status Indicator (hidden from users) -->
<div id="python-engine-status" class="python-engine-status loading" style="display: none;">
<i class="fas fa-spinner fa-spin"></i> <span id="engine-status-text">Initializing Python engine...</span>
<div style="font-size: 0.8em; margin-top: 5px;">
<span id="pyodide-status">Pyodide: On-demand</span>
</div>
</div>
<div class="tab-content active" data-tab-content="classic-editor">
<div class="main-content">
<div class="editor-container">
<div class="editor-toolbar">
<button id="run-btn" class="btn-run" type="button" disabled><i class="fas fa-play"></i> Run Code</button>
<button id="reset-btn" class="btn-reset" type="button"><i class="fas fa-undo"></i> Reset</button>
<button id="clear-output-btn" class="btn-clear" type="button"><i class="fas fa-trash-alt"></i> Clear Output</button>
<button id="editor-theme-toggle-btn" class="btn-theme" type="button"><i class="fas fa-adjust"></i> Toggle Theme</button>
<div id="execution-count" style="display: none; margin-left: 15px; align-self: center;"></div>
</div>
<div class="editor-section">
<div id="editor"></div>
</div>
</div>
<div class="output-container">
<div class="output-header">
<span><i class="fas fa-terminal"></i> Output</span>
<button id="clear-output" class="btn-clear" type="button" aria-label="Clear output"><i class="fas fa-trash-alt"></i></button>
</div>
<div id="output" class="output">🐍 Python engine ready. Libraries like numpy and pandas are available.</div>
</div>
</div>
</div>
<div class="tab-content" data-tab-content="readme">
<div class="readme-content">
<!-- README content will be loaded dynamically -->
<div id="example-buttons"></div>
<pre id="example-code-display"></pre>
</div>
</div>
<div class="tab-content" data-tab-content="guide">
<div class="guide-content" style="padding: 20px;">
<h2>How to Use Python Practice</h2>
<p>Welcome to Python Practice! Here’s a quick guide to get you started:</p>
<ul>
<li><strong>Classic Editor:</strong> Write and run your Python code here. The editor supports syntax highlighting and autocompletion. Please note that it would only work in desktop version due to some limitations.</li>
<li><strong>Run Code:</strong> Click the "Run Code" button to execute your code. The output will appear in the output panel.</li>
<li><strong>README:</strong> This tab contains example code snippets that you can load into the editor by just visiting any tab under README.</li>
<li><strong>Guide:</strong> You're here! This tab provides instructions on how to use the application.</li>
<li><strong>Login/Register:</strong> Create an account to save your code and track your progress.</li>
</ul>
</div>
</div>
<!-- Login Modal -->
<div id="login-modal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>Login</h2>
<button type="button" class="close" aria-label="Close">×</button>
</div>
<div class="modal-body">
<form id="login-form">
<div class="form-group">
<label for="login-username">Username or Email</label>
<input type="text" id="login-username" name="username" required>
</div>
<div class="form-group">
<label for="login-password">Password</label>
<input type="password" id="login-password" name="password" required>
</div>
<div class="form-actions">
<button type="submit">Login</button>
<p>No account? <a href="#" id="show-register">Register here</a></p>
</div>
<div id="login-message" class="form-message"></div>
</form>
</div>
</div>
</div>
<!-- Register Modal -->
<div id="register-modal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>Register</h2>
<button type="button" class="close" aria-label="Close">×</button>
</div>
<div class="modal-body">
<form id="register-form" action="php/register.php" method="POST" onsubmit="return handleRegister(event)">
<div class="form-group">
<label for="register-username">Username</label>
<input type="text" id="register-username" name="username" required minlength="3" maxlength="50">
</div>
<div class="form-group">
<label for="register-email">Email</label>
<input type="email" id="register-email" name="email" required>
</div>
<div class="form-group">
<label for="register-password">Password</label>
<input type="password" id="register-password" name="password" required minlength="6">
</div>
<div class="form-group">
<label for="register-confirm-password">Confirm Password</label>
<input type="password" id="register-confirm-password" name="confirm_password" required minlength="6">
</div>
<div class="form-actions">
<button type="submit">Register</button>
<p>Already have an account? <a href="#" id="show-login">Login here</a></p>
</div>
<div id="register-message" class="form-message"></div>
</form>
</div>
</div>
</div>
<!-- My Codes Modal -->
<div id="my-codes-modal" class="modal">
<div class="modal-content">
<div class="modal-header">
<h2>My Saved Codes</h2>
<button type="button" class="close" aria-label="Close">×</button>
</div>
<div class="modal-body">
<div id="saved-codes-list" class="saved-codes-list">
<!-- Saved codes will be displayed here -->
</div>
</div>
</div>
</div>
<div id="toast" class="toast">Notification message</div>
<!-- CodeMirror and JS files with correct paths -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<!-- CodeMirror 5 JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/mode/python/python.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/addon/hint/show-hint.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/addon/hint/anyword-hint.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/addon/edit/closebrackets.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/addon/edit/matchbrackets.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/addon/comment/comment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/addon/lint/lint.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/addon/fold/foldcode.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/addon/fold/foldgutter.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/addon/fold/brace-fold.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.65.16/addon/fold/indent-fold.min.js"></script>
<!-- New Modular JS Files -->
<script src="js/ui-helpers.js"></script>
<script src="js/theme.js?v=3"></script>
<script src="js/auth.js"></script>
<script src="js/editor.js"></script>
<script src="js/readme.js"></script>
<script src="js/hybrid-python-engine.js"></script>
<script src="js/app-controller.js"></script>
<script>
// Test hybrid engine
function testHybridEngine() {
console.log('=== Hybrid Engine Test ===');
if (typeof window.hybridPythonEngine === 'undefined') {
console.error('❌ Hybrid engine not available');
return;
}
const testCode = 'print("Hello from Hybrid Engine!")';
window.hybridPythonEngine.runPythonCode(testCode, 'output').then(() => {
console.log('✅ Hybrid engine test successful');
}).catch(error => {
console.error('❌ Hybrid engine test failed:', error);
});
}
// Test the specific input + f-string case
function testInputFString() {
console.log('=== Testing Input + F-String Case ===');
if (typeof window.hybridPythonEngine === 'undefined') {
console.error('❌ Hybrid engine not available');
return;
}
const testCode = `name = input("Enter your name: ")
age = int(input("Enter your age: "))
place = input("Enter your place of birth: ")
print(f"Welcome {name}, you are {age} years old and you were born in {place}")`;
console.log('Testing problematic code:', testCode);
window.hybridPythonEngine.runPythonCode(testCode, 'output').then(() => {
console.log('✅ Input + F-string test successful');
}).catch(error => {
console.error('❌ Input + F-string test failed:', error);
});
}
function handleRegister(event) {
event.preventDefault();
const form = event.target;
const formData = new FormData(form);
const data = Object.fromEntries(formData.entries());
// Basic client-side validation
if (data.password !== data.confirm_password) {
document.getElementById('register-message').textContent = 'Passwords do not match';
document.getElementById('register-message').style.display = 'block';
return false;
}
// Send the form data to the server
fetch(form.action, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
const messageEl = document.getElementById('register-message');
messageEl.textContent = data.message;
messageEl.style.display = 'block';
messageEl.className = 'form-message ' + (data.success ? 'success' : 'error');
if (data.success) {
// Clear the form on success
form.reset();
// Optionally close the modal or redirect
setTimeout(() => {
document.getElementById('register-modal').style.display = 'none';
// Show login modal
document.getElementById('login-modal').style.display = 'block';
}, 1500);
}
})
.catch(error => {
console.error('Error:', error);
const messageEl = document.getElementById('register-message');
messageEl.textContent = 'An error occurred. Please try again.';
messageEl.className = 'form-message error';
messageEl.style.display = 'block';
});
return false;
}
</script>
<!-- Simplified jQuery handlers for auth buttons without conflicting event handlers -->
<script>
$(document).ready(function() {
console.log('Setting up visual effects for auth buttons');
// Only add visual effect styling without click handlers
$('#login-btn, #register-btn').css('position', 'relative');
// Use a delegated approach to handle button visual effects without interfering with click events
$(document).on('click', '#login-btn', function() {
$(this).css('background-color', '#ffcc00').delay(300).queue(function() {
$(this).css('background-color', '').dequeue();
});
});
$(document).on('click', '#register-btn', function() {
$(this).css('background-color', '#ffcc00').delay(300).queue(function() {
$(this).css('background-color', '').dequeue();
});
});
// Close buttons for modals - keep these as they don't conflict
$('.modal .close').click(function() {
const $modal = $(this).closest('.modal');
$modal.removeClass('show');
setTimeout(() => {
$modal.hide();
}, 300); // Match the transition time in CSS
});
// Click outside modal to close - keep these as they don't conflict
$('.modal').click(function(e) {
if (e.target === this) {
const $modal = $(this);
$modal.removeClass('show');
setTimeout(() => {
$modal.hide();
}, 300); // Match the transition time in CSS
}
});
});
</script>
</body>
</html>