Skip to content

Commit

Permalink
conditionally display the "Demos" tab
Browse files Browse the repository at this point in the history
This change makes the server-rendered "Demos" tab invisible by default, and updates the toggle-labs script to conditionally make the tab visible on specific category pages.
  • Loading branch information
zeke committed Feb 14, 2022
1 parent f2ac6a7 commit 8dc1713
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
17 changes: 11 additions & 6 deletions browse/static/js/toggle-labs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,27 @@ $(document).ready(function() {

var pwcEnabled = true;

// infer the current category from the DOM (`cs.AI`, `stat.ML`, etc)
const currentCategory = $('.current')?.text()?.toLowerCase();

// enable Replicate integration for these categories
const replicateCategories = [
const demoCategories = [
"cs", // Computer Science
"eess", // Electrical Engineering and Systems Science
"stat" // Statistics
]
var replicateEnabled = currentCategory && replicateCategories.some(category => currentCategory.startsWith(category));

const demosEnabled = currentCategory && demoCategories.some(category => currentCategory.startsWith(category));

if (demosEnabled) {
document.getElementById("labstabs-demos-input").removeAttribute("disabled");
document.getElementById("labstabs-demos-label").style.display = "block";
}

var replicateEnabled = demosEnabled

var labsCookie = Cookies.getJSON("arxiv_labs");
if (labsCookie) {
has_enabled = false;
if ( labsCookie["last_tab"] ){
$("input#"+labsCookie["last_tab"]).click();
$(`input#${labsCookie["last_tab"]}:not([disabled])`).click();
}
for (var key in labsCookie) {
if (labsCookie[key] && labsCookie[key] == "enabled") {
Expand Down
9 changes: 6 additions & 3 deletions browse/templates/abs/labs_tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ <h1>Code and Data Associated with this Article</h1>
<div id="pwc-data-output"></div>
</div>


<input type="radio" name="tabs" id="tabthree">
<label for="tabthree">Demos</label>
<!--
hide the "Demos" tab by default, and conditionally display it using
JavaScript on pages in specific categories like `cs`, `eess``, and `stat`
-->
<input type="radio" name="tabs" id="labstabs-demos-input" disabled>
<label for="labstabs-demos-input" id="labstabs-demos-label" style="display:none">Demos</label>
<div class="tab">
<h1>Demos Associated with this Article</h1>
<div class="toggle">
Expand Down

0 comments on commit 8dc1713

Please sign in to comment.