idolezal commited on
Commit
8ef5b4f
ยท
1 Parent(s): fc05bae

Set model_title to every row (not cell) and only if table is scrolled

Browse files
Files changed (1) hide show
  1. app.py +32 -21
app.py CHANGED
@@ -397,9 +397,9 @@ tr.row_odd {
397
  font-weight: bolder;
398
  }
399
 
400
- .leaderboard-table td[model_title]:hover::after, .leaderboard-table-model-details td[model_title]:hover::after {
401
  content: attr(model_title);
402
- position: absolute;
403
  background-color: rgba(50, 50, 50, 0.9);
404
  color: white;
405
  padding: 5px;
@@ -407,6 +407,8 @@ tr.row_odd {
407
  white-space: nowrap;
408
  z-index: 10;
409
  pointer-events: none;
 
 
410
  }
411
 
412
  """
@@ -414,34 +416,43 @@ tr.row_odd {
414
  custom_js = """
415
  <script>
416
 
417
- function addTitleForEachCellOfLeaderboardTable(){
418
- const rows = document.querySelectorAll('.leaderboard-table tr, .leaderboard-table-model-details tr');
419
 
420
- rows.forEach(row => {
421
- // Find the first cell in the row that contains a link
422
- const firstCellLink = row.querySelector('td a');
423
 
424
- if (firstCellLink) {
425
- // Get the value of the title attribute from the first link
426
- const titleText = firstCellLink.getAttribute('title');
427
-
428
- // Set the model_title attribute for all cells in the row except the first one
429
- row.querySelectorAll('td').forEach((cell, index) => {
430
- if (index !== 0) {
431
- // If the cell already has a model_title attribute, break the loop
432
- if (cell.hasAttribute('model_title')) {
433
- return; // Exit the current iteration for this row
434
- }
 
 
 
 
 
 
 
 
 
 
435
 
436
- // Set the model_title attribute permanently
437
- cell.setAttribute('model_title', titleText);
438
  }
439
  });
440
  }
441
  });
442
  }
443
 
444
- const intervalId = setInterval(addTitleForEachCellOfLeaderboardTable, 1000);
445
 
446
  </script>
447
  """
 
397
  font-weight: bolder;
398
  }
399
 
400
+ .leaderboard-table tr[model_title]:hover::after, .leaderboard-table-model-details tr[model_title]:hover::after {
401
  content: attr(model_title);
402
+ position: fixed;
403
  background-color: rgba(50, 50, 50, 0.9);
404
  color: white;
405
  padding: 5px;
 
407
  white-space: nowrap;
408
  z-index: 10;
409
  pointer-events: none;
410
+ left: 120px;
411
+ transform: translateY(150%);
412
  }
413
 
414
  """
 
416
  custom_js = """
417
  <script>
418
 
419
+ function addTitleForEachRowOfLeaderboardTable(){
420
+ const tables = document.querySelectorAll('.leaderboard-table table, .leaderboard-table-model-details table');
421
 
422
+ tables.forEach(table => {
423
+ const rows = table.querySelectorAll('tr');
 
424
 
425
+ if (table.scrollLeft > 10) {
426
+ rows.forEach(row => {
427
+ // Find the first cell in the row that contains a link
428
+ const firstCellLink = row.querySelector('td a');
429
+
430
+ if (firstCellLink) {
431
+ // Get the value of the title attribute from the first link
432
+ const titleText = firstCellLink.getAttribute('title');
433
+
434
+ // Set the model_title attribute for the row
435
+ row.setAttribute('model_title', titleText);
436
+ }
437
+ });
438
+ } else {
439
+ rows.forEach(row => {
440
+ // Find the first cell in the row that contains a link
441
+ const firstCellLink = row.querySelector('td a');
442
+
443
+ if (firstCellLink) {
444
+ // Get the value of the title attribute from the first link
445
+ const titleText = firstCellLink.getAttribute('title');
446
 
447
+ // Remove the model_title attribute for the row
448
+ row.removeAttribute('model_title');
449
  }
450
  });
451
  }
452
  });
453
  }
454
 
455
+ const intervalId = setInterval(addTitleForEachRowOfLeaderboardTable, 1000);
456
 
457
  </script>
458
  """