wordpress custom theme on click event slug throwing error - javascript

I trying to add another custom post type to my navigation with a dynamic link, since it is taking you to the first blog post of this newly added post type.
The links and sites are generated finely, the type is showing up in my navigation, yet the click event is throwing an error, so not taking me to the archive/post.
the website is: www.vaterblut.com
the navigation item is: Muttererde
Uncaught TypeError: Cannot read properties of undefined (reading 'slug')
at HTMLAnchorElement.<anonymous> (main.min.js?ver=2.4:507:31)
at HTMLDivElement.dispatch (lib.min.js?ver=2.4:2:43090)
at v.handle (lib.min.js?ver=2.4:2:41074)
This is my javascript, the error is telling me it doesn't find my slug, but the same code works on fine on the other custom post type (schlagzeilen). I am not finding the mistake and would be happy for any help!
var VATERBLUT = function () {
function e(i) {
(i = parseInt(i, 10)),
$(".nav__link").each(function () {
var e = $("span", this),
t = e.parent(),
t = (t.height(), t.width()),
t = parseInt(e.css("fontSize"), 10) * (t / e.width());
e.css("fontSize", 0 < i && i < t ? i : t);
});
}
setTimeout(function () {
var e = Math.floor(11 * Math.random()) + 6;
$(".nav").animate({ scrollTop: "+=" + e + "000px" }, 1400, "swing");
}, 200),
e();
$(".nav__inner").outerHeight();
$(".nav__inner").contents().clone().appendTo(".nav__inner"),
$(".nav").scroll(function () {
$(this).scrollTop() + $(this).innerHeight() >=
$(this)[0].scrollHeight - 300 &&
$(".nav__inner").contents().clone().appendTo(".nav__inner");
});
var l,
t = [],
n = [],
d = [];
function a() {
$("#video").remove(),
$(".flickity-lazyloaded").removeClass("flickity-lazyloaded--hidden"),
$(".carousel-play-trigger").removeClass("carousel-play-trigger--active");
}
function g() {
$(window).width() < 769
? $(".carousel-main").hasClass("flickity-enabled")
? l.destroy()
: $(".carousel-cell").each(function () {
var e = $(this).find("img"),
t = e.data("flickity-lazyload");
e.attr("src", t), e.addClass("flickity-lazyloaded");
})
: $(".carousel-main").hasClass("flickity-enabled") ||
(0 < $(".carousel").length &&
((l = new Flickity(".carousel-main", {
cellAlign: "center",
contain: !0,
wrapAround: !0,
lazyLoad: 4,
imagesLoaded: !0,
pageDots: !1,
prevNextButtons: !1,
setGallerySize: !1,
})).on("staticClick", function (e, t, i, s) {
var a = $(window).width() / 2;
e.pageX < a - 80 ? l.previous() : e.pageX > 80 + a && l.next();
}),
l.on("change", function (e, t, i, s) {
0 < $("#video").length && a(),
$(l.selectedElement).data("id") &&
o($(l.selectedElement).data("id"));
})));
}
function h(e) {
$(".languages").length &&
((e =
"en" == wp.curLang
? e
? wp.siteUrl + "/" + e
: wp.siteUrl + "/"
: e
? wp.siteUrl + "/en/" + e
: wp.siteUrl + "/en/"),
$(".languages__link").attr("href", e));
}
function o(s) {
$.each(n, function (e) {
var t, i;
s == this.id &&
((i = this.slug),
(t = this.date),
(t = new Date(t).toLocaleDateString("de-De", {
year: "numeric",
month: "long",
day: "2-digit",
})),
window.history.pushState(
null,
null,
"en" == wp.curLang
? wp.siteUrl + "/en/schlagzeile/" + i + "/"
: wp.siteUrl + "/schlagzeile/" + i + "/"
),
$(".languages").length &&
((i =
"en" == wp.curLang
? i
? wp.siteUrl + "/schlagzeile/" + i
: wp.siteUrl + "/"
: i
? wp.siteUrl + "/en/schlagzeile/" + i
: wp.siteUrl + "/en/"),
$(".languages__link").attr("href", i)),
$(".article").empty(),
$(".article").append(
("bottom" == this.acf["schlagzeile_title-placement"]
? '<h1 class="article__header blog__header"><span style="background-color: ' +
this.acf.highlight_color +
'">' +
this.title.rendered +
"</span></h1>"
: "") +
'<div class="article__content">' +
this.acf.schlagzeile_text +
"</div>"
),
$(".details__inner").remove(),
$(".details").append(
'<div class="details__inner"><div class="details__content"><div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang ? "Date" : "Datum") +
'</h3><div class="details__text">' +
t +
"</div></div>" +
(this.acf.schlagzeile_links
? '<div class="details__item"><h3 class="details__title">Links</h3><div class="details__text">' +
this.acf.schlagzeile_links +
"</div></div>"
: "") +
(this.acf.schlagzeile_hashtags
? '<div class="details__item"><h3 class="details__title">Hashtags</h3><div class="details__text">' +
this.acf.schlagzeile_hashtags +
"</div></div>"
: "") +
(this.acf.schlagzeile_author
? '<div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang ? "Author" : "Autor") +
'</h3><div class="details__text">' +
this.acf.schlagzeile_author +
"</div></div>"
: "") +
"</div></div>"
));
});
}
function oy(t) {
$.each(n, function (e) {
var t, i;
s == this.id &&
((i = this.slug),
(t = this.date),
(t = new Date(t).toLocaleDateString("de-De", {
year: "numeric",
month: "long",
day: "2-digit",
})),
window.history.pushState(
null,
null,
"en" == wp.curLang
? wp.siteUrl + "/en/muttererde/" + i + "/"
: wp.siteUrl + "/muttererde/" + i + "/"
),
$(".languages").length &&
((i =
"en" == wp.curLang
? s
? wp.siteUrl + "/muttererde/" + i
: wp.siteUrl + "/"
: s
? wp.siteUrl + "/en/muttererde/" + i
: wp.siteUrl + "/en/"),
$(".languages__link").attr("href", i)),
$(".article").empty(),
$(".article").append(
("bottom" == this.acf["muttererde_title-placement"]
? '<h1 class="article__header blog__header"><span style="background-color: ' +
this.acf.highlight_color +
'">' +
this.title.rendered +
"</span></h1>"
: "") +
'<div class="article__content">' +
this.acf.muttererde_text +
"</div>"
),
$(".details__inner").remove(),
$(".details").append(
'<div class="details__inner"><div class="details__content"><div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang ? "Date" : "Datum") +
'</h3><div class="details__text">' +
t +
"</div></div>" +
(this.acf.muttererde_links
? '<div class="details__item"><h3 class="details__title">Links</h3><div class="details__text">' +
this.acf.muttererde_links +
"</div></div>"
: "") +
(this.acf.muttererde_hashtags
? '<div class="details__item"><h3 class="details__title">Hashtags</h3><div class="details__text">' +
this.acf.muttererde_hashtags +
"</div></div>"
: "") +
(this.acf.muttererde_author
? '<div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang ? "Author" : "Autor") +
'</h3><div class="details__text">' +
this.acf.muttererde_author +
"</div></div>"
: "") +
(this.acf.muttererde_checklisten
? '<div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang ? "Checklisten" : "Checklist") +
'</h3><div class="details__text">' +
this.acf.muttererde_checklisten +
"</div></div>"
: "") +
"</div></div>"
));
});
}
function i() {
window.history.pushState(
null,
null,
"en" == wp.curLang ? wp.siteUrl + "/en/" : wp.siteUrl + "/"
),
$(".section").addClass("section--invisible"),
setTimeout(function () {
$(".section").remove();
}, 450);
}
function _() {
$(".section").on("scroll", function () {
0 < $(this).scrollTop()
? $(".content-trigger").addClass("content-trigger--active")
: $(".content-trigger").removeClass("content-trigger--active");
var e = $(".section__footer").position().top - $(window).height();
e <= 0
? ((e = 1 + e / $(".section__footer").height()),
$(".section").css("opacity", e))
: $(".section").css("opacity", "1"),
$(this).scrollTop() >=
$(this)[0].scrollHeight - ($(window).height() + 5) && i();
}),
$(".carousel-main").on("scroll", function () {
$(this).scrollTop() + $(this).innerHeight() >=
$(this)[0].scrollHeight &&
$(".section").scrollTop() <= 0 &&
($(".content-trigger").hasClass("content-trigger--active") ||
setTimeout(function () {
var e = $(window).height() / 3;
$(".section").animate({ scrollTop: e }, 300, "swing");
}, 300),
$(".content-trigger").addClass("content-trigger--active"));
});
}
$(".root").on("click", ".banner", function (e) {
e.preventDefault(), h(), i();
}),
$(".root").on("click", ".carousel-cell", function (e) {
var t;
e.preventDefault(),
$(window).width() < 769 &&
((e = $(this).data("id")),
(t = $(window).height() / 3),
$(".section").animate({ scrollTop: t }, 200, "swing"),
$(".content-trigger").addClass("content-trigger--active"),
o(e));
}),
$(".root").on(
"click",
".nav__link:not(.nav__link--blog,.nav__link--mutter)",
function (e) {
var r;
e.preventDefault(),
$(this).hasClass("nav__link--active") &&
((e = $(this).data("id")), $(".section").length <= 0) &&
((r = e),
$.each(t, function (e) {
var t, i, s, a, l, n, o, c;
r == this.id &&
((t = this.slug),
this.acf.highlight_color,
(i = this.acf["text-editor"]),
(s = this.acf.highlight_color),
(a = this.acf.gallery),
(l = this.acf.project_kunde),
(n = this.acf["project_credits-fotos"]),
(o = this.acf.project_links),
(c = this.acf.project_leistung),
window.history.pushState(
null,
null,
"en" == wp.curLang
? wp.siteUrl + "/en/" + t + "/"
: wp.siteUrl + "/" + t + "/"
),
h(t),
$(".root").append(
'<main class="section section--hidden"><div class="section__inner">' +
(a
? '<div class="carousel" style="background-color: ' +
s +
'"><div class="carousel-main"></div><button class="button content-trigger"><svg class="content-trigger__icon" width="25" height="21" viewBox="0 0 25 21" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 21L0.808657 0.75L24.1913 0.750002L12.5 21Z" fill="black"/></svg></button></div>'
: "") +
(i
? '<div class="section__article article"><div class="article__content">' +
i +
"</div></div>"
: "") +
'<div class="section__details details"></div><div class="section__footer"></div></div></main>'
),
(l || n || o || c) &&
$(".details").append(
'<div class="details__inner"><div class="details__content">' +
(l
? '<div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang
? d[0].acf["credits_field_1_lang-en"]
: d[0].acf.credits_field_1) +
'</h3><div class="details__text">' +
l +
"</div></div>"
: "") +
(n
? '<div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang
? d[0].acf["credits_field_2_lang-en"]
: d[0].acf.credits_field_2) +
'</h3><div class="details__text">' +
n +
"</div></div>"
: "") +
(o
? '<div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang
? d[0].acf["credits_field_3_lang-en"]
: d[0].acf.credits_field_3) +
'</h3><div class="details__text">' +
o +
"</div></div>"
: "") +
(c
? '<div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang
? d[0].acf["credits_field_4_lang-en"]
: d[0].acf.credits_field_4) +
'</h3><div class="details__text">' +
c +
"</div></div>"
: "") +
"</div></div>"
),
0 < $(".carousel").length &&
$.each(a, function (e) {
var t = this.caption;
t
? $(".carousel-main").append(
'<div class="carousel-cell" data-id="' +
t +
'"><span class="carousel-overlay" style="background-color: ' +
s +
'"></span><button class="button carousel-play-trigger"><svg viewBox="0 0 21 25" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M21 12.5L0.750001 24.1913L0.750001 0.808657L21 12.5Z" fill="black"/></svg></button><div class="carousel-video"><img data-flickity-lazyload="' +
this.url +
'" alt="" class="carousel-image"></div></div>'
)
: $(".carousel-main").append(
'<div class="carousel-cell"><span class="carousel-overlay" style="background-color: ' +
s +
'"></span><img data-flickity-lazyload="' +
this.url +
'" alt="" class="carousel-image"></div>'
);
}),
_(),
setTimeout(function () {
$(".section").removeClass("section--hidden"),
setTimeout(function () {
g();
}, 650);
}, 200));
}));
}
),
$(".root").on("click", ".nav__link--blog", function (e) {
e.preventDefault();
var t,
i,
a,
e = $(this).data("ids");
(filteredBlogPosts = []),
(t = e).toString().includes(",")
? t.split(",").map(function (t) {
(blogPost = n.filter((e) => e.id == t)),
filteredBlogPosts.push(blogPost[0]);
})
: ((blogPost = n.filter((e) => e.id == t)),
filteredBlogPosts.push(blogPost[0])),
(e = filteredBlogPosts[0].slug),
(i = filteredBlogPosts[0].date),
(i = new Date(i).toLocaleDateString("de-De", {
year: "numeric",
month: "long",
day: "2-digit",
})),
(a = d[0].acf["schlagzeile_highlight-color"]),
window.history.pushState(
null,
null,
"en" == wp.curLang
? wp.siteUrl + "/en/schlagzeile/" + e + "/"
: wp.siteUrl + "/schlagzeile/" + e + "/"
),
$(".languages").length &&
((e =
"en" == wp.curLang
? e
? wp.siteUrl + "/schlagzeile/" + e
: wp.siteUrl + "/"
: e
? wp.siteUrl + "/en/schlagzeile/" + e
: wp.siteUrl + "/en/"),
$(".languages__link").attr("href", e)),
$(".root").append(
'<main class="blog blog--hidden section section--hidden"><div class="section__inner"><div class="carousel" style="background-color: ' +
a +
'"><div class="carousel-main"></div><button class="button content-trigger"><svg class="content-trigger__icon" width="25" height="21" viewBox="0 0 25 21" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 21L0.808657 0.75L24.1913 0.750002L12.5 21Z" fill="black"/></svg></button></div><div class="section__article article">' +
("bottom" == filteredBlogPosts[0].acf["schlagzeile_title-placement"]
? '<h1 class="article__header blog__header"><span style="background-color: ' +
filteredBlogPosts[0].acf.highlight_color +
'">' +
filteredBlogPosts[0].title.rendered +
"</span></h1>"
: "") +
'<div class="article__content">' +
filteredBlogPosts[0].acf.schlagzeile_text +
'</div></div><div class="section__details details"></div><div class="section__footer"></div></div></main>'
),
$.each(filteredBlogPosts, function (e) {
var t = this.title,
i = this.acf.highlight_color,
s = this.acf["schlagzeile_featured-image"];
$(".carousel-main").append(
'<div class="carousel-cell" data-id="' +
this.id +
'"><span class="carousel-overlay" style="background-color: ' +
a +
'"></span>' +
("top" == this.acf["schlagzeile_title-placement"]
? '<h1 class="blog__header"><span style="background-color: ' +
i +
'">' +
t.rendered +
"</span></h1>"
: "") +
'<img data-flickity-lazyload="' +
s.url +
'" alt="" class="carousel-image"></div>'
);
}),
$(".details").append(
'<div class="details__inner"><div class="details__content"><div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang ? "Date" : "Datum") +
'</h3><div class="details__text">' +
i +
"</div></div>" +
(filteredBlogPosts[0].acf.schlagzeile_links
? '<div class="details__item"><h3 class="details__title">Links</h3><div class="details__text">' +
filteredBlogPosts[0].acf.schlagzeile_links +
"</div></div>"
: "") +
(filteredBlogPosts[0].acf.schlagzeile_hashtags
? '<div class="details__item"><h3 class="details__title">Hashtags</h3><div class="details__text">' +
filteredBlogPosts[0].acf.schlagzeile_hashtags +
"</div></div>"
: "") +
(filteredBlogPosts[0].acf.schlagzeile_author
? '<div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang ? "Author" : "Autor") +
'</h3><div class="details__text">' +
filteredBlogPosts[0].acf.schlagzeile_author +
"</div></div>"
: "") +
"</div></div>"
),
_(),
setTimeout(function () {
$(".section").removeClass("section--hidden"),
setTimeout(function () {
g(), $(".blog").removeClass("blog--hidden");
}, 650);
}, 200);
}),
$(".root").on("click", ".nav__link--mutter", function (e) {
e.preventDefault();
var t,
i,
a,
e = $(this).data("ids");
(filteredBlogPosts = []),
(t = e).toString().includes(",")
? t.split(",").map(function (t) {
(blogPost = n.filter((e) => e.id == t)),
filteredBlogPosts.push(blogPost[0]);
})
: ((blogPost = n.filter((e) => e.id == t)),
filteredBlogPosts.push(blogPost[0])),
(e = filteredBlogPosts[0].slug),
(i = filteredBlogPosts[0].date),
(i = new Date(i).toLocaleDateString("de-De", {
year: "numeric",
month: "long",
day: "2-digit",
})),
(a = d[0].acf["muttererde_highlight-color"]),
window.history.pushState(
null,
null,
"en" == wp.curLang
? wp.siteUrl + "/en/muttererde/" + e + "/"
: wp.siteUrl + "/muttererde/" + e + "/"
),
$(".languages").length &&
((e =
"en" == wp.curLang
? e
? wp.siteUrl + "/muttererde/" + e
: wp.siteUrl + "/"
: e
? wp.siteUrl + "/en/muttererde/" + e
: wp.siteUrl + "/en/"),
$(".languages__link").attr("href", e)),
$(".root").append(
'<main class="blog blog--hidden section section--hidden"><div class="section__inner"><div class="carousel" style="background-color: ' +
a +
'"><div class="carousel-main"></div><button class="button content-trigger"><svg class="content-trigger__icon" width="25" height="21" viewBox="0 0 25 21" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M12.5 21L0.808657 0.75L24.1913 0.750002L12.5 21Z" fill="black"/></svg></button></div><div class="section__article article">' +
("bottom" == filteredBlogPosts[0].acf["muttererde_title-placement"]
? '<h1 class="article__header blog__header"><span style="background-color: ' +
filteredBlogPosts[0].acf.highlight_color +
'">' +
filteredBlogPosts[0].title.rendered +
"</span></h1>"
: "") +
'<div class="article__content">' +
filteredBlogPosts[0].acf.muttererde_text +
'</div></div><div class="section__details details"></div><div class="section__footer"></div></div></main>'
),
$.each(filteredBlogPosts, function (e) {
var t = this.title,
i = this.acf.highlight_color,
s = this.acf["muttererde_featured-image"];
$(".carousel-main").append(
'<div class="carousel-cell" data-id="' +
this.id +
'"><span class="carousel-overlay" style="background-color: ' +
a +
'"></span>' +
("top" == this.acf["muttererde_title-placement"]
? '<h1 class="blog__header"><span style="background-color: ' +
i +
'">' +
t.rendered +
"</span></h1>"
: "") +
'<img data-flickity-lazyload="' +
s.url +
'" alt="" class="carousel-image"></div>'
);
}),
$(".details").append(
'<div class="details__inner"><div class="details__content"><div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang ? "Date" : "Datum") +
'</h3><div class="details__text">' +
i +
"</div></div>" +
(filteredBlogPosts[0].acf.muttererde_links
? '<div class="details__item"><h3 class="details__title">Links</h3><div class="details__text">' +
filteredBlogPosts[0].acf.muttererde_links +
"</div></div>"
: "") +
(filteredBlogPosts[0].acf.muttererde_hashtags
? '<div class="details__item"><h3 class="details__title">Hashtags</h3><div class="details__text">' +
filteredBlogPosts[0].acf.muttererde_hashtags +
"</div></div>"
: "") +
(filteredBlogPosts[0].acf.muttererde_author
? '<div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang ? "Author" : "Autor") +
'</h3><div class="details__text">' +
filteredBlogPosts[0].acf.muttererde_author +
"</div></div>"
: "") +
(filteredBlogPosts[0].acf.muttererde_checkllisten
? '<div class="details__item"><h3 class="details__title">' +
("en" == wp.curLang ? "Checklisten" : "Checklist") +
'</h3><div class="details__text">' +
filteredBlogPosts[0].acf.muttererde_checklisten +
"</div></div>"
: "") +
"</div></div>"
),
_(),
setTimeout(function () {
$(".section").removeClass("section--hidden"),
setTimeout(function () {
g(), $(".blog").removeClass("blog--hidden");
}, 650);
}, 200);
}),
$(".root").on("click", ".content-trigger", function (e) {
var t;
$(".content-trigger").hasClass("content-trigger--active")
? ($(".section").animate({ scrollTop: 0 }, 200, "swing"),
$(".content-trigger").removeClass("content-trigger--active"))
: ((t = $(window).height() / 3),
$(".section").animate({ scrollTop: t }, 200, "swing"),
$(".content-trigger").addClass("content-trigger--active"));
}),
$(".root").on("click", ".carousel-play-trigger", function (e) {
a();
var t = $(this).closest(".carousel-cell").data("id");
$(this)
.parent()
.find(".carousel-video")
.append(
'<div id="video" data-vimeo-id="' +
t +
'" data-vimeo-autoplay="true" data-vimeo-loop="true" data-vimeo-controls="true" data-vimeo-playsinline="false"></div>'
),
new Vimeo.Player("video").on("play", function () {
var e = $("#video")
.closest(".carousel-cell")
.find(".carousel-play-trigger");
$("#video")
.closest(".carousel-cell")
.find(".carousel-image")
.addClass("flickity-lazyloaded--hidden"),
setTimeout(function () {
e.addClass("carousel-play-trigger--active");
}, 800);
});
}),
$(window).on("resize", function () {
e(), g();
}),
$.ajax({
type: "GET",
url:
wp.root +
"wp/v2/multiple-post-type?per_page=100&type[]=post&type[]=page&type[]=blog",
dataType: "JSON",
beforeSend: function () {},
success: function (e) {
$.each(e, function (e) {
("blog" == this.type ? n : t).push(this);
});
},
error: function () {
console.error("Oops, there was an error! Please try again.");
},
}),
$.ajax({
type: "GET",
url: wp.root + "acf/v3/options/options",
dataType: "JSON",
beforeSend: function () {},
success: function (e) {
d.push(e);
},
error: function () {
console.error("Oops, there was an error! Please try again.");
},
}),
g(),
Marquee3k.init(),
setTimeout(function () {
$(".nav").removeClass("nav--hidden");
}, 200),
_(),
$(".nav")
.on("scroll", function () {
var e = $(this).scrollTop() + $(window).height() / 2,
t = ($(".nav__link").removeClass("nav__link--active"), 0);
$(".nav__link").each(function () {
if (((t += $(this).outerHeight(!0)), e <= t))
return $(this).addClass("nav__link--active"), !1;
});
})
.trigger("scroll");
};
$(document).ready(function () {
VATERBLUT();
});

Related

How to use the first image like Thumbnail in Related Post widget for blogger?

r = ("media$thumbnail" in x[q] && d.thumbnailSize !== false) ? x[q].media$thumbnail.url.replace(/\/s[0-9]+(\-c)?/, "/s" + d.thumbnailSize + "-c") : d.noImage;
This line requires an image to be uploaded to Blogger.
What I want is to replace it so that it brings the first picture from the post and the link is external and not from Blogger.
The complete code is -
//<![CDATA[
/*! Related Post Widget for Blogger by Taufik Nurrohman => http://gplus.to/tovic */
var randomRelatedIndex, showRelatedPost;
(function(n, m, k) {
var d = {
widgetTitle: "<h4>Artikel Terkait:</h4>",
widgetStyle: 1,
homePage: "http://www.dte.web.id",
numPosts: 7,
summaryLength: 370,
titleLength: "auto",
thumbnailSize: 72,
noImage: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAA3NCSVQICAjb4U/gAAAADElEQVQImWOor68HAAL+AX7vOF2TAAAAAElFTkSuQmCC",
containerId: "related-post",
newTabLink: false,
moreText: "Baca Selengkapnya",
callBack: function() {}
};
for (var f in relatedPostConfig) {
d[f] = (relatedPostConfig[f] == "undefined") ? d[f] : relatedPostConfig[f]
}
var j = function(a) {
var b = m.createElement("script");
b.type = "text/javascript";
b.src = a;
k.appendChild(b)
},
o = function(b, a) {
return Math.floor(Math.random() * (a - b + 1)) + b
},
l = function(a) {
var p = a.length,
c, b;
if (p === 0) {
return false
}
while (--p) {
c = Math.floor(Math.random() * (p + 1));
b = a[p];
a[p] = a[c];
a[c] = b
}
return a
},
e = (typeof labelArray == "object" && labelArray.length > 0) ? "/-/" + l(labelArray)[0] : "",
h = function(b) {
var c = b.feed.openSearch$totalResults.$t - d.numPosts,
a = o(1, (c > 0 ? c : 1));
j(d.homePage.replace(/\/$/, "") + "/feeds/posts/summary" + e + "?alt=json-in-script&orderby=updated&start-index=" + a + "&max-results=" + d.numPosts + "&callback=showRelatedPost")
},
g = function(z) {
var s = document.getElementById(d.containerId),
x = l(z.feed.entry),
A = d.widgetStyle,
c = d.widgetTitle + '<ul class="related-post-style-' + A + '">',
b = d.newTabLink ? ' target="_blank"' : "",
y = '<span style="display:block;clear:both;"></span>',
v, t, w, r, u;
if (!s) {
return
}
for (var q = 0; q < d.numPosts; q++) {
if (q == x.length) {
break
}
t = x[q].title.$t;
w = (d.titleLength !== "auto" && d.titleLength < t.length) ? t.substring(0, d.titleLength) + "…" : t;
r = ("media$thumbnail" in x[q] && d.thumbnailSize !== false) ? x[q].media$thumbnail.url.replace(/\/s[0-9]+(\-c)?/, "/s" + d.thumbnailSize + "-c") : d.noImage;
u = ("summary" in x[q] && d.summaryLength > 0) ? x[q].summary.$t.replace(/<br ?\/?>/g, " ").replace(/<.*?>/g, "").replace(/[<>]/g, "").substring(0, d.summaryLength) + "…" : "";
for (var p = 0, a = x[q].link.length; p < a; p++) {
v = (x[q].link[p].rel == "alternate") ? x[q].link[p].href : "#"
}
if (A == 2) {
c += '<li><img class="related-post-item-thumbnail" alt="" src="' + r + '" width="' + d.thumbnailSize + '" height="' + d.thumbnailSize + '"><a class="related-post-item-title" title="' + t + '" href="' + v + '"' + b + ">" + w + '</a><span class="related-post-item-summary"><span class="related-post-item-summary-text">' + u + '</span> " + d.moreText + "</span>" + y + "</li>"
} else {
if (A == 3 || A == 4) {
c += '<li class="related-post-item" tabindex="0"><a class="related-post-item-title" href="' + v + '"' + b + '><img alt="" class="related-post-item-thumbnail" src="' + r + '" width="' + d.thumbnailSize + '" height="' + d.thumbnailSize + '"></a><div class="related-post-item-tooltip"><a class="related-post-item-title" title="' + t + '" href="' + v + '"' + b + ">" + w + "</a></div>" + y + "</li>"
} else {
if (A == 5) {
c += '<li class="related-post-item" tabindex="0"><a class="related-post-item-wrapper" href="' + v + '" title="' + t + '"' + b + '><img alt="" class="related-post-item-thumbnail" src="' + r + '" width="' + d.thumbnailSize + '" height="' + d.thumbnailSize + '"><span class="related-post-item-tooltip">' + w + "</span></a>" + y + "</li>"
} else {
if (A == 6) {
c += '<li><a class="related-post-item-title" title="' + t + '" href="' + v + '"' + b + ">" + w + '</a><div class="related-post-item-tooltip"><img alt="" class="related-post-item-thumbnail" src="' + r + '" width="' + d.thumbnailSize + '" height="' + d.thumbnailSize + '"><span class="related-post-item-summary"><span class="related-post-item-summary-text">' + u + "</span></span>" + y + "</div></li>"
} else {
c += '<li><a title="' + t + '" href="' + v + '"' + b + ">" + w + "</a></li>"
}
}
}
}
}
s.innerHTML = c += "</ul>" + y;
d.callBack()
};
randomRelatedIndex = h;
showRelatedPost = g;
j(d.homePage.replace(/\/$/, "") + "/feeds/posts/summary" + e + "?alt=json-in-script&orderby=updated&max-results=0&callback=randomRelatedIndex")
})(window, document, document.getElementsByTagName("head")[0]);
//]]>
I find a solution
change this
"/feeds/posts/default"
to
"/feeds/posts/summary"
and this
r = ("media$thumbnail" in x[q] && d.thumbnailSize !== false) ? x[q].media$thumbnail.url.replace(/\/s[0-9]+(\-c)?/, "/s" + d.thumbnailSize + "-c") : d.noImage;
to
if ("media$thumbnail" in x[q] && d.thumbnailSize !== false) {
r = x[q].media$thumbnail.url.replace(/\/s[0-9]+(-c)?/, "/s" + d.thumbnailSize + "/s72-c");
} else if (x[q].content.$t.match(/\<img.+src\=(?:\"|\')(.+?)(?:\"|\')(?:.+?)\>/)) {
r = x[q].content.$t.match(/\<img.+src\=(?:\"|\')(.+?)(?:\"|\')(?:.+?)\>/)[1];
} else {
r = d.noImage;
}
and this line
u = ("summary" in x[q] && d.summaryLength > 0) ? x[q].summary.$t.replace(/<br ?\/?>/g, " ").replace(/<.*?>/g, "").replace(/[<>]/g, "").substring(0, d.summaryLength) + "…" : "";
to
u = ("content" in x[q]) ? (x[q].content.$t.replace(/<.*?>/g, "")).substring(0, d.summaryLength) + '…' : "";

need to re-enable onmouseon disabled with onclick event

I'm trying to modify a prestashop module which allows to display groups of attributes by block: if the product has more than one group of attributes, the first block is displayed. After selecting one attribute of this group, the second group is displayed.
If the group of attributes is color, I need to display it in a popup.
I added this code at the end of the js file of the module:
$(document).ready(function(e) {
$('.input-color').on('mouseover', function(e){
let color = $(this).parent().find('.color').css('background-color');
let image = $(this).parent().find('.color').css('background-image');
console.log(color, 'this');
if(color) {
$('#cover-background').show().css({'background-color': color,'width': '400px', 'height': '400px',
'margin': '0 auto', 'position': 'absolute', 'z-index': 99, 'left': '-60%', 'top': '40%'});
}
if(image) {
$('#cover-background').show().css({'background-image': image,'width': '400px', 'height': '400px',
'margin': '0 auto', 'position': 'fixed', 'z-index':999, 'left': '20%', 'top':'30%'});
}
});
$('.input-color').on('mouseout', function(e){
$('#cover-background').hide();
});
});
And a div with id=cover-background
The popup works fine for the first group of attributes.
But after clicking on one of attributes, the onmouseover is disabled.
You can see it here : http://decoelem2.kamilane.odns.fr/16-15976-table-basse-relevable-extensible-bessy.html (click on the button PERSONNALISER to display the first group)
The code to display the block (it's just a part of all the code of the module):
$output += '<li class="float-xs-left pull-xs-left input-container color_' + k + ((/*(sizecolors && fa_colors[k]['value'] == '') ||*/ (fa_gray_color && in_array(k, attribNotInStockWith) && !allowBuyWhenOutOfStock)) ? ' fl_color_unavalable_li' : '') + '">\n\
<input id="color_' + k + '_' + j + '" class="input-color" type="radio"' + ((fa_gray_color && in_array(k, attribNotInStockWith) && !allowBuyWhenOutOfStock) ? ' disabled="true" title="' + not_avialable + '"' : ' title="' + attributes[l] + '"') + ' \n\
data-product-attribute="' + y + '" name="group[' + y + ']" \n\
value="' + k + '" onclick="set_selected_n(\'' + j + '\', ' + k + ',\'' + fa_key_val[j] + '\', 1);">\n\
<span ' + ((sizecolors && fa_colors[k]['value'] != '') ? 'class="color_select color" style="background-color: ' + fa_colors[k]['value'] + ';"' : '') + '\n\
' + ((sizecolors && fa_colors[k]['value'] == '') ? 'class="color_select color texture" style="background-image: url('+fa_colors[k]['img']+')"' : '') + '\
title="' + attributes[l] + '">\n\
<span class="sr-only">' + attributes[l] + '</span>\n\
' + ((fa_gray_color && in_array(k, attribNotInStockWith) && !allowBuyWhenOutOfStock) ? '<span title="' + not_avialable + '" class="disabled"></span>' : '') + '\n\
</span>\n\
</li>';
}
}
I can send the file or all the module if you need it.
Thanks a lot for your help!
[edit] Here is all of the function (I think):
function generate_html_content_bloc(first, id_group, id_group_next)
{
$output = '';
class_sup = '';
for (j in fa_groups) { //on parcourt les groupes d'attributs
groupName_id = 'fa_group_' + j;
groups = fa_groups[j];
name_group = groups['name'];
y = j.replace('g_', '');
if (!first && id_group_next != j){
if(array_key_exists(j, tread_group)){
$(".product-variants").append(tread_group[j]);
}
continue;
}
$output += '<div id="field_' + j + '" class="clearfix product-variants-item">';
$output += '<span class="control-label"><strong>Choisissez : </strong>' + name_group + ' </span><br />';
attributes = groups['attributes']; //On a ici le tableau des attributs pour le groupe
if (groups['group_type'] == 'radio') {
$output += '<ul id="group_' + j + '" class="radio_btn_list radio_btn_list_' + j + '">';
$output += '<li id="li_list_0_' + j + '" class="input-container pull-xs-left float-xs-left hide-element ' + class_sup + ' attr_disabled">\n\
<input id="g_radio_0' + j + '" class="input-radio attribute_radio g_radio_' + j + '" type="radio" data-product-attribute="' + y + '" \n\
name="group[' + y + ']" value="0" checked="checked" title="' + not_avialable + '" disabled="true">\n\
<span class="radio-label radio-label-desabled"> </span>\n\
</li>';
for (var k in attributes) {
l = k;
k = k.replace('k_','');
if (!fa_gray_radio && in_array(k, attribNotInStockWith) && !allowBuyWhenOutOfStock)
continue;
else if(!first && allowBuyWhenOutOfStock && displaydecoop && !in_array(k, attri_int_dec)) //on supprime les déclinaison non existantes
continue;
$output += '<li id="radio_' + k + '" class="input-container pull-xs-left float-xs-left' + ((fa_gray_radio && in_array(k, attribNotInStockWith) && !allowBuyWhenOutOfStock) ? ' attr_disabled"' : '') + '">\n\
<input type="radio"' + ((fa_gray_radio && in_array(k, attribNotInStockWith) && !allowBuyWhenOutOfStock) ? ' disabled="true" title="' + not_avialable + '"' : '') + ' id="g_radio_' + j + '_' + k + '" \n\
class="input-radio attribute_radio g_radio_' + j + '" data-product-attribute="' + y + '" name="group[' + y + ']" \n\
value="' + k + '" onclick="set_selected_n(\'' + j + '\', ' + k + ',\'' + fa_key_val[j] + '\', 0);" />\n\
<span class="radio-label">' + attributes[l] + '</span>\n\
</li>';
}
$output += '</ul>';
} else if (groups['group_type'] == 'color') {
$output += '<ul id="group_' + j + '" class="clearfix">';
$output += '<li id="li_list_0_' + j + '" class="float-xs-left pull-xs-left input-container color_' + j + ' selected hide-element ' + class_sup + '">\n\
<input id="color_0_' + j + '" class="input-color" type="radio" data-product-attribute="' + j + '" name="group[' + y + ']" \n\
value="0" checked="checked" disabled="true">\n\
<span class="color_select color texture" style="background-image: url(' + fa_col_img_dir + 'croix.png)" title=""></span>\n\
</li>';
for (var k in attributes) {
l = k;
k = k.replace('k_','');
if (!fa_gray_color && in_array(k, attribNotInStockWith) && !allowBuyWhenOutOfStock)
continue;
else if(!first && allowBuyWhenOutOfStock && displaydecoop && !in_array(k, attri_int_dec)) //on supprime les déclinaison non existantes
continue;
$output += '<li class="float-xs-left pull-xs-left input-container color_' + k + ((/*(sizecolors && fa_colors[k]['value'] == '') ||*/ (fa_gray_color && in_array(k, attribNotInStockWith) && !allowBuyWhenOutOfStock)) ? ' fl_color_unavalable_li' : '') + '">\n\
<input id="color_' + k + '_' + j + '" class="input-color" type="radio"' + ((fa_gray_color && in_array(k, attribNotInStockWith) && !allowBuyWhenOutOfStock) ? ' disabled="true" title="' + not_avialable + '"' : ' title="' + attributes[l] + '"') + ' \n\
data-product-attribute="' + y + '" name="group[' + y + ']" \n\
value="' + k + '" onclick="set_selected_n(\'' + j + '\', ' + k + ',\'' + fa_key_val[j] + '\', 1);">\n\
<span ' + ((sizecolors && fa_colors[k]['value'] != '') ? 'class="color_select color" style="background-color: ' + fa_colors[k]['value'] + ';"' : '') + '\n\
' + ((sizecolors && fa_colors[k]['value'] == '') ? 'class="color_select color texture" style="background-image: url('+fa_colors[k]['img']+')"' : '') + '\
title="' + attributes[l] + '">\n\
<span class="sr-only">' + attributes[l] + '</span>\n\
' + ((fa_gray_color && in_array(k, attribNotInStockWith) && !allowBuyWhenOutOfStock) ? '<span title="' + not_avialable + '" class="disabled"></span>' : '') + '\n\
</span>\n\
</li>';
}
} else if (groups['group_type'] == 'select') {
$output += '<select class="form-control form-control-select" name="group[' + y + ']" data-product-attribute="' + y + '" id="group_' + j + '" \n\
onchange="set_selected_n(\'' + j + '\', this.value,\'' + fa_key_val[j] + '\', 2);">';
$output += '<option value="0" selected="selected" id="li_list_0_' + j + '">' + name_select + '</option>';
for (var k in attributes) {
l = k;
k = k.replace('k_','');
if (!fa_gray_select && in_array(k, attribNotInStockWith) && !allowBuyWhenOutOfStock)
continue;
else if(!first && allowBuyWhenOutOfStock && displaydecoop && !in_array(k, attri_int_dec)) //on supprime les déclinaison non existantes
continue;
$output += '<option value="' + k + '"' + ((fa_gray_select && in_array(k, attribNotInStockWith) && !allowBuyWhenOutOfStock) ? ' disabled="true" class="fa_disabled"' : '') + '>' + attributes[l] + '</option>';
}
$output += '</select>';
}
$output += '<span class="attribute-arrow-right arrow-'+groups['group_type']+' group_' + j + ' displaynone icon icon-arrow-right'+(((fa_attr_all && (id_group_next == j/* || first_first*/)) ? ' arrow-right-show' : ''))+'"><i class="material-icons">arrow_forward</i></span>';
if(fa_attr_all && first_first)
first_first = false;
if(first || !fa_attr_all)
$output += '</div>';
if (first && !fa_attr_all) //si c'est lors du chargement et que c'est l'option bloc par bloc, on s'arrete à la premiere boucle
return $output;
if (!first && fa_attr_all){/*On affiche le résultat quand nous sommes en tout les blocs*/
$('#field_' + id_group+' .attribute-arrow-right.group_'+ id_group).removeClass('arrow-right-show');
$('#field_' + j).html($output);
$output = '';
}
}
if (first || !fa_attr_all)/*On retourne le résultat quand nous sommes en bloc par bloc*/
return $output;
}

When it is a number display text center else display text left

The numbers must center align and the text must left align
I'm getting a error in my code. Can anyone tell me what am I doing wrong
Image
Code
color = color !== "" && color !== undefined ? " <span class=\"color\" style=\"background: #" + color + "\"></span>" : " <span class=\"color\"></span>";
contentHtml += "<td rowspan1=\"" + 1 + "\" class=\"" + (rowspan !== "" && rowspan > 1 ? "groups" : "") + " " + (typeof value == Number) ? "text-center" : "text-left" + "\">" + value + (Number(value) ? preFix : "") + color + (Number(value) ? postFix : "") + "</td>";
if (rowspan > 1) {
var rowspanContent = "<td rowspan1=\"" + rowspan + "\" class=\"" + (rowspan !== "" && rowspan > 1 ? "groups" : "") + " " + (typeof value == Number) ? "text-center" : "text-left" + "\">" + value + (Number(value) ? preFix : "") + color + (Number(value) ? postFix : "") + "</td>"; }
Wrap your ternary statement (typeof value == Number) ? "text-center" : "text-left" in brackets so that you have ... + ((typeof value == Number) ? "text-center" : "text-left") + ... in both instances where you use it

How can I add a header to my JSON output table?

I'm trying to add a header to this JSON output table, but I have no clue how to do that. This code gives me a table populated with the data returned from the database and puts it in a table format as structured by the <td><tr> tags. The problem is that I need a header for the table and I don't know how to get that part coded. Any ideas?
function renderSearchResults( results, domNode ) {
var i;
var out = "<table>";
if (results.length === 0) {
domNode.innerHTML = 'No results matching your search.';
return;
}
// loop to print the JSON in a table format
results.forEach(function (result) {
console.info(result);
out += "<tr><td>" +
result.ContractId +
"</td><td>" +
result.ContractTitle +
"</td><td>" +
result.Terminal +
"</td><td>" +
result.Cabinet +
"</td><td>" +
result.Section +
"</td><td>" +
result.Folder +
"</td><td>" +
result.Sheet +
"</td><td>" +
result.Consult +
"</td><td>" +
result.Location +
"</td><td>" +
result.Active +
"</td><td>" +
result.Theme +
"</td><td>" +
result.Construction +
"</td><td>" +
result.Subtheme +
"</td><td>" +
result.AsBuilt +
"</td><td>" +
result.Year +
"</td><td>" +
"<a href= " + result.Path + " target=_blank>" + "Binder" + "</a>"
} );
out += "</table>";
domNode.innerHTML = out;
}
During your initial declaration of out you can put in <th> or tableheader tags, i.e:
function renderSearchResults( results, domNode ) {
var i;
var out = "<table><th>ContractId</th><th>ContractTitle</th><th>Terminal</th><th>Cabinet </th><th>Section </th><th>Folder </th><th>Sheet </th><th>Consult </th><th>Location </th><th>Active </th><th>Theme </th><th>Construction </th><th>Subtheme </th><th>AsBuilt </th><th>Year </th>";
if (results.length === 0) {
domNode.innerHTML = 'No results matching your search.';
return;
}
results.forEach(function (result) {
console.info(result);
out += "<tr><td>" +
(result.ContractId !== null ? result.ContractId : 'Not Applicable') +
"</td><td>" +
(result.ContractTitle !== null ? result.ContractTitle : 'Not Applicable') +
"</td><td>" +
(result.Terminal !== null ? result.Terminal : 'Not Applicable') +
"</td><td>" +
(result.Cabinet !== null ? result.Cabinet : 'Not Applicable') +
"</td><td>" +
(result.Section !== null ? result.Section : 'Not Applicable') +
"</td><td>" +
(result.Folder !== null ? result.Folder : 'Not Applicable') +
"</td><td>" +
(result.Sheet !== null ? result.Sheet : 'Not Applicable') +
"</td><td>" +
(result.Consult !== null ? result.Consult : 'Not Applicable') +
"</td><td>" +
(result.Location !== null ? result.Location : 'Not Applicable') +
"</td><td>" +
(result.Active !== null ? result.Active : 'Not Applicable') +
"</td><td>" +
(result.Theme !== null ? result.Theme : 'Not Applicable') +
"</td><td>" +
(result.Construction !== null ? result.Construction : 'Not Applicable') +
"</td><td>" +
(result.Subtheme !== null ? result.Subtheme : 'Not Applicable') +
"</td><td>" +
(result.AsBuilt !== null ? result.AsBuilt: 'Not Applicable') +
"</td><td>" +
(result.Year !== null ? result.Year : 'Not Applicable')+
"</td><td>" +
"<a href= " + result.Path + " target=_blank>" + "Binder" + "</a>"
} );
out += "</table>";
console.log(out);
domNode.innerHTML = out;
}
There is a different tag for the table header.
<tr> is for row <th> for your headers and <td> for the data.
You can check here for more info.
You can either add your header after your check for results:
if (results.length === 0) {
domNode.innerHTML = 'No results matching your search.';
return;
} else {
out += "<tr><th>Header</th></tr>"
}

Ajax and Javascript - get filename

How can I get loaded filename? I have to put this instead of header, but I don't know how. I've tried to add additional parameter to xmlParser function, but actually it didn't work for me. Here is my code:
$(document).ready(function () {
doAJAX('LoadedFile1.xml');
doAJAX('LoadedFile2.xml');
});
function doAJAX(url) {
$.ajax({
type: "GET",
url: url,
dataType: "xml",
success: xmlParser
});
}
function xmlParser(xml) {
$('#load').fadeOut();
var myDate = new Date();
var currentdate = new Date();
var n =
currentdate.getFullYear()
+ ("0" + (currentdate.getMonth() + 1)).slice(-2)
+ ("0" + currentdate.getDate()).slice(-2)
+ ("0" + currentdate.getHours()).slice(-2)
+ ("0" + currentdate.getMinutes()).slice(-2)
+ ("0" + currentdate.getSeconds()).slice(-2);
var x = false;
var y = false;
$(xml).find("programme").each(function () {
if ((parseFloat(n) > (parseFloat($(this).attr("start").slice(0,-6)))) && (parseFloat(n) < (parseFloat($(this).attr("stop").slice(0,-6)))))
{
$(".main").append('<div class="header">HEADER</div><div class="programme"><div class="title">' + $(this).find("title").text() + '</div><div class="timec">' + n + '</div><div class="time">' + $(this).attr("start").slice(0,-6) + '</div><div class="time">' + $(this).attr("stop").slice(0,-6) + '</div><div class="description">' + $(this).find("desc").text() + '</div><div class="date">Published ' + $(this).find("category").text() + '</div>');
x = true;
}
else if ( x == true && y == true)
{
$(".main").append('<div class="programme"><div class="title">' + $(this).find("title").text() + '</div><div class="timec">' + n + '</div><div class="time">' + $(this).attr("start").slice(0,-6) + '</div><div class="time">' + $(this).attr("stop").slice(0,-6) + '</div><div class="description">' + $(this).find("desc").text() + '</div><div class="date">Published ' + $(this).find("category").text() + '</div></div>');
x = false;
}
y = true;
$(".programme").fadeIn(1000);
});
}

Categories