PluginProbe
WP Directory Kit / 1.5.9
WP Directory Kit v1.5.9
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
← All changes | admin/js/wpdirectorykit-admin.js +297 -156 1.5.4 → 1.5.9 View file →
@@ -1,5 +1,5 @@
1 -(function( $ ) {
1 +(function ($) {
2 2 'use strict';
3 3
4 4 /**
5 5 * All of the code for your admin-facing JavaScript source
@@ -28,202 +28,204 @@
28 28 * Although scripts in the WordPress core, Plugins and Themes may be
29 29 * practising this, we should strive to set a better example in our own work.
30 30 */
31 31
32 - jQuery(document).ready(function($) {
33 - $('.event-ajax-indicator').on('click submit', function () {
32 + jQuery(document).ready(function ($) {
33 + $('.event-ajax-indicator').on('click submit', function () {
34 34 if ($(this).find('.wdk-ajax-indicator').length) {
35 35 $(this).find('.wdk-ajax-indicator').removeClass('hidden')
36 - .removeClass('wdk-hidden');
36 + .removeClass('wdk-hidden');
37 37 $(this).find('.hidden-onloading').addClass('wdk-hidden');
38 38 }
39 39 else {
40 40 $(this).parent().find('.wdk-ajax-indicator').removeClass('hidden');
41 41 }
42 - })
42 + })
43 43
44 -
45 - $('.wdk-submit-loading').on('click', function () {
46 - var form;
47 - form = $(this).closest('form');
48 44
49 - if( $(this).hasClass('wdk_btn_load_indicator')) {
50 - console.log('disabled')
51 - return false;
52 - }
45 + $('.wdk-submit-loading').on('click', function () {
46 + var form;
47 + form = $(this).closest('form');
53 48
54 - $(this).addClass('wdk_btn_load_indicator disabled');
55 - });
56 -
57 - $('.wdk-click-loading').on('click', function (e) {
58 - $(this).addClass('wdk_btn_load_indicator').attr('disabled','disabled');
59 - });
60 -
61 - /* date time fields init */
62 - if ($('.wdk-fielddate').length && typeof $.datepicker != 'undefined') {
63 -
64 - $('.wdk-fielddate').each(function () {
65 - let dateFormat = script_parameters.format_date_js;
49 + if ($(this).hasClass('wdk_btn_load_indicator')) {
50 + console.log('disabled')
51 + return false;
52 + }
53 +
54 + $(this).addClass('wdk_btn_load_indicator disabled');
55 + });
56 +
57 + $('.wdk-click-loading').on('click', function (e) {
58 + $(this).addClass('wdk_btn_load_indicator').attr('disabled', 'disabled');
59 + });
60 +
61 + /* date time fields init */
62 + if ($('.wdk-fielddate').length && typeof $.datepicker != 'undefined') {
63 +
64 + $('.wdk-fielddate').each(function () {
65 + let dateFormat = script_parameters.format_date_js;
66 66 var self = $(this);
67 67
68 - if (self.attr('date-format'))
69 - dateFormat = self.attr('date-format');
68 + if (self.attr('date-format'))
69 + dateFormat = self.attr('date-format');
70 70
71 - self.datepicker({ dateFormat: dateFormat, onSelect: function() {
71 + self.datepicker({
72 + dateFormat: dateFormat, onSelect: function () {
72 73 self.parent().find('.db-date').val(wdk_date_sql_normalize(self.val(), self)).trigger('input');
73 74 }
74 - }).on( "change", function() {
75 - if(self.val() == '') {
75 + }).on("change", function () {
76 + if (self.val() == '') {
76 77 self.parent().find('.db-date').val('');
77 78 } else {
78 79 self.parent().find('.db-date').val(wdk_date_sql_normalize(self.val(), self));
79 80 }
80 81 });
81 -
82 - if(self.parent().find('.db-date').val() == '' && false) {
83 - self.parent().find('.db-date').val(wdk_date_sql_normalize());
84 - }
85 - })
82 +
83 + if (self.parent().find('.db-date').val() == '' && false) {
84 + self.parent().find('.db-date').val(wdk_date_sql_normalize());
85 + }
86 + })
86 87 };
87 88
88 - if ($('.wdk-fielddatetime').length && typeof $.datepicker != 'undefined') {
89 + if ($('.wdk-fielddatetime').length && typeof $.datepicker != 'undefined') {
89 90
90 91 $('.wdk-fielddatetime').each(function () {
91 - let dateFormat = script_parameters.format_datetime_js;
92 + let dateFormat = script_parameters.format_datetime_js;
92 93
93 94 var self = $(this);
94 - if (self.attr('date-format'))
95 - dateFormat = self.attr('date-format');
95 + if (self.attr('date-format'))
96 + dateFormat = self.attr('date-format');
96 97
97 - self.datepicker({ dateFormat: dateFormat, onSelect: function() {
98 -
98 + self.datepicker({
99 + dateFormat: dateFormat, onSelect: function () {
99 100
100 - var datetime = wdk_date_notime_sql_normalize(self.val(), self);
101 - if(self.parent().find('[name="hours_mask"]').val() !='') {
102 - datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
103 - } else {
104 - datetime += ' 00';
105 - }
106 - if(self.parent().find('[name="minutes_mask"]').val() !='') {
107 - datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
108 - } else {
109 - datetime += ':00';
110 - }
111 - datetime += ':00';
112 101
102 + var datetime = wdk_date_notime_sql_normalize(self.val(), self);
103 + if (self.parent().find('[name="hours_mask"]').val() != '') {
104 + datetime += ' ' + wdk_pad(self.parent().find('[name="hours_mask"]').val());
105 + } else {
106 + datetime += ' 00';
107 + }
108 + if (self.parent().find('[name="minutes_mask"]').val() != '') {
109 + datetime += ':' + wdk_pad(self.parent().find('[name="minutes_mask"]').val());
110 + } else {
111 + datetime += ':00';
112 + }
113 + datetime += ':00';
114 +
113 115 self.parent().find('.db-date').val(datetime).trigger('input');
114 116 }
115 - }).on( "change", function() {
116 -
117 - var datetime = wdk_date_notime_sql_normalize(self.val(), self);
118 - if(self.parent().find('[name="hours_mask"]').val() !='') {
119 - datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
120 - } else {
121 - datetime += ' 00';
122 - }
123 - if(self.parent().find('[name="minutes_mask"]').val() !='') {
124 - datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
125 - } else {
126 - datetime += ':00';
127 - }
128 - datetime += ':00';
117 + }).on("change", function () {
118 +
119 + var datetime = wdk_date_notime_sql_normalize(self.val(), self);
120 + if (self.parent().find('[name="hours_mask"]').val() != '') {
121 + datetime += ' ' + wdk_pad(self.parent().find('[name="hours_mask"]').val());
122 + } else {
123 + datetime += ' 00';
124 + }
125 + if (self.parent().find('[name="minutes_mask"]').val() != '') {
126 + datetime += ':' + wdk_pad(self.parent().find('[name="minutes_mask"]').val());
127 + } else {
128 + datetime += ':00';
129 + }
130 + datetime += ':00';
129 131 self.parent().find('.db-date').val(datetime).trigger('input');
130 132
131 133 });
132 134
133 - if(self.parent().find('.db-date').val() == '') {
134 - self.parent().find('.db-date').val(wdk_date_sql_normalize());
135 - }
135 + if (self.parent().find('.db-date').val() == '') {
136 + self.parent().find('.db-date').val(wdk_date_sql_normalize());
137 + }
136 138
137 - self.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
138 - var datetime = wdk_date_notime_sql_normalize(self.val(), self);
139 - if(self.parent().find('[name="hours_mask"]').val() !='') {
140 - datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
141 - } else {
142 - datetime += ' 00';
143 - }
144 - if(self.parent().find('[name="minutes_mask"]').val() !='') {
145 - datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
146 - } else {
147 - datetime += ':00';
148 - }
149 - datetime += ':00';
139 + self.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function () {
140 + var datetime = wdk_date_notime_sql_normalize(self.val(), self);
141 + if (self.parent().find('[name="hours_mask"]').val() != '') {
142 + datetime += ' ' + wdk_pad(self.parent().find('[name="hours_mask"]').val());
143 + } else {
144 + datetime += ' 00';
145 + }
146 + if (self.parent().find('[name="minutes_mask"]').val() != '') {
147 + datetime += ':' + wdk_pad(self.parent().find('[name="minutes_mask"]').val());
148 + } else {
149 + datetime += ':00';
150 + }
151 + datetime += ':00';
150 152 self.parent().find('.db-date').val(datetime);
151 - });
152 - })
153 + });
154 + })
153 155 };
154 156
155 157 if ($('.wdk-fielddate_from').length && $('.wdk-fielddate_to').length && typeof $.datepicker != 'undefined') {
156 158 var dateFormat, from, to;
157 - const getDate = ( element ) => {
159 + const getDate = (element) => {
158 160 var date;
159 161 try {
160 - date = $.datepicker.parseDate( dateFormat, element.value );
161 - } catch( error ) {
162 + date = $.datepicker.parseDate(dateFormat, element.value);
163 + } catch (error) {
162 164 date = null;
163 165 }
164 166 return date;
165 - }
167 + }
166 168
167 169 dateFormat = script_parameters.format_date_js;
168 170 if ($('.wdk-fielddate_from').attr('date-format'))
169 - dateFormat = $('.wdk-fielddate_from').attr('date-format');
171 + dateFormat = $('.wdk-fielddate_from').attr('date-format');
170 172
171 173 from = $('.wdk-fielddate_from')
172 174 .datepicker({
173 175 dateFormat: dateFormat,
174 - onSelect: function( selectedDate ) {
175 - to.datepicker("option", "minDate", selectedDate );
176 - setTimeout(function(){
176 + onSelect: function (selectedDate) {
177 + to.datepicker("option", "minDate", selectedDate);
178 + setTimeout(function () {
177 179 to.datepicker('show');
178 180 }, 16);
179 -
181 +
180 182 from.parent().find('.db-date').val(wdk_date_sql_normalize(from.val(), from)).trigger('input');
181 183 wdk_date_add_hours(from);
182 -
184 +
183 185 }
184 - }).on( "change", function() {
186 + }).on("change", function () {
185 187
186 188 });
187 -
189 +
188 190 to = $('.wdk-fielddate_to').datepicker({
189 191 dateFormat: dateFormat
190 192 })
191 - .on( "change", function() {
192 - from.datepicker( "option", "maxDate", getDate( this ) );
193 + .on("change", function () {
194 + from.datepicker("option", "maxDate", getDate(this));
193 195
194 - to.parent().find('.db-date').val(wdk_date_sql_normalize(to.val(), to)).trigger('input');
195 - wdk_date_add_hours(to);
196 - });
197 -
198 - if(to.parent().find('.db-date').val() == '') {
199 - to.parent().find('.db-date').val(wdk_date_sql_normalize());
200 - }
196 + to.parent().find('.db-date').val(wdk_date_sql_normalize(to.val(), to)).trigger('input');
197 + wdk_date_add_hours(to);
198 + });
201 199
202 - if(from.parent().find('.db-date').val() == '') {
203 - from.parent().find('.db-date').val(wdk_date_sql_normalize());
204 - }
200 + if (to.parent().find('.db-date').val() == '') {
201 + to.parent().find('.db-date').val(wdk_date_sql_normalize());
202 + }
205 203
206 - from.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
204 + if (from.parent().find('.db-date').val() == '') {
205 + from.parent().find('.db-date').val(wdk_date_sql_normalize());
206 + }
207 +
208 + from.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function () {
207 209 wdk_date_add_hours(from);
208 210 });
209 -
210 - to.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
211 +
212 + to.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function () {
211 213 wdk_date_add_hours(to);
212 214 });
213 -
215 +
214 216 }
215 217
216 - jQuery(document).ready( function($) {
217 - $( "ul#adminmenu a[href*='wordpress.org/support/plugin/wpdirectorykit']" ).attr( 'target', '_blank' );
218 - $( "ul#adminmenu a[href*='wpdirectorykit.com/contact.html']" ).attr( 'target', '_blank' );
219 - $( "ul#adminmenu a[href*='wpdirectorykit.com/documentation']" ).attr( 'target', '_blank' );
220 - });
218 + jQuery(document).ready(function ($) {
219 + $("ul#adminmenu a[href*='wordpress.org/support/plugin/wpdirectorykit']").attr('target', '_blank');
220 + $("ul#adminmenu a[href*='wpdirectorykit.com/contact.html']").attr('target', '_blank');
221 + $("ul#adminmenu a[href*='wpdirectorykit.com/documentation']").attr('target', '_blank');
222 + });
221 223
222 224
223 225 /* wdk pro feature ask */
224 226 if (typeof $.fn.confirm == 'function') {
225 - $('.wdk-pro, .wdk-pro a, .wdk-pro button, .wdk-pro input').off().on('click', function(e){
227 + $('.wdk-pro, .wdk-pro a, .wdk-pro button, .wdk-pro input').off().on('click', function (e) {
226 228 e.preventDefault();
227 229 var self = jQuery(this)
228 230 jQuery.confirm({
229 231 boxWidth: '400px',
@@ -228,9 +230,9 @@
228 230 jQuery.confirm({
229 231 boxWidth: '400px',
230 232 useBootstrap: false,
231 233 title: self.data('title'),
232 - content: self.data('content'),
234 + content: self.data('content'),
233 235 buttons: {
234 236 cancel: function () {
235 237 return true;
236 238 },
@@ -237,9 +239,9 @@
237 239 somethingElse: {
238 240 text: self.data('button-succuss'),
239 241 btnClass: 'btn-blue activate-now',
240 242 keys: ['enter', 'shift'],
241 - action: function(){
243 + action: function () {
242 244 window.location = self.data('action');
243 245 return false;
244 246 }
245 247 }
@@ -246,13 +248,13 @@
246 248 }
247 249 });
248 250 return false;
249 251 });
250 - $('select.wdk-pro-select').off().on('input', function(e) {
251 -
252 + $('select.wdk-pro-select').off().on('input', function (e) {
253 +
252 254 var self = jQuery(this);
253 255 var selected = self.find('option:selected');
254 -
256 +
255 257 if (selected.hasClass('pro-value')) {
256 258 jQuery.confirm({
257 259 boxWidth: '400px',
258 260 useBootstrap: false,
@@ -265,9 +267,9 @@
265 267 somethingElse: {
266 268 text: self.data('button-success'),
267 269 btnClass: 'btn-blue activate-now',
268 270 keys: ['enter', 'shift'],
269 - action: function() {
271 + action: function () {
270 272 window.location = self.data('action');
271 273 return false;
272 274 }
273 275 }
@@ -275,37 +277,37 @@
275 277 });
276 278 self.val("").change();
277 279 }
278 280 });
279 - $('.wdk-pro,.wdk-pro a, .wdk-pro button, .wdk-pro input').on('focus', function(){
280 - $(this).trigger('blur');
281 + $('.wdk-pro,.wdk-pro a, .wdk-pro button, .wdk-pro input').on('focus', function () {
282 + $(this).trigger('blur');
281 283 return false;
282 284 });
283 285 }
284 286
285 - if(jQuery('.wdk-tabs-navs').length) {
286 - jQuery('.wdk-tabs-navs').find('label').on('click', function(){
287 + if (jQuery('.wdk-tabs-navs').length) {
288 + jQuery('.wdk-tabs-navs').find('label').on('click', function () {
287 289 jQuery(this).parent().find('label').removeClass('active');
288 290 jQuery(this).addClass('active');
289 291 });
290 292 }
291 293 })
292 -})( jQuery );
294 +})(jQuery);
293 295
294 296 const wdk_pad = (num = '') => {
295 - return ('00'+num).slice(-2);
297 + return ('00' + num).slice(-2);
296 298 };
297 299
298 300 const wdk_date_add_hours = (selector = '') => {
299 - if(typeof selector !='undefined' && selector.parent().find('[name="hours_mask"]').length) {
301 + if (typeof selector != 'undefined' && selector.parent().find('[name="hours_mask"]').length) {
300 302 var datetime = wdk_date_notime_sql_normalize(selector.val(), selector);
301 - if(selector.parent().find('[name="hours_mask"]').val() !='') {
302 - datetime += ' '+wdk_pad(selector.parent().find('[name="hours_mask"]').val());
303 + if (selector.parent().find('[name="hours_mask"]').val() != '') {
304 + datetime += ' ' + wdk_pad(selector.parent().find('[name="hours_mask"]').val());
303 305 } else {
304 306 datetime += ' 00';
305 307 }
306 - if(selector.parent().find('[name="minutes_mask"]').val() !='') {
307 - datetime += ':'+wdk_pad(selector.parent().find('[name="minutes_mask"]').val());
308 + if (selector.parent().find('[name="minutes_mask"]').val() != '') {
309 + datetime += ':' + wdk_pad(selector.parent().find('[name="minutes_mask"]').val());
308 310 } else {
309 311 datetime += ':00';
310 312 }
311 313 datetime += ':00';
@@ -313,46 +315,185 @@
313 315 }
314 316 };
315 317
316 318 /*
317 - Convert date to sql format
319 + Convert date to sql format
318 320
319 - @param string $date, string of date
321 + @param string $date, string of date
320 322
321 - @return string normalize date or Current date/time
323 + @return string normalize date or Current date/time
322 324 */
323 325 const wdk_date_sql_normalize = (date = '', datepicker_el = null) => {
324 - if(date == '') {
326 + if (date == '') {
325 327 var d = new Date();
326 328 } else {
327 329 var d = new Date(date);
328 330 }
329 331
330 - if(d == 'Invalid Date' && datepicker_el) {
332 + if (d == 'Invalid Date' && datepicker_el) {
331 333 var d = new Date(+(jQuery.datepicker.formatDate("@", datepicker_el.datepicker("getDate"))));
332 - }
333 -
334 - d = d.getUTCFullYear() + '-' +
335 - wdk_pad(d.getMonth() + 1) + '-' +
336 - wdk_pad(d.getDate()) + ' ' +
337 - wdk_pad(d.getHours()) + ':' +
338 - wdk_pad(d.getMinutes()) + ':' +
339 - wdk_pad(d.getSeconds());
334 + }
335 +
336 + d = d.getUTCFullYear() + '-' +
337 + wdk_pad(d.getMonth() + 1) + '-' +
338 + wdk_pad(d.getDate()) + ' ' +
339 + wdk_pad(d.getHours()) + ':' +
340 + wdk_pad(d.getMinutes()) + ':' +
341 + wdk_pad(d.getSeconds());
340 342 return d;
341 343 };
342 344
343 345 const wdk_date_notime_sql_normalize = (date = '', datepicker_el = null) => {
344 - if(date == '') {
346 + if (date == '') {
345 347 var d = new Date();
346 348 } else {
347 349 var d = new Date(date);
348 350 }
349 351
350 - if(d == 'Invalid Date' && datepicker_el) {
352 + if (d == 'Invalid Date' && datepicker_el) {
351 353 var d = new Date(+(jQuery.datepicker.formatDate("@", datepicker_el.datepicker("getDate"))));
352 - }
353 -
354 - d = d.getUTCFullYear() + '-' +
355 - wdk_pad(d.getMonth() + 1) + '-' +
356 - wdk_pad(d.getDate());
354 + }
355 +
356 + d = d.getUTCFullYear() + '-' +
357 + wdk_pad(d.getMonth() + 1) + '-' +
358 + wdk_pad(d.getDate());
357 359 return d;
358 360 };
361 +
362 +
363 +
364 +document.addEventListener('DOMContentLoaded', () => {
365 +
366 + class WDKListingSearch {
367 + constructor(inputSelector, resultsSelector, executedId = null) {
368 + this.executedId = executedId;
369 + this.input = document.querySelector(inputSelector);
370 + this.results = document.querySelector(resultsSelector);
371 + this.timer = null;
372 + this.controller = null;
373 + this.init();
374 + }
375 +
376 + init() {
377 + if (!this.input || !this.results) return;
378 +
379 + this.input.addEventListener('input', () => this.onInput());
380 + document.addEventListener('click', (e) => this.onDocumentClick(e));
381 + this.input.addEventListener('focus', () => this.onFocus());
382 + this.input.addEventListener('keydown', (e) => this.onKeyDown(e));
383 + }
384 +
385 + onInput() {
386 + clearTimeout(this.timer);
387 +
388 + const keyword = this.input.value.trim();
389 +
390 + if (this.controller) {
391 + this.controller.abort();
392 + }
393 +
394 + if (keyword.length < 2) {
395 + this.results.replaceChildren();
396 + this.results.hidden = true;
397 + return;
398 + }
399 +
400 + this.timer = setTimeout(() => this.fetchResults(keyword), 250);
401 + }
402 +
403 + async fetchResults(keyword) {
404 + this.controller = new AbortController();
405 +
406 + // Show dropdown + loading
407 + this.results.hidden = false;
408 + this.results.innerHTML = `
409 + <div class="wdk-search-loading">
410 + <span class="spinner is-active"></span>
411 + Searching...
412 + </div>
413 + `;
414 +
415 + try {
416 + const response = await fetch(
417 + wdk_script_parameters.wpApiSettings.root + 'wdk/v1/listing/autosuggestion',
418 + {
419 + method: 'POST',
420 + credentials: 'same-origin',
421 + headers: {
422 + 'Content-Type': 'application/json',
423 + 'X-WP-Nonce': wdk_script_parameters.wpApiSettings.nonce
424 + },
425 + body: JSON.stringify({
426 + keyword: keyword,
427 + executedId: this.executedId
428 + }),
429 + signal: this.controller.signal
430 + }
431 + );
432 +
433 + const json = await response.json();
434 +
435 + this.results.replaceChildren();
436 +
437 + if (!json.success || !json.data.length) {
438 + this.results.innerHTML = `
439 + <div class="wdk-search-empty">
440 + No results found
441 + </div>
442 + `;
443 + return;
444 + }
445 +
446 + json.data.forEach(item => {
447 + const a = document.createElement('a');
448 + a.href = item.edit ? decodeURIComponent(item.edit) : '#';
449 + a.className = 'wdk-search-item';
450 + a.textContent = item.title;
451 +
452 + this.results.appendChild(a);
453 + });
454 +
455 + } catch (e) {
456 + if (e.name === 'AbortError') {
457 + return;
458 + }
459 + this.results.innerHTML = `
460 + <div class="wdk-search-empty">
461 + ${e.message ? 'Error: ' + e.message : 'An unexpected error occurred'}
462 + </div>
463 + `;
464 + this.results.innerHTML = `
465 + <div class="wdk-search-empty">
466 + Search failed
467 + </div>
468 + `;
469 + }
470 + }
471 +
472 + onDocumentClick(e) {
473 + if (!e.target.closest('.wdk-toolbar-search')) {
474 + this.results.hidden = true;
475 + }
476 + }
477 +
478 + onFocus() {
479 + if (this.results.children.length) {
480 + this.results.hidden = false;
481 + }
482 + }
483 +
484 + onKeyDown(e) {
485 + if (e.key === 'Escape') {
486 + this.results.hidden = true;
487 + }
488 + }
489 + }
490 +
491 + // Initialize on DOMContentLoaded
492 + const wdkListingSearchElem = document.getElementById('wdk-listing-search');
493 + if (wdkListingSearchElem) {
494 + new WDKListingSearch('#wdk-listing-search', '.wdk-search-results', wdkListingSearchElem.getAttribute('idexecuted'));
495 + }
496 +});
497 +
498 +
499 +