From 1e2d65d3d715664c6c95e74b17bdb7024bb02c17 Mon Sep 17 00:00:00 2001 From: abhiabhi94 <13880786+abhiabhi94@users.noreply.github.com> Date: Tue, 20 Oct 2020 10:05:30 +0530 Subject: [PATCH] Fix icon title when flagging/unflagging --- flag/static/flag/js/flag.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/flag/static/flag/js/flag.js b/flag/static/flag/js/flag.js index 3675f0c..68e4077 100644 --- a/flag/static/flag/js/flag.js +++ b/flag/static/flag/js/flag.js @@ -44,6 +44,15 @@ document.addEventListener('DOMContentLoaded', function () { } }; + const toggleTitle = function (element, action) { + const spanEle = element.querySelector('span'); + if (action == 'add') { + spanEle.title = 'Remove flag'; + } else { + spanEle.title = 'Report content'; + } + }; + const createInfoElement = function (responseEle, status, msg, duration = 2) { switch (status) { case -1: @@ -144,20 +153,23 @@ document.addEventListener('DOMContentLoaded', function () { if (response) { createInfoElement(flagEle.parentElement, response.status, response.msg); const modal = flagEle.nextElementSibling; + let action; if (response.flag === 1) { - toggleClass(flagIcon, addClass, removeClass, action = 'add'); + action = 'add'; hideModal(modal); flagEle.removeEventListener('click', showModal); flagEle.addEventListener('click', removeFlag); } else { - toggleClass(flagIcon, addClass, removeClass, action = 'remove'); + action = 'remove'; flagEle.removeEventListener('click', removeFlag); flagEle.addEventListener('click', showModal); prepareFlagModal(flagEle); - }; - }; + } + toggleClass(flagIcon, addClass, removeClass, action); + toggleTitle(flagEle, action); + } }).catch(function (error) { - alert('The flagging request could not be processed. Please try again.') + alert('The flagging request could not be processed. Please try again.'); }); };