PluginProbe
WP Directory Kit / 1.5.3
WP Directory Kit v1.5.3
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.3, at public/js/wpdirectorykit-public.js

893 lines 33.6 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 // Remove all query params starting with 'search_' or 'field_' and hash '#results' from the URL on reset
214 if (window.history && window.history.replaceState) {
215 let url = window.location.href;
216 let parser = document.createElement('a');
217 parser.href = url;
218
219 // Get query string and hash
220 let query = parser.search.replace(/^\?/, '');
221 let hash = parser.hash;
222
223 // Split query into key-value pairs
224 let params = query ? query.split('&') : [];
225 let filteredParams = [];
226
227 // Remove params whose key starts with 'search_' or 'field_'
228 params.forEach(function(param) {
229 let key = param.split('=')[0];
230 if (!(key.startsWith('search_') || key.startsWith('field_'))) {
231 filteredParams.push(param);
232 }
233 });
234
235 // Rebuild the URL without the removed params and hash
236 let newQuery = filteredParams.length ? '?' + filteredParams.join('&') : '';
237 let newUrl = parser.protocol + '//' + parser.host + parser.pathname + newQuery;
238
239 // Remove hash if it is '#results'
240 if (hash && hash !== '#results') {
241 newUrl += hash;
242 }
243
244 window.history.replaceState({}, document.title, newUrl);
245 }
246
247 if(this_form.hasClass('auto_search')) {
248 $("form.wdk-search-form").first().trigger('submit')
249 }
250 return false;
251 })
252 };
253 wdk_reset_form();
254
255 /* date time fields init */
256 if ($('.wdk-fielddate').length && typeof $.datepicker != 'undefined') {
257
258 $('.wdk-fielddate').each(function () {
259 let dateFormat = wdk_script_parameters.format_date_js;
260 var self = $(this);
261
262 if (self.attr('date-format'))
263 dateFormat = self.attr('date-format');
264
265 self.datepicker({ dateFormat: dateFormat, onSelect: function() {
266 self.parent().find('.db-date').val(wdk_date_sql_normalize(self.datepicker("getDate"), self)).trigger('input');
267 }
268 }).on( "change", function() {
269 if(self.val() == '') {
270 self.parent().find('.db-date').val('');
271 } else {
272 self.parent().find('.db-date').val(wdk_date_sql_normalize(self.datepicker("getDate"), self));
273 }
274 });
275
276 if(self.parent().find('.db-date').val() == '' && false) {
277 self.parent().find('.db-date').val(wdk_date_notime_sql_normalize());
278 }
279 })
280 } ;
281
282
283 if ($('.wdk-fielddatetime').length && typeof $.datepicker != 'undefined') {
284
285 $('.wdk-fielddatetime').each(function () {
286 let dateFormat = wdk_script_parameters.format_datetime_js;
287
288 var self = $(this);
289 if (self.attr('date-format'))
290 dateFormat = self.attr('date-format');
291
292 self.datepicker({ dateFormat: dateFormat, onSelect: function() {
293 var datetime = wdk_date_notime_sql_normalize(self.datepicker("getDate"), self);
294 if(self.parent().find('[name="hours_mask"]').val() !='') {
295 datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
296 } else {
297 datetime += ' 00';
298 }
299 if(self.parent().find('[name="minutes_mask"]').val() !='') {
300 datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
301 } else {
302 datetime += ':00';
303 }
304 datetime += ':00';
305
306 self.parent().find('.db-date').val(datetime).trigger('input');
307 }
308 }).on( "change", function() {
309
310 var datetime = wdk_date_notime_sql_normalize(self.datepicker("getDate"), self);
311 if(self.parent().find('[name="hours_mask"]').val() !='') {
312 datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
313 } else {
314 datetime += ' 00';
315 }
316 if(self.parent().find('[name="minutes_mask"]').val() !='') {
317 datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
318 } else {
319 datetime += ':00';
320 }
321 datetime += ':00';
322 self.parent().find('.db-date').val(datetime);
323 });
324
325 if(self.parent().find('.db-date').val() == '') {
326 self.parent().find('.db-date').val(wdk_date_sql_normalize());
327 }
328
329 self.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
330 var datetime = wdk_date_notime_sql_normalize(self.datepicker("getDate"), self);
331 if(self.parent().find('[name="hours_mask"]').val() !='') {
332 datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
333 } else {
334 datetime += ' 00';
335 }
336 if(self.parent().find('[name="minutes_mask"]').val() !='') {
337 datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
338 } else {
339 datetime += ':00';
340 }
341 datetime += ':00';
342 self.parent().find('.db-date').val(datetime);
343 });
344 })
345 };
346
347 if ($('.wdk-fielddate_from').length && $('.wdk-fielddate_to').length && typeof $.datepicker != 'undefined') {
348 var dateFormat, from, to;
349 const getDate = ( element ) => {
350 var date;
351 try {
352 date = $.datepicker.parseDate( dateFormat, element.value );
353 } catch( error ) {
354 date = null;
355 }
356 return date;
357 }
358
359 dateFormat = wdk_script_parameters.format_date_js;
360 if ($('.wdk-fielddate_from').attr('date-format'))
361 dateFormat = $('.wdk-fielddate_from').attr('date-format');
362
363 from = $('.wdk-fielddate_from')
364 .datepicker({
365 dateFormat: dateFormat,
366 onSelect: function( selectedDate ) {
367 to.datepicker("option", "minDate", selectedDate );
368 setTimeout(function(){
369 to.datepicker('show');
370 }, 16);
371
372 from.parent().find('.db-date').val(wdk_date_sql_normalize(from.datepicker("getDate"), from));
373 wdk_date_add_hours(from);
374 }
375 }).on( "change", function() {
376 from.parent().find('.db-date').val(wdk_date_sql_normalize(from.datepicker("getDate"), from)).trigger('input');
377 });
378
379 to = $('.wdk-fielddate_to').datepicker({
380 dateFormat: dateFormat
381 })
382 .on( "change", function() {
383 from.datepicker( "option", "maxDate", getDate( this ) );
384 to.parent().find('.db-date').val(wdk_date_sql_normalize(to.datepicker("getDate"), to)).trigger('input');
385 wdk_date_add_hours(to);
386 });
387
388 if(to.parent().find('.db-date').val() == '') {
389 to.parent().find('.db-date').val(wdk_date_sql_normalize());
390 }
391
392 if(from.parent().find('.db-date').val() == '') {
393 from.parent().find('.db-date').val(wdk_date_sql_normalize());
394 }
395
396 from.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
397 wdk_date_add_hours(from);
398 });
399
400 to.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
401 wdk_date_add_hours(to);
402 });
403 }
404 if(typeof $.fn.wdkSuggestion == 'function') {
405
406 if(typeof wdk_script_parameters.settings_wdk_field_search_suggestion_disable != 'undefined' && wdk_script_parameters.settings_wdk_field_search_suggestion_disable == 1) {
407
408 } else {
409 $('#wdk_field_search').wdkSuggestion({
410 ajax_url: wdk_script_parameters.ajax_url,
411 ajax_param: {
412 "action": 'wdk_public_action',
413 "page": 'wdk_frontendajax',
414 "function": 'search_suggestion',
415 },
416 language_id: '',
417 text_search: 'Search',
418 callback_selected: function(key) {
419
420 }
421 });
422 }
423
424 }
425
426 $('.wdk-control[type="number"]').on('change',function(){
427 let val = $(this).val();
428 let step = 1;
429 if(val.length>=7){
430 step = 10000;
431 } else if(val.length>=4) {
432 step = 10;
433 }
434 $(this).attr('step', step);
435 })
436
437
438 if(typeof $.fn.fieldSliderRange == 'function' && typeof $.fn.ionRangeSlider == 'function') {
439 $('.wdk-slider-range-field').fieldSliderRange();
440 }
441
442 wdk_result_listings_thumbnail_slider();
443
444 /* if video exists on thumbnail css trick */
445 $('.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');
446
447
448 if(typeof $.fn.WdkScrollMobileSwipe == 'function') {
449 $('.WdkScrollMobileSwipe_enable').WdkScrollMobileSwipe();
450 $('.WdkScrollMobileSwipe_elementor_enable .elementor-container').WdkScrollMobileSwipe();
451 }
452
453 if($('.wl-menu-toggle').length) {
454 $('.wdk-footer-menu .wdk_mobile_footer_menu_gumb-open').addClass('trigger')
455 $('.wdk-footer-menu .wdk_mobile_footer_menu_gumb-open').on('click', function(e){
456 e.preventDefault();
457 $('.wl-menu-toggle').trigger('click');
458 });
459 }
460
461
462 /* Read More Button */
463 jQuery('.wdk-field-value.TEXTAREA').each(function(){
464 // Find the target div containing additional content
465 var moreContentDiv = $(this).find("[id*='more-']");
466 // Hide the additional content initially
467 var additionalContent = moreContentDiv.nextUntil(":not(p)");
468 additionalContent.hide();
469
470 // Create a "Read More" button
471 var readMoreButtonWrapper = $("<div class='wdk-textarea-load-more-wrapper'><a class='wdk-textarea-load-more-button'></a></div>"),
472 readMoreButton = readMoreButtonWrapper.find('a').text(wdk_script_parameters.text.read_more || '');
473 readMoreButton.on("click", function() {
474 // Toggle the visibility of the additional content
475 additionalContent.slideToggle();
476 if (readMoreButton.text() === wdk_script_parameters.text.read_more) {
477 readMoreButton.text(wdk_script_parameters.text.read_less);
478 } else {
479 readMoreButton.text(wdk_script_parameters.text.read_more);
480 }
481 });
482
483 // Replace the target div with the "Read More" button
484 moreContentDiv.before(readMoreButtonWrapper);
485 moreContentDiv.remove();
486 });
487
488 $('.wdk-language-switcher-drop .wdk-language-switcher-btn-toggle').on('click', function (e) {
489 e.preventDefault();
490 $(this).closest('.wdk-language-switcher-drop').toggleClass('wdk-show');
491 });
492 // Add click event to each share link
493 document.querySelectorAll('.wdk-device-share-link').forEach(link => {
494 link.addEventListener('click', function(event) {
495 event.preventDefault();
496 shareUrl(link.getAttribute('href'));
497 });
498 });
499
500 $('.wdk-search_sensitive_link').on('click',function(e) {
501 e.preventDefault();
502 var href = $(this).attr('href'),
503 search_url = wdk_start_search($("form.wdk-search-form"));
504
505 if(search_url == href) {
506 window.location.href = href;
507 return;
508 }
509
510 // Parse the href to extract search_location and search_category
511 var urlParams = new URLSearchParams(href.split('?')[1]);
512 var searchLocation = urlParams.get('search_location');
513 var searchCategory = urlParams.get('search_category');
514
515 // Parse the search_url to update with new params
516 var searchParams = new URLSearchParams(search_url.split('?')[1]);
517
518 if (searchLocation) {
519 searchParams.set('search_location', searchLocation);
520 }
521 if (searchCategory) {
522 searchParams.set('search_category', searchCategory);
523 }
524
525 var updatedSearchUrl = search_url.split('?')[0] + '?' + searchParams.toString();
526 window.location.href = updatedSearchUrl;
527
528 })
529 resetSearchFields();
530 });
531
532 })(jQuery);
533
534
535
536 var resetSearchFields = () => {
537 jQuery(".wdk-control[type='text']:not(.wdk-hidden)").each(function(){
538 var $searchField = jQuery(this);
539 // Create reset button
540 var $resetButton = jQuery("<span>&times;</span>")
541 .css({
542 cursor: "pointer",
543 display: "none", // Initially hidden
544 position: "absolute",
545 right: "10px",
546 top: "50%",
547 transform: "translateY(-50%)",
548 fontSize: "18px"
549 });
550
551 /* Text Fields */
552
553 // Wrap input field in a relative container
554 var $wrapper = jQuery("<div></div>")
555 .css({ position: "relative" })
556 .insertBefore($searchField);
557
558 $wrapper.append($searchField).append($resetButton);
559
560 // Show/hide reset button based on input
561 $searchField.on("input", function () {
562 $resetButton.toggle(!!$searchField.val()); // Toggle visibility based on input
563 });
564
565 // Clear field when reset button is clicked
566 $resetButton.on("click", function () {
567 $searchField.val("").trigger("input").focus(); // Reset field and trigger input event to hide button
568 });
569 });
570 /* Tree Fields */
571
572 jQuery(`input[name="search_location"],input[name="search_category"]`).each(function(){
573
574 var $searchField = jQuery(this);
575 var resetButton;
576
577 // Show/hide reset button based on input
578 $searchField.on("change", function () {
579 if (jQuery(this).val() !== "") {
580 // Wrap input field in a relative container
581 var $wrapper = $searchField.closest('.wdk-field-group').find('.wdk_dropdown_tree button:first-child')
582 .css({ position: "relative" });
583 console.log($wrapper);
584 console.log(resetButton);
585 if (!resetButton) {
586 resetButton = jQuery("<span>&times;</span>")
587 .css({
588 cursor: "pointer",
589 position: "absolute",
590 right: "10px",
591 top: "50%",
592 transform: "translateY(-50%)",
593 fontSize: "18px"
594 })
595 .on("click", function (e) {
596 e.stopPropagation();
597 e.preventDefault();
598
599 $searchField.val("").trigger("input").focus();
600 resetButton.remove();
601 resetButton = null;
602 $searchField.closest('.wdk-field-group').find('.wdk_dropdown_tree button:first-child').html( $searchField.closest('.wdk-field-group').find('.list_items li:first').text());
603
604 return false;
605 });
606 $wrapper.append(resetButton);
607 }
608 } else if (resetButton) {
609 resetButton.remove();
610 resetButton = null;
611 }
612 });
613
614 });
615
616 };
617
618 /* slider for result listings thumbnails */
619 if (typeof wdk_result_listings_thumbnail_slider != 'function') {
620 var wdk_result_listings_thumbnail_slider = ($wrapper = 'body') => {
621 if(typeof jQuery.fn.slick == 'function') {
622 jQuery('.wdk_js_gallery_slider_box', $wrapper).each(function(){
623 var _this = jQuery(this);
624
625 if($wrapper == 'body') {
626 if(_this.closest('.wdk_results_listings_slider_ini').length){return true;}
627 }
628
629 if (_this.closest('.slick-slide').hasClass('slick-cloned')) {
630 return true;
631 }
632
633 // Check if the slider exists and is initialized
634 if (_this.find('.wdk_js_gallery_slider').length > 0 && _this.find('.wdk_js_gallery_slider').hasClass('slick-initialized')) {
635 _this.find('.wdk_js_gallery_slider').slick('unslick');
636 }
637
638
639 _this.find('.wdk_js_gallery_slider').slick({
640 dots: true,
641 infinite: true,
642 speed: 500,
643 fade: true,
644 arrows: true,
645 cssEase: 'linear',
646 nextArrow: _this.find('.wdk_js_gallery_slider-carousel_arrows .wdk-slider-next'),
647 prevArrow: _this.find('.wdk_js_gallery_slider-carousel_arrows .wdk-slider-prev'),
648 });
649 });
650 }
651 };
652 }
653 /*
654 Fix for slick slider, event after init slick
655
656 @param object el slick object
657 @param function callback
658 */
659
660 if (typeof wdk_slick_slider_init != 'function') {
661 var wdk_slick_slider_init = (el, callback) => {
662 try {
663 el.slick("slickGoTo", 0, true);
664 }
665 catch(error) {
666 setTimeout(wdk_slick_slider_init, 1000);
667 return;
668 }
669
670 if(callback) {
671 callback.call();
672 }
673 };
674 }
675 if (typeof wdk_pad != 'function') {
676 var wdk_pad = (num = '') => {
677 return ('00'+num).slice(-2);
678 };
679 }
680
681 if (typeof wdk_date_add_hours != 'function') {
682 var wdk_date_add_hours = (selector = '') => {
683 if(typeof selector !='undefined' && selector.parent().find('[name="hours_mask"]').length) {
684 var datetime = wdk_date_notime_sql_normalize(selector.datepicker("getDate"), selector);
685 if(selector.parent().find('[name="hours_mask"]').val() !='') {
686 datetime += ' '+wdk_pad(selector.parent().find('[name="hours_mask"]').val());
687 } else {
688 datetime += ' 00';
689 }
690 if(selector.parent().find('[name="minutes_mask"]').val() !='') {
691 datetime += ':'+wdk_pad(selector.parent().find('[name="minutes_mask"]').val());
692 } else {
693 datetime += ':00';
694 }
695 datetime += ':00';
696 selector.parent().find('.db-date').val(datetime);
697 }
698 };
699 }
700 /*
701 Convert date to sql format
702
703 @param string $date, string of date
704
705 @return string normalize date or Current date/time
706 */
707 if (typeof wdk_date_sql_normalize != 'function') {
708 var wdk_date_sql_normalize = (date = '', datepicker_el = null) => {
709 if(date == '') {
710 var d = new Date();
711 } else {
712 var d = new Date(date);
713 }
714
715 if(d == 'Invalid Date' && datepicker_el) {
716 var d = new Date(+(jQuery.datepicker.formatDate("@", datepicker_el.datepicker("getDate"))));
717 }
718
719 d = d.getUTCFullYear() + '-' +
720 wdk_pad(d.getMonth() + 1) + '-' +
721 wdk_pad(d.getDate()) + ' ' +
722 wdk_pad(d.getHours()) + ':' +
723 wdk_pad(d.getMinutes()) + ':' +
724 wdk_pad(d.getSeconds());
725 return d;
726 };
727 }
728
729 if (typeof wdk_date_notime_sql_normalize != 'function') {
730 var wdk_date_notime_sql_normalize = (date = '', datepicker_el = null) => {
731 if(date == '') {
732 var d = new Date();
733 } else {
734 var d = new Date(date);
735 }
736
737 if(d == 'Invalid Date' && datepicker_el) {
738 var d = new Date(+(jQuery.datepicker.formatDate("@", datepicker_el.datepicker("getDate"))));
739 }
740
741 d = d.getUTCFullYear() + '-' +
742 wdk_pad(d.getMonth() + 1) + '-' +
743 wdk_pad(d.getDate());
744 return d;
745 };
746 }
747
748 if (typeof wdk_generate_marker_ajax_popup != 'function') {
749 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 = '') => {
750
751 if(auto) {
752 var marker = L.marker(
753 [lat, lng],
754 {icon: L.divIcon({
755 html: innerMarker,
756 className: 'open_steet_map_marker',
757 iconSize: 'auto',
758 })
759 }
760 );
761 } else {
762 var marker = L.marker(
763 [lat, lng],
764 {icon: L.divIcon({
765 html: innerMarker,
766 className: 'open_steet_map_marker',
767 iconSize: [40, 60],
768 popupAnchor: [-1, -35],
769 iconAnchor: [23, 73],
770 })
771 }
772 );
773 }
774
775 var data = {
776 "action": 'wdk_public_action',
777 "page": 'wdk_frontendajax',
778 "function": 'map_infowindow',
779 "listing_post_id": listing_post_id,
780 "custom_layout_id": custom_layout_id,
781 };
782
783 let favorite_init = false;
784 let compare_init = false;
785 marker.bindPopup(function () {
786 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>';
787 marker.getPopup().setContent(content);
788 marker.getPopup().update();
789 jQuery.ajax({
790 url : ajax_url,
791 type : "POST",
792 data: data,
793 success: function (data) {
794 marker.getPopup().setContent(data.popup_content);
795 marker.getPopup().update();
796 if (!favorite_init && typeof wdk_favorite == 'function')
797 wdk_favorite('.infobox');
798
799 favorite_init = false;
800
801 if (!compare_init && typeof wdk_init_compare_elem == 'function')
802 wdk_init_compare_elem();
803
804 compare_init = false;
805 },
806 });
807 return content;
808 }, wdk_jpopup_customOptions);
809
810 if (typeof wdk_favorite == 'function')
811 marker.on('popupopen', function (popup) {
812 if (!favorite_init)
813 wdk_favorite('.infobox');
814 });
815
816 if (typeof wdk_init_compare_elem == 'function')
817 marker.on('popupopen', function (popup) {
818 if (!compare_init)
819 wdk_init_compare_elem();
820 });
821
822 if (typeof wdk_favorite == 'function')
823 marker.on('popupclose', function (popup) {
824 marker.getPopup().setContent(jQuery('.leaflet-popup-content-wrapper .leaflet-popup-content').html());
825 marker.getPopup().update();
826 });
827
828 if(clusters_enabled) {
829 wdk_clusters.addLayer(marker);
830 } else {
831 wdk_map.addLayer(marker);
832 }
833 return marker;
834 }
835 }
836
837 if (typeof wdk_generate_marker_basic_popup != 'function') {
838 var wdk_generate_marker_basic_popup = (lat, lng, innerMarker, wdk_jpopup_content, wdk_jpopup_customOptions) => {
839 var marker = L.marker(
840 [lat, lng],
841 {icon: L.divIcon({
842 html: innerMarker,
843 className: 'open_steet_map_marker',
844 iconSize: [40, 60],
845 popupAnchor: [-1, -35],
846 iconAnchor: [23, 73],
847 })
848 }
849 );
850
851 marker.bindPopup(wdk_jpopup_content, wdk_jpopup_customOptions);
852
853 return marker;
854 }
855 }
856
857 if (typeof wdk_generate_marker_nopopup != 'function') {
858 var wdk_generate_marker_nopopup = (lat, lng,innerMarker) => {
859 var marker = L.marker(
860 [lat, lng],
861 {icon: L.divIcon({
862 html: innerMarker,
863 className: 'open_steet_map_marker',
864 iconSize: [40, 60],
865 popupAnchor: [-1, -35],
866 iconAnchor: [23, 73],
867 })
868 }
869 );
870
871 return marker;
872 }
873 }
874
875 // Share URL function
876 var shareUrl = (url = window.location.href) => {
877 // Check if the browser supports the Web Share API
878 if (!navigator.share) {
879 console.log("Web Share API not supported.");
880 return;
881 }
882
883 navigator.share({
884 url: url, // Share the current page URL
885 })
886 .then(() => {
887 console.log("Shared successfully!");
888 })
889 .catch((error) => {
890 console.error("Sharing failed:", error);
891 });
892 };
893