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

522 lines 18.4 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 = () => {
318 if(typeof jQuery.fn.slick == 'function') {
319 jQuery('.wdk_js_gallery_slider_box').each(function(){
320 var _this = jQuery(this);
321 _this.find('.wdk_js_gallery_slider').slick({
322 dots: true,
323 infinite: true,
324 speed: 500,
325 fade: true,
326 arrows: true,
327 cssEase: 'linear',
328 nextArrow: _this.find('.wdk_js_gallery_slider-carousel_arrows .wdk-slider-next'),
329 prevArrow: _this.find('.wdk_js_gallery_slider-carousel_arrows .wdk-slider-prev'),
330 });
331 });
332
333
334 }
335 };
336
337 const wdk_pad = (num = '') => {
338 return ('00'+num).slice(-2);
339 };
340
341 const wdk_date_add_hours = (selector = '') => {
342 if(typeof selector !='undefined' && selector.parent().find('[name="hours_mask"]').length) {
343 var datetime = wdk_date_notime_sql_normalize(selector.val(), selector);
344 if(selector.parent().find('[name="hours_mask"]').val() !='') {
345 datetime += ' '+wdk_pad(selector.parent().find('[name="hours_mask"]').val());
346 } else {
347 datetime += ' 00';
348 }
349 if(selector.parent().find('[name="minutes_mask"]').val() !='') {
350 datetime += ':'+wdk_pad(selector.parent().find('[name="minutes_mask"]').val());
351 } else {
352 datetime += ':00';
353 }
354 datetime += ':00';
355 selector.parent().find('.db-date').val(datetime);
356 }
357 };
358
359 /*
360 Convert date to sql format
361
362 @param string $date, string of date
363
364 @return string normalize date or Current date/time
365 */
366 const wdk_date_sql_normalize = (date = '', datepicker_el = null) => {
367 if(date == '') {
368 var d = new Date();
369 } else {
370 var d = new Date(date);
371 }
372
373 if(d == 'Invalid Date' && datepicker_el) {
374 var d = new Date(+(jQuery.datepicker.formatDate("@", datepicker_el.datepicker("getDate"))));
375 }
376
377 d = d.getUTCFullYear() + '-' +
378 wdk_pad(d.getMonth() + 1) + '-' +
379 wdk_pad(d.getDate()) + ' ' +
380 wdk_pad(d.getHours()) + ':' +
381 wdk_pad(d.getMinutes()) + ':' +
382 wdk_pad(d.getSeconds());
383 return d;
384 };
385
386 const wdk_date_notime_sql_normalize = (date = '', datepicker_el = null) => {
387 if(date == '') {
388 var d = new Date();
389 } else {
390 var d = new Date(date);
391 }
392
393 if(d == 'Invalid Date' && datepicker_el) {
394 var d = new Date(+(jQuery.datepicker.formatDate("@", datepicker_el.datepicker("getDate"))));
395 }
396
397 d = d.getUTCFullYear() + '-' +
398 wdk_pad(d.getMonth() + 1) + '-' +
399 wdk_pad(d.getDate());
400 return d;
401 };
402
403
404 const wdk_generate_marker_ajax_popup = (ajax_url, listing_post_id, lat, lng,innerMarker, wdk_jpopup_customOptions, auto = false) => {
405
406 if(auto) {
407 var marker = L.marker(
408 [lat, lng],
409 {icon: L.divIcon({
410 html: innerMarker,
411 className: 'open_steet_map_marker',
412 iconSize: 'auto',
413 })
414 }
415 );
416 } else {
417 var marker = L.marker(
418 [lat, lng],
419 {icon: L.divIcon({
420 html: innerMarker,
421 className: 'open_steet_map_marker',
422 iconSize: [40, 60],
423 popupAnchor: [-1, -35],
424 iconAnchor: [25, 60],
425 })
426 }
427 );
428 }
429
430 var data = {
431 "action": 'wdk_public_action',
432 "page": 'wdk_frontendajax',
433 "function": 'map_infowindow',
434 "listing_post_id": listing_post_id
435 };
436
437 let favorite_init = false;
438 let compare_init = false;
439 marker.bindPopup(function () {
440 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>';
441 marker.getPopup().setContent(content);
442 marker.getPopup().update();
443 jQuery.ajax({
444 url : ajax_url,
445 type : "POST",
446 data: data,
447 success: function (data) {
448 marker.getPopup().setContent(data.popup_content);
449 marker.getPopup().update();
450 if (!favorite_init && typeof wdk_favorite == 'function')
451 wdk_favorite('.infobox');
452
453 favorite_init = false;
454
455 if (!compare_init && typeof wdk_init_compare_elem == 'function')
456 wdk_init_compare_elem();
457
458 compare_init = false;
459 },
460 });
461 return content;
462 }, wdk_jpopup_customOptions);
463
464 if (typeof wdk_favorite == 'function')
465 marker.on('popupopen', function (popup) {
466 if (!favorite_init)
467 wdk_favorite('.infobox');
468 });
469
470 if (typeof wdk_init_compare_elem == 'function')
471 marker.on('popupopen', function (popup) {
472 if (!compare_init)
473 wdk_init_compare_elem();
474 });
475
476 if (typeof wdk_favorite == 'function')
477 marker.on('popupclose', function (popup) {
478 marker.getPopup().setContent(jQuery('.leaflet-popup-content-wrapper .leaflet-popup-content').html());
479 marker.getPopup().update();
480 });
481
482 wdk_clusters.addLayer(marker);
483 return marker;
484 }
485
486 const wdk_generate_marker_basic_popup = (lat, lng, innerMarker, wdk_jpopup_content, wdk_jpopup_customOptions) => {
487 var marker = L.marker(
488 [lat, lng],
489 {icon: L.divIcon({
490 html: innerMarker,
491 className: 'open_steet_map_marker',
492 iconSize: [40, 60],
493 popupAnchor: [-1, -35],
494 iconAnchor: [25, 60],
495 })
496 }
497 );
498
499 marker.bindPopup(wdk_jpopup_content, wdk_jpopup_customOptions);
500
501 wdk_clusters.addLayer(marker);
502 return marker;
503 }
504
505 const wdk_generate_marker_nopopup = (lat, lng,innerMarker) => {
506 var marker = L.marker(
507 [lat, lng],
508 {icon: L.divIcon({
509 html: innerMarker,
510 className: 'open_steet_map_marker',
511 iconSize: [40, 60],
512 popupAnchor: [-1, -35],
513 iconAnchor: [25, 60],
514 })
515 }
516 );
517
518 wdk_clusters.addLayer(marker);
519 return marker;
520 }
521
522