Spaces:
Running
Running
File size: 2,480 Bytes
56b3258 | 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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | class CustomSettings extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
this.wallpapers = [
'http://static.photos/nature/1200x630/42',
'http://static.photos/cityscape/1200x630/23',
'http://static.photos/abstract/1200x630/15',
'http://static.photos/workspace/1200x630/7'
];
}
connectedCallback() {
this.render();
this.setupEventListeners();
}
render() {
this.shadowRoot.innerHTML = `
<style>
:host {
display: block;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 500px;
height: 400px;
background: white;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
z-index: 100;
padding: 20px;
}
h2 {
margin-top: 0;
color: #333;
}
.wallpaper-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 15px;
margin-top: 20px;
}
.wallpaper-item {
height: 120px;
background-size: cover;
background-position: center;
border-radius: 4px;
cursor: pointer;
border: 2px solid transparent;
}
.wallpaper-item:hover {
border-color: #4f46e5;
}
.close-btn {
position: absolute;
top: 15px;
right: 15px;
background: none;
border: none;
cursor: pointer;
}
</style>
<button class="close-btn">
<i data-feather="x"></i>
</button>
<h2>Настройки системы</h2>
<h3>Обои рабочего стола</h3>
<div class="wallpaper-grid">
${this.wallpapers.map(wp => `
<div class="wallpaper-item" style="background-image: url(${wp})" data-url="${wp}"></div>
`).join('')}
</div>
`;
feather.replace();
}
setupEventListeners() {
this.shadowRoot.querySelectorAll('.wallpaper-item').forEach(item => {
item.addEventListener('click', () => {
const desktop = document.querySelector('custom-desktop');
desktop.setWallpaper(item.dataset.url);
});
});
this.shadowRoot.querySelector('.close-btn').addEventListener('click', () => {
this.remove();
});
}
}
customElements.define('custom-settings', CustomSettings); |