Last active
June 30, 2023 14:12
-
-
Save anoopt/1c2387eeea1b49cb6de659ab1b2bf405 to your computer and use it in GitHub Desktop.
This file contains 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
NWF$(document).ready(function () { | |
$pnp.setup({ | |
sp: { | |
headers: { | |
"Accept": "application/json; odata=verbose" | |
} | |
} | |
}); | |
var isDisplayMode = document.location.pathname.indexOf("/DispForm.aspx") > -1; | |
if (isDisplayMode) { | |
showAttachments(); | |
} | |
}); | |
function showAttachments() { | |
/* get item ID from URL */ | |
var urlParams = new URLSearchParams(window.location.search); | |
var itemId = urlParams.get('ID'); | |
var item = $pnp.sp.web.lists.getByTitle("SimpleList").items.getById(itemId); | |
var attachmentsTarget = NWF$('#tbxAttachments'); | |
item.attachmentFiles.select("FileName,ServerRelativeUrl").get().then(function (itemAttachments) { | |
var attachments = itemAttachments.map(function (result) { | |
return NWF$('<img/>', { | |
src: result.ServerRelativeUrl, | |
alt: result.FileName, | |
style: "margin:5px;width:100px;height:100px;float:left;", | |
class: "item-attachment" | |
}); | |
}); | |
/* add the images to the target element */ | |
attachments.forEach(function (element) { | |
element.appendTo(attachmentsTarget); | |
}); | |
/* add click event for each image */ | |
NWF$(".item-attachment").each(function (index) { | |
NWF$(this).click(function () { | |
Swal.fire({ | |
imageUrl: NWF$(this).attr('src'), | |
imageAlt: NWF$(this).attr('alt') | |
}) | |
}); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment