Add blog image JS to list page.
This commit is contained in:
parent
e36459c3b8
commit
f5fa4ca853
3 changed files with 2 additions and 2 deletions
29
Website/Views/Shared/_BlogImageJs.cshtml
Normal file
29
Website/Views/Shared/_BlogImageJs.cshtml
Normal file
|
@ -0,0 +1,29 @@
|
|||
<script type="text/javascript">
|
||||
function adornImage(image, append) {
|
||||
var parent = image.parentNode;
|
||||
parent.removeChild(image);
|
||||
image.className = "blog-post__image-container--image";
|
||||
|
||||
var tagLine = document.createElement("span");
|
||||
tagLine.className = "blog-post__image-container--tagline";
|
||||
tagLine.innerText = image.getAttribute("alt");
|
||||
|
||||
var container = document.createElement("div");
|
||||
container.className = "blog-post__image-container";
|
||||
container.appendChild(image);
|
||||
container.appendChild(tagLine);
|
||||
|
||||
var containerContainer = document.createElement("div");
|
||||
containerContainer.className = "blog-post__image-container--container";
|
||||
containerContainer.appendChild(container);
|
||||
|
||||
if (append)
|
||||
parent.appendChild(containerContainer);
|
||||
else
|
||||
parent.prepend(containerContainer);
|
||||
}
|
||||
|
||||
|
||||
document.querySelectorAll("p>img:only-child,p>img:first-child").forEach(image => adornImage(image, false));
|
||||
document.querySelectorAll("p>img:last-child").forEach(image => adornImage(image, true));
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue