From 94b133d5cbe0f59ca57fc9ee72ecf517f248dfb4 Mon Sep 17 00:00:00 2001
From: Yuriy Maksymets <iurii.maksymets@gmail.com>
Date: Sun, 1 Dec 2019 23:13:25 +0000
Subject: [PATCH] Fixed colour and radius setting

---
 src/tool-selection.js | 28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/src/tool-selection.js b/src/tool-selection.js
index e8b0e8c..2928c0f 100644
--- a/src/tool-selection.js
+++ b/src/tool-selection.js
@@ -27,8 +27,20 @@ const hideElement = (element) => {
   element.style.display = "none"
 }
 
-HTML.strokeColorPicker.setAttribute("value", strokeColour)
-HTML.strokeRadiusSlider.setAttribute("value", strokeRadius)
+function setStrokeColour(colour) {
+  HTML.rectangle.style.backgroundColor = colour
+  HTML.strokeColorPicker.value = colour
+  HTML.labelColours.style.backgroundColor = colour
+  strokeColour = colour
+}
+
+function setStrokeRadius(value) {
+  HTML.strokeRadiusSlider.setAttribute("value", value)
+  strokeRadius = value / 2
+}
+
+setStrokeColour(strokeColour)
+setStrokeRadius(strokeRadius)
 
 HTML.recognitionModeButton.addEventListener("click", () => {
   recognitionEnabled = !recognitionEnabled
@@ -57,9 +69,7 @@ HTML.eraserButton.addEventListener("click", () => {
 
 HTML.strokeColorPicker.addEventListener("change", () => {
   const paletteColour = event.target.value
-  HTML.rectangle.style.backgroundColor = paletteColour
-  HTML.labelColours.style.backgroundColor = paletteColour
-  strokeColour = paletteColour
+  setStrokeColour(paletteColour)
 })
 
 HTML.strokeRadiusSlider.oninput = function() {
@@ -72,8 +82,7 @@ HTML.output.innerHTML = HTML.strokeRadiusSlider.value
 // If the page has been refreshed
 if (performance.navigation.type == 1) {
   const sliderValue = parseInt(HTML.output.innerHTML)
-  HTML.strokeRadiusSlider.setAttribute("value", sliderValue)
-  strokeRadius = sliderValue / 2
+  setStrokeRadius(sliderValue)
 }
 
 const x = window.matchMedia(
@@ -111,10 +120,7 @@ const svg = HTML.wheel.children
 for (let i = 1; i < svg.length; i++) {
   svg[i].addEventListener("click", (event) => {
     const paletteColour = event.target.getAttribute("fill")
-    HTML.rectangle.style.backgroundColor = paletteColour
-    HTML.strokeColorPicker.value = paletteColour
-    HTML.labelColours.style.backgroundColor = paletteColour
-    strokeColour = paletteColour
+    setStrokeColour(paletteColour)
     hideElement(HTML.palette)
   })
 }
-- 
GitLab