welcome-page-scripts.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright 2019 Red Hat, Inc. and/or its affiliates.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. var isWelcomePage = function () {
  17. var winHash = window.location.hash;
  18. return winHash === '#/';
  19. };
  20. var toggleReact = function () {
  21. var welcomeScreen = document.getElementById("welcomeScreen");
  22. var spinnerScreen = document.getElementById("spinner_screen");
  23. var reactScreen = document.getElementById("main_react_container");
  24. if (!isWelcomePage() && !isReactLoading) {
  25. if (welcomeScreen) welcomeScreen.style.display = 'none';
  26. if (spinnerScreen) spinnerScreen.style.display = 'none';
  27. if (reactScreen) reactScreen.style.display = 'block';
  28. if (reactScreen) reactScreen.style.height = '100%';
  29. } else if (!isWelcomePage() && isReactLoading) {
  30. if (welcomeScreen) welcomeScreen.style.display = 'none';
  31. if (reactScreen) reactScreen.style.display = 'none';
  32. if (spinnerScreen) spinnerScreen.style.display = 'block';
  33. if (spinnerScreen) spinnerScreen.style.height = '100%';
  34. } else {
  35. if (reactScreen) reactScreen.style.display = 'none';
  36. if (spinnerScreen) spinnerScreen.style.display = 'none';
  37. if (welcomeScreen) welcomeScreen.style.display = 'block';
  38. if (welcomeScreen) welcomeScreen.style.height = '100%';
  39. }
  40. };
  41. function loggedInUserName() {
  42. let userName = l18nMsg['unknownUser'];
  43. if (keycloak.tokenParsed) {
  44. const givenName = keycloak.tokenParsed.given_name;
  45. const familyName = keycloak.tokenParsed.family_name;
  46. const preferredUsername = keycloak.tokenParsed.preferred_username;
  47. if (givenName && familyName) {
  48. userName = [givenName, familyName].reduce((acc, value, index) =>
  49. acc.replace('{{param_'+ index + '}}', value), l18nMsg['fullName']
  50. );
  51. } else {
  52. userName = (givenName || familyName) || preferredUsername || userName;
  53. }
  54. }
  55. return sanitize(userName);
  56. }
  57. function sanitize(dirtyString) {
  58. let element = document.createElement("span");
  59. element.textContent = dirtyString;
  60. return element.innerHTML;
  61. }
  62. var toggleMobileDropdown = function () {
  63. var mobileDropdown = document.getElementById("landingMobileDropdown");
  64. var mobileKebab = document.getElementById("landingMobileKebab");
  65. var mobileKebabButton = document.getElementById("landingMobileKebabButton");
  66. if (mobileDropdown.style.display === 'none') {
  67. mobileDropdown.style.display = 'block';
  68. mobileKebab.classList.add("pf-m-expanded");
  69. mobileKebabButton.setAttribute("aria-expanded", "true");
  70. } else {
  71. mobileDropdown.style.display = 'none';
  72. mobileKebab.classList.remove("pf-m-expanded");
  73. mobileKebabButton.setAttribute("aria-expanded", "false");
  74. }
  75. }
  76. var loadjs = function (url, loadListener) {
  77. const script = document.createElement("script");
  78. script.src = resourceUrl + url;
  79. script.type = "module";
  80. if (loadListener)
  81. script.addEventListener("load", loadListener);
  82. document.head.appendChild(script);
  83. };