update to pc
This commit is contained in:
@@ -1,13 +1,66 @@
|
||||
import { Fragment, Helper, Translator } from './pwa-lib.js';
|
||||
import { Helper, Fragment, Translator } from './pwa-lib.js';
|
||||
|
||||
class DelayPromise extends Promise{
|
||||
constructor(delay) {
|
||||
super((resolve) => {
|
||||
class DelayPromise extends Promise {
|
||||
static async delay(delay) {
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, delay);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class ScaleHelper {
|
||||
scaleTo(scale, fontElement, container, ignoreHeight, ignoreWidth, margin, fontWeight) {
|
||||
margin = Helper.nonNull(margin, 10);
|
||||
ignoreHeight = Helper.nonNull(ignoreHeight, false);
|
||||
ignoreWidth = Helper.nonNull(ignoreWidth, false);
|
||||
fontWeight = Helper.nonNull(fontWeight, fontElement.innerHTML.length);
|
||||
|
||||
let hasNoTransitionClass = container.classList.contains("no-transition");
|
||||
container.classList.add("no-transition");
|
||||
|
||||
let currentFontSize = 1;
|
||||
let diff = 0;
|
||||
let widthDiff = 0;
|
||||
let heightDiff = 0;
|
||||
let containerWidth = 0;
|
||||
let containerHeight = 0;
|
||||
do {
|
||||
currentFontSize += diff / (fontWeight + 1);
|
||||
fontElement.style.fontSize = currentFontSize + 'px';
|
||||
|
||||
let containerStyle = window.getComputedStyle(container);
|
||||
|
||||
containerWidth = containerStyle.getPropertyValue("width").replace('px', '');
|
||||
containerHeight = containerStyle.getPropertyValue("height").replace('px', '');
|
||||
|
||||
widthDiff = containerWidth - fontElement.offsetWidth;
|
||||
heightDiff = containerHeight - fontElement.offsetHeight;
|
||||
|
||||
let newDiff = (ignoreWidth ? heightDiff : (ignoreHeight ? widthDiff : Math.min(widthDiff, heightDiff)));
|
||||
if (newDiff === diff) {
|
||||
break;
|
||||
}
|
||||
diff = newDiff;
|
||||
} while ((widthDiff > (1 - scale) * containerWidth || ignoreWidth) && (heightDiff > (1 - scale) * containerHeight || ignoreHeight));
|
||||
fontElement.style.fontSize = (currentFontSize - margin) + 'px';
|
||||
|
||||
if (!hasNoTransitionClass) {
|
||||
container.classList.remove("no-transition");
|
||||
}
|
||||
|
||||
let self = this;
|
||||
window.addEventListener("resize", function () {
|
||||
setTimeout(() => {
|
||||
self.scaleTo(scale, fontElement, container, ignoreHeight, ignoreWidth, margin, fontWeight);
|
||||
}, 255);
|
||||
});
|
||||
}
|
||||
|
||||
scaleToFull(fontElement, container, ignoreHeight, ignoreWidth, margin, fontWeight) {
|
||||
return this.scaleTo(1, fontElement, container, ignoreHeight, ignoreWidth, margin, fontWeight);
|
||||
}
|
||||
}
|
||||
|
||||
class TabbedFragment extends Fragment {
|
||||
constructor(site) {
|
||||
super(site, 'pwaAssets/html/fragment/tabbedFragment.html');
|
||||
@@ -73,4 +126,4 @@ class TabbedFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
export { DelayPromise, TabbedFragment };
|
||||
export { DelayPromise, ScaleHelper, TabbedFragment };
|
||||
|
||||
@@ -2419,8 +2419,9 @@ class Dialog {
|
||||
return this;
|
||||
}
|
||||
|
||||
setContent(content) {
|
||||
this.content = content;
|
||||
async setContent(content) {
|
||||
this.contentPromise = Promise.resolve(content);
|
||||
this.content = await this.contentPromise;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -2465,70 +2466,71 @@ class Dialog {
|
||||
this.buttons.push(button);
|
||||
}
|
||||
|
||||
show() {
|
||||
async show() {
|
||||
|
||||
let titleElement = document.createElement("span");
|
||||
titleElement.classList.add("title");
|
||||
if (this.translatable && this.title !== "") {
|
||||
titleElement.appendChild(Translator.makePersistentTranslation(this.title));
|
||||
}
|
||||
else {
|
||||
titleElement.innerHTML = this.title;
|
||||
}
|
||||
|
||||
let titleBar = document.createElement("div");
|
||||
titleBar.appendChild(titleElement);
|
||||
|
||||
let contentContainer = document.createElement("div");
|
||||
contentContainer.classList.add("content-container");
|
||||
|
||||
let modalDialog = document.createElement("div");
|
||||
modalDialog.className = this.additionalClasses;
|
||||
modalDialog.classList.add("modal");
|
||||
modalDialog.appendChild(titleBar);
|
||||
modalDialog.appendChild(contentContainer);
|
||||
|
||||
let buttonBar = document.createElement("div");
|
||||
buttonBar.classList.add("modal-button-container");
|
||||
|
||||
for (let i = 0, n = this.buttons.length; i < n; i++) {
|
||||
buttonBar.appendChild(this.buttons[i]);
|
||||
}
|
||||
|
||||
await this.contentPromise;
|
||||
if (!(this.content instanceof Node)) {
|
||||
this.content = (this.translatable) ? Translator.makePersistentTranslation(this.content) : document.createTextNode(this.content);
|
||||
}
|
||||
contentContainer.appendChild(this.content);
|
||||
|
||||
this.backgroundElement = document.createElement("div");
|
||||
this.backgroundElement.classList.add("background");
|
||||
this.backgroundElement.appendChild(modalDialog);
|
||||
|
||||
this.backgroundElement.querySelector(".modal").appendChild(buttonBar);
|
||||
this.backgroundElement.style.display = "block";
|
||||
|
||||
let self = this;
|
||||
return new Promise(function (resolve) {
|
||||
|
||||
if (!(self.content instanceof Node)) {
|
||||
self.content = (self.translatable) ? Translator.makePersistentTranslation(self.content) : document.createTextNode(self.content);
|
||||
}
|
||||
|
||||
if (this.cancelable) {
|
||||
let closeButton = document.createElement("span");
|
||||
closeButton.classList.add("close");
|
||||
closeButton.innerHTML = "×";
|
||||
|
||||
let titleElement = document.createElement("span");
|
||||
titleElement.classList.add("title");
|
||||
if (self.translatable && self.title !== "") {
|
||||
titleElement.appendChild(Translator.makePersistentTranslation(self.title));
|
||||
}
|
||||
else {
|
||||
titleElement.innerHTML = self.title;
|
||||
}
|
||||
|
||||
let titlteBar = document.createElement("div");
|
||||
titlteBar.appendChild(titleElement);
|
||||
|
||||
let contentContainer = document.createElement("div");
|
||||
contentContainer.classList.add("content-container");
|
||||
contentContainer.appendChild(self.content);
|
||||
|
||||
let modalDialog = document.createElement("div");
|
||||
modalDialog.className = self.additionalClasses;
|
||||
modalDialog.classList.add("modal");
|
||||
modalDialog.appendChild(titlteBar);
|
||||
modalDialog.appendChild(contentContainer);
|
||||
|
||||
self.backgroundElement = document.createElement("div");
|
||||
self.backgroundElement.classList.add("background");
|
||||
self.backgroundElement.appendChild(modalDialog);
|
||||
|
||||
if (self.cancelable) {
|
||||
titlteBar.appendChild(closeButton);
|
||||
closeButton.addEventListener("click", function () {
|
||||
titleBar.appendChild(closeButton);
|
||||
closeButton.addEventListener("click", function () {
|
||||
self.close();
|
||||
});
|
||||
window.addEventListener("click", function (e) {
|
||||
if (e.target === self.backgroundElement) {
|
||||
self.close();
|
||||
});
|
||||
window.addEventListener("click", function (e) {
|
||||
if (e.target === self.backgroundElement) {
|
||||
self.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let buttonBar = document.createElement("div");
|
||||
buttonBar.classList.add("modal-button-container");
|
||||
document.body.appendChild(this.backgroundElement);
|
||||
Translator.getInstance().updateTranslations();
|
||||
|
||||
for (let i = 0, n = self.buttons.length; i < n; i++) {
|
||||
buttonBar.appendChild(self.buttons[i]);
|
||||
}
|
||||
|
||||
self.backgroundElement.querySelector(".modal").appendChild(buttonBar);
|
||||
|
||||
self.backgroundElement.style.display = "block";
|
||||
document.body.appendChild(self.backgroundElement);
|
||||
return new Promise(function (resolve) {
|
||||
self.resolver = resolve;
|
||||
|
||||
Translator.getInstance().updateTranslations();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2539,7 +2541,7 @@ class Dialog {
|
||||
this.backgroundElement = null;
|
||||
}
|
||||
if (Helper.isNotNull(this.resolver)) {
|
||||
this.resolver();
|
||||
this.resolver(this.result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2551,52 +2553,13 @@ class Dialog {
|
||||
class ConfirmDialog extends Dialog {
|
||||
constructor(content, title) {
|
||||
super(content, title);
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
show() {
|
||||
|
||||
async show() {
|
||||
this.addButton("confirm-button", true);
|
||||
this.addButton("cancel-button", false);
|
||||
|
||||
let showPromise = super.show();
|
||||
let self = this;
|
||||
|
||||
//Sorgt dafür, dass eine mögliche Exception im Promise geworfen wird
|
||||
return new Promise(function (resolve) {
|
||||
// let confirmButton = document.createElement("button");
|
||||
// confirmButton.classList.add("button");
|
||||
// confirmButton.classList.add("right");
|
||||
// confirmButton.appendChild(Translator.makePersistentTranslation("confirm-button"));
|
||||
|
||||
// let cancelButton = document.createElement("button");
|
||||
// cancelButton.classList.add("button");
|
||||
// cancelButton.classList.add("right");
|
||||
// cancelButton.appendChild(Translator.makePersistentTranslation("cancel-button"));
|
||||
|
||||
// let buttonBar = document.createElement("div");
|
||||
// buttonBar.classList.add("modal-button-container");
|
||||
|
||||
// buttonBar.appendChild(confirmButton);
|
||||
// buttonBar.appendChild(cancelButton);
|
||||
|
||||
|
||||
|
||||
// confirmButton.addEventListener("click", function(){
|
||||
// self.result = true;
|
||||
// self.close();
|
||||
// });
|
||||
|
||||
// cancelButton.addEventListener("click", function(){
|
||||
// self.result = false;
|
||||
// self.close();
|
||||
// });
|
||||
|
||||
// self.backgroundElement.querySelector(".modal").appendChild(buttonBar);
|
||||
resolve(showPromise.then(function(){
|
||||
return self.result;
|
||||
}));
|
||||
});
|
||||
return super.show();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user