Bläddra i källkod

refactor for desc and img handleInputButtonClick

weichen 4 år sedan
förälder
incheckning
d7b1095f71
2 ändrade filer med 9 tillägg och 15 borttagningar
  1. 3 9
      editor.js
  2. 6 6
      parsers.js

+ 3 - 9
editor.js

@@ -39,26 +39,20 @@ axios.get('/公仔與爵士鼓.md').then(function(response) {
       dataIndex += 1;
       const {p, descTextArea, descInputButton} = getdescElements(blockDiv);
       descInputButton.onclick = function() {
-        const text = descTextArea.value;
-        p.textContent = text;
-        addDataToBlockArray({description: {text: text}}, blockArray, blockIndex, ownDataIndex)
+        blockArray = handleDescInputClick(p, descTextArea.value, blockArray, blockindex, ownDataIndex);
       }
     }
     imgButton.onclick = function() {
-      const ownDataIndex = dataIndex;
+      const imgDataIndex = dataIndex;
       dataIndex += 1;
       const {img, imgInput, widthInput, heightInput, imgInputButton} = getImgElements(blockDiv);
       imgInputButton.onclick = function() {
-        img.setAttribute('src', imgInput.value);
-        img.setAttribute('width', widthInput.value);
-        img.setAttribute('height', heightInput.value);
-        img.setAttribute('alt', 'image field');
         const imgObject = {image: {src: imgInput.value,
                                    height: heightInput.value,
                                    width: widthInput.value,
                                    alt: 'image field',
                                    layout: 'responsive'}};
-        blockArray = addDataToBlockArray(imgObject, blockArray, blockIndex, ownDataIndex)
+        blockArray = handleImgInputClick(img, imgObject, blockArray, blockIndex, imgDataIndex);
       }
     }
   }

+ 6 - 6
parsers.js

@@ -41,7 +41,7 @@ function parseMd(content) {
         const ownDataIndex = blockArray[preBlockindex].data.length;
         const {p, descTextArea, descInputButton} = getdescElements(blockDiv);
         descInputButton.onclick = function() {
-          blockArray = handleDescInputClick(p, descTextArea.value, blockArray, preBlockindex, ownDataIndex)
+          blockArray = handleDescInputClick(p, descTextArea.value, blockArray, preBlockindex, ownDataIndex);
         }
       }
       imgButton.onclick = function() {
@@ -53,13 +53,13 @@ function parseMd(content) {
                                      width: widthInput.value,
                                      alt: 'image field',
                                      layout: 'responsive'}};
-          blockArray = handleImgInputClick(img, imgObject, blockArray, preBlockindex, imgDataIndex)
+          blockArray = handleImgInputClick(img, imgObject, blockArray, preBlockindex, imgDataIndex);
         }
       }
     } else if (line.includes('amp-img')) {
       const preBlockindex = blockCount;
       if (line.includes('</amp-img>')) {
-        blockArray = addDataToBlockArray(preImgObject, blockArray, preBlockindex, imgDataIndex)
+        blockArray = addDataToBlockArray(preImgObject, blockArray, preBlockindex, imgDataIndex);
         isAmpImgRange = false;
         continue;
       }
@@ -74,7 +74,7 @@ function parseMd(content) {
                                    width: widthInput.value,
                                    alt: 'image field',
                                    layout: 'responsive'}};
-        blockArray = handleImgInputClick(img, imgObject, blockArray, preBlockindex, imgDataIndex)
+        blockArray = handleImgInputClick(img, imgObject, blockArray, preBlockindex, imgDataIndex);
       }
     } else {
       const preBlockindex = blockCount;
@@ -83,9 +83,9 @@ function parseMd(content) {
       const {p, descTextArea, descInputButton} = getdescElements(parseBlockDiv);
       const text = line;
       p.textContent = text;
-      blockArray = addDataToBlockArray({description: {text: text}}, blockArray, preBlockindex, ownDataIndex)
+      blockArray = addDataToBlockArray({description: {text: text}}, blockArray, preBlockindex, ownDataIndex);
       descInputButton.onclick = function() {
-        blockArray = handleDescInputClick(p, descTextArea.value, blockArray, preBlockindex, ownDataIndex)
+        blockArray = handleDescInputClick(p, descTextArea.value, blockArray, preBlockindex, ownDataIndex);
       }
     }
   }