1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-23 13:20:27 +01:00

80 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-10-03 12:17:14 +02:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
(function(){
"use strict";
const scope = window.scope.gui = {};
const {error, warning, message, notice, verbose, setPrefix: setLogPrefix} = require("./logging");
scope.createCollapser = function(){
2017-10-10 13:38:55 +02:00
const messages = {
more: browser.i18n.getMessage("more"),
less: browser.i18n.getMessage("less")
};
2017-10-03 12:17:14 +02:00
return function createCollapser(container){
var collapser = document.createElement("span");
collapser.className = "collapser";
2017-10-10 13:38:55 +02:00
["more", "less"].forEach(function(type){
var span = document.createElement("span");
span.className = type;
span.textContent = messages[type];
collapser.appendChild(span);
});
2017-10-03 12:17:14 +02:00
container.appendChild(collapser);
collapser.addEventListener("click", function(){
container.classList.toggle("collapsed");
});
2018-08-22 22:16:49 +02:00
container.classList.add("collapsible");
2017-10-03 12:17:14 +02:00
container.classList.add("collapsed");
};
}();
scope.createActionButtons = function createActionButtons(container, actions, data, horizontal){
2017-10-03 12:17:14 +02:00
actions.forEach(function(action, i){
var button = document.createElement("button");
button.className = action.name + " action";
button.title = browser.i18n.getMessage(action.name);
if (action.isIcon || action.icon){
button.classList.add("isIcon");
var img = document.createElement("img");
button.appendChild(img);
img.src = "../icons/" + (action.icon || `pageAction-${action.name}.svg`);
}
else {
button.textContent = button.title;
}
2017-10-03 12:17:14 +02:00
button.addEventListener("click", action.callback.bind(undefined, data));
container.appendChild(button);
if (horizontal){
2017-10-03 12:17:14 +02:00
container.appendChild(document.createElement("br"));
}
});
};
scope.modalPrompt = function modalPrompt(messageText, defaultValue){
message("open modal prompt");
return new Promise(function(resolve, reject){
document.body.innerHTML = "";
document.body.appendChild(document.createTextNode(messageText));
var input = document.createElement("input");
input.value = defaultValue;
document.body.appendChild(input);
var button = document.createElement("button");
button.textContent = "OK";
button.addEventListener("click", function(){
resolve(input.value);
message("modal prompt closed with value", input.value);
});
document.body.appendChild(button);
});
};
}());