From 343b02bf196bac17866f439d653bb559d9371291 Mon Sep 17 00:00:00 2001 From: cutls Date: Tue, 11 Feb 2020 02:15:54 +0900 Subject: [PATCH] Fix: #227 --- app/js/tl/parse.js | 17 +++++++++-------- app/js/tl/poll.js | 35 +++++++++++++++-------------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/app/js/tl/parse.js b/app/js/tl/parse.js index 627ec291..95ae3f86 100644 --- a/app/js/tl/parse.js +++ b/app/js/tl/parse.js @@ -1391,6 +1391,7 @@ function client(name) { } //Poll Parser function pollParse(poll, acct_id, emojis) { + var rand = randomStr(8) var datetype = localStorage.getItem('datetype') var anime = localStorage.getItem('animation') if (anime == 'yes' || !anime) { @@ -1408,7 +1409,7 @@ function pollParse(poll, acct_id, emojis) { } else { var minechoice = [] } - var refresh = ` + var refresh = ` ${lang.lang_manager_refresh} ` if (poll.voted && poll.own_votes.length) { @@ -1423,11 +1424,11 @@ function pollParse(poll, acct_id, emojis) { var myvote = lang.lang_parse_endedvote var result_hide = '' } else { - var myvote = `${lang.lang_parse_vote}
` + var myvote = `${lang.lang_parse_vote}
` if (choices[0].votes_count === 0 || choices[0].votes_count > 0) { myvote = myvote + - ` + ` ${lang.lang_parse_unvoted}  ` } @@ -1454,7 +1455,7 @@ function pollParse(poll, acct_id, emojis) { } if (!poll.voted && !poll.expired) { var votesel = - "voteSelMastodon('" + acct_id + "','" + poll.id + "'," + keyc + ',' + poll.multiple + ')' + `voteSelMastodon('${acct_id}','${poll.id}',${keyc},${poll.multiple}, this)` var voteclass = 'pointer' } else { var votesel = '' @@ -1469,9 +1470,9 @@ function pollParse(poll, acct_id, emojis) { } var openData = '' if (choice.votes_count !== null) { - openData = `${choice.votes_count}(${per}%)` + openData = `${voteit}${choice.votes_count}(${per}%)` } else { - openData = `?(-%)` + openData = `${voteit}?(-%)` } var choiceText = escapeHTML(choice.title) if (emojis) { @@ -1497,7 +1498,7 @@ function pollParse(poll, acct_id, emojis) { pollHtml + `
- ${choiceText}${voteit} + ${choiceText} ${openData} @@ -1506,7 +1507,7 @@ function pollParse(poll, acct_id, emojis) { if (poll.expired) { refresh = '' } - pollHtml = `
+ pollHtml = `
${pollHtml}${myvote} ${refresh} diff --git a/app/js/tl/poll.js b/app/js/tl/poll.js index 01136306..212fe844 100644 --- a/app/js/tl/poll.js +++ b/app/js/tl/poll.js @@ -49,30 +49,25 @@ function pollCalc() { return days * 86400 + hrs * 3600 + mins * 60 } //Vote -function voteSelMastodon(acct_id, id, to, mul) { - if ($('.vote_' + acct_id + '_' + id + '_' + to).hasClass('sel')) { - $('.vote_' + acct_id + '_' + id + '_' + to).css('background-color', 'transparent') - $('.vote_' + acct_id + '_' + id + '_' + to).removeClass('sel') +function voteSelMastodon(acct_id, id, to, mul, elem) { + if ($(elem).hasClass('sel')) { + $(elem).css('background-color', 'transparent') + $(elem).removeClass('sel') } else { if (!mul) { - $('.vote_' + acct_id + '_' + id + ' div').each(function(i, elem) { - if (i == to) { - $(this).css('background-color', 'var(--emphasized)') - $(this).addClass('sel') - } else { - $(this).css('background-color', 'transparent') - $(this).removeClass('sel') - } - }) + $('.vote_' + acct_id + '_' + id + ' div').css('background-color', 'transparent') + $('.vote_' + acct_id + '_' + id + ' div').removeClass('sel') + $(elem).css('background-color', 'var(--emphasized)') + $(elem).addClass('sel') } else { - $('.vote_' + acct_id + '_' + id + '_' + to).css('background-color', 'var(--emphasized)') - $('.vote_' + acct_id + '_' + id + '_' + to).addClass('sel') + $(elem).css('background-color', 'var(--emphasized)') + $(elem).addClass('sel') } } } -function voteMastodon(acct_id, id) { +function voteMastodon(acct_id, id, target) { var choice = [] - $('.vote_' + acct_id + '_' + id + ' div').each(function(i, elem) { + $(`#vote${target} div`).each(function(i, elem) { if ($(this).hasClass('sel')) { choice.push(i + '') } @@ -90,13 +85,13 @@ function voteMastodon(acct_id, id) { httpreq.responseType = 'json' httpreq.send(JSON.stringify({ choices: choice })) httpreq.onreadystatechange = function() { - voteMastodonrefresh(acct_id, id) + voteMastodonrefresh(acct_id, id, target) } } function showResult(acct_id, id) { $('.vote_' + acct_id + '_' + id + '_result').toggleClass('hide') } -function voteMastodonrefresh(acct_id, id) { +function voteMastodonrefresh(acct_id, id, target) { var datetype = localStorage.getItem('datetype') if (!datetype) { datetype = 'absolute' @@ -121,7 +116,7 @@ function voteMastodonrefresh(acct_id, id) { return false } var poll = pollParse(json, acct_id, json.emojis) - $('.vote_' + acct_id + '_' + json.id).html(poll) + $(`#vote${target}`).html(poll) } } }