the-glorious-startpage/js/dock-buttons.js

98 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-06-04 02:14:24 +02:00
var dock = document.getElementById('dock');
// Generate button from user
const generateFromManual = (id, icon, callback) => {
var customButtonCallback;
2020-06-04 02:35:05 +02:00
var dockButton = document.createElement('div');
dockButton.id = 'button' + id;
dockButton.className = 'dockButton';
2020-06-04 02:14:24 +02:00
2020-06-04 02:35:05 +02:00
dockButton.onmouseup = callback;
2020-06-04 02:14:24 +02:00
var buttonImage = document.createElement('div');
buttonImage.id = 'buttonImage' + id;
2020-06-04 02:35:05 +02:00
buttonImage.className = 'dockButtonImage';
2020-06-04 02:14:24 +02:00
buttonImage.style.background = "url('assets/buttons/" + icon + ".svg')";
buttonImage.style.backgroundSize = 'cover';
2020-06-04 02:35:05 +02:00
dockButton.appendChild(buttonImage);
dock.appendChild(dockButton);
2020-06-04 02:14:24 +02:00
}
// Generate buttons from array
const generateFromList = () => {
for (i = 0; i < (dockSites.length); i++) {
var site = dockSites[i].site;
var icon = dockSites[i].icon;
var url = dockSites[i].url;
2020-06-05 00:19:31 +02:00
// Create a href
var aDock = document.createElement('a');
aDock.className = 'dockLink';
aDock.href = url;
2020-06-05 00:19:31 +02:00
// Create div container
2020-06-04 02:35:05 +02:00
var dockButton = document.createElement('div');
dockButton.id = 'button' + i;
dockButton.className = 'dockButton';
2020-06-04 02:14:24 +02:00
2020-06-05 00:19:31 +02:00
// Create div container for button icon
2020-06-04 02:14:24 +02:00
var buttonImage = document.createElement('div');
buttonImage.id = 'buttonImage' + i;
2020-06-04 02:35:05 +02:00
buttonImage.className = 'dockButtonImage';
2020-06-04 02:14:24 +02:00
buttonImage.style.background = "url('assets/webcons/" + icon + ".svg')";
buttonImage.style.backgroundSize = 'cover';
// Append divs
2020-06-04 02:35:05 +02:00
dockButton.appendChild(buttonImage);
aDock.appendChild(dockButton);
dock.appendChild(aDock);
2020-06-04 02:14:24 +02:00
};
2020-06-04 02:39:09 +02:00
}
const populateDock = () => {
// Create launcher button
generateFromManual(
'Launch',
'launch',
() => {
2020-06-04 06:15:59 +02:00
// Toggle web menu
toggleWebMenu();
2020-06-04 02:39:09 +02:00
}
);
// Create dock buttons fetched from sites-list.js
generateFromList();
2020-06-04 02:14:24 +02:00
// Create weather button
generateFromManual(
'Weather',
'weather',
() => {
// Toggle weather screen
toggleWeatherScreen();
2020-06-04 02:14:24 +02:00
}
);
// Create menu button
generateFromManual(
'Dashboard',
'dashboard',
() => {
// Toggle dashboard
2020-06-04 04:23:40 +02:00
toggleDashboard();
2020-06-04 02:14:24 +02:00
}
);
2020-06-04 02:39:09 +02:00
2020-06-04 02:14:24 +02:00
}
2020-06-04 02:39:09 +02:00
// Populate dock
window.onload = populateDock();
2020-06-04 02:14:24 +02:00