From d15348ed505096f68dc8df2bac01083d26016538 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Wed, 8 May 2024 13:15:10 +0200 Subject: [PATCH] Extend updateStatusIcon() to set title too All calls to updateStatusIcon() were followed by setting the title. --- service.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/service.js b/service.js index 5a2e846..4dc6a0d 100644 --- a/service.js +++ b/service.js @@ -73,9 +73,7 @@ class BesService { * @param {Node} node DOM root node to proof */ proof(node) { - this.updateStatusIcon('bes-status-loading') - this.statusDiv.title = 'BesService je v procesu preverjanja pravopisa.' - + this.updateStatusIcon('bes-status-loading', 'BesService je v procesu preverjanja pravopisa.') this.recursiveProof(node) // TODO: Check count in 'makrofinančno' case. @@ -83,13 +81,10 @@ class BesService { (total, child) => total + child.matches.length, 0 ) - if (count > 0) { - this.updateStatusIcon('bes-status-mistakes') - this.statusDiv.title = 'Število napak: ' + count - } else { - this.updateStatusIcon('bes-status-success') - this.statusDiv.title = 'V besedilu ni napak.' - } + if (count > 0) + this.updateStatusIcon('bes-status-mistakes', 'Število napak: ' + count) + else + this.updateStatusIcon('bes-status-success', 'V besedilu ni napak.') } /** @@ -136,8 +131,7 @@ class BesService { await fetch(request, { signal }) .then(response => { if (!response.ok) { - this.updateStatusIcon('bes-status-error') - this.statusDiv.title = 'Napaka pri preverjanju pravopisa.' + this.updateStatusIcon('bes-status-error', 'Napaka pri preverjanju pravopisa.') throw new Error('Backend server response was not OK') } return response.json() @@ -196,8 +190,7 @@ class BesService { }) .catch(error => { if (error.name === 'AbortError') return - this.updateStatusIcon('bes-status-error') - this.statusDiv.title = 'Napaka pri preverjanju pravopisa.' + this.updateStatusIcon('bes-status-error', 'Napaka pri preverjanju pravopisa.') throw new Error( 'Parsing backend server response failed: ' + error ) @@ -410,7 +403,13 @@ class BesService { return { clientRects, highlights } } - updateStatusIcon(status) { + /** + * Sets status icon style and title + * + * @param {String} status CSS class name to set status icon to + * @param {String} title Title of the status icon + */ + updateStatusIcon(status, title) { const statuses = [ 'bes-status-loading', 'bes-status-success', @@ -421,6 +420,7 @@ class BesService { this.statusIcon.classList.remove(statusClass) }) this.statusIcon.classList.add(status) + this.statusDiv.title = title } handleStatusClick(e, popup) {