UNPKG

jodit

Version:

Jodit is an awesome and useful wysiwyg editor with filebrowser

91 lines (90 loc) 2.76 kB
/*! * Jodit Editor (https://xdsoft.net/jodit/) * Released under MIT see LICENSE.txt in the project root for license information. * Copyright (c) 2013-2026 Valerii Chupurnov. All rights reserved. https://xdsoft.net */ import { Dom } from "../../dom/dom.js"; import { getContainer } from "../../global.js"; import { position } from "../../helpers/size/position.js"; import { css } from "../../helpers/utils/css.js"; import { UIElement } from "../element.js"; import { Icon } from "../icon.js"; export class ProgressBar extends UIElement { constructor() { super(...arguments); this.__animationElement = null; } /** @override */ className() { return 'ProgressBar'; } /** @override */ render() { return '<div><div></div></div>'; } /** * Show progress bar */ show() { const container = this.j.workplace || this.j.container; container.appendChild(this.container); return this; } hide() { Dom.safeRemove(this.container); return this; } progress(percentage) { this.container.style.width = percentage.toFixed(2) + '%'; return this; } showFileUploadAnimation(from, to) { this.__cleanUpAnimation(); const box = getContainer(this.j, ProgressBar); const pos = position(this.j.container, this.j); const el = this.j.c.div(this.getFullElName('file-animation')); const iconSvg = Icon.get('file', ''); if (iconSvg) { el.innerHTML = iconSvg; } const start = from !== null && from !== void 0 ? from : { x: pos.width / 2, y: 0 }; const end = to !== null && to !== void 0 ? to : { x: start.x + 60, y: start.y - 80 }; css(el, { left: pos.left + start.x, top: pos.top + start.y }); box.appendChild(el); this.__animationElement = el; // Force reflow before starting transition // eslint-disable-next-line no-unused-expressions el.offsetWidth; css(el, { left: pos.left + end.x, top: pos.top + end.y, opacity: 0, transform: 'scale(0.4)' }); const onEnd = () => { el.removeEventListener('transitionend', onEnd); this.__cleanUpAnimation(); }; el.addEventListener('transitionend', onEnd); } __cleanUpAnimation() { if (this.__animationElement) { Dom.safeRemove(this.__animationElement); this.__animationElement = null; } } destruct() { this.__cleanUpAnimation(); this.hide(); return super.destruct(); } }