@kupola/kupola 1.7.2 → 1.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/js/theme.js CHANGED
@@ -40,13 +40,7 @@ function setTheme(theme) {
40
40
  const toggleBtn = document.querySelector('[data-theme-toggle]');
41
41
  if (toggleBtn) {
42
42
  toggleBtn.setAttribute('data-current-theme', theme);
43
- const icon = toggleBtn.querySelector('.theme-icon');
44
- if (icon) {
45
- const iconPath = icon.src.substring(0, icon.src.lastIndexOf('/') + 1);
46
- icon.src = theme === 'dark'
47
- ? iconPath + 'sun.svg'
48
- : iconPath + 'moon.svg';
49
- }
43
+ updateThemeIcon(toggleBtn);
50
44
  }
51
45
  }
52
46
 
@@ -95,6 +89,13 @@ function updateThemeIcon(toggleBtn) {
95
89
  }
96
90
  }
97
91
 
92
+ function _themeToggleHandler(e) {
93
+ e.preventDefault();
94
+ const currentTheme = getTheme();
95
+ const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
96
+ setTheme(newTheme);
97
+ }
98
+
98
99
  function initTheme() {
99
100
 
100
101
  const toggleBtn = document.querySelector('[data-theme-toggle]');
@@ -102,46 +103,18 @@ function initTheme() {
102
103
  if (!_themeInitialized) {
103
104
  _themeInitialized = true;
104
105
 
105
- if (toggleBtn) {
106
- const iconEl = toggleBtn.querySelector('.theme-icon');
107
- if (iconEl && iconEl.src) {
108
- const currentIconsPath = getIconsPath();
109
- if (currentIconsPath === '/icons/') {
110
- const iconPath = iconEl.src.substring(0, iconEl.src.lastIndexOf('/') + 1);
111
- const basePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/') + 1);
112
- const relativeIconsPath = iconPath.replace(window.location.origin + basePath, '');
113
- if (relativeIconsPath !== iconPath) {
114
- setConfig({
115
- paths: {
116
- icons: relativeIconsPath,
117
- base: basePath
118
- }
119
- });
120
- }
121
- }
122
- }
123
- }
106
+ const savedTheme = getTheme();
107
+ setTheme(savedTheme);
108
+
109
+ const savedBrand = getBrand();
110
+ setBrand(savedBrand);
124
111
  }
125
112
 
126
- const savedTheme = getTheme();
127
- setTheme(savedTheme);
128
-
129
- const savedBrand = getBrand();
130
- setBrand(savedBrand);
131
-
132
113
  if (toggleBtn) {
133
114
  updateThemeIcon(toggleBtn);
134
- const existingOnClick = toggleBtn.onclick;
135
- toggleBtn.onclick = function(e) {
136
- e.preventDefault();
137
- const currentTheme = getTheme();
138
- const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
139
- setTheme(newTheme);
140
- updateThemeIcon(toggleBtn);
141
- if (typeof existingOnClick === 'function') {
142
- existingOnClick.call(this, e);
143
- }
144
- };
115
+
116
+ toggleBtn.removeEventListener('click', _themeToggleHandler);
117
+ toggleBtn.addEventListener('click', _themeToggleHandler);
145
118
  }
146
119
 
147
120
  let brandPicker = document.getElementById('brand-picker');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kupola/kupola",
3
- "version": "1.7.2",
3
+ "version": "1.7.4",
4
4
  "description": "A lightweight UI toolkit for any web project. No heavy frontend frameworks required.",
5
5
  "main": "dist/kupola.cjs.js",
6
6
  "module": "dist/kupola.esm.js",