Created
November 3, 2017 19:38
-
-
Save hayduke19us/22c490166e4382daa3effb61de771a01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function setModalElementByClass(class_name, inner_html) { | |
var element = document.getElementsByClassName(class_name)[0] | |
if (element) { | |
element.innerHTML = inner_html; | |
} else { | |
console.log('Missing modal element class: ' + class_name) | |
} | |
} | |
function sendContentToModalListener(funct) { | |
return function() { | |
funct(this.dataset); | |
} | |
} | |
function sendImageToModal(content) { | |
setModalElementByClass('modal-title', '<a target="_blank" href=' + content.title + '>' + content.title + '</a>'); | |
setModalElementByClass('modal-body', '<img src=' + content.url + ' height="100%" width="100%"><img>'); | |
setModalElementByClass('modal-table', "<table class='table'>" + content.content + "</table>"); | |
} | |
function addOnClickListenersByClass(class_name, funct) { | |
var elements = document.getElementsByClassName(class_name); | |
if (elements.length) { | |
for(i = 0; i < elements.length; i++) { | |
elements[i].addEventListener('click', funct) | |
} | |
} | |
} | |
document.addEventListener( | |
'DOMContentLoaded', | |
addOnClickListenersByClass('thumbnail property-image', sendContentToModalListener(sendImageToModal)) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment