jQuery(function ($){
var selector=null;
var lightbox=null;
var allowedTags={
a: ["href", "title", "target", "rel"],
b: [],
i: [],
u: [],
em: [],
strong: [],
p: [],
br: [],
span: ["class", "id", "style"],
img: ["src", "alt", "title"],
h1: [],
h2: [],
h4: [],
h4: [],
h5: [],
h6: [],
ul: [],
ol: [],
li: [],
};
var sanitizeHTML=function (str){
var tempDiv=document.createElement("div");
tempDiv.innerHTML=str;
var elements=tempDiv.querySelectorAll("*");
elements.forEach(function (el){
var tagName=el.tagName.toLowerCase();
if(!allowedTags.hasOwnProperty(tagName)){
el.replaceWith(el.innerHTML);
return;
}
var allowedAttributes=allowedTags[tagName];
for (var i=el.attributes.length - 1; i >=0; i--){
var attrName=el.attributes[i].name;
var attrValue=el.attributes[i].value;
if(!allowedAttributes.includes(attrName)){
el.removeAttribute(attrName);
}
if(["href", "src"].includes(attrName) &&
attrValue.startsWith("javascript:")
){
el.removeAttribute(attrName);
}
if(attrName==="title"){
el.setAttribute("title", sanitizeTitle(attrValue));
}}
});
var sanitizedText=tempDiv.innerHTML;
return sanitizedText.replace(/\\/g, "");
};
var sanitizeTitle=function (title){
return title
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;");
};
var sanitizeCaptions=function (){
$(".ngg-simplelightbox").each(function (){
var caption=$(this).attr("title");
if(caption){
var sanitizedCaption=sanitizeHTML(caption);
$(this).attr("title", sanitizedCaption);
}});
};
var nextgen_simplebox_options={
history: false,
animationSlide: false,
animationSpeed: 100,
captionSelector: "self",
};
var nextgen_simplelightbox_init=function (){
sanitizeCaptions();
selector=nextgen_lightbox_filter_selector($, $(".ngg-simplelightbox"));
if(selector.length > 0){
lightbox=selector.simpleLightbox(nextgen_simplebox_options);
}};
nextgen_simplelightbox_init();
$(window).on("refreshed", function (){
if(lightbox){
lightbox.destroy();
}
sanitizeCaptions();
selector=nextgen_lightbox_filter_selector($, $(".ngg-simplelightbox"));
if(selector.length > 0){
lightbox=selector.simpleLightbox(nextgen_simplebox_options);
}});
});