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

649 lines 23.5 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($(".wdk-search-popup .toggle-btn:visible"), function (i, k) {
93 let el = $($(this).attr('data-wdk-target'));
94 if(el && el.length) {
95 $.each(el.find('.wdk-search-form').serializeArray(), function (i, k) {
96 if (k.value != '' && k.name.indexOf('skip') == -1) {
97 if (str_parameters != "") {
98 str_parameters += "&";
99 }
100 str_parameters += k.name + "=" + encodeURIComponent(k.value);
101 }
102 });
103 }
104 });
105
106 /* view_type */
107 if($('.wmvc-view-type .nav-link.active').length) {
108 str_parameters += "&wmvc_view_type="+$('.wmvc-view-type .nav-link.active').attr('data-id');
109 }
110
111 /* order by */
112 if($('.wdk-order').val() != '' && $('.wdk-order').val()) {
113 str_parameters += "&order_by="+$('.wdk-order').val();
114 }
115
116 if ($('.wdk-search-form[data-scrollto]').length)
117 scrollTo = '#'+$('.wdk-search-form[data-scrollto]').attr('data-scrollto');
118
119
120
121 var setCookie = (cname, cvalue, exdays) => {
122 var d = new Date();
123 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
124 var expires = "expires="+d.toUTCString();
125 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
126 }
127 setCookie('wdk_last_search', str_parameters);
128
129 return url+str_parameters+scrollTo;
130 }
131
132 /* set current page for search results if exists results widget and enabled in setttings*/
133 if($('form.wdk-search-form').length && $('.wdk-listings-results').length && $("form.wdk-search-form").attr('data-current-link') != '') {
134 $('form.wdk-search-form').attr('action', $("form.wdk-search-form").attr('data-current-link'));
135 }
136
137 $("form.wdk-search-form").on('submit', function (e) {
138 e.preventDefault();
139 var url = wdk_start_search($(this));
140 $(this).closest('form').addClass('loading')
141 if (decodeURI(window.location.href) == decodeURI(url)) {
142 window.location.reload();
143 } else {
144 window.location.href = url;
145 }
146 return false;
147 });
148
149 $("form.wdk-search-form.auto_search").find('input, select').on('input', function (e) {
150 $("form.wdk-search-form").first().trigger('submit')
151 });
152
153 $("form.wdk-search-form .wdk-search-start").on('click', function (e) {
154 e.preventDefault();
155 var url = wdk_start_search($(this).closest('form'));
156 $(this).closest('form').addClass('loading')
157
158 if($(this).closest('.ajax_results_enabled').length) {
159 if (typeof wdk_ajax_loading_listings == 'function') {
160 wdk_ajax_loading_listings(url);
161 }
162 } else if (decodeURI(window.location.href) == decodeURI(url)) {
163 window.location.reload(url);
164 } else {
165 window.location.href = url;
166 }
167 return false;
168 })
169
170 $('.wdk-listings-results.ajax_results_enabled .wdk-pagination .page-numbers').on('click', function (e) {
171 e.preventDefault();
172 if (typeof wdk_ajax_loading_listings == 'function') {
173 wdk_ajax_loading_listings($(this).attr('href'));
174 }
175 })
176
177 /* elementor popup */
178 jQuery( document ).on( 'elementor/popup/show', () => {
179 wdk_reset_form();
180 } );
181
182 const wdk_reset_form = () => {
183 $("form.wdk-search-form .wdk-search-reset").off().on('click', function (e) {
184 e.preventDefault();
185 let this_form = jQuery(this).closest('form');
186 this_form.find('input:not([type="checkbox"]):not([name="element_id"]):not([type="radio"]):not([type="hidden"]),textarea,select').val('');
187 this_form.find('select').val(jQuery(this).find('option:first').val()).trigger('change')
188 this_form.find('input[type="checkbox"]').prop('checked', false);
189 this_form.find('.wdk-field.LOCATION .wdk_dropdown_tree button:first-child').html(this_form.find('.wdk-field.LOCATION .list_items li:first').text());
190 this_form.find('.wdk-field.CATEGORY .wdk_dropdown_tree button:first-child').html(this_form.find('.wdk-field.CATEGORY .list_items li:first').text());
191
192 return false;
193 })
194 };
195 wdk_reset_form();
196
197 /* date time fields init */
198 if ($('.wdk-fielddate').length && typeof $.datepicker != 'undefined') {
199
200 $('.wdk-fielddate').each(function () {
201 let dateFormat = script_parameters.format_date_js;
202 var self = $(this);
203
204 if (self.attr('date-format'))
205 dateFormat = self.attr('date-format');
206
207 self.datepicker({ dateFormat: dateFormat, onSelect: function() {
208 self.parent().find('.db-date').val(wdk_date_sql_normalize(self.val(), self)).trigger('input');
209 }
210 }).on( "change", function() {
211 self.parent().find('.db-date').val(wdk_date_sql_normalize(self.val(), self));
212 });
213
214 if(self.parent().find('.db-date').val() == '') {
215 self.parent().find('.db-date').val(wdk_date_notime_sql_normalize());
216 }
217 })
218 } ;
219
220
221 if ($('.wdk-fielddatetime').length && typeof $.datepicker != 'undefined') {
222
223 $('.wdk-fielddatetime').each(function () {
224 let dateFormat = script_parameters.format_datetime_js;
225
226 var self = $(this);
227 if (self.attr('date-format'))
228 dateFormat = self.attr('date-format');
229
230 self.datepicker({ dateFormat: dateFormat, onSelect: function() {
231 var datetime = wdk_date_notime_sql_normalize(self.val(), self);
232 if(self.parent().find('[name="hours_mask"]').val() !='') {
233 datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
234 } else {
235 datetime += ' 00';
236 }
237 if(self.parent().find('[name="minutes_mask"]').val() !='') {
238 datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
239 } else {
240 datetime += ':00';
241 }
242 datetime += ':00';
243
244 self.parent().find('.db-date').val(datetime).trigger('input');
245 }
246 }).on( "change", function() {
247
248 var datetime = wdk_date_notime_sql_normalize(self.val(), self);
249 if(self.parent().find('[name="hours_mask"]').val() !='') {
250 datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
251 } else {
252 datetime += ' 00';
253 }
254 if(self.parent().find('[name="minutes_mask"]').val() !='') {
255 datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
256 } else {
257 datetime += ':00';
258 }
259 datetime += ':00';
260 self.parent().find('.db-date').val(datetime);
261 });
262
263 if(self.parent().find('.db-date').val() == '') {
264 self.parent().find('.db-date').val(wdk_date_sql_normalize());
265 }
266
267 self.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
268 var datetime = wdk_date_notime_sql_normalize(self.val(), self);
269 if(self.parent().find('[name="hours_mask"]').val() !='') {
270 datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
271 } else {
272 datetime += ' 00';
273 }
274 if(self.parent().find('[name="minutes_mask"]').val() !='') {
275 datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
276 } else {
277 datetime += ':00';
278 }
279 datetime += ':00';
280 self.parent().find('.db-date').val(datetime);
281 });
282 })
283 };
284
285 if ($('.wdk-fielddate_from').length && $('.wdk-fielddate_to').length && typeof $.datepicker != 'undefined') {
286 var dateFormat, from, to;
287 const getDate = ( element ) => {
288 var date;
289 try {
290 date = $.datepicker.parseDate( dateFormat, element.value );
291 } catch( error ) {
292 date = null;
293 }
294 return date;
295 }
296
297 dateFormat = script_parameters.format_date_js;
298 if ($('.wdk-fielddate_from').attr('date-format'))
299 dateFormat = $('.wdk-fielddate_from').attr('date-format');
300
301 from = $('.wdk-fielddate_from')
302 .datepicker({
303 dateFormat: dateFormat,
304 onSelect: function( selectedDate ) {
305 to.datepicker("option", "minDate", selectedDate );
306 setTimeout(function(){
307 to.datepicker('show');
308 }, 16);
309
310 from.parent().find('.db-date').val(wdk_date_sql_normalize(from.val(), from));
311 wdk_date_add_hours(from);
312 }
313 }).on( "change", function() {
314 from.parent().find('.db-date').val(wdk_date_sql_normalize(from.val(), from)).trigger('input');
315 });
316
317 to = $('.wdk-fielddate_to').datepicker({
318 dateFormat: dateFormat
319 })
320 .on( "change", function() {
321 from.datepicker( "option", "maxDate", getDate( this ) );
322 to.parent().find('.db-date').val(wdk_date_sql_normalize(to.val(), to)).trigger('input');
323 wdk_date_add_hours(to);
324 });
325
326 if(to.parent().find('.db-date').val() == '') {
327 to.parent().find('.db-date').val(wdk_date_sql_normalize());
328 }
329
330 if(from.parent().find('.db-date').val() == '') {
331 from.parent().find('.db-date').val(wdk_date_sql_normalize());
332 }
333
334 from.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
335 wdk_date_add_hours(from);
336 });
337
338 to.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
339 wdk_date_add_hours(to);
340 });
341 }
342 if(typeof $.fn.wdkSuggestion == 'function') {
343
344 if(typeof script_parameters.settings_wdk_field_search_suggestion_disable != 'undefined' && script_parameters.settings_wdk_field_search_suggestion_disable == 1) {
345
346 } else {
347 $('#wdk_field_search').wdkSuggestion({
348 ajax_url: script_parameters.ajax_url,
349 ajax_param: {
350 "action": 'wdk_public_action',
351 "page": 'wdk_frontendajax',
352 "function": 'search_suggestion',
353 },
354 language_id: '',
355 text_search: 'Search',
356 callback_selected: function(key) {
357
358 }
359 });
360 }
361
362 }
363
364 $('.wdk-control[type="number"]').on('change',function(){
365 let val = $(this).val();
366 let step = 1;
367 if(val.length>=7){
368 step = 10000;
369 } else if(val.length>=4) {
370 step = 10;
371 }
372 $(this).attr('step', step);
373 })
374
375
376 if(typeof $.fn.fieldSliderRange == 'function' && typeof $.fn.ionRangeSlider == 'function') {
377 $('.wdk-slider-range-field').fieldSliderRange();
378 }
379
380 wdk_result_listings_thumbnail_slider();
381
382 /* if video exists on thumbnail css trick */
383 $('.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');
384
385
386 if(typeof $.fn.WdkScrollMobileSwipe == 'function') {
387 $('.WdkScrollMobileSwipe_enable').WdkScrollMobileSwipe();
388 $('.WdkScrollMobileSwipe_elementor_enable .elementor-container').WdkScrollMobileSwipe();
389 }
390
391 if($('.wl-menu-toggle').length) {
392 $('.wdk-footer-menu .wdk_mobile_footer_menu_gumb-open').addClass('trigger')
393 $('.wdk-footer-menu .wdk_mobile_footer_menu_gumb-open').on('click', function(e){
394 e.preventDefault();
395 $('.wl-menu-toggle').trigger('click');
396 });
397 }
398 });
399
400 })(jQuery);
401
402 /* slider for result listings thumbnails */
403 if (typeof wdk_result_listings_thumbnail_slider != 'function') {
404 var wdk_result_listings_thumbnail_slider = ($wrapper = 'body') => {
405 if(typeof jQuery.fn.slick == 'function') {
406 jQuery('.wdk_js_gallery_slider_box', $wrapper).each(function(){
407 var _this = jQuery(this);
408
409 if(_this.closest('.slick-slide').hasClass('slick-cloned')){return true;}
410
411 if(_this.find('.wdk_js_gallery_slider').hasClass('slick-initialized')) {
412 _this.find('.wdk_js_gallery_slider').slick("unslick");
413 }
414
415 _this.find('.wdk_js_gallery_slider').slick({
416 dots: true,
417 infinite: true,
418 speed: 500,
419 fade: true,
420 arrows: true,
421 cssEase: 'linear',
422 nextArrow: _this.find('.wdk_js_gallery_slider-carousel_arrows .wdk-slider-next'),
423 prevArrow: _this.find('.wdk_js_gallery_slider-carousel_arrows .wdk-slider-prev'),
424 });
425 });
426 }
427 };
428 }
429 /*
430 Fix for slick slider, event after init slick
431
432 @param object el slick object
433 @param function callback
434 */
435
436 if (typeof wdk_slick_slider_init != 'function') {
437 var wdk_slick_slider_init = (el, callback) => {
438 try {
439 el.slick("slickGoTo", 0, true);
440 }
441 catch(error) {
442 setTimeout(wdk_slick_slider_init, 1000);
443 return;
444 }
445
446 if(callback) {
447 callback.call();
448 }
449 };
450 }
451 if (typeof wdk_pad != 'function') {
452 var wdk_pad = (num = '') => {
453 return ('00'+num).slice(-2);
454 };
455 }
456
457 if (typeof wdk_date_add_hours != 'function') {
458 var wdk_date_add_hours = (selector = '') => {
459 if(typeof selector !='undefined' && selector.parent().find('[name="hours_mask"]').length) {
460 var datetime = wdk_date_notime_sql_normalize(selector.val(), selector);
461 if(selector.parent().find('[name="hours_mask"]').val() !='') {
462 datetime += ' '+wdk_pad(selector.parent().find('[name="hours_mask"]').val());
463 } else {
464 datetime += ' 00';
465 }
466 if(selector.parent().find('[name="minutes_mask"]').val() !='') {
467 datetime += ':'+wdk_pad(selector.parent().find('[name="minutes_mask"]').val());
468 } else {
469 datetime += ':00';
470 }
471 datetime += ':00';
472 selector.parent().find('.db-date').val(datetime);
473 }
474 };
475 }
476 /*
477 Convert date to sql format
478
479 @param string $date, string of date
480
481 @return string normalize date or Current date/time
482 */
483 if (typeof wdk_date_sql_normalize != 'function') {
484 var wdk_date_sql_normalize = (date = '', datepicker_el = null) => {
485 if(date == '') {
486 var d = new Date();
487 } else {
488 var d = new Date(date);
489 }
490
491 if(d == 'Invalid Date' && datepicker_el) {
492 var d = new Date(+(jQuery.datepicker.formatDate("@", datepicker_el.datepicker("getDate"))));
493 }
494
495 d = d.getUTCFullYear() + '-' +
496 wdk_pad(d.getMonth() + 1) + '-' +
497 wdk_pad(d.getDate()) + ' ' +
498 wdk_pad(d.getHours()) + ':' +
499 wdk_pad(d.getMinutes()) + ':' +
500 wdk_pad(d.getSeconds());
501 return d;
502 };
503 }
504
505 if (typeof wdk_date_notime_sql_normalize != 'function') {
506 var wdk_date_notime_sql_normalize = (date = '', datepicker_el = null) => {
507 if(date == '') {
508 var d = new Date();
509 } else {
510 var d = new Date(date);
511 }
512
513 if(d == 'Invalid Date' && datepicker_el) {
514 var d = new Date(+(jQuery.datepicker.formatDate("@", datepicker_el.datepicker("getDate"))));
515 }
516
517 d = d.getUTCFullYear() + '-' +
518 wdk_pad(d.getMonth() + 1) + '-' +
519 wdk_pad(d.getDate());
520 return d;
521 };
522 }
523
524 if (typeof wdk_generate_marker_ajax_popup != 'function') {
525 var wdk_generate_marker_ajax_popup = (ajax_url, listing_post_id, lat, lng,innerMarker, wdk_jpopup_customOptions, auto = false, clusters_enabled = true) => {
526
527 if(auto) {
528 var marker = L.marker(
529 [lat, lng],
530 {icon: L.divIcon({
531 html: innerMarker,
532 className: 'open_steet_map_marker',
533 iconSize: 'auto',
534 })
535 }
536 );
537 } else {
538 var marker = L.marker(
539 [lat, lng],
540 {icon: L.divIcon({
541 html: innerMarker,
542 className: 'open_steet_map_marker',
543 iconSize: [40, 60],
544 popupAnchor: [-1, -35],
545 iconAnchor: [25, 60],
546 })
547 }
548 );
549 }
550
551 var data = {
552 "action": 'wdk_public_action',
553 "page": 'wdk_frontendajax',
554 "function": 'map_infowindow',
555 "listing_post_id": listing_post_id
556 };
557
558 let favorite_init = false;
559 let compare_init = false;
560 marker.bindPopup(function () {
561 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>';
562 marker.getPopup().setContent(content);
563 marker.getPopup().update();
564 jQuery.ajax({
565 url : ajax_url,
566 type : "POST",
567 data: data,
568 success: function (data) {
569 marker.getPopup().setContent(data.popup_content);
570 marker.getPopup().update();
571 if (!favorite_init && typeof wdk_favorite == 'function')
572 wdk_favorite('.infobox');
573
574 favorite_init = false;
575
576 if (!compare_init && typeof wdk_init_compare_elem == 'function')
577 wdk_init_compare_elem();
578
579 compare_init = false;
580 },
581 });
582 return content;
583 }, wdk_jpopup_customOptions);
584
585 if (typeof wdk_favorite == 'function')
586 marker.on('popupopen', function (popup) {
587 if (!favorite_init)
588 wdk_favorite('.infobox');
589 });
590
591 if (typeof wdk_init_compare_elem == 'function')
592 marker.on('popupopen', function (popup) {
593 if (!compare_init)
594 wdk_init_compare_elem();
595 });
596
597 if (typeof wdk_favorite == 'function')
598 marker.on('popupclose', function (popup) {
599 marker.getPopup().setContent(jQuery('.leaflet-popup-content-wrapper .leaflet-popup-content').html());
600 marker.getPopup().update();
601 });
602
603 if(clusters_enabled) {
604 wdk_clusters.addLayer(marker);
605 } else {
606 wdk_map.addLayer(marker);
607 }
608 return marker;
609 }
610 }
611
612 if (typeof wdk_generate_marker_basic_popup != 'function') {
613 var wdk_generate_marker_basic_popup = (lat, lng, innerMarker, wdk_jpopup_content, wdk_jpopup_customOptions) => {
614 var marker = L.marker(
615 [lat, lng],
616 {icon: L.divIcon({
617 html: innerMarker,
618 className: 'open_steet_map_marker',
619 iconSize: [40, 60],
620 popupAnchor: [-1, -35],
621 iconAnchor: [25, 60],
622 })
623 }
624 );
625
626 marker.bindPopup(wdk_jpopup_content, wdk_jpopup_customOptions);
627
628 return marker;
629 }
630 }
631
632 if (typeof wdk_generate_marker_nopopup != 'function') {
633 var wdk_generate_marker_nopopup = (lat, lng,innerMarker) => {
634 var marker = L.marker(
635 [lat, lng],
636 {icon: L.divIcon({
637 html: innerMarker,
638 className: 'open_steet_map_marker',
639 iconSize: [40, 60],
640 popupAnchor: [-1, -35],
641 iconAnchor: [25, 60],
642 })
643 }
644 );
645
646 return marker;
647 }
648 }
649