From 68c78235192a78336e556375f80e3d1b45917ce5 Mon Sep 17 00:00:00 2001
From: Xavier Grosjean <grosjean@adobe.com>
Date: Thu, 26 Oct 2017 13:00:43 +0200
Subject: [PATCH] Factorized caption initialization.

---
 resources/glyphEditor.html | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/resources/glyphEditor.html b/resources/glyphEditor.html
index cd550be..3125189 100644
--- a/resources/glyphEditor.html
+++ b/resources/glyphEditor.html
@@ -164,13 +164,17 @@ const char My_Font[] PROGMEM = {
         // Should we have a Char and a Pixel class ? not sure it's worth it.
         // Let's use the DOM to store everything for now
         
+        static updateCaption(element, code) {
+          element.textContent = `Char #${code}`;
+        }
+        
         // Add a pixel matrix to draw a new character
         // jumpaData not used for now: some day, use the last byte for optimisation 
         addChar(jumpData, charData) {
           let charContainer = this.fontContainer.appendChild(document.createElement("table"));
           charContainer.setAttribute("code", this.currentCharCode);
           let caption = charContainer.appendChild(document.createElement("caption"));
-          caption.textContent =`Char #${this.currentCharCode}`;
+          Font.updateCaption(caption, this.currentCharCode);
           let header = charContainer.appendChild(document.createElement("tr"));
           header.innerHTML = '<th  title="Delete this char" action="delete">&cross;</th>'
               + '<th title="Add a char above" action="add">+</th>'
@@ -298,7 +302,7 @@ const char My_Font[] PROGMEM = {
           // Browse each character
           for(let ch = 0; ch < charCount; ch++) {
             // Fix renumbering in case first char code was modified  
-            chars[ch].getElementsByTagName('caption')[0].textContent = `Char #${ch + firstCharCode}`;
+            Font.updateCaption(chars[ch].getElementsByTagName('caption')[0], ch + firstCharCode);
             let charBytes = [];
             let charCode = ch + firstCharCode;
             let rows = chars[ch].getElementsByTagName('tr');
@@ -403,7 +407,7 @@ const char My_Font[] PROGMEM = {
             currentContainer.parentNode.insertBefore(nextContainer, currentContainer);
             do {
               nextContainer.setAttribute('code', code);
-              nextContainer.getElementsByTagName('caption')[0].textContent = `Char #${code}`;
+              Font.updateCaption(nextContainer.getElementsByTagName('caption')[0], code);
               code ++;
             } while (nextContainer = nextContainer.nextSibling);
             break;
@@ -415,7 +419,7 @@ const char My_Font[] PROGMEM = {
             nextContainer = currentContainer;
             while (nextContainer = nextContainer.nextSibling) {
               nextContainer.setAttribute('code', code);
-              nextContainer.getElementsByTagName('caption')[0].textContent = `Char #${code}`;
+              Font.updateCaption(nextContainer.getElementsByTagName('caption')[0], code);
               code ++;
             }
             currentContainer.parentNode.removeChild(currentContainer);
-- 
GitLab