Telegram Web K with changes to work inside I2P https://web.telegram.i2p/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

737 lines
25 KiB

3 years ago
/*
* https://github.com/morethanwords/tweb
* Copyright (C) 2019-2021 Eduard Kuzmenko
* https://github.com/morethanwords/tweb/blob/master/LICENSE
*/
2 years ago
import mediaSizes from '../helpers/mediaSizes';
import IS_TOUCH_SUPPORTED from '../environment/touchSupport';
import appImManager from '../lib/appManagers/appImManager';
import rootScope from '../lib/rootScope';
import ripple from './ripple';
import appSidebarRight from './sidebarRight';
import AppPollResultsTab from './sidebarRight/tabs/pollResults';
import {FormatterArguments, i18n, LangPackKey} from '../lib/langPack';
import {fastRaf} from '../helpers/schedulers';
import SetTransition from './singleTransition';
import findUpClassName from '../helpers/dom/findUpClassName';
import cancelEvent from '../helpers/dom/cancelEvent';
import {attachClickEvent, detachClickEvent} from '../helpers/dom/clickEvent';
import replaceContent from '../helpers/dom/replaceContent';
import windowSize from '../helpers/windowSize';
import {Message, MessageMedia, Poll, PollResults} from '../layer';
import toHHMMSS from '../helpers/string/toHHMMSS';
import StackedAvatars from './stackedAvatars';
import setInnerHTML from '../helpers/dom/setInnerHTML';
import {AppManagers} from '../lib/appManagers/managers';
import wrapEmojiText from '../lib/richTextProcessor/wrapEmojiText';
import wrapRichText from '../lib/richTextProcessor/wrapRichText';
3 years ago
let lineTotalLength = 0;
3 years ago
const tailLength = 9;
3 years ago
const times = 10;
const fullTime = 340;
const oneTime = fullTime / times;
export const roundPercents = (percents: number[]) => {
2 years ago
// console.log('roundPercents before percents:', percents);
3 years ago
const sum = percents.reduce((acc, p) => acc + Math.round(p), 0);
if(sum > 100) {
const diff = sum - 100;
const length = percents.length;
for(let i = 0; i < diff; ++i) {
let minIndex = -1, minRemainder = 1;
for(let k = 0; k < length; ++k) {
2 years ago
const remainder = percents[k] % 1;
3 years ago
if(remainder >= 0.5 && remainder < minRemainder) {
minRemainder = remainder;
minIndex = k;
}
}
if(minIndex === -1) {
2 years ago
// throw new Error('lol chto');
3 years ago
return;
}
percents[minIndex] -= minRemainder;
}
} else if(sum < 100) {
const diff = 100 - sum;
const length = percents.length;
for(let i = 0; i < diff; ++i) {
let minIndex = -1, maxRemainder = 0;
for(let k = 0; k < length; ++k) {
2 years ago
const remainder = percents[k] % 1;
3 years ago
if(remainder < 0.5 && remainder > maxRemainder) {
maxRemainder = remainder;
minIndex = k;
}
}
if(minIndex === -1) {
2 years ago
// throw new Error('lol chto');
3 years ago
return;
}
percents[minIndex] += 1 - maxRemainder;
}
}
2 years ago
// console.log('roundPercents after percents:', percents);
3 years ago
};
/* const connectedPolls: {id: string, element: PollElement}[] = [];
rootScope.on('poll_update', (e) => {
const {poll, results} = e as {poll: Poll, results: PollResults};
//console.log('poll_update', poll, results);
for(const connected of connectedPolls) {
if(connected.id === poll.id) {
const pollElement = connected.element;
pollElement.isClosed = !!poll.pFlags.closed;
pollElement.performResults(results, poll.chosenIndexes);
}
}
}); */
3 years ago
rootScope.addEventListener('poll_update', ({poll, results}) => {
3 years ago
const pollElements = Array.from(document.querySelectorAll(`poll-element[poll-id="${poll.id}"]`)) as PollElement[];
pollElements.forEach((pollElement) => {
2 years ago
// console.log('poll_update', poll, results);
3 years ago
pollElement.isClosed = !!poll.pFlags.closed;
pollElement.performResults(results, poll.chosenIndexes);
});
});
3 years ago
mediaSizes.addEventListener('resize', () => {
PollElement.setMaxLength();
PollElement.resizePolls();
});
mediaSizes.addEventListener('changeScreen', () => {
PollElement.setMaxLength();
});
3 years ago
const hideQuizHint = (element: HTMLElement, onHide: () => void, timeout: number) => {
element.classList.remove('active');
clearTimeout(timeout);
setTimeout(() => {
onHide();
element.remove();
if(prevQuizHint === element && prevQuizHintOnHide === onHide && prevQuizHintTimeout === timeout) {
prevQuizHint = prevQuizHintOnHide = null;
prevQuizHintTimeout = 0;
}
}, 200);
};
let prevQuizHint: HTMLElement, prevQuizHintOnHide: () => void, prevQuizHintTimeout: number;
let isListenerSet = false;
3 years ago
const setQuizHint = (solution: string, solution_entities: any[], onHide: () => void) => {
if(prevQuizHint) {
hideQuizHint(prevQuizHint, prevQuizHintOnHide, prevQuizHintTimeout);
}
const element = document.createElement('div');
element.classList.add('quiz-hint');
const container = document.createElement('div');
container.classList.add('container', 'tgico');
const textEl = document.createElement('div');
textEl.classList.add('text');
container.append(textEl);
element.append(container);
3 years ago
setInnerHTML(textEl, wrapRichText(solution, {entities: solution_entities}));
appImManager.chat.bubbles.container.append(element);
3 years ago
void element.offsetLeft; // reflow
element.classList.add('active');
prevQuizHint = element;
prevQuizHintOnHide = onHide;
prevQuizHintTimeout = window.setTimeout(() => {
hideQuizHint(element, onHide, prevQuizHintTimeout);
}, IS_TOUCH_SUPPORTED ? 5000 : 7000);
if(!isListenerSet) {
isListenerSet = true;
appImManager.addEventListener('peer_changed', () => {
if(prevQuizHint) {
hideQuizHint(prevQuizHint, prevQuizHintOnHide, prevQuizHintTimeout);
}
});
}
3 years ago
};
export default class PollElement extends HTMLElement {
3 years ago
public static MAX_OFFSET = -46.5;
public static MAX_LENGTH = 0;
public svgLines: SVGSVGElement[];
3 years ago
private numberDivs: HTMLDivElement[];
private answerDivs: HTMLDivElement[];
private descDiv: HTMLElement;
private typeDiv: HTMLElement;
private avatarsDiv: HTMLElement;
private viewResults: HTMLElement;
private votersCountDiv: HTMLDivElement;
3 years ago
// private maxLength: number;
// private maxLengths: number[];
3 years ago
private maxPercents: number[];
public isClosed = false;
private isQuiz = false;
private isRetracted = false;
private isPublic = false;
private isMultiple = false;
private chosenIndexes: number[] = [];
private percents: number[];
public message: Message.message;
3 years ago
public managers: AppManagers;
3 years ago
private quizInterval: number;
private quizTimer: SVGSVGElement;
private sendVoteBtn: HTMLElement;
private chosingIndexes: number[] = [];
private sendVotePromise: Promise<void>;
private sentVote = false;
3 years ago
public static setMaxLength() {
3 years ago
const width = windowSize.width <= 360 ? windowSize.width - 120 : mediaSizes.active.poll.width;
3 years ago
this.MAX_LENGTH = width + tailLength + this.MAX_OFFSET + -13.7; // 13 - position left
}
public static resizePolls() {
if(!this.MAX_LENGTH) return;
const pollElements = Array.from(document.querySelectorAll('poll-element.is-voted')) as PollElement[];
pollElements.forEach((pollElement) => {
3 years ago
pollElement.svgLines.forEach((svg, idx) => {
2 years ago
// void svg.getBoundingClientRect(); // reflow
3 years ago
pollElement.setLineProgress(idx, 1);
});
});
}
public async render() {
3 years ago
// браузер вызывает этот метод при добавлении элемента в документ
// (может вызываться много раз, если элемент многократно добавляется/удаляется)
if(!lineTotalLength) {
lineTotalLength = (document.getElementById('poll-line') as any as SVGPathElement).getTotalLength();
2 years ago
// console.log('line total length:', lineTotalLength);
3 years ago
PollElement.setMaxLength();
3 years ago
}
// const {poll, results} = this.managers.appPollsManager.getPoll(pollId);
const {poll, results} = this.message.media as MessageMedia.messageMediaPoll;
3 years ago
/* const timestamp = Date.now() / 1000 | 0;
if(timestamp < this.message.date) { */
if(this.message.pFlags.is_scheduled) {
this.classList.add('disable-hover');
}
2 years ago
// console.log('pollElement poll:', poll, results);
3 years ago
let descKey: LangPackKey;
if(poll.pFlags) {
this.isPublic = !!poll.pFlags.public_voters;
this.isQuiz = !!poll.pFlags.quiz;
this.isClosed = !!poll.pFlags.closed;
this.isMultiple = !!poll.pFlags.multiple_choice;
if(this.isClosed) {
descKey = 'Chat.Poll.Type.Closed';
this.classList.add('is-closed');
} else if(this.isQuiz) {
descKey = this.isPublic ? 'Chat.Poll.Type.Quiz' : 'Chat.Poll.Type.AnonymousQuiz';
} else {
descKey = this.isPublic ? 'Chat.Poll.Type.Public' : 'Chat.Poll.Type.Anonymous';
}
}
3 years ago
this.classList.toggle('is-multiple', this.isMultiple);
3 years ago
const multipleSelect = this.isMultiple ? '<span class="poll-answer-selected tgico-check"></span>' : '';
const votes = poll.answers.map((answer, idx) => {
return `
<div class="poll-answer" data-index="${idx}">
<div class="circle-hover">
<div class="animation-ring"></div>
<svg class="progress-ring">
<circle class="progress-ring__circle" cx="13" cy="13" r="9"></circle>
</svg>
${multipleSelect}
</div>
<div class="poll-answer-percents"></div>
3 years ago
<div class="poll-answer-text"></div>
3 years ago
<svg version="1.1" class="poll-line" style="display: none;" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 485.9 35" xml:space="preserve">
3 years ago
<use href="#poll-line"></use>
</svg>
<span class="poll-answer-selected tgico"></span>
</div>
`;
}).join('');
this.innerHTML = `
<div class="poll-title"></div>
3 years ago
<div class="poll-desc">
<div class="poll-type"></div>
<div class="poll-avatars"></div>
</div>
${votes}`;
2 years ago
3 years ago
setInnerHTML(this.firstElementChild, wrapEmojiText(poll.question));
3 years ago
3 years ago
Array.from(this.querySelectorAll('.poll-answer-text')).forEach((el, idx) => {
setInnerHTML(el, wrapEmojiText(poll.answers[idx].text));
3 years ago
});
3 years ago
this.descDiv = this.firstElementChild.nextElementSibling as HTMLElement;
this.typeDiv = this.descDiv.firstElementChild as HTMLElement;
this.avatarsDiv = this.descDiv.lastElementChild as HTMLElement;
if(descKey) {
this.typeDiv.append(i18n(descKey));
}
if(this.isQuiz) {
this.classList.add('is-quiz');
if(poll.close_period && poll.close_date) {
const timeLeftDiv = document.createElement('div');
timeLeftDiv.classList.add('poll-time');
this.descDiv.append(timeLeftDiv);
2 years ago
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
// svg.setAttributeNS(null, 'viewBox', '0 0 15 15');
3 years ago
svg.classList.add('poll-quiz-timer');
this.quizTimer = svg;
const strokeWidth = 2;
const radius = 7;
const circumference = 2 * Math.PI * radius;
2 years ago
const circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
3 years ago
circle.classList.add('poll-quiz-timer-circle');
circle.setAttributeNS(null, 'cx', '16');
circle.setAttributeNS(null, 'cy', '16');
circle.setAttributeNS(null, 'r', '' + radius);
circle.setAttributeNS(null, 'stroke-width', '' + strokeWidth);
svg.append(circle);
this.descDiv.append(svg);
2 years ago
3 years ago
const period = poll.close_period * 1000;
const closeTime = (poll.close_date - await rootScope.managers.timeManager.getServerTimeOffset()) * 1000;
3 years ago
2 years ago
// console.log('closeTime:', poll.close_date, serverTimeManager.serverTimeOffset, Date.now() / 1000 | 0);
3 years ago
// let time = Date.now();
// let percents = (closeTime - time) / period;
// timeLeftDiv.innerHTML = String((closeTime - time) / 1000 + 1 | 0).toHHMMSS();
// // @ts-ignore
// circle.style.strokeDashoffset = circumference + percents * circumference;
// circle.style.strokeDasharray = ${circumference} ${circumference};
this.quizInterval = window.setInterval(() => {
const time = Date.now();
const percents = (closeTime - time) / period;
const timeLeft = (closeTime - time) / 1000 + 1 | 0;
timeLeftDiv.innerHTML = toHHMMSS(timeLeft);
2 years ago
if(timeLeft <= 5) {
3 years ago
timeLeftDiv.style.color = '#ee545c';
circle.style.stroke = '#ee545c';
}
2 years ago
// timeLeftDiv.style.visibility = 'visible';
3 years ago
// @ts-ignore
circle.style.strokeDashoffset = circumference + percents * circumference;
circle.style.strokeDasharray = `${circumference} ${circumference}`;
if(time >= closeTime) {
clearInterval(this.quizInterval);
timeLeftDiv.innerHTML = '';
// @ts-ignore
circle.style.strokeDashoffset = circumference;
this.quizInterval = 0;
setTimeout(() => {
// нужно запросить апдейт чтобы опрос обновился
3 years ago
this.managers.appPollsManager.getResults(this.message);
3 years ago
}, 3e3);
}
}, 1e3);
}
}
2 years ago
3 years ago
this.answerDivs = Array.from(this.querySelectorAll('.poll-answer')) as HTMLDivElement[];
this.svgLines = Array.from(this.querySelectorAll('.poll-line')) as SVGSVGElement[];
this.numberDivs = Array.from(this.querySelectorAll('.poll-answer-percents')) as HTMLDivElement[];
const footerDiv = document.createElement('div');
footerDiv.classList.add('poll-footer');
this.viewResults = document.createElement('div');
this.viewResults.className = 'poll-footer-button poll-view-results hide';
this.viewResults.append(i18n('Chat.Poll.ViewResults'));
this.votersCountDiv = document.createElement('div');
this.votersCountDiv.className = 'poll-votes-count';
footerDiv.append(this.viewResults, this.votersCountDiv);
this.append(footerDiv);
this.viewResults.addEventListener('click', (e) => {
cancelEvent(e);
if(!appSidebarRight.isTabExists(AppPollResultsTab)) {
3 years ago
appSidebarRight.createTab(AppPollResultsTab).open(this.message);
3 years ago
}
});
ripple(this.viewResults);
if(this.isMultiple) {
this.sendVoteBtn = document.createElement('div');
this.sendVoteBtn.classList.add('poll-footer-button', 'poll-send-vote');
this.sendVoteBtn.append(i18n('Chat.Poll.SubmitVote'));
ripple(this.sendVoteBtn);
if(!poll.chosenIndexes.length) {
this.votersCountDiv.classList.add('hide');
}
attachClickEvent(this.sendVoteBtn, (e) => {
cancelEvent(e);
/* const indexes = this.answerDivs.filter((el) => el.classList.contains('is-chosing')).map((el) => +el.dataset.index);
3 years ago
if(indexes.length) {
2 years ago
3 years ago
} */
if(this.chosingIndexes.length) {
this.sendVotes(this.chosingIndexes).then(() => {
this.chosingIndexes.length = 0;
this.answerDivs.forEach((el) => {
3 years ago
el.classList.remove('is-chosing');
});
});
}
});
footerDiv.append(this.sendVoteBtn);
}
3 years ago
// const width = this.getBoundingClientRect().width;
// const width = mediaSizes.active.poll.width;
// this.maxLength = width + tailLength + this.maxOffset + -13.7; // 13 - position left
3 years ago
const canVote = !(poll.chosenIndexes.length || this.isClosed);
if(!canVote || this.isPublic) {
3 years ago
this.performResults(results, poll.chosenIndexes, false);
}
if(canVote) {
3 years ago
this.setVotersCount(results);
attachClickEvent(this, this.clickHandler);
}
}
initQuizHint(results: PollResults) {
if(results.solution && results.solution_entities) {
const toggleHint = document.createElement('div');
toggleHint.classList.add('tgico-tip', 'poll-hint');
this.descDiv.append(toggleHint);
2 years ago
// let active = false;
3 years ago
attachClickEvent(toggleHint, (e) => {
cancelEvent(e);
2 years ago
// active = true;
3 years ago
toggleHint.classList.add('active');
setQuizHint(results.solution, results.solution_entities, () => {
2 years ago
// active = false;
3 years ago
toggleHint.classList.remove('active');
});
});
if(this.sentVote) {
const correctResult = results.results.find((r) => r.pFlags.correct);
3 years ago
if(correctResult && !correctResult.pFlags.chosen) {
toggleHint.click();
}
}
}
}
clickHandler(e: Event) {
const target = findUpClassName(e.target, 'poll-answer') as HTMLElement;
if(!target) {
return;
}
2 years ago
3 years ago
cancelEvent(e);
const answerIndex = +target.dataset.index;
if(this.isMultiple) {
target.classList.toggle('is-chosing');
const foundIndex = this.chosingIndexes.indexOf(answerIndex);
if(foundIndex !== -1) {
this.chosingIndexes.splice(foundIndex, 1);
} else {
this.chosingIndexes.push(answerIndex);
}
} else {
this.sendVotes([answerIndex]);
}
2 years ago
3 years ago
/* target.classList.add('is-voting');
setTimeout(() => { // simulate
this.setResults([100, 0], answerIndex);
target.classList.remove('is-voting');
}, 1000); */
}
sendVotes(indexes: number[]) {
if(this.sendVotePromise) return this.sendVotePromise;
const targets = this.answerDivs.filter((_, idx) => indexes.includes(idx));
targets.forEach((target) => {
3 years ago
target.classList.add('is-voting');
});
2 years ago
3 years ago
this.classList.add('disable-hover');
this.sentVote = true;
3 years ago
return this.sendVotePromise = this.managers.appPollsManager.sendVote(this.message, indexes).then(() => {
targets.forEach((target) => {
3 years ago
target.classList.remove('is-voting');
});
this.classList.remove('disable-hover');
}).catch(() => {
this.sentVote = false;
}).finally(() => {
this.sendVotePromise = null;
});
}
performResults(results: PollResults, chosenIndexes: number[], animate = true) {
if(!rootScope.settings.animationsEnabled) {
animate = false;
}
if(this.isQuiz && (results.results?.length || this.isClosed)) {
this.answerDivs.forEach((el, idx) => {
el.classList.toggle('is-correct', !!results.results[idx].pFlags.correct);
});
if(this.initQuizHint) {
this.initQuizHint(results);
this.initQuizHint = null;
}
if(this.quizInterval) {
clearInterval(this.quizInterval);
this.quizInterval = 0;
}
if(this.quizTimer?.parentElement) {
this.quizTimer.remove();
}
const timeEl = this.descDiv.querySelector('.poll-time');
if(timeEl) {
timeEl.remove();
}
}
if(this.isClosed) {
this.classList.add('is-closed');
replaceContent(this.typeDiv, i18n('Chat.Poll.Type.Closed'));
}
// set chosen
if(this.chosenIndexes.length !== chosenIndexes.length || this.isClosed) { // if we voted
this.isRetracted = this.chosenIndexes.length && !chosenIndexes.length;
this.chosenIndexes = chosenIndexes.slice();
if(this.isRetracted) {
attachClickEvent(this, this.clickHandler);
} else {
detachClickEvent(this, this.clickHandler);
}
}
2 years ago
3 years ago
// is need update
if(this.chosenIndexes.length || this.isRetracted || this.isClosed) {
const percents = results.results.map((v) => results.total_voters ? v.voters / results.total_voters * 100 : 0);
3 years ago
this.classList.toggle('no-transition', !animate);
if(animate) {
SetTransition(this, '', !this.isRetracted, 340);
}
fastRaf(() => {
this.setResults(this.isRetracted ? this.percents : percents, this.chosenIndexes, animate);
this.percents = percents;
this.isRetracted = false;
});
}
2 years ago
3 years ago
this.setVotersCount(results);
if(this.isPublic) {
if(!this.isMultiple) {
this.viewResults.classList.toggle('hide', !results.total_voters || !this.chosenIndexes.length);
this.votersCountDiv.classList.toggle('hide', !!this.chosenIndexes.length);
}
const peerIds = (results.recent_voters || []).map((userId) => userId.toPeerId());
3 years ago
const stackedAvatars = new StackedAvatars({avatarSize: 16});
stackedAvatars.render(peerIds);
replaceContent(this.avatarsDiv, stackedAvatars.container);
3 years ago
}
if(this.isMultiple) {
3 years ago
const isVoted = !!this.chosenIndexes.length;
const hideSendVoteBtn = this.isClosed || isVoted;
const hideViewResultsBtn = !this.isPublic || !results.total_voters || (!isVoted && !this.isClosed);
this.sendVoteBtn.classList.toggle('hide', hideSendVoteBtn);
this.viewResults.classList.toggle('hide', hideViewResultsBtn);
this.votersCountDiv.classList.toggle('hide', !hideSendVoteBtn || !hideViewResultsBtn);
3 years ago
}
}
setResults(percents: number[], chosenIndexes: number[], animate: boolean) {
this.svgLines.forEach((svg) => svg.style.display = '');
3 years ago
this.answerDivs.forEach((el, idx) => {
el.classList.toggle('is-chosen', chosenIndexes.includes(idx));
});
const maxValue = Math.max(...percents);
// this.maxLengths = percents.map((p) => p / maxValue * this.maxLength);
this.maxPercents = percents.map((p) => p / maxValue);
3 years ago
// line
if(this.isRetracted) {
this.svgLines.forEach((svg, idx) => {
this.setLineProgress(idx, -1);
});
} else {
const cb = () => {
this.svgLines.forEach((svg, idx) => {
2 years ago
// void svg.getBoundingClientRect(); // reflow
3 years ago
this.setLineProgress(idx, 1);
});
};
2 years ago
3 years ago
animate ? fastRaf(cb) : cb();
}
percents = percents.slice();
roundPercents(percents);
let getPercentValue: (percents: number, index: number) => number;
const iterate = (i: number) => {
percents.forEach((percents, idx) => {
const value = getPercentValue(percents, i);
this.numberDivs[idx].innerText = value + '%';
});
};
// numbers
if(this.isRetracted) {
getPercentValue = (percents, index) => Math.round(percents / times * index);
if(animate) {
for(let i = (times - 1), k = 0; i >= 0; --i, ++k) {
setTimeout(() => {
iterate(i);
}, oneTime * k);
}
} else {
iterate(0);
}
} else {
getPercentValue = (percents, index) => Math.round(percents / times * (index + 1));
if(animate) {
for(let i = 0; i < times; ++i) {
setTimeout(() => {
iterate(i);
}, oneTime * i);
}
} else {
iterate(times - 1);
}
}
if(this.isRetracted) {
if(animate) {
this.classList.add('is-retracting');
}
this.classList.remove('is-voted');
const cb = () => {
this.svgLines.forEach((svg) => svg.style.display = 'none');
3 years ago
};
if(animate) {
setTimeout(() => {
this.classList.remove('is-retracting');
cb();
}, fullTime);
} else {
cb();
}
} else {
this.classList.add('is-voted');
}
}
setVotersCount(results: PollResults) {
const votersCount = results.total_voters || 0;
2 years ago
let key: LangPackKey;
const args: FormatterArguments = [votersCount];
3 years ago
if(this.isClosed) {
if(this.isQuiz) key = votersCount ? 'Chat.Quiz.TotalVotes' : 'Chat.Quiz.TotalVotesResultEmpty';
else key = votersCount ? 'Chat.Poll.TotalVotes1' : 'Chat.Poll.TotalVotesResultEmpty';
} else {
if(this.isQuiz) key = votersCount ? 'Chat.Quiz.TotalVotes' : 'Chat.Quiz.TotalVotesEmpty';
else key = votersCount ? 'Chat.Poll.TotalVotes1' : 'Chat.Poll.TotalVotesEmpty';
}
2 years ago
3 years ago
replaceContent(this.votersCountDiv, i18n(key, args));
}
setLineProgress(index: number, multiplier: number) {
const svg = this.svgLines[index];
if(multiplier === -1) {
svg.style.strokeDasharray = '';
svg.style.strokeDashoffset = '';
} else {
3 years ago
// svg.style.strokeDasharray = (multiplier * this.maxLengths[index]) + ', 485.9';
svg.style.strokeDasharray = (multiplier * this.maxPercents[index] * PollElement.MAX_LENGTH) + ', 485.9';
// svg.style.strokeDasharray = (multiplier * this.maxPercents[index] * 100) + '%, 485.9';
svg.style.strokeDashoffset = '' + multiplier * PollElement.MAX_OFFSET;
3 years ago
}
}
// у элемента могут быть ещё другие методы и свойства
}
2 years ago
customElements.define('poll-element', PollElement);