diff options
author | weru <fromweru@gmail.com> | 2022-02-22 03:08:49 +0300 |
---|---|---|
committer | weru <fromweru@gmail.com> | 2022-02-22 03:09:18 +0300 |
commit | 17e6574dd5c9a87ab1033538a4b426ce9e93f18a (patch) | |
tree | f752c67f5601a2c3e903a1175c2cc921dfefceae /assets | |
parent | d9bf479a91bc6ae590d2c0b48271d694de90d1a2 (diff) |
fix: prevent double captioning #265
Signed-off-by: weru <fromweru@gmail.com>
Diffstat (limited to 'assets')
-rw-r--r-- | assets/js/index.js | 6 | ||||
-rw-r--r-- | assets/js/variables.js | 3 |
2 files changed, 7 insertions, 2 deletions
diff --git a/assets/js/index.js b/assets/js/index.js index 4aec3e6..57354c2 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -267,7 +267,7 @@ function fileClosure(){ const showImagePosition = showingImagePosition(); let desc = document.createElement('figcaption'); - desc.classList.add('img_alt'); + desc.classList.add(imageAltClass); const thisImgPos = image.dataset.pos; // modify image caption is necessary @@ -276,6 +276,10 @@ function fileClosure(){ if(!image.matches(`.${featuredImageClass}`)) { // add a caption below image only if the image isn't a featured image + if(image.nextElementSibling) { + // check if a caption exist already and remove it + image.nextElementSibling.remove(); + } image.insertAdjacentHTML('afterend', desc.outerHTML); } } diff --git a/assets/js/variables.js b/assets/js/variables.js index 7c774e2..75fefe4 100644 --- a/assets/js/variables.js +++ b/assets/js/variables.js @@ -1,4 +1,5 @@ const featuredImageClass = 'image_featured'; const imageScalableClass = 'image-scalable'; const scaleImageClass = 'image-scale'; -const pageHasLoaded = 'DOMContentLoaded';
\ No newline at end of file +const pageHasLoaded = 'DOMContentLoaded'; +const imageAltClass = 'img_alt'
\ No newline at end of file |