PluginProbe
WP Directory Kit / 1.5.6
WP Directory Kit v1.5.6
1.5.9 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 trunk 1.1.0 1.1.6 1.1.8 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.8 All 37 releases
wpdirectorykit / public / js / wpdirectorykit-public.js

wpdirectorykit-public.js in WP Directory Kit 1.5.6, at public/js/wpdirectorykit-public.js

903 lines 33.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function( $ ) {
2 'use strict';
3
4 /**
5 * All of the code for your public-facing JavaScript source
6 * should reside in this file.
7 *
8 * Note: It has been assumed you will write jQuery code here, so the
9 * $ function reference has been prepared for usage within the scope
10 * of this function.
11 *
12 * This enables you to define handlers, for when the DOM is ready:
13 *
14 * $(function() {
15 *
16 * });
17 *
18 * When the window is loaded:
19 *
20 * $( window ).load(function() {
21 *
22 * });
23 *
24 * ...and/or other possibilities.
25 *
26 * Ideally, it is not considered best practise to attach more than a
27 * single DOM-ready or window-load handler for a particular page.
28 * Although scripts in the WordPress core, Plugins and Themes may be
29 * practising this, we should strive to set a better example in our own work.
30 */
31
32 $(function () {
33 $('.wdk-click-load-animation').on('click', function () {
34 $(this).find('.fa-ajax-indicator').css('display', 'inline-block');
35
36 if ($(this).closest('form').length) {
37 if (!$(this).closest('form')[0].checkValidity()) {
38 $(this).find('.fa-ajax-indicator').css('display', 'none');
39 }
40 }
41 });
42
43 $('.wdk-form-animation').on('submit', function () {
44 var form, indicator;
45 form = $(this);
46 indicator = form.find('.fa-ajax-indicator');
47 indicator.css('display', 'inline-block');
48
49 if(form[0].checkValidity())
50 indicator.css('display', 'none');
51 });
52
53
54 $('.wdk-submit-loading').on('click', function () {
55 var form;
56 form = $(this).closest('form');
57
58 if( $(this).hasClass('wdk_btn_load_indicator')) {
59 console.log('disabled')
60 return false;
61 }
62
63 $(this).addClass('wdk_btn_load_indicator disabled');
64 });
65
66 $('.wdk-click-loading').on('click', function (e) {
67
68 if( $(this).hasClass('wdk_btn_load_indicator')) {
69 return false;
70 }
71 $(this).addClass('wdk_btn_load_indicator disabled');
72 });
73
74 const wdk_start_search = (form) => {
75 var url,scrollTo, data = {};
76 url = form.attr('action').replace(/#results/, '');
77 if (url.indexOf('?') == -1) {
78 url += '?';
79 } else {
80 url += '&';
81 }
82 var str_parameters = "";
83 $.each($("form.wdk-search-form:visible").serializeArray(), function (i, k) {
84 if (k.value != '' && k.name.indexOf('skip') == -1) {
85 if (str_parameters != "") {
86 str_parameters += "&";
87 }
88 str_parameters += k.name + "=" + encodeURIComponent(k.value);
89 }
90 });
91
92 $.each($("form.wdk-search-form.map").serializeArray(), function (i, k) {
93 if (k.value != '' && k.name.indexOf('skip') == -1) {
94 if (str_parameters != "") {
95 str_parameters += "&";
96 }
97 str_parameters += k.name + "=" + encodeURIComponent(k.value);
98 }
99 });
100
101 $.each($(".wdk-search-popup .toggle-btn:visible"), function (i, k) {
102 let el = $($(this).attr('data-wdk-target'));
103 if(el && el.length) {
104 $.each(el.find('.wdk-search-form').serializeArray(), function (i, k) {
105 if (k.value != '' && k.name.indexOf('skip') == -1) {
106 if (str_parameters != "") {
107 str_parameters += "&";
108 }
109 str_parameters += k.name + "=" + encodeURIComponent(k.value);
110 }
111 });
112 }
113 });
114
115 /* view_type */
116 if($('.wmvc-view-type .nav-link.active').length) {
117 str_parameters += "&wmvc_view_type="+$('.wmvc-view-type .nav-link.active').attr('data-id');
118 }
119
120 /* order by */
121 if($('.wdk-order').val() != '' && $('.wdk-order').val()) {
122 str_parameters += "&order_by="+$('.wdk-order').val();
123 }
124
125 if ($('.wdk-search-form[data-scrollto]').length)
126 scrollTo = '#'+$('.wdk-search-form[data-scrollto]').attr('data-scrollto');
127
128
129
130 var setCookie = (cname, cvalue, exdays) => {
131 var d = new Date();
132 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
133 var expires = "expires="+d.toUTCString();
134 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
135 }
136 setCookie('wdk_last_search', str_parameters);
137
138 return url+str_parameters+scrollTo;
139 }
140
141 /* set current page for search results if exists results widget and enabled in setttings*/
142 $('form.wdk-search-form').each(function() {
143 var $form = $(this);
144 if ($('.wdk-listings-results').length && $('.wdk-listings-results#results').length && $form.attr('data-current-link')) {
145 $form.attr('action', $form.attr('data-current-link'));
146 }
147 });
148
149 $("form.wdk-search-form").on('submit', function (e) {
150 e.preventDefault();
151 var url = wdk_start_search($(this));
152 $(this).closest('form').addClass('loading')
153 if (decodeURI(window.location.href) == decodeURI(url)) {
154 window.location.reload();
155 } else {
156 window.location.href = url;
157 }
158 return false;
159 });
160
161 $("form.wdk-search-form.auto_search").find('input, select').on('input', function (e) {
162 $("form.wdk-search-form").first().trigger('submit')
163 });
164
165 $("form.wdk-search-form .wdk-search-start:not(.wdk-search-reset)").on('click', function (e) {
166 e.preventDefault();
167 var url = wdk_start_search($(this).closest('form'));
168 $(this).closest('form').addClass('loading')
169
170 if($(this).closest('.ajax_results_enabled').length) {
171 if (typeof wdk_ajax_loading_listings == 'function') {
172 wdk_ajax_loading_listings(url);
173 }
174 } else if (decodeURI(window.location.href) == decodeURI(url)) {
175 window.location.reload(url);
176 } else {
177 window.location.href = url;
178 }
179 return false;
180 })
181
182 $('.wdk-listings-results.ajax_results_enabled .wdk-pagination .page-numbers').on('click', function (e) {
183 e.preventDefault();
184 if (typeof wdk_ajax_loading_listings == 'function') {
185 wdk_ajax_loading_listings($(this).attr('href'));
186 }
187 })
188
189 /* elementor popup */
190 jQuery( document ).on( 'elementor/popup/show', () => {
191 wdk_reset_form();
192 } );
193
194 const wdk_reset_form = () => {
195 $("form.wdk-search-form .wdk-search-reset").off().on('click', function (e) {
196 e.preventDefault();
197 let this_form = jQuery(this).closest('form');
198 jQuery('input:not([type="checkbox"]):not([name="element_id"]):not([type="radio"]):not([type="hidden"]),textarea,select').val('');
199 jQuery('select').val(jQuery(this).find('option:first').val())
200 jQuery('input[type="checkbox"]').prop('checked', false);
201 jQuery('input[type="radio"]').prop('checked', false);
202 jQuery('.wdk-field.LOCATION .wdk_dropdown_tree button:first-child').html(jQuery('.wdk-field.LOCATION .list_items li:first').text());
203 jQuery('.wdk-field.CATEGORY .wdk_dropdown_tree button:first-child').html(jQuery('.wdk-field.CATEGORY .list_items li:first').text());
204 jQuery('input[name="rectangle_ne"],input[name="rectangle_sw"] ').val('');
205
206 // Reset Select2 fields with .select_ajax class
207 jQuery('.select_ajax').each(function() {
208 if (typeof jQuery(this).select2 === 'function') {
209 jQuery(this).val(null).trigger('change'); // Clear selection and notify Select2
210 }
211 });
212
213 $('.wdk-slider-range-field').each(function () {
214
215 var instance = $(this).data('fieldSliderRange');
216
217 if(instance) {
218 instance.reset();
219 }
220
221 });
222
223 // Remove all query params starting with 'search_' or 'field_' and hash '#results' from the URL on reset
224 if (window.history && window.history.replaceState) {
225 let url = window.location.href;
226 let parser = document.createElement('a');
227 parser.href = url;
228
229 // Get query string and hash
230 let query = parser.search.replace(/^\?/, '');
231 let hash = parser.hash;
232
233 // Split query into key-value pairs
234 let params = query ? query.split('&') : [];
235 let filteredParams = [];
236
237 // Remove params whose key starts with 'search_' or 'field_'
238 params.forEach(function(param) {
239 let key = param.split('=')[0];
240 if (!(key.startsWith('search_') || key.startsWith('field_'))) {
241 filteredParams.push(param);
242 }
243 });
244
245 // Rebuild the URL without the removed params and hash
246 let newQuery = filteredParams.length ? '?' + filteredParams.join('&') : '';
247 let newUrl = parser.protocol + '//' + parser.host + parser.pathname + newQuery;
248
249 // Remove hash if it is '#results'
250 if (hash && hash !== '#results') {
251 newUrl += hash;
252 }
253
254 window.history.replaceState({}, document.title, newUrl);
255 }
256
257 if(this_form.hasClass('auto_search')) {
258 $("form.wdk-search-form").first().trigger('submit')
259 }
260 return false;
261 })
262 };
263 wdk_reset_form();
264
265 /* date time fields init */
266 if ($('.wdk-fielddate').length && typeof $.datepicker != 'undefined') {
267
268 $('.wdk-fielddate').each(function () {
269 let dateFormat = wdk_script_parameters.format_date_js;
270 var self = $(this);
271
272 if (self.attr('date-format'))
273 dateFormat = self.attr('date-format');
274
275 self.datepicker({ dateFormat: dateFormat, onSelect: function() {
276 self.parent().find('.db-date').val(wdk_date_sql_normalize(self.datepicker("getDate"), self)).trigger('input');
277 }
278 }).on( "change", function() {
279 if(self.val() == '') {
280 self.parent().find('.db-date').val('');
281 } else {
282 self.parent().find('.db-date').val(wdk_date_sql_normalize(self.datepicker("getDate"), self));
283 }
284 });
285
286 if(self.parent().find('.db-date').val() == '' && false) {
287 self.parent().find('.db-date').val(wdk_date_notime_sql_normalize());
288 }
289 })
290 } ;
291
292
293 if ($('.wdk-fielddatetime').length && typeof $.datepicker != 'undefined') {
294
295 $('.wdk-fielddatetime').each(function () {
296 let dateFormat = wdk_script_parameters.format_datetime_js;
297
298 var self = $(this);
299 if (self.attr('date-format'))
300 dateFormat = self.attr('date-format');
301
302 self.datepicker({ dateFormat: dateFormat, onSelect: function() {
303 var datetime = wdk_date_notime_sql_normalize(self.datepicker("getDate"), self);
304 if(self.parent().find('[name="hours_mask"]').val() !='') {
305 datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
306 } else {
307 datetime += ' 00';
308 }
309 if(self.parent().find('[name="minutes_mask"]').val() !='') {
310 datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
311 } else {
312 datetime += ':00';
313 }
314 datetime += ':00';
315
316 self.parent().find('.db-date').val(datetime).trigger('input');
317 }
318 }).on( "change", function() {
319
320 var datetime = wdk_date_notime_sql_normalize(self.datepicker("getDate"), self);
321 if(self.parent().find('[name="hours_mask"]').val() !='') {
322 datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
323 } else {
324 datetime += ' 00';
325 }
326 if(self.parent().find('[name="minutes_mask"]').val() !='') {
327 datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
328 } else {
329 datetime += ':00';
330 }
331 datetime += ':00';
332 self.parent().find('.db-date').val(datetime);
333 });
334
335 if(self.parent().find('.db-date').val() == '') {
336 self.parent().find('.db-date').val(wdk_date_sql_normalize());
337 }
338
339 self.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
340 var datetime = wdk_date_notime_sql_normalize(self.datepicker("getDate"), self);
341 if(self.parent().find('[name="hours_mask"]').val() !='') {
342 datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
343 } else {
344 datetime += ' 00';
345 }
346 if(self.parent().find('[name="minutes_mask"]').val() !='') {
347 datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
348 } else {
349 datetime += ':00';
350 }
351 datetime += ':00';
352 self.parent().find('.db-date').val(datetime);
353 });
354 })
355 };
356
357 if ($('.wdk-fielddate_from').length && $('.wdk-fielddate_to').length && typeof $.datepicker != 'undefined') {
358 var dateFormat, from, to;
359 const getDate = ( element ) => {
360 var date;
361 try {
362 date = $.datepicker.parseDate( dateFormat, element.value );
363 } catch( error ) {
364 date = null;
365 }
366 return date;
367 }
368
369 dateFormat = wdk_script_parameters.format_date_js;
370 if ($('.wdk-fielddate_from').attr('date-format'))
371 dateFormat = $('.wdk-fielddate_from').attr('date-format');
372
373 from = $('.wdk-fielddate_from')
374 .datepicker({
375 dateFormat: dateFormat,
376 onSelect: function( selectedDate ) {
377 to.datepicker("option", "minDate", selectedDate );
378 setTimeout(function(){
379 to.datepicker('show');
380 }, 16);
381
382 from.parent().find('.db-date').val(wdk_date_sql_normalize(from.datepicker("getDate"), from));
383 wdk_date_add_hours(from);
384 }
385 }).on( "change", function() {
386 from.parent().find('.db-date').val(wdk_date_sql_normalize(from.datepicker("getDate"), from)).trigger('input');
387 });
388
389 to = $('.wdk-fielddate_to').datepicker({
390 dateFormat: dateFormat
391 })
392 .on( "change", function() {
393 from.datepicker( "option", "maxDate", getDate( this ) );
394 to.parent().find('.db-date').val(wdk_date_sql_normalize(to.datepicker("getDate"), to)).trigger('input');
395 wdk_date_add_hours(to);
396 });
397
398 if(to.parent().find('.db-date').val() == '') {
399 to.parent().find('.db-date').val(wdk_date_sql_normalize());
400 }
401
402 if(from.parent().find('.db-date').val() == '') {
403 from.parent().find('.db-date').val(wdk_date_sql_normalize());
404 }
405
406 from.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
407 wdk_date_add_hours(from);
408 });
409
410 to.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
411 wdk_date_add_hours(to);
412 });
413 }
414 if(typeof $.fn.wdkSuggestion == 'function') {
415
416 if(typeof wdk_script_parameters.settings_wdk_field_search_suggestion_disable != 'undefined' && wdk_script_parameters.settings_wdk_field_search_suggestion_disable == 1) {
417
418 } else {
419 $('#wdk_field_search').wdkSuggestion({
420 ajax_url: wdk_script_parameters.ajax_url,
421 ajax_param: {
422 "action": 'wdk_public_action',
423 "page": 'wdk_frontendajax',
424 "function": 'search_suggestion',
425 },
426 language_id: '',
427 text_search: 'Search',
428 callback_selected: function(key) {
429
430 }
431 });
432 }
433
434 }
435
436 $('.wdk-control[type="number"]').on('change',function(){
437 let val = $(this).val();
438 let step = 1;
439 if(val.length>=7){
440 step = 10000;
441 } else if(val.length>=4) {
442 step = 10;
443 }
444 $(this).attr('step', step);
445 })
446
447
448 if(typeof $.fn.fieldSliderRange == 'function' && typeof $.fn.ionRangeSlider == 'function') {
449 $('.wdk-slider-range-field').fieldSliderRange();
450 }
451
452 wdk_result_listings_thumbnail_slider();
453
454 /* if video exists on thumbnail css trick */
455 $('.wdk-listing-card .wdk-thumbnail .wdk-image.media').find('iframe,video').css('padding-bottom', +($('.wdk-listing-card .wdk-thumbnail .wdk-over-image-bottom').outerHeight())+'px');
456
457
458 if(typeof $.fn.WdkScrollMobileSwipe == 'function') {
459 $('.WdkScrollMobileSwipe_enable').WdkScrollMobileSwipe();
460 $('.WdkScrollMobileSwipe_elementor_enable .elementor-container').WdkScrollMobileSwipe();
461 }
462
463 if($('.wl-menu-toggle').length) {
464 $('.wdk-footer-menu .wdk_mobile_footer_menu_gumb-open').addClass('trigger')
465 $('.wdk-footer-menu .wdk_mobile_footer_menu_gumb-open').on('click', function(e){
466 e.preventDefault();
467 $('.wl-menu-toggle').trigger('click');
468 });
469 }
470
471
472 /* Read More Button */
473 jQuery('.wdk-field-value.TEXTAREA').each(function(){
474 // Find the target div containing additional content
475 var moreContentDiv = $(this).find("[id*='more-']");
476 // Hide the additional content initially
477 var additionalContent = moreContentDiv.nextUntil(":not(p)");
478 additionalContent.hide();
479
480 // Create a "Read More" button
481 var readMoreButtonWrapper = $("<div class='wdk-textarea-load-more-wrapper'><a class='wdk-textarea-load-more-button'></a></div>"),
482 readMoreButton = readMoreButtonWrapper.find('a').text(wdk_script_parameters.text.read_more || '');
483 readMoreButton.on("click", function() {
484 // Toggle the visibility of the additional content
485 additionalContent.slideToggle();
486 if (readMoreButton.text() === wdk_script_parameters.text.read_more) {
487 readMoreButton.text(wdk_script_parameters.text.read_less);
488 } else {
489 readMoreButton.text(wdk_script_parameters.text.read_more);
490 }
491 });
492
493 // Replace the target div with the "Read More" button
494 moreContentDiv.before(readMoreButtonWrapper);
495 moreContentDiv.remove();
496 });
497
498 $('.wdk-language-switcher-drop .wdk-language-switcher-btn-toggle').on('click', function (e) {
499 e.preventDefault();
500 $(this).closest('.wdk-language-switcher-drop').toggleClass('wdk-show');
501 });
502 // Add click event to each share link
503 document.querySelectorAll('.wdk-device-share-link').forEach(link => {
504 link.addEventListener('click', function(event) {
505 event.preventDefault();
506 shareUrl(link.getAttribute('href'));
507 });
508 });
509
510 $('.wdk-search_sensitive_link').on('click',function(e) {
511 e.preventDefault();
512 var href = $(this).attr('href'),
513 search_url = wdk_start_search($("form.wdk-search-form"));
514
515 if(search_url == href) {
516 window.location.href = href;
517 return;
518 }
519
520 // Parse the href to extract search_location and search_category
521 var urlParams = new URLSearchParams(href.split('?')[1]);
522 var searchLocation = urlParams.get('search_location');
523 var searchCategory = urlParams.get('search_category');
524
525 // Parse the search_url to update with new params
526 var searchParams = new URLSearchParams(search_url.split('?')[1]);
527
528 if (searchLocation) {
529 searchParams.set('search_location', searchLocation);
530 }
531 if (searchCategory) {
532 searchParams.set('search_category', searchCategory);
533 }
534
535 var updatedSearchUrl = search_url.split('?')[0] + '?' + searchParams.toString();
536 window.location.href = updatedSearchUrl;
537
538 })
539 resetSearchFields();
540 });
541
542 })(jQuery);
543
544
545
546 var resetSearchFields = () => {
547 jQuery(".wdk-control[type='text']:not(.wdk-hidden)").each(function(){
548 var $searchField = jQuery(this);
549 // Create reset button
550 var $resetButton = jQuery("<span>&times;</span>")
551 .css({
552 cursor: "pointer",
553 display: "none", // Initially hidden
554 position: "absolute",
555 right: "10px",
556 top: "50%",
557 transform: "translateY(-50%)",
558 fontSize: "18px"
559 });
560
561 /* Text Fields */
562
563 // Wrap input field in a relative container
564 var $wrapper = jQuery("<div></div>")
565 .css({ position: "relative" })
566 .insertBefore($searchField);
567
568 $wrapper.append($searchField).append($resetButton);
569
570 // Show/hide reset button based on input
571 $searchField.on("input", function () {
572 $resetButton.toggle(!!$searchField.val()); // Toggle visibility based on input
573 });
574
575 // Clear field when reset button is clicked
576 $resetButton.on("click", function () {
577 $searchField.val("").trigger("input").focus(); // Reset field and trigger input event to hide button
578 });
579 });
580 /* Tree Fields */
581
582 jQuery(`input[name="search_location"],input[name="search_category"]`).each(function(){
583
584 var $searchField = jQuery(this);
585 var resetButton;
586
587 // Show/hide reset button based on input
588 $searchField.on("change", function () {
589 if (jQuery(this).val() !== "") {
590 // Wrap input field in a relative container
591 var $wrapper = $searchField.closest('.wdk-field-group').find('.wdk_dropdown_tree button:first-child')
592 .css({ position: "relative" });
593 console.log($wrapper);
594 console.log(resetButton);
595 if (!resetButton) {
596 resetButton = jQuery("<span>&times;</span>")
597 .css({
598 cursor: "pointer",
599 position: "absolute",
600 right: "10px",
601 top: "50%",
602 transform: "translateY(-50%)",
603 fontSize: "18px"
604 })
605 .on("click", function (e) {
606 e.stopPropagation();
607 e.preventDefault();
608
609 $searchField.val("").trigger("input").focus();
610 resetButton.remove();
611 resetButton = null;
612 $searchField.closest('.wdk-field-group').find('.wdk_dropdown_tree button:first-child').html( $searchField.closest('.wdk-field-group').find('.list_items li:first').text());
613
614 return false;
615 });
616 $wrapper.append(resetButton);
617 }
618 } else if (resetButton) {
619 resetButton.remove();
620 resetButton = null;
621 }
622 });
623
624 });
625
626 };
627
628 /* slider for result listings thumbnails */
629 if (typeof wdk_result_listings_thumbnail_slider != 'function') {
630 var wdk_result_listings_thumbnail_slider = ($wrapper = 'body') => {
631 if(typeof jQuery.fn.slick == 'function') {
632 jQuery('.wdk_js_gallery_slider_box', $wrapper).each(function(){
633 var _this = jQuery(this);
634
635 if($wrapper == 'body') {
636 if(_this.closest('.wdk_results_listings_slider_ini').length){return true;}
637 }
638
639 if (_this.closest('.slick-slide').hasClass('slick-cloned')) {
640 return true;
641 }
642
643 // Check if the slider exists and is initialized
644 if (_this.find('.wdk_js_gallery_slider').length > 0 && _this.find('.wdk_js_gallery_slider').hasClass('slick-initialized')) {
645 _this.find('.wdk_js_gallery_slider').slick('unslick');
646 }
647
648
649 _this.find('.wdk_js_gallery_slider').slick({
650 dots: true,
651 infinite: true,
652 speed: 500,
653 fade: true,
654 arrows: true,
655 cssEase: 'linear',
656 nextArrow: _this.find('.wdk_js_gallery_slider-carousel_arrows .wdk-slider-next'),
657 prevArrow: _this.find('.wdk_js_gallery_slider-carousel_arrows .wdk-slider-prev'),
658 });
659 });
660 }
661 };
662 }
663 /*
664 Fix for slick slider, event after init slick
665
666 @param object el slick object
667 @param function callback
668 */
669
670 if (typeof wdk_slick_slider_init != 'function') {
671 var wdk_slick_slider_init = (el, callback) => {
672 try {
673 el.slick("slickGoTo", 0, true);
674 }
675 catch(error) {
676 setTimeout(wdk_slick_slider_init, 1000);
677 return;
678 }
679
680 if(callback) {
681 callback.call();
682 }
683 };
684 }
685 if (typeof wdk_pad != 'function') {
686 var wdk_pad = (num = '') => {
687 return ('00'+num).slice(-2);
688 };
689 }
690
691 if (typeof wdk_date_add_hours != 'function') {
692 var wdk_date_add_hours = (selector = '') => {
693 if(typeof selector !='undefined' && selector.parent().find('[name="hours_mask"]').length) {
694 var datetime = wdk_date_notime_sql_normalize(selector.datepicker("getDate"), selector);
695 if(selector.parent().find('[name="hours_mask"]').val() !='') {
696 datetime += ' '+wdk_pad(selector.parent().find('[name="hours_mask"]').val());
697 } else {
698 datetime += ' 00';
699 }
700 if(selector.parent().find('[name="minutes_mask"]').val() !='') {
701 datetime += ':'+wdk_pad(selector.parent().find('[name="minutes_mask"]').val());
702 } else {
703 datetime += ':00';
704 }
705 datetime += ':00';
706 selector.parent().find('.db-date').val(datetime);
707 }
708 };
709 }
710 /*
711 Convert date to sql format
712
713 @param string $date, string of date
714
715 @return string normalize date or Current date/time
716 */
717 if (typeof wdk_date_sql_normalize != 'function') {
718 var wdk_date_sql_normalize = (date = '', datepicker_el = null) => {
719 if(date == '') {
720 var d = new Date();
721 } else {
722 var d = new Date(date);
723 }
724
725 if(d == 'Invalid Date' && datepicker_el) {
726 var d = new Date(+(jQuery.datepicker.formatDate("@", datepicker_el.datepicker("getDate"))));
727 }
728
729 d = d.getUTCFullYear() + '-' +
730 wdk_pad(d.getMonth() + 1) + '-' +
731 wdk_pad(d.getDate()) + ' ' +
732 wdk_pad(d.getHours()) + ':' +
733 wdk_pad(d.getMinutes()) + ':' +
734 wdk_pad(d.getSeconds());
735 return d;
736 };
737 }
738
739 if (typeof wdk_date_notime_sql_normalize != 'function') {
740 var wdk_date_notime_sql_normalize = (date = '', datepicker_el = null) => {
741 if(date == '') {
742 var d = new Date();
743 } else {
744 var d = new Date(date);
745 }
746
747 if(d == 'Invalid Date' && datepicker_el) {
748 var d = new Date(+(jQuery.datepicker.formatDate("@", datepicker_el.datepicker("getDate"))));
749 }
750
751 d = d.getUTCFullYear() + '-' +
752 wdk_pad(d.getMonth() + 1) + '-' +
753 wdk_pad(d.getDate());
754 return d;
755 };
756 }
757
758 if (typeof wdk_generate_marker_ajax_popup != 'function') {
759 var wdk_generate_marker_ajax_popup = (ajax_url, listing_post_id, lat, lng,innerMarker, wdk_jpopup_customOptions, auto = false, clusters_enabled = true, custom_layout_id = '') => {
760
761 if(auto) {
762 var marker = L.marker(
763 [lat, lng],
764 {icon: L.divIcon({
765 html: innerMarker,
766 className: 'open_steet_map_marker',
767 iconSize: 'auto',
768 })
769 }
770 );
771 } else {
772 var marker = L.marker(
773 [lat, lng],
774 {icon: L.divIcon({
775 html: innerMarker,
776 className: 'open_steet_map_marker',
777 iconSize: [40, 60],
778 popupAnchor: [-1, -35],
779 iconAnchor: [23, 73],
780 })
781 }
782 );
783 }
784
785 var data = {
786 "action": 'wdk_public_action',
787 "page": 'wdk_frontendajax',
788 "function": 'map_infowindow',
789 "listing_post_id": listing_post_id,
790 "custom_layout_id": custom_layout_id,
791 };
792
793 let favorite_init = false;
794 let compare_init = false;
795 marker.bindPopup(function () {
796 var content = '<div class="infobox"><div class="map_infowindow"><div class="loading_content animated-background"><div class="box_line m170"></div><div class="box_line m20"></div><div class="box_line m20"></div><div class="box_line m20"></div><div class="box_line m20"></div><div class="box_line m20"></div></div></div></div>';
797 marker.getPopup().setContent(content);
798 marker.getPopup().update();
799 jQuery.ajax({
800 url : ajax_url,
801 type : "POST",
802 data: data,
803 success: function (data) {
804 marker.getPopup().setContent(data.popup_content);
805 marker.getPopup().update();
806 if (!favorite_init && typeof wdk_favorite == 'function')
807 wdk_favorite('.infobox');
808
809 favorite_init = false;
810
811 if (!compare_init && typeof wdk_init_compare_elem == 'function')
812 wdk_init_compare_elem();
813
814 compare_init = false;
815 },
816 });
817 return content;
818 }, wdk_jpopup_customOptions);
819
820 if (typeof wdk_favorite == 'function')
821 marker.on('popupopen', function (popup) {
822 if (!favorite_init)
823 wdk_favorite('.infobox');
824 });
825
826 if (typeof wdk_init_compare_elem == 'function')
827 marker.on('popupopen', function (popup) {
828 if (!compare_init)
829 wdk_init_compare_elem();
830 });
831
832 if (typeof wdk_favorite == 'function')
833 marker.on('popupclose', function (popup) {
834 marker.getPopup().setContent(jQuery('.leaflet-popup-content-wrapper .leaflet-popup-content').html());
835 marker.getPopup().update();
836 });
837
838 if(clusters_enabled) {
839 wdk_clusters.addLayer(marker);
840 } else {
841 wdk_map.addLayer(marker);
842 }
843 return marker;
844 }
845 }
846
847 if (typeof wdk_generate_marker_basic_popup != 'function') {
848 var wdk_generate_marker_basic_popup = (lat, lng, innerMarker, wdk_jpopup_content, wdk_jpopup_customOptions) => {
849 var marker = L.marker(
850 [lat, lng],
851 {icon: L.divIcon({
852 html: innerMarker,
853 className: 'open_steet_map_marker',
854 iconSize: [40, 60],
855 popupAnchor: [-1, -35],
856 iconAnchor: [23, 73],
857 })
858 }
859 );
860
861 marker.bindPopup(wdk_jpopup_content, wdk_jpopup_customOptions);
862
863 return marker;
864 }
865 }
866
867 if (typeof wdk_generate_marker_nopopup != 'function') {
868 var wdk_generate_marker_nopopup = (lat, lng,innerMarker) => {
869 var marker = L.marker(
870 [lat, lng],
871 {icon: L.divIcon({
872 html: innerMarker,
873 className: 'open_steet_map_marker',
874 iconSize: [40, 60],
875 popupAnchor: [-1, -35],
876 iconAnchor: [23, 73],
877 })
878 }
879 );
880
881 return marker;
882 }
883 }
884
885 // Share URL function
886 var shareUrl = (url = window.location.href) => {
887 // Check if the browser supports the Web Share API
888 if (!navigator.share) {
889 console.log("Web Share API not supported.");
890 return;
891 }
892
893 navigator.share({
894 url: url, // Share the current page URL
895 })
896 .then(() => {
897 console.log("Shared successfully!");
898 })
899 .catch((error) => {
900 console.error("Sharing failed:", error);
901 });
902 };
903