-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
74 lines (68 loc) · 2.98 KB
/
main.js
File metadata and controls
74 lines (68 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
document.addEventListener('DOMContentLoaded', () => {
// seleziona gli elementi principali del layout
const categoryList = document.getElementById('category-list');
const gridContainer = document.querySelector('.grid-container');
const sidebar = document.querySelector('.sidebar');
// carica i dati dei widget dal file json
fetch('widgets.json')
.then(response => response.json())
.then(data => {
// crea i pulsanti per ogni categoria
data.categories.forEach(category => {
const button = document.createElement('button');
button.textContent = category.name;
button.className = 'widget-button';
button.addEventListener('click', () => loadWidgets(category.widgets));
categoryList.appendChild(button);
});
// funzione per caricare i widget nella griglia
function loadWidgets(widgets) {
gridContainer.innerHTML = '';
widgets.forEach(widget => {
const widgetDiv = document.createElement('div');
widgetDiv.className = 'widget';
widgetDiv.innerHTML = `
<h3 class="widget-title" title="${widget.description}">${widget.title}</h3>
<div class="widget-options">
${
widget.type === 'color-picker'
? '<input type="color" class="widget-color-picker" value="#20e5f2">'
+ '<input type="number" class="widget-alpha-picker" min="0" max="1" step="0.01" value="1">'
: widget.options.map(option => `<button class="widget-button">${option}</button>`).join('')
}
</div>
`;
gridContainer.appendChild(widgetDiv);
const buttons = widgetDiv.querySelectorAll('.widget-button');
buttons.forEach(button => {
button.addEventListener('click', () => {
buttons.forEach(btn => btn.classList.remove('selected'));
button.classList.add('selected');
});
});
const alphaInput = widgetDiv.querySelector('.widget-alpha-picker');
if (alphaInput) {
alphaInput.addEventListener('change', function() {
const val = parseFloat(this.value);
if (isNaN(val) || val < parseFloat(this.min) || val > parseFloat(this.max)) {
this.value = this.defaultValue;
}
});
}
});
}
// aggiunge eventi per selezionare le categorie
const categoryButtons = categoryList.querySelectorAll('.widget-button');
categoryButtons.forEach(catBtn => {
catBtn.addEventListener('click', () => {
categoryButtons.forEach(btn => btn.classList.remove('selected'));
catBtn.classList.add('selected');
});
});
})
.catch(error => console.error('errore nel caricamento dei widget:', error));
const gButton = document.getElementById('static-button-g');
gButton.addEventListener('click', () => {
window.location.href = 'https://github.com/sculk3/TPpicker';
});
});