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 +326 -152 1.3.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,198 +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 - self.parent().find('.db-date').val(wdk_date_sql_normalize(self.val(), self));
75 + }).on("change", function () {
76 + if (self.val() == '') {
77 + self.parent().find('.db-date').val('');
78 + } else {
79 + self.parent().find('.db-date').val(wdk_date_sql_normalize(self.val(), self));
80 + }
76 81 });
77 -
78 - if(self.parent().find('.db-date').val() == '' && false) {
79 - self.parent().find('.db-date').val(wdk_date_sql_normalize());
80 - }
81 - })
82 +
83 + if (self.parent().find('.db-date').val() == '' && false) {
84 + self.parent().find('.db-date').val(wdk_date_sql_normalize());
85 + }
86 + })
82 87 };
83 88
84 - if ($('.wdk-fielddatetime').length && typeof $.datepicker != 'undefined') {
89 + if ($('.wdk-fielddatetime').length && typeof $.datepicker != 'undefined') {
85 90
86 91 $('.wdk-fielddatetime').each(function () {
87 - let dateFormat = script_parameters.format_datetime_js;
92 + let dateFormat = script_parameters.format_datetime_js;
88 93
89 94 var self = $(this);
90 - if (self.attr('date-format'))
91 - dateFormat = self.attr('date-format');
95 + if (self.attr('date-format'))
96 + dateFormat = self.attr('date-format');
92 97
93 - self.datepicker({ dateFormat: dateFormat, onSelect: function() {
94 -
98 + self.datepicker({
99 + dateFormat: dateFormat, onSelect: function () {
95 100
96 - var datetime = wdk_date_notime_sql_normalize(self.val(), self);
97 - if(self.parent().find('[name="hours_mask"]').val() !='') {
98 - datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
99 - } else {
100 - datetime += ' 00';
101 - }
102 - if(self.parent().find('[name="minutes_mask"]').val() !='') {
103 - datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
104 - } else {
105 - datetime += ':00';
106 - }
107 - datetime += ':00';
108 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 +
109 115 self.parent().find('.db-date').val(datetime).trigger('input');
110 116 }
111 - }).on( "change", function() {
112 -
113 - var datetime = wdk_date_notime_sql_normalize(self.val(), self);
114 - if(self.parent().find('[name="hours_mask"]').val() !='') {
115 - datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
116 - } else {
117 - datetime += ' 00';
118 - }
119 - if(self.parent().find('[name="minutes_mask"]').val() !='') {
120 - datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
121 - } else {
122 - datetime += ':00';
123 - }
124 - 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';
125 131 self.parent().find('.db-date').val(datetime).trigger('input');
126 132
127 133 });
128 134
129 - if(self.parent().find('.db-date').val() == '') {
130 - self.parent().find('.db-date').val(wdk_date_sql_normalize());
131 - }
135 + if (self.parent().find('.db-date').val() == '') {
136 + self.parent().find('.db-date').val(wdk_date_sql_normalize());
137 + }
132 138
133 - self.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
134 - var datetime = wdk_date_notime_sql_normalize(self.val(), self);
135 - if(self.parent().find('[name="hours_mask"]').val() !='') {
136 - datetime += ' '+wdk_pad(self.parent().find('[name="hours_mask"]').val());
137 - } else {
138 - datetime += ' 00';
139 - }
140 - if(self.parent().find('[name="minutes_mask"]').val() !='') {
141 - datetime += ':'+wdk_pad(self.parent().find('[name="minutes_mask"]').val());
142 - } else {
143 - datetime += ':00';
144 - }
145 - 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';
146 152 self.parent().find('.db-date').val(datetime);
147 - });
148 - })
153 + });
154 + })
149 155 };
150 156
151 157 if ($('.wdk-fielddate_from').length && $('.wdk-fielddate_to').length && typeof $.datepicker != 'undefined') {
152 158 var dateFormat, from, to;
153 - const getDate = ( element ) => {
159 + const getDate = (element) => {
154 160 var date;
155 161 try {
156 - date = $.datepicker.parseDate( dateFormat, element.value );
157 - } catch( error ) {
162 + date = $.datepicker.parseDate(dateFormat, element.value);
163 + } catch (error) {
158 164 date = null;
159 165 }
160 166 return date;
161 - }
167 + }
162 168
163 169 dateFormat = script_parameters.format_date_js;
164 170 if ($('.wdk-fielddate_from').attr('date-format'))
165 - dateFormat = $('.wdk-fielddate_from').attr('date-format');
171 + dateFormat = $('.wdk-fielddate_from').attr('date-format');
166 172
167 173 from = $('.wdk-fielddate_from')
168 174 .datepicker({
169 175 dateFormat: dateFormat,
170 - onSelect: function( selectedDate ) {
171 - to.datepicker("option", "minDate", selectedDate );
172 - setTimeout(function(){
176 + onSelect: function (selectedDate) {
177 + to.datepicker("option", "minDate", selectedDate);
178 + setTimeout(function () {
173 179 to.datepicker('show');
174 180 }, 16);
175 -
181 +
176 182 from.parent().find('.db-date').val(wdk_date_sql_normalize(from.val(), from)).trigger('input');
177 183 wdk_date_add_hours(from);
178 -
184 +
179 185 }
180 - }).on( "change", function() {
186 + }).on("change", function () {
181 187
182 188 });
183 -
189 +
184 190 to = $('.wdk-fielddate_to').datepicker({
185 191 dateFormat: dateFormat
186 192 })
187 - .on( "change", function() {
188 - from.datepicker( "option", "maxDate", getDate( this ) );
193 + .on("change", function () {
194 + from.datepicker("option", "maxDate", getDate(this));
189 195
190 - to.parent().find('.db-date').val(wdk_date_sql_normalize(to.val(), to)).trigger('input');
191 - wdk_date_add_hours(to);
192 - });
193 -
194 - if(to.parent().find('.db-date').val() == '') {
195 - to.parent().find('.db-date').val(wdk_date_sql_normalize());
196 - }
196 + to.parent().find('.db-date').val(wdk_date_sql_normalize(to.val(), to)).trigger('input');
197 + wdk_date_add_hours(to);
198 + });
197 199
198 - if(from.parent().find('.db-date').val() == '') {
199 - from.parent().find('.db-date').val(wdk_date_sql_normalize());
200 - }
200 + if (to.parent().find('.db-date').val() == '') {
201 + to.parent().find('.db-date').val(wdk_date_sql_normalize());
202 + }
201 203
202 - 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 () {
203 209 wdk_date_add_hours(from);
204 210 });
205 -
206 - 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 () {
207 213 wdk_date_add_hours(to);
208 214 });
209 -
215 +
210 216 }
211 217
212 - jQuery(document).ready( function($) {
213 - $( "ul#adminmenu a[href*='wordpress.org/support/plugin/wpdirectorykit']" ).attr( 'target', '_blank' );
214 - $( "ul#adminmenu a[href*='wpdirectorykit.com/contact.html']" ).attr( 'target', '_blank' );
215 - $( "ul#adminmenu a[href*='wpdirectorykit.com/documentation']" ).attr( 'target', '_blank' );
216 - });
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 + });
217 223
218 224
219 225 /* wdk pro feature ask */
220 226 if (typeof $.fn.confirm == 'function') {
221 - $('.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) {
222 228 e.preventDefault();
223 229 var self = jQuery(this)
224 230 jQuery.confirm({
225 231 boxWidth: '400px',
@@ -224,9 +230,9 @@
224 230 jQuery.confirm({
225 231 boxWidth: '400px',
226 232 useBootstrap: false,
227 233 title: self.data('title'),
228 - content: self.data('content'),
234 + content: self.data('content'),
229 235 buttons: {
230 236 cancel: function () {
231 237 return true;
232 238 },
@@ -233,9 +239,9 @@
233 239 somethingElse: {
234 240 text: self.data('button-succuss'),
235 241 btnClass: 'btn-blue activate-now',
236 242 keys: ['enter', 'shift'],
237 - action: function(){
243 + action: function () {
238 244 window.location = self.data('action');
239 245 return false;
240 246 }
241 247 }
@@ -242,37 +248,66 @@
242 248 }
243 249 });
244 250 return false;
245 251 });
246 - $('.wdk-pro, .wdk-pro a, .wdk-pro button, .wdk-pro input').on('focus', function(){
247 - $(this).trigger('blur');
252 + $('select.wdk-pro-select').off().on('input', function (e) {
253 +
254 + var self = jQuery(this);
255 + var selected = self.find('option:selected');
256 +
257 + if (selected.hasClass('pro-value')) {
258 + jQuery.confirm({
259 + boxWidth: '400px',
260 + useBootstrap: false,
261 + title: self.data('title'),
262 + content: self.data('content'),
263 + buttons: {
264 + cancel: function () {
265 + return true;
266 + },
267 + somethingElse: {
268 + text: self.data('button-success'),
269 + btnClass: 'btn-blue activate-now',
270 + keys: ['enter', 'shift'],
271 + action: function () {
272 + window.location = self.data('action');
273 + return false;
274 + }
275 + }
276 + }
277 + });
278 + self.val("").change();
279 + }
280 + });
281 + $('.wdk-pro,.wdk-pro a, .wdk-pro button, .wdk-pro input').on('focus', function () {
282 + $(this).trigger('blur');
248 283 return false;
249 284 });
250 285 }
251 286
252 - if(jQuery('.wdk-tabs-navs').length) {
253 - 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 () {
254 289 jQuery(this).parent().find('label').removeClass('active');
255 290 jQuery(this).addClass('active');
256 291 });
257 292 }
258 293 })
259 -})( jQuery );
294 +})(jQuery);
260 295
261 296 const wdk_pad = (num = '') => {
262 - return ('00'+num).slice(-2);
297 + return ('00' + num).slice(-2);
263 298 };
264 299
265 300 const wdk_date_add_hours = (selector = '') => {
266 - if(typeof selector !='undefined' && selector.parent().find('[name="hours_mask"]').length) {
301 + if (typeof selector != 'undefined' && selector.parent().find('[name="hours_mask"]').length) {
267 302 var datetime = wdk_date_notime_sql_normalize(selector.val(), selector);
268 - if(selector.parent().find('[name="hours_mask"]').val() !='') {
269 - 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());
270 305 } else {
271 306 datetime += ' 00';
272 307 }
273 - if(selector.parent().find('[name="minutes_mask"]').val() !='') {
274 - 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());
275 310 } else {
276 311 datetime += ':00';
277 312 }
278 313 datetime += ':00';
@@ -280,46 +315,185 @@
280 315 }
281 316 };
282 317
283 318 /*
284 - Convert date to sql format
319 + Convert date to sql format
285 320
286 - @param string $date, string of date
321 + @param string $date, string of date
287 322
288 - @return string normalize date or Current date/time
323 + @return string normalize date or Current date/time
289 324 */
290 325 const wdk_date_sql_normalize = (date = '', datepicker_el = null) => {
291 - if(date == '') {
326 + if (date == '') {
292 327 var d = new Date();
293 328 } else {
294 329 var d = new Date(date);
295 330 }
296 331
297 - if(d == 'Invalid Date' && datepicker_el) {
332 + if (d == 'Invalid Date' && datepicker_el) {
298 333 var d = new Date(+(jQuery.datepicker.formatDate("@", datepicker_el.datepicker("getDate"))));
299 - }
300 -
301 - d = d.getUTCFullYear() + '-' +
302 - wdk_pad(d.getMonth() + 1) + '-' +
303 - wdk_pad(d.getDate()) + ' ' +
304 - wdk_pad(d.getHours()) + ':' +
305 - wdk_pad(d.getMinutes()) + ':' +
306 - 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());
307 342 return d;
308 343 };
309 344
310 345 const wdk_date_notime_sql_normalize = (date = '', datepicker_el = null) => {
311 - if(date == '') {
346 + if (date == '') {
312 347 var d = new Date();
313 348 } else {
314 349 var d = new Date(date);
315 350 }
316 351
317 - if(d == 'Invalid Date' && datepicker_el) {
352 + if (d == 'Invalid Date' && datepicker_el) {
318 353 var d = new Date(+(jQuery.datepicker.formatDate("@", datepicker_el.datepicker("getDate"))));
319 - }
320 -
321 - d = d.getUTCFullYear() + '-' +
322 - wdk_pad(d.getMonth() + 1) + '-' +
323 - wdk_pad(d.getDate());
354 + }
355 +
356 + d = d.getUTCFullYear() + '-' +
357 + wdk_pad(d.getMonth() + 1) + '-' +
358 + wdk_pad(d.getDate());
324 359 return d;
325 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 +