You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by bh...@apache.org on 2022/04/15 19:39:18 UTC

[beam] branch master updated: [BEAM-13204] Fix website bug where code tabs do not appear if the default language is not available (#17379)

This is an automated email from the ASF dual-hosted git repository.

bhulette pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new cff9ccd86b3 [BEAM-13204] Fix website bug where code tabs do not appear if the default language is not available (#17379)
cff9ccd86b3 is described below

commit cff9ccd86b390d8e5edfaa850fcf132da178330e
Author: David Huntsperger <56...@users.noreply.github.com>
AuthorDate: Fri Apr 15 12:39:07 2022 -0700

    [BEAM-13204] Fix website bug where code tabs do not appear if the default language is not available (#17379)
    
    * fix website bug where codetabs do not appear
    
    * add better comments and tweak solution for code tab display
---
 website/www/site/assets/js/language-switch-v2.js | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/website/www/site/assets/js/language-switch-v2.js b/website/www/site/assets/js/language-switch-v2.js
index 5caabd49883..a0ec6488c12 100644
--- a/website/www/site/assets/js/language-switch-v2.js
+++ b/website/www/site/assets/js/language-switch-v2.js
@@ -13,7 +13,8 @@
 $(document).ready(function() {
     function Switcher(conf) {
         var id = conf["class-prefix"],
-            def = conf["default"];
+            def = conf["default"],
+            langs = [];
         var prefix = id + "-";
         return {
             "id": id,
@@ -76,6 +77,7 @@ $(document).ready(function() {
             */
             "lookup": function(el, lang) {
                 if (!el.is("div"+this.selector)) {
+                    langs = lang;
                     return lang;
                 }
 
@@ -102,8 +104,16 @@ $(document).ready(function() {
                     }
                 });
 
-                if(!isPrefSelected) {
-                  pref = this.default;
+                if (!isPrefSelected) {
+                  // if there's a code block for the default language,
+                  // set the preferred language to the default language
+                  if (langs.includes(this.default)) {
+                    pref = this.default;
+                  // otherwise set the preferred language to the first available
+                  // language, so we don't have a page with no code blocks
+                  } else {
+                    pref = langs[0];
+                  }
 
                   $("." + this.wrapper + " li").each(function() {
                       if ($(this).data("type") === pref) {
@@ -111,7 +121,6 @@ $(document).ready(function() {
                       }
                   });
                }
-
                 // Swapping visibility of code blocks.
                 $(this.selector).hide();
                 $("nav"+this.selector).show();