|
8 | 8 | 'integrity' => 'sha384-e4Bm/JKXqLbEnnDNLZIbB0u9VBy3H9D+TNdLb22ybxTLsmtWgRhQ3/BKEgJ13zU2', |
9 | 9 | 'crossorigin' => 'anonymous', |
10 | 10 | ]) |
11 | | -@basset('https://cdn.jsdelivr.net/gh/RobiNN1/elFinder-Material-Theme@3.0.0/Material/css/theme.min.css') |
| 11 | +@php($elFinderLightTheme = 'https://cdn.jsdelivr.net/gh/RobiNN1/elFinder-Material-Theme@3.0.0/Material/css/theme-gray.min.css') |
| 12 | +@basset($elFinderLightTheme, false) |
| 13 | +<link |
| 14 | + rel="prefetch" |
| 15 | + href="{{ Basset::getUrl($elFinderLightTheme) }}" |
| 16 | + data-stylesheet-name="elfinder-theme-light" |
| 17 | +/> |
| 18 | +@php($elFinderDarkTheme = 'https://cdn.jsdelivr.net/gh/RobiNN1/elFinder-Material-Theme@3.0.0/Material/css/theme.min.css') |
| 19 | +@basset($elFinderDarkTheme, false) |
| 20 | +<link |
| 21 | + rel="prefetch" |
| 22 | + href="{{ Basset::getUrl($elFinderDarkTheme) }}" |
| 23 | + data-stylesheet-name="elfinder-theme-dark" |
| 24 | +/> |
12 | 25 | @basset('https://cdn.jsdelivr.net/gh/RobiNN1/elFinder-Material-Theme@3.0.0/Material/images/loading.svg', false) |
13 | 26 | @basset('https://cdn.jsdelivr.net/gh/RobiNN1/elFinder-Material-Theme@3.0.0/Material/font/material.eot', false) |
14 | 27 | @basset('https://cdn.jsdelivr.net/gh/RobiNN1/elFinder-Material-Theme@3.0.0/Material/font/material.svg', false) |
|
17 | 30 | @basset('https://cdn.jsdelivr.net/gh/RobiNN1/elFinder-Material-Theme@3.0.0/Material/font/material.woff', false) |
18 | 31 | @basset('https://cdn.jsdelivr.net/gh/RobiNN1/elFinder-Material-Theme@3.0.0/Material/font/material.ttf', false) |
19 | 32 | @basset('https://cdn.jsdelivr.net/gh/RobiNN1/elFinder-Material-Theme@3.0.0/Material/font/material.woff2', false) |
20 | | -@basset('https://cdn.jsdelivr.net/gh/RobiNN1/elFinder-Material-Theme@3.0.0/Material/css/theme-gray.min.css', false) |
| 33 | + |
21 | 34 | @bassetBlock('elfinderCommonStyles.css') |
22 | 35 | <style> |
23 | 36 | .elfinder .elfinder-toolbar .elfinder-button, |
|
32 | 45 | } |
33 | 46 | </style> |
34 | 47 | @endBassetBlock |
35 | | -<span data-elfinder-light-theme-url="{{ Basset::getUrl('https://cdn.jsdelivr.net/gh/RobiNN1/elFinder-Material-Theme@3.0.0/Material/css/theme-gray.min.css') }}" style="display:none"></span> |
| 48 | + |
36 | 49 | @bassetBlock('elfinderThemeSwitcherScript.js') |
37 | 50 | <script type="text/javascript"> |
38 | 51 | document.addEventListener('DOMContentLoaded', function() { |
39 | | - function getElfinderStyleSheet(main = true) { |
40 | | - const regex = new RegExp(main ? `RobiNN1\/elFinder-Material-Theme@3.0.0\/Material\/css\/theme\.min\.css` : `RobiNN1\/elFinder-Material-Theme@3.0.0\/Material\/css\/theme-gray\.min\.css`); const linkElements = document.querySelectorAll('link[rel="stylesheet"]'); |
41 | | - // Find the main elfinder stylesheet |
42 | | - let selectedLinkElement; |
43 | | - for (const linkElement of linkElements) { |
44 | | - if (regex.test(linkElement.href)) { |
45 | | - selectedLinkElement = linkElement; |
46 | | - break; |
47 | | - } |
48 | | - } |
49 | | - return selectedLinkElement; |
50 | | - } |
51 | | -
|
52 | | - function addElfinderLightStylesheet() { |
53 | | - let lightThemeEl = document.querySelector('[data-elfinder-light-theme-url]'); |
54 | | - if (!lightThemeEl) return; |
55 | | - let lightThemeUrl = lightThemeEl.getAttribute('data-elfinder-light-theme-url'); |
56 | | - if (!lightThemeUrl) return; |
57 | | -
|
58 | | - let mainStyleSheet = getElfinderStyleSheet(); |
59 | | - let lightStyleSheet = getElfinderStyleSheet(false); |
60 | | - // if found append the light mode css to the main theme stylesheet |
61 | | - if (mainStyleSheet && ! lightStyleSheet) { |
62 | | - let themeLight = document.createElement('link'); |
63 | | - themeLight.href = lightThemeUrl; |
64 | | - themeLight.rel = 'stylesheet'; |
65 | | - themeLight.type = 'text/css'; |
66 | | - mainStyleSheet.insertAdjacentElement('afterend', themeLight); |
67 | | - } |
68 | | - } |
| 52 | + const getElfinderStyleLink = (name) => document.querySelector(`[data-stylesheet-name="elfinder-theme-${name}"]`); |
69 | 53 |
|
70 | | - let colorMode = window.parent.colorMode?.result ?? window.colorMode?.result ?? false; |
71 | | - |
72 | | - if(colorMode !== 'dark') { |
73 | | - addElfinderLightStylesheet(); |
| 54 | + const setElfinderMode = (name) => { |
| 55 | + const darkModeStyleLink = getElfinderStyleLink('dark'); |
| 56 | + darkModeStyleLink.rel = name === 'dark' ? 'stylesheet' : 'prefetch'; |
| 57 | + const lightModeStyleLink = getElfinderStyleLink('light'); |
| 58 | + lightModeStyleLink.rel = name === 'light' ? 'stylesheet' : 'prefetch'; |
74 | 59 | } |
75 | 60 |
|
76 | | - // register a color mode change event so that we remove |
77 | | - // the light stylesheet when the color mode change |
78 | | - if(colorMode) { |
79 | | - let colorModeClass = window.parent.colorMode ?? window.colorMode; |
80 | | - colorModeClass.onChange(function(scheme) { |
81 | | - let getMainStylesheet = scheme === 'dark' ? false : true; |
82 | | - let selectedLinkElement = getElfinderStyleSheet(getMainStylesheet); |
83 | | -
|
84 | | - if (! selectedLinkElement) { |
85 | | - return true; |
86 | | - } |
87 | | - // in case we switched to dark mode, remove the ligth theme css |
88 | | - if(scheme === 'dark') { |
89 | | - selectedLinkElement.parentNode.removeChild(selectedLinkElement); |
90 | | - return true; |
91 | | - } |
92 | | - addElfinderLightStylesheet() |
93 | | - }); |
| 61 | + const colorModeClass = window.parent.colorMode ?? window.colorMode ?? null; |
| 62 | + if (colorModeClass) { |
| 63 | + // Set mode based on configuration and watch for changes |
| 64 | + setElfinderMode(colorModeClass.result); |
| 65 | + colorModeClass.onChange((scheme) => setElfinderMode(scheme)); |
| 66 | + } else { |
| 67 | + // Default to light mode |
| 68 | + setElfinderMode('light'); |
94 | 69 | } |
95 | | -
|
96 | 70 | }); |
97 | 71 | </script> |
98 | 72 | @endBassetBlock |
| 73 | +
|
99 | 74 | @if($styleBodyElement ?? false) |
100 | | -<script type="text/javascript"> |
101 | | - document.addEventListener('DOMContentLoaded', function() { |
102 | | - // we dont want to style the body when elfinder is loaded as a component in a backpack view |
103 | | - // we pass true when loading elfinder inside an iframe to style the iframe body. |
104 | | - // use the topbar and footbar darker color as the background to ease transitions |
105 | | - document.getElementsByTagName('body')[0].style.background = '#061325'; |
106 | | - document.getElementsByTagName('body')[0].style.opacity = 1; |
107 | | - }); |
| 75 | +<script type="module"> |
| 76 | + // we dont want to style the body when elfinder is loaded as a component in a backpack view |
| 77 | + // we pass true when loading elfinder inside an iframe to style the iframe body. |
| 78 | + // use the topbar and footbar darker color as the background to ease transitions |
| 79 | + document.body.style.background = '#061325'; |
| 80 | + document.body.style.opacity = 1; |
108 | 81 | </script> |
109 | 82 | @endif |
0 commit comments