ProCreations commited on
Commit
68b5c20
·
verified ·
1 Parent(s): a348bb0

Complete walkthrough JavaScript file and fix black page issue

Browse files
Files changed (1) hide show
  1. walkthrough-enhancement.js +380 -1
walkthrough-enhancement.js CHANGED
@@ -175,4 +175,383 @@ const enhancedTutorials = {
175
  element: '#taskOutput',
176
  position: 'top',
177
  duration: 10000,
178
- explanation: 'Linear separability means a simple
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  element: '#taskOutput',
176
  position: 'top',
177
  duration: 10000,
178
+ explanation: 'Linear separability means a simple perceptron (single layer) can solve this problem.'
179
+ },
180
+ {
181
+ title: 'OR Gate - At Least One Must Be True',
182
+ content: 'OR outputs 1 when at least one input is 1. Like "I\'ll be happy if I have coffee OR chocolate." Also linearly separable, so it learns quickly. Watch how the network adjusts to recognize this different pattern!',
183
+ element: '#taskOutput',
184
+ position: 'top',
185
+ duration: 8000,
186
+ explanation: 'OR and AND gates have different decision boundaries but both are linearly separable.'
187
+ },
188
+ {
189
+ title: 'XOR Gate - The Challenge',
190
+ content: 'XOR (exclusive OR) outputs 1 when inputs are different. This is NOT linearly separable! You can\'t draw a single straight line to separate the patterns. This is why we need multiple layers - hidden layers create complex decision boundaries.',
191
+ element: '#taskOutput',
192
+ position: 'top',
193
+ duration: 12000,
194
+ explanation: 'XOR was historically important because it proved that multi-layer networks were necessary for complex problems.'
195
+ },
196
+ {
197
+ title: 'Why Multiple Layers Matter',
198
+ content: 'Hidden layers transform the input space, making non-linear problems solvable. The first hidden layer might separate some patterns, the second layer combines those patterns in new ways. Each layer adds expressive power!',
199
+ element: '#networkCanvas',
200
+ position: 'bottom',
201
+ duration: 10000,
202
+ explanation: 'Universal approximation theorem: neural networks with enough hidden units can approximate any continuous function.'
203
+ }
204
+ ]
205
+ }
206
+ };
207
+
208
+ // Walkthrough state management
209
+ let walkthroughState = {
210
+ active: false,
211
+ currentTutorial: null,
212
+ currentStep: 0,
213
+ autoPlay: false,
214
+ speed: 'normal'
215
+ };
216
+
217
+ // DOM elements for walkthrough
218
+ const walkthroughElements = {
219
+ overlay: null,
220
+ highlight: null,
221
+ popup: null,
222
+ progress: null,
223
+ indicator: null
224
+ };
225
+
226
+ // Initialize walkthrough elements
227
+ function initializeWalkthrough() {
228
+ // Get DOM elements
229
+ walkthroughElements.overlay = document.getElementById('walkthroughOverlay');
230
+ walkthroughElements.highlight = document.getElementById('walkthroughHighlight');
231
+ walkthroughElements.popup = document.getElementById('walkthroughPopup');
232
+ walkthroughElements.progress = document.getElementById('walkthroughProgress');
233
+ walkthroughElements.indicator = document.getElementById('walkthroughIndicator');
234
+
235
+ // Set up event listeners
236
+ setupWalkthroughEventListeners();
237
+ }
238
+
239
+ // Setup event listeners for walkthrough
240
+ function setupWalkthroughEventListeners() {
241
+ // Previous button
242
+ const prevBtn = document.getElementById('walkthroughPrev');
243
+ if (prevBtn) {
244
+ prevBtn.addEventListener('click', () => {
245
+ if (walkthroughState.currentStep > 0) {
246
+ walkthroughState.currentStep--;
247
+ updateWalkthroughStep();
248
+ }
249
+ });
250
+ }
251
+
252
+ // Next button
253
+ const nextBtn = document.getElementById('walkthroughNext');
254
+ if (nextBtn) {
255
+ nextBtn.addEventListener('click', () => {
256
+ const tutorial = enhancedTutorials[walkthroughState.currentTutorial];
257
+ if (walkthroughState.currentStep < tutorial.steps.length - 1) {
258
+ walkthroughState.currentStep++;
259
+ updateWalkthroughStep();
260
+ } else {
261
+ endWalkthrough();
262
+ }
263
+ });
264
+ }
265
+
266
+ // Skip/Exit button
267
+ const skipBtn = document.getElementById('walkthroughSkip');
268
+ if (skipBtn) {
269
+ skipBtn.addEventListener('click', endWalkthrough);
270
+ }
271
+
272
+ // Overlay click to exit
273
+ if (walkthroughElements.overlay) {
274
+ walkthroughElements.overlay.addEventListener('click', (e) => {
275
+ if (e.target === walkthroughElements.overlay) {
276
+ endWalkthrough();
277
+ }
278
+ });
279
+ }
280
+
281
+ // Keyboard navigation
282
+ document.addEventListener('keydown', (e) => {
283
+ if (!walkthroughState.active) return;
284
+
285
+ switch(e.key) {
286
+ case 'ArrowLeft':
287
+ e.preventDefault();
288
+ if (walkthroughState.currentStep > 0) {
289
+ walkthroughState.currentStep--;
290
+ updateWalkthroughStep();
291
+ }
292
+ break;
293
+ case 'ArrowRight':
294
+ e.preventDefault();
295
+ const tutorial = enhancedTutorials[walkthroughState.currentTutorial];
296
+ if (walkthroughState.currentStep < tutorial.steps.length - 1) {
297
+ walkthroughState.currentStep++;
298
+ updateWalkthroughStep();
299
+ } else {
300
+ endWalkthrough();
301
+ }
302
+ break;
303
+ case 'Escape':
304
+ e.preventDefault();
305
+ endWalkthrough();
306
+ break;
307
+ }
308
+ });
309
+ }
310
+
311
+ // Start a specific walkthrough tutorial
312
+ function startWalkthrough(tutorialId) {
313
+ console.log('Starting walkthrough:', tutorialId);
314
+
315
+ // Check if tutorial exists
316
+ if (!enhancedTutorials[tutorialId]) {
317
+ console.error('Tutorial not found:', tutorialId);
318
+ return;
319
+ }
320
+
321
+ // Start with AND gate for logic tutorial
322
+ if (tutorialId === 'logic') {
323
+ selectTask('and'); // This should trigger the AND gate task
324
+ setTimeout(() => {
325
+ startWalkthroughOnTask(tutorialId);
326
+ }, 100);
327
+ } else {
328
+ startWalkthroughOnTask(tutorialId);
329
+ }
330
+ }
331
+
332
+ // Start walkthrough on current task
333
+ function startWalkthroughOnTask(tutorialId) {
334
+ walkthroughState.active = true;
335
+ walkthroughState.currentTutorial = tutorialId;
336
+ walkthroughState.currentStep = 0;
337
+
338
+ // Show overlay and indicator
339
+ if (walkthroughElements.overlay) {
340
+ walkthroughElements.overlay.style.display = 'block';
341
+ }
342
+ if (walkthroughElements.indicator) {
343
+ walkthroughElements.indicator.style.display = 'block';
344
+ }
345
+
346
+ // Hide walkthrough mode menu
347
+ const walkthroughMode = document.getElementById('walkthroughMode');
348
+ if (walkthroughMode) {
349
+ walkthroughMode.style.display = 'none';
350
+ }
351
+
352
+ // Show training interface if not already shown
353
+ const trainingInterface = document.getElementById('trainingInterface');
354
+ if (trainingInterface && trainingInterface.style.display === 'none') {
355
+ trainingInterface.style.display = 'block';
356
+ }
357
+
358
+ updateWalkthroughStep();
359
+ }
360
+
361
+ // Update the current walkthrough step
362
+ function updateWalkthroughStep() {
363
+ const tutorial = enhancedTutorials[walkthroughState.currentTutorial];
364
+ const step = tutorial.steps[walkthroughState.currentStep];
365
+
366
+ if (!step) return;
367
+
368
+ // Update progress indicator
369
+ if (walkthroughElements.progress) {
370
+ walkthroughElements.progress.style.display = 'block';
371
+ document.getElementById('walkthroughStep').textContent = walkthroughState.currentStep + 1;
372
+ document.getElementById('walkthroughTotal').textContent = tutorial.steps.length;
373
+ }
374
+
375
+ // Update popup content
376
+ if (walkthroughElements.popup) {
377
+ document.getElementById('walkthroughTitle').textContent = step.title;
378
+ document.getElementById('walkthroughContent').textContent = step.content;
379
+
380
+ // Position popup
381
+ positionWalkthroughPopup(step);
382
+
383
+ // Show popup
384
+ walkthroughElements.popup.style.display = 'block';
385
+ }
386
+
387
+ // Update highlight
388
+ if (step.element && step.highlight) {
389
+ highlightElement(step.element, step.highlight);
390
+ } else if (step.element) {
391
+ highlightElement(step.element);
392
+ } else {
393
+ // Center mode - no specific element highlighted
394
+ if (walkthroughElements.highlight) {
395
+ walkthroughElements.highlight.style.display = 'none';
396
+ }
397
+ }
398
+
399
+ // Update button states
400
+ const prevBtn = document.getElementById('walkthroughPrev');
401
+ const nextBtn = document.getElementById('walkthroughNext');
402
+
403
+ if (prevBtn) {
404
+ prevBtn.disabled = walkthroughState.currentStep === 0;
405
+ prevBtn.style.opacity = walkthroughState.currentStep === 0 ? '0.5' : '1';
406
+ }
407
+
408
+ if (nextBtn) {
409
+ const isLastStep = walkthroughState.currentStep === tutorial.steps.length - 1;
410
+ nextBtn.textContent = isLastStep ? 'Finish' : 'Next';
411
+ }
412
+ }
413
+
414
+ // Position the walkthrough popup
415
+ function positionWalkthroughPopup(step) {
416
+ const popup = walkthroughElements.popup;
417
+ if (!popup) return;
418
+
419
+ // Remove all position classes
420
+ popup.className = 'walkthrough-popup';
421
+
422
+ if (step.position === 'center') {
423
+ // Center the popup
424
+ popup.style.position = 'fixed';
425
+ popup.style.top = '50%';
426
+ popup.style.left = '50%';
427
+ popup.style.transform = 'translate(-50%, -50%)';
428
+ popup.style.maxWidth = '90vw';
429
+ } else if (step.element) {
430
+ const element = document.querySelector(step.element);
431
+ if (element) {
432
+ const rect = element.getBoundingClientRect();
433
+
434
+ popup.style.position = 'fixed';
435
+ popup.style.transform = 'none';
436
+
437
+ switch(step.position) {
438
+ case 'top':
439
+ popup.style.left = `${rect.left + rect.width / 2 - 175}px`;
440
+ popup.style.top = `${rect.top - 200}px`;
441
+ popup.className += ' top';
442
+ break;
443
+ case 'bottom':
444
+ popup.style.left = `${rect.left + rect.width / 2 - 175}px`;
445
+ popup.style.top = `${rect.bottom + 20}px`;
446
+ popup.className += ' bottom';
447
+ break;
448
+ case 'left':
449
+ popup.style.left = `${rect.left - 370}px`;
450
+ popup.style.top = `${rect.top + rect.height / 2 - 100}px`;
451
+ popup.className += ' left';
452
+ break;
453
+ case 'right':
454
+ popup.style.left = `${rect.right + 20}px`;
455
+ popup.style.top = `${rect.top + rect.height / 2 - 100}px`;
456
+ popup.className += ' right';
457
+ break;
458
+ }
459
+
460
+ // Ensure popup stays within viewport
461
+ const popupRect = popup.getBoundingClientRect();
462
+ if (popupRect.right > window.innerWidth) {
463
+ popup.style.left = `${window.innerWidth - popupRect.width - 20}px`;
464
+ }
465
+ if (popupRect.left < 0) {
466
+ popup.style.left = '20px';
467
+ }
468
+ if (popupRect.bottom > window.innerHeight) {
469
+ popup.style.top = `${window.innerHeight - popupRect.height - 20}px`;
470
+ }
471
+ if (popupRect.top < 0) {
472
+ popup.style.top = '20px';
473
+ }
474
+ }
475
+ }
476
+ }
477
+
478
+ // Highlight a specific element
479
+ function highlightElement(selector, customBounds = null) {
480
+ const element = document.querySelector(selector);
481
+ const highlight = walkthroughElements.highlight;
482
+
483
+ if (!element || !highlight) return;
484
+
485
+ const rect = element.getBoundingClientRect();
486
+
487
+ let bounds = {
488
+ x: rect.left,
489
+ y: rect.top,
490
+ width: rect.width,
491
+ height: rect.height
492
+ };
493
+
494
+ // Use custom bounds if provided (for highlighting parts of elements)
495
+ if (customBounds) {
496
+ bounds = {
497
+ x: rect.left + customBounds.x,
498
+ y: rect.top + customBounds.y,
499
+ width: customBounds.width,
500
+ height: customBounds.height
501
+ };
502
+ }
503
+
504
+ // Position the highlight
505
+ highlight.style.display = 'block';
506
+ highlight.style.left = `${bounds.x - 5}px`;
507
+ highlight.style.top = `${bounds.y - 5}px`;
508
+ highlight.style.width = `${bounds.width + 10}px`;
509
+ highlight.style.height = `${bounds.height + 10}px`;
510
+ }
511
+
512
+ // End the walkthrough
513
+ function endWalkthrough() {
514
+ walkthroughState.active = false;
515
+ walkthroughState.currentTutorial = null;
516
+ walkthroughState.currentStep = 0;
517
+
518
+ // Hide all walkthrough elements
519
+ if (walkthroughElements.overlay) {
520
+ walkthroughElements.overlay.style.display = 'none';
521
+ }
522
+ if (walkthroughElements.highlight) {
523
+ walkthroughElements.highlight.style.display = 'none';
524
+ }
525
+ if (walkthroughElements.popup) {
526
+ walkthroughElements.popup.style.display = 'none';
527
+ }
528
+ if (walkthroughElements.progress) {
529
+ walkthroughElements.progress.style.display = 'none';
530
+ }
531
+ if (walkthroughElements.indicator) {
532
+ walkthroughElements.indicator.style.display = 'none';
533
+ }
534
+
535
+ // Return to walkthrough mode menu
536
+ const walkthroughMode = document.getElementById('walkthroughMode');
537
+ if (walkthroughMode) {
538
+ walkthroughMode.style.display = 'block';
539
+ }
540
+
541
+ // Hide training interface if we were in walkthrough
542
+ const trainingInterface = document.getElementById('trainingInterface');
543
+ if (trainingInterface) {
544
+ trainingInterface.style.display = 'none';
545
+ }
546
+ }
547
+
548
+ // Initialize when the page loads
549
+ document.addEventListener('DOMContentLoaded', () => {
550
+ console.log('Initializing walkthrough system...');
551
+ initializeWalkthrough();
552
+ });
553
+
554
+ // Make functions globally available
555
+ window.startWalkthrough = startWalkthrough;
556
+ window.endWalkthrough = endWalkthrough;
557
+ window.walkthroughState = walkthroughState;