alex buz commited on
Commit
f10d421
·
1 Parent(s): 7936cc5
Files changed (1) hide show
  1. app.py +18 -12
app.py CHANGED
@@ -33,7 +33,7 @@ def create_anchor_link(text):
33
  return ""
34
  anchor = text.strip().lower().replace(' ', '-').replace(',', '').replace('.', '').replace(chr(39), '-')
35
  anchor = urllib.parse.quote(anchor)
36
- return f"<a href='#' onclick='navigateToSection(\"{anchor}\");'>{text}</a>"
37
 
38
  def on_stop():
39
  st.session_state.stopped = True
@@ -148,24 +148,30 @@ st.markdown(
148
  """
149
  <script>
150
  function navigateToSection(anchor) {
151
- const element = document.querySelector(`[id='${anchor}']`);
152
  if (element) {
153
  element.scrollIntoView({behavior: 'smooth'});
154
  } else {
155
  console.error('Section not found:', anchor);
156
  }
157
  }
 
 
 
 
158
 
159
- // Intercept all anchor clicks
160
- document.addEventListener('click', function(e) {
161
- const target = e.target;
162
- if (target.tagName === 'A' && target.getAttribute('href') === '#') {
163
- e.preventDefault();
164
- const onclickAttr = target.getAttribute('onclick');
165
- if (onclickAttr && onclickAttr.startsWith('navigateToSection')) {
166
- eval(onclickAttr);
167
- }
168
- }
 
 
169
  });
170
  </script>
171
  """,
 
33
  return ""
34
  anchor = text.strip().lower().replace(' ', '-').replace(',', '').replace('.', '').replace(chr(39), '-')
35
  anchor = urllib.parse.quote(anchor)
36
+ return f"<a href='#{anchor}' onclick='navigateToSection(\"{anchor}\");'>{text}</a>"
37
 
38
  def on_stop():
39
  st.session_state.stopped = True
 
148
  """
149
  <script>
150
  function navigateToSection(anchor) {
151
+ const element = document.getElementById(anchor);
152
  if (element) {
153
  element.scrollIntoView({behavior: 'smooth'});
154
  } else {
155
  console.error('Section not found:', anchor);
156
  }
157
  }
158
+ </script>
159
+ """,
160
+ unsafe_allow_html=True
161
+ )
162
 
163
+ # JavaScript for intercepting clicks
164
+ st.markdown(
165
+ """
166
+ <script>
167
+ document.addEventListener('DOMContentLoaded', function() {
168
+ document.querySelectorAll('a').forEach(anchor => {
169
+ anchor.addEventListener('click', function(e) {
170
+ e.preventDefault();
171
+ const href = this.getAttribute('href').substring(1);
172
+ navigateToSection(href);
173
+ });
174
+ });
175
  });
176
  </script>
177
  """,