25 lines
1.2 KiB
JavaScript
25 lines
1.2 KiB
JavaScript
/* One action control for the Downloads page and Settings download manager. */
|
|
(function(root) {
|
|
'use strict';
|
|
const paths = {
|
|
retry: '<path d="M3 11a9 9 0 1 1 2.6 7M3 3v8h8"/>',
|
|
cancel: '<path d="m6 6 12 12M6 18 18 6"/>',
|
|
pause: '<path d="M8 5v14M16 5v14"/>',
|
|
resume: '<path d="m9 5 10 7-10 7z"/>',
|
|
};
|
|
function create(doc, action, title) {
|
|
if (!paths[action]) throw new Error('Unknown download action');
|
|
const label = action[0].toUpperCase() + action.slice(1);
|
|
const button = doc.createElement('button'); button.type = 'button';
|
|
button.className = `dl-act download-action${action === 'cancel' ? ' danger' : ''}`;
|
|
button.setAttribute('aria-label', `${label} ${title}`);
|
|
const icon = doc.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
icon.setAttribute('viewBox', '0 0 24 24'); icon.setAttribute('aria-hidden', 'true'); icon.setAttribute('focusable', 'false');
|
|
icon.classList.add('download-action-icon'); icon.innerHTML = paths[action];
|
|
const text = doc.createElement('span'); text.textContent = label;
|
|
button.append(icon, text); return button;
|
|
}
|
|
const api = { create };
|
|
if (typeof module !== 'undefined' && module.exports) module.exports = api; else root.DownloadActions = api;
|
|
})(globalThis);
|