PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.35
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.35
51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 All 39 releases
king-addons / includes / widgets / Image_Accordion / script.js

script.js in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.35, at includes/widgets/Image_Accordion/script.js

281 lines 16.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3 (function ($) {
4 $(window).on("elementor/frontend/init", function () {
5 elementorFrontend.hooks.addAction(
6 "frontend/element_ready/king-addons-image-accordion.default",
7 function ($scope) {
8 elementorFrontend.elementsHandler.addHandler(
9 elementorModules.frontend.handlers.Base.extend({
10 onInit() {
11 const $elem = this.$element,
12 $wrap = $elem.find(".king-addons-image-accordion"),
13 $wrapContainer = $elem.find(".king-addons-image-accordion-wrap"),
14 settings = JSON.parse(
15 $elem
16 .find(".king-addons-img-accordion-media-hover")
17 .attr("data-settings")
18 ),
19 lightboxAttr = $wrap.attr("lightbox"),
20 lightboxSettings = lightboxAttr ? JSON.parse(lightboxAttr) : "",
21 $accordionItems = $elem.find(".king-addons-image-accordion-item");
22
23 // Adjust row/column layout if necessary
24 if ($wrapContainer.hasClass("king-addons-acc-no-column")) {
25 if (!$elem.hasClass("king-addons-image-accordion-row")) {
26 $elem
27 .removeClass("king-addons-image-accordion-column")
28 .addClass("king-addons-image-accordion-row");
29 $wrap.css("flex-direction", "row");
30 }
31 }
32
33 // Initialize lightbox if settings exist
34 if (lightboxSettings) {
35 $wrap.lightGallery(lightboxSettings);
36
37 // Adjust thumbnails in lightbox
38 $wrap.on("onAfterOpen.lg", function () {
39 const $lgOuter = $(".lg-outer");
40 if ($lgOuter.find(".lg-thumb-item").length) {
41 $lgOuter.find(".lg-thumb-item").each(function () {
42 const $img = $(this).find("img");
43 const imgSrc = $img.attr("src");
44 const extIndex = imgSrc.lastIndexOf(".");
45 const ext = imgSrc.slice(extIndex);
46 const cropIndex = imgSrc.lastIndexOf("-");
47 let cropSize = /\d{3,}x\d{3,}/.test(
48 imgSrc.substring(extIndex, cropIndex)
49 )
50 ? imgSrc.substring(extIndex, cropIndex)
51 : false;
52 let newImgSrc = imgSrc;
53
54 if (cropSize && cropSize.length >= 42) {
55 cropSize = "";
56 }
57
58 if (cropSize !== "") {
59 if (cropSize !== false) {
60 newImgSrc = imgSrc.replace(cropSize, "-150x150");
61 } else {
62 newImgSrc = [
63 imgSrc.slice(0, extIndex),
64 "-150x150",
65 ext
66 ].join("");
67 }
68 }
69
70 $img.attr("src", newImgSrc);
71
72 // Restore original if invalid crop size
73 if (cropSize === false || cropSize === "-450x450") {
74 $img.attr("src", imgSrc);
75 }
76 });
77 }
78 });
79
80 // Control certain lightbox behaviors
81 $wrap.on("onAferAppendSlide.lg onAfterSlide.lg", function () {
82 const $lightboxDownload = $("#lg-download"),
83 lightboxControls = $(
84 "#lg-actual-size, #lg-zoom-in, #lg-zoom-out, #lg-download"
85 ),
86 downloadHref = $lightboxDownload.attr("href");
87
88 if ($lightboxDownload.length) {
89 if (downloadHref.indexOf("wp-content") === -1) {
90 lightboxControls.addClass("king-addons-hidden-element");
91 } else {
92 lightboxControls.removeClass("king-addons-hidden-element");
93 }
94 }
95
96 // Hide autoplay if not enabled
97 if (!lightboxSettings.autoplay) {
98 $(".lg-autoplay-button").css({
99 width: "0",
100 height: "0",
101 overflow: "hidden"
102 });
103 }
104 });
105 }
106
107 // Make the entire accordion item clickable
108 $wrap.css("cursor", "pointer");
109
110 // Handle hover interactions for clickable links
111 function mediaHoverLink() {
112 // Avoid linking in the Elementor editor
113 if (!$("body").hasClass("elementor-editor-active")) {
114 $elem
115 .find(".king-addons-img-accordion-media-hover")
116 .on("click", function (event) {
117 const isTarget = event.target.className.includes(
118 "king-addons-img-accordion-media-hover"
119 );
120 const thisSettings = JSON.parse(
121 isTarget
122 ? $(this).attr("data-settings")
123 : $(this)
124 .closest(".king-addons-img-accordion-media-hover")
125 .attr("data-settings")
126 );
127 if (
128 !$(event.target).hasClass(
129 "king-addons-img-accordion-item-lightbox"
130 ) &&
131 !$(event.target).closest(
132 ".king-addons-img-accordion-item-lightbox"
133 ).length
134 ) {
135 const itemUrl = thisSettings.activeItem.overlayLink;
136 if (itemUrl) {
137 if (
138 thisSettings.activeItem.overlayLinkTarget ===
139 "_blank"
140 ) {
141 window.open(itemUrl, "_blank").focus();
142 } else {
143 window.location.href = itemUrl;
144 }
145 }
146 }
147 });
148 }
149 }
150
151 // Interaction type: "hover"
152 if (settings.activeItem.interaction === "hover") {
153 mediaHoverLink();
154
155 $accordionItems
156 .on("mouseenter", function () {
157 $accordionItems.removeClass(
158 "king-addons-image-accordion-item-grow"
159 );
160 $accordionItems
161 .find(".king-addons-animation-wrap")
162 .removeClass("king-addons-animation-wrap-active");
163
164 $(this).addClass("king-addons-image-accordion-item-grow");
165 $(this)
166 .find(".king-addons-animation-wrap")
167 .addClass("king-addons-animation-wrap-active");
168 })
169 .on("mouseleave", function () {
170 $(this).removeClass("king-addons-image-accordion-item-grow");
171 $(this)
172 .find(".king-addons-animation-wrap")
173 .removeClass("king-addons-animation-wrap-active");
174 });
175
176 // Interaction type: "click"
177 } else if (settings.activeItem.interaction === "click") {
178 $elem
179 .find(".king-addons-img-accordion-media-hover")
180 .removeClass("king-addons-animation-wrap");
181
182 $accordionItems.on(
183 "click",
184 ".king-addons-img-accordion-media-hover",
185 function (event) {
186 const isTarget = event.target.className.includes(
187 "king-addons-img-accordion-media-hover"
188 );
189 const hasActiveClass = isTarget
190 ? event.target.className.includes(
191 "king-addons-animation-wrap-active"
192 )
193 : $(this)
194 .closest(".king-addons-img-accordion-media-hover")
195 .hasClass("king-addons-animation-wrap-active");
196
197 // If this item is already active, redirect if a link is set
198 if (
199 hasActiveClass &&
200 !$("body").hasClass("elementor-editor-active")
201 ) {
202 const thisSettings = JSON.parse(
203 isTarget
204 ? $(this).attr("data-settings")
205 : $(this)
206 .closest(".king-addons-img-accordion-media-hover")
207 .attr("data-settings")
208 );
209
210 if (
211 !$(event.target).hasClass(
212 "king-addons-img-accordion-item-lightbox"
213 ) &&
214 !$(event.target).closest(
215 ".king-addons-img-accordion-item-lightbox"
216 ).length
217 ) {
218 const itemUrl = thisSettings.activeItem.overlayLink;
219 if (itemUrl) {
220 if (
221 thisSettings.activeItem.overlayLinkTarget ===
222 "_blank"
223 ) {
224 window.open(itemUrl, "_blank").focus();
225 } else {
226 window.location.href = itemUrl;
227 }
228 }
229 }
230 } else {
231 // Activate this item
232 $elem
233 .find(".king-addons-img-accordion-media-hover")
234 .removeClass("king-addons-animation-wrap king-addons-animation-wrap-active");
235 $accordionItems.removeClass(
236 "king-addons-image-accordion-item-grow"
237 );
238
239 $(this)
240 .closest(".king-addons-image-accordion-item")
241 .addClass("king-addons-image-accordion-item-grow");
242 $(this)
243 .closest(".king-addons-img-accordion-media-hover")
244 .addClass("king-addons-animation-wrap-active");
245 }
246 }
247 );
248 } else {
249 // If interaction is neither hover nor click
250 $elem
251 .find(".king-addons-img-accordion-media-hover")
252 .removeClass("king-addons-animation-wrap");
253 }
254
255 // Set default active item
256 $accordionItems.each(function () {
257 if ($(this).index() === settings.activeItem.defaultActive - 1) {
258 setTimeout(() => {
259 const action =
260 settings.activeItem.interaction === "click"
261 ? "click"
262 : "mouseenter";
263 $(this)
264 .find(".king-addons-img-accordion-media-hover")
265 .trigger(action);
266 }, 400);
267 }
268 });
269
270 // Show the accordion after initialization
271 $wrapContainer.css("opacity", 1);
272 }
273 }),
274 {
275 $element: $scope
276 }
277 );
278 }
279 );
280 });
281 })(jQuery);