base.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. {# Base template for (almost) all NetBox pages #}
  2. {% load static %}
  3. {% load helpers %}
  4. <!DOCTYPE html>
  5. <html
  6. lang="en"
  7. data-netbox-url-name="{{ request.resolver_match.url_name }}"
  8. data-netbox-base-path="{{ settings.BASE_PATH }}"
  9. {% if preferences|get_key:'ui.colormode' == 'dark'%}
  10. data-netbox-color-mode="dark"
  11. {% else %}
  12. data-netbox-color-mode="light"
  13. {% endif %}
  14. >
  15. <head>
  16. <meta charset="UTF-8" />
  17. <meta
  18. name="viewport"
  19. content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width, viewport-fit=cover"
  20. />
  21. {# Page title #}
  22. <title>{% block title %}Home{% endblock %} | NetBox</title>
  23. <script type="text/javascript">
  24. /**
  25. * Determine the best initial color mode to use prior to rendering.
  26. */
  27. (function() {
  28. // Browser prefers dark color scheme.
  29. var preferDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
  30. // Browser prefers light color scheme.
  31. var preferLight = window.matchMedia('(prefers-color-scheme: light)').matches;
  32. // Client NetBox color-mode override.
  33. var clientMode = localStorage.getItem('netbox-color-mode');
  34. // NetBox server-rendered value.
  35. var serverMode = document.documentElement.getAttribute('data-netbox-color-mode');
  36. if ((clientMode !== null) && (clientMode !== serverMode)) {
  37. // If the client mode is set, use its value over the server's value.
  38. return document.documentElement.setAttribute('data-netbox-color-mode', clientMode);
  39. }
  40. if (preferDark && serverMode === 'light') {
  41. // If the client value matches the server value, the browser preferrs dark-mode, but
  42. // the server value doesn't match the browser preference, use dark mode.
  43. return document.documentElement.setAttribute('data-netbox-color-mode', 'dark');
  44. }
  45. if (preferLight && serverMode === 'dark') {
  46. // If the client value matches the server value, the browser preferrs dark-mode, but
  47. // the server value doesn't match the browser preference, use light mode.
  48. return document.documentElement.setAttribute('data-netbox-color-mode', 'light');
  49. }
  50. })();
  51. </script>
  52. {# Static resources #}
  53. <link
  54. rel="stylesheet"
  55. href="{% static 'netbox-external.css'%}"
  56. onerror="window.location='{% url 'media_failure' %}?filename=netbox-external.css'"
  57. />
  58. <link
  59. rel="stylesheet"
  60. href="{% static 'netbox-light.css'%}"
  61. onerror="window.location='{% url 'media_failure' %}?filename=netbox-light.css'"
  62. />
  63. <link
  64. rel="stylesheet"
  65. href="{% static 'netbox-dark.css'%}"
  66. onerror="window.location='{% url 'media_failure' %}?filename=netbox-dark.css'"
  67. />
  68. <link
  69. rel="stylesheet"
  70. media="print"
  71. href="{% static 'netbox-print.css'%}"
  72. onerror="window.location='{% url 'media_failure' %}?filename=netbox-print.css'"
  73. />
  74. <link rel="icon" type="image/png" href="{% static 'netbox.ico' %}" />
  75. {# Javascript #}
  76. <script
  77. type="text/javascript"
  78. src="{% static 'netbox.js' %}"
  79. onerror="window.location='{% url 'media_failure' %}?filename=netbox.js'">
  80. </script>
  81. {# Additional <head> content #}
  82. {% block head %}{% endblock %}
  83. </head>
  84. <body>
  85. <script type="text/javascript">
  86. (function() {
  87. // Check localStorage to see if the sidebar should be pinned.
  88. var sideNavRaw = localStorage.getItem('netbox-sidenav');
  89. // Determine if the device has a small screeen. This media query is equivalent to
  90. // bootstrap's media-breakpoint-down(lg) breakpoint mixin, which is what the sidenav's
  91. // CSS uses.
  92. var isSmallScreen = window.matchMedia('(max-width: 991.98px)').matches;
  93. if (typeof sideNavRaw === 'string') {
  94. var sideNavState = JSON.parse(sideNavRaw);
  95. if (sideNavState.pinned === true && !isSmallScreen) {
  96. // If the sidebar should be pinned and this is not a small screen, set the appropriate
  97. // body attributes prior to the rest of the content rendering. This prevents
  98. // jumpy/glitchy behavior on page reloads.
  99. document.body.setAttribute('data-sidenav-pinned', '');
  100. document.body.setAttribute('data-sidenav-show', '');
  101. } else {
  102. document.body.setAttribute('data-sidenav-hidden', '');
  103. }
  104. }
  105. })();
  106. </script>
  107. {# Page layout #}
  108. {% block layout %}{% endblock %}
  109. {# Additional Javascript #}
  110. {% block javascript %}{% endblock %}
  111. {# User messages #}
  112. {% include 'inc/messages.html' %}
  113. {# Data container #}
  114. <div id="netbox-data" style="display: none!important; visibility: hidden!important">
  115. {% block data %}{% endblock %}
  116. </div>
  117. </body>
  118. </html>