Aashish34 commited on
Commit
7e9fb6b
·
1 Parent(s): 2da7131

update ml links

Browse files
Files changed (1) hide show
  1. math-ds-complete/app.js +36 -15
math-ds-complete/app.js CHANGED
@@ -81,8 +81,8 @@ function switchSubject(subject) {
81
  });
82
 
83
  // Scroll to first topic of subject
84
- const firstTopic = document.querySelector(`.topic-section[data-subject="${subject}"], .topic-section:not([data-subject])`);
85
- if (firstTopic && subject !== 'statistics') {
86
  setTimeout(() => {
87
  firstTopic.scrollIntoView({ behavior: 'smooth', block: 'start' });
88
  }, 100);
@@ -94,6 +94,12 @@ function switchSubject(subject) {
94
  }, 100);
95
  }
96
  }
 
 
 
 
 
 
97
  }
98
 
99
  // ===== NAVIGATION =====
@@ -114,18 +120,21 @@ function initNavigation() {
114
  link.addEventListener('click', (e) => {
115
  e.preventDefault();
116
  const topicId = link.getAttribute('data-topic');
117
- // Handle both regular topics and ML topics
118
- const target = document.getElementById(topicId.startsWith('ml-') ? topicId : `topic-${topicId}`);
 
 
 
119
 
120
- if (target) {
121
- target.scrollIntoView({ behavior: 'smooth', block: 'start' });
122
- updateActiveLink(topicId);
123
-
124
- // Close mobile menu if open
125
- if (window.innerWidth <= 1024) {
126
- sidebar.classList.remove('active');
127
- }
128
- }
129
  });
130
  });
131
  }
@@ -137,10 +146,22 @@ function updateActiveLink(topicId) {
137
  const activeLink = document.querySelector(`[data-topic="${topicId}"]`);
138
  if (activeLink) {
139
  activeLink.classList.add('active');
 
 
 
 
 
 
 
 
 
140
  }
141
- // Only update currentTopic if it's a number
142
- if (!topicId.startsWith('ml-')) {
 
143
  currentTopic = parseInt(topicId);
 
 
144
  }
145
  }
146
 
 
81
  });
82
 
83
  // Scroll to first topic of subject
84
+ const firstTopic = document.querySelector(`.topic-section[data-subject="${subject}"]`);
85
+ if (firstTopic) {
86
  setTimeout(() => {
87
  firstTopic.scrollIntoView({ behavior: 'smooth', block: 'start' });
88
  }, 100);
 
94
  }, 100);
95
  }
96
  }
97
+
98
+ // Set initial active state for the first topic link of the subject
99
+ const firstLink = document.querySelector(`.topic-link[data-topic^="${subject === 'machine-learning' ? 'ml-' : 'topic-'}"]`);
100
+ if (firstLink) {
101
+ updateActiveLink(firstLink.getAttribute('data-topic'));
102
+ }
103
  }
104
 
105
  // ===== NAVIGATION =====
 
120
  link.addEventListener('click', (e) => {
121
  e.preventDefault();
122
  const topicId = link.getAttribute('data-topic');
123
+ let targetId = topicId;
124
+ if (!topicId.startsWith('ml-')) {
125
+ targetId = `topic-${topicId}`;
126
+ }
127
+ const target = document.getElementById(targetId);
128
 
129
+ if (target) {
130
+ target.scrollIntoView({ behavior: 'smooth', block: 'start' });
131
+ updateActiveLink(topicId);
132
+
133
+ // Close mobile menu if open
134
+ if (window.innerWidth <= 1024) {
135
+ sidebar.classList.remove('active');
136
+ }
137
+ }
138
  });
139
  });
140
  }
 
146
  const activeLink = document.querySelector(`[data-topic="${topicId}"]`);
147
  if (activeLink) {
148
  activeLink.classList.add('active');
149
+
150
+ // Get subject from parent module's data-subject attribute
151
+ const moduleElement = activeLink.closest('.module');
152
+ const subjectFromModule = moduleElement ? moduleElement.dataset.subject : null;
153
+
154
+ // Only update subject if module has an explicit subject
155
+ if (subjectFromModule && currentSubject !== subjectFromModule) {
156
+ switchSubject(subjectFromModule);
157
+ }
158
  }
159
+
160
+ // Update currentTopic - preserve numeric ID for stats, or null for others
161
+ if (!topicId.startsWith('ml-') && !isNaN(parseInt(topicId))) {
162
  currentTopic = parseInt(topicId);
163
+ } else {
164
+ currentTopic = null;
165
  }
166
  }
167