PluginProbe
WP Directory Kit / 1.2.7
WP Directory Kit v1.2.7
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 1.4.0 All 36 releases
wpdirectorykit / public / js / wpdirectorykit-public.js

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

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