PluginProbe
WP Directory Kit / 1.2.3
WP Directory Kit v1.2.3
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 1.4.0 1.4.1 All 35 releases
wpdirectorykit / public / js / wpdirectorykit-public.js

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

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