PluginProbe
WP Directory Kit / 1.5.4
WP Directory Kit v1.5.4
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 / admin / js / wpdirectorykit-admin.js

wpdirectorykit-admin.js in WP Directory Kit 1.5.4, at admin/js/wpdirectorykit-admin.js

359 lines 11.7 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 admin-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 jQuery(document).ready(function($) {
33 $('.event-ajax-indicator').on('click submit', function () {
34 if ($(this).find('.wdk-ajax-indicator').length) {
35 $(this).find('.wdk-ajax-indicator').removeClass('hidden')
36 .removeClass('wdk-hidden');
37 $(this).find('.hidden-onloading').addClass('wdk-hidden');
38 }
39 else {
40 $(this).parent().find('.wdk-ajax-indicator').removeClass('hidden');
41 }
42 })
43
44
45 $('.wdk-submit-loading').on('click', function () {
46 var form;
47 form = $(this).closest('form');
48
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 var self = $(this);
67
68 if (self.attr('date-format'))
69 dateFormat = self.attr('date-format');
70
71 self.datepicker({ dateFormat: dateFormat, onSelect: function() {
72 self.parent().find('.db-date').val(wdk_date_sql_normalize(self.val(), self)).trigger('input');
73 }
74 }).on( "change", function() {
75 if(self.val() == '') {
76 self.parent().find('.db-date').val('');
77 } else {
78 self.parent().find('.db-date').val(wdk_date_sql_normalize(self.val(), self));
79 }
80 });
81
82 if(self.parent().find('.db-date').val() == '' && false) {
83 self.parent().find('.db-date').val(wdk_date_sql_normalize());
84 }
85 })
86 };
87
88 if ($('.wdk-fielddatetime').length && typeof $.datepicker != 'undefined') {
89
90 $('.wdk-fielddatetime').each(function () {
91 let dateFormat = script_parameters.format_datetime_js;
92
93 var self = $(this);
94 if (self.attr('date-format'))
95 dateFormat = self.attr('date-format');
96
97 self.datepicker({ dateFormat: dateFormat, onSelect: function() {
98
99
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
113 self.parent().find('.db-date').val(datetime).trigger('input');
114 }
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';
129 self.parent().find('.db-date').val(datetime).trigger('input');
130
131 });
132
133 if(self.parent().find('.db-date').val() == '') {
134 self.parent().find('.db-date').val(wdk_date_sql_normalize());
135 }
136
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';
150 self.parent().find('.db-date').val(datetime);
151 });
152 })
153 };
154
155 if ($('.wdk-fielddate_from').length && $('.wdk-fielddate_to').length && typeof $.datepicker != 'undefined') {
156 var dateFormat, from, to;
157 const getDate = ( element ) => {
158 var date;
159 try {
160 date = $.datepicker.parseDate( dateFormat, element.value );
161 } catch( error ) {
162 date = null;
163 }
164 return date;
165 }
166
167 dateFormat = script_parameters.format_date_js;
168 if ($('.wdk-fielddate_from').attr('date-format'))
169 dateFormat = $('.wdk-fielddate_from').attr('date-format');
170
171 from = $('.wdk-fielddate_from')
172 .datepicker({
173 dateFormat: dateFormat,
174 onSelect: function( selectedDate ) {
175 to.datepicker("option", "minDate", selectedDate );
176 setTimeout(function(){
177 to.datepicker('show');
178 }, 16);
179
180 from.parent().find('.db-date').val(wdk_date_sql_normalize(from.val(), from)).trigger('input');
181 wdk_date_add_hours(from);
182
183 }
184 }).on( "change", function() {
185
186 });
187
188 to = $('.wdk-fielddate_to').datepicker({
189 dateFormat: dateFormat
190 })
191 .on( "change", function() {
192 from.datepicker( "option", "maxDate", getDate( this ) );
193
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 }
201
202 if(from.parent().find('.db-date').val() == '') {
203 from.parent().find('.db-date').val(wdk_date_sql_normalize());
204 }
205
206 from.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
207 wdk_date_add_hours(from);
208 });
209
210 to.parent().find('[name="hours_mask"],[name="minutes_mask"]').on('input', function(){
211 wdk_date_add_hours(to);
212 });
213
214 }
215
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 });
221
222
223 /* wdk pro feature ask */
224 if (typeof $.fn.confirm == 'function') {
225 $('.wdk-pro, .wdk-pro a, .wdk-pro button, .wdk-pro input').off().on('click', function(e){
226 e.preventDefault();
227 var self = jQuery(this)
228 jQuery.confirm({
229 boxWidth: '400px',
230 useBootstrap: false,
231 title: self.data('title'),
232 content: self.data('content'),
233 buttons: {
234 cancel: function () {
235 return true;
236 },
237 somethingElse: {
238 text: self.data('button-succuss'),
239 btnClass: 'btn-blue activate-now',
240 keys: ['enter', 'shift'],
241 action: function(){
242 window.location = self.data('action');
243 return false;
244 }
245 }
246 }
247 });
248 return false;
249 });
250 $('select.wdk-pro-select').off().on('input', function(e) {
251
252 var self = jQuery(this);
253 var selected = self.find('option:selected');
254
255 if (selected.hasClass('pro-value')) {
256 jQuery.confirm({
257 boxWidth: '400px',
258 useBootstrap: false,
259 title: self.data('title'),
260 content: self.data('content'),
261 buttons: {
262 cancel: function () {
263 return true;
264 },
265 somethingElse: {
266 text: self.data('button-success'),
267 btnClass: 'btn-blue activate-now',
268 keys: ['enter', 'shift'],
269 action: function() {
270 window.location = self.data('action');
271 return false;
272 }
273 }
274 }
275 });
276 self.val("").change();
277 }
278 });
279 $('.wdk-pro,.wdk-pro a, .wdk-pro button, .wdk-pro input').on('focus', function(){
280 $(this).trigger('blur');
281 return false;
282 });
283 }
284
285 if(jQuery('.wdk-tabs-navs').length) {
286 jQuery('.wdk-tabs-navs').find('label').on('click', function(){
287 jQuery(this).parent().find('label').removeClass('active');
288 jQuery(this).addClass('active');
289 });
290 }
291 })
292 })( jQuery );
293
294 const wdk_pad = (num = '') => {
295 return ('00'+num).slice(-2);
296 };
297
298 const wdk_date_add_hours = (selector = '') => {
299 if(typeof selector !='undefined' && selector.parent().find('[name="hours_mask"]').length) {
300 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 } else {
304 datetime += ' 00';
305 }
306 if(selector.parent().find('[name="minutes_mask"]').val() !='') {
307 datetime += ':'+wdk_pad(selector.parent().find('[name="minutes_mask"]').val());
308 } else {
309 datetime += ':00';
310 }
311 datetime += ':00';
312 selector.parent().find('.db-date').val(datetime);
313 }
314 };
315
316 /*
317 Convert date to sql format
318
319 @param string $date, string of date
320
321 @return string normalize date or Current date/time
322 */
323 const wdk_date_sql_normalize = (date = '', datepicker_el = null) => {
324 if(date == '') {
325 var d = new Date();
326 } else {
327 var d = new Date(date);
328 }
329
330 if(d == 'Invalid Date' && datepicker_el) {
331 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());
340 return d;
341 };
342
343 const wdk_date_notime_sql_normalize = (date = '', datepicker_el = null) => {
344 if(date == '') {
345 var d = new Date();
346 } else {
347 var d = new Date(date);
348 }
349
350 if(d == 'Invalid Date' && datepicker_el) {
351 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());
357 return d;
358 };
359