PageSourceSearch

https://www.makpetrol.com.mk/wp-content/plugins/wpdatatables/assets/js/wpdatatables/wpdatatables.js?ver=4.5

js makpetrol.com.mk collected 2026-10-02 12:41:53 UTC 124,269 bytes, 2,065 lines download raw bytes

1/** New JS controller for wpDataTables **/
2
3
4var wpDataTables = {};
5var wpDataTablesSelRows = {};
6var wpDataTablesFunctions = {};
7var wpDataTablesUpdatingFlags = {};
8var wpDataTablesResponsiveHelpers = {};
9var wpDataTablesHooks = wpDataTablesHooks || {
10    onRenderFilter: [],
11    onRenderDetails:[]
12};
13var wpDataTablesEditors = {};
14var wdtBreakpointDefinition = {
15    tablet: 1024,
16    phone: 480
17};
18var wdtCustomUploader = null;
19
20var wdtRenderDataTable = null;
21var singleClick = false;
22
23(function ($) {
24    $(function () {
25
26        /**
27         * Helper function to render a DataTable
28         *
29         * @param $table jQuery link to the container table object
30         * @param tableDescription JSON with the table description
31         */
32        wdtRenderDataTable = function ($table, tableDescription) {
33
34            // Parse the DataTable init options
35            var dataTableOptions = tableDescription.dataTableParams;
36
37            //[<-- Full version -->]//
38            /**
39             * Responsive-mode related stuff
40             */
41            if (tableDescription.responsive) {
42                wpDataTablesResponsiveHelpers[tableDescription.tableId] = false;
43                dataTableOptions.preDrawCallback = function () {
44                    if (!wpDataTablesResponsiveHelpers[tableDescription.tableId]) {
45                        if (typeof tableDescription.mobileWidth !== 'undefined') {
46                            wdtBreakpointDefinition.phone = parseInt(tableDescription.mobileWidth);
47                        }
48                        if (typeof tableDescription.tabletWidth !== 'undefined') {
49                            wdtBreakpointDefinition.tablet = parseInt(tableDescription.tabletWidth);
50                        }
51                        wpDataTablesResponsiveHelpers[tableDescription.tableId] = new ResponsiveDatatablesHelper($(tableDescription.selector).dataTable(), wdtBreakpointDefinition, {
52                            clickOn: tableDescription.responsiveAction ? tableDescription.responsiveAction : 'icon',
53                            showDetail: function (detailsRow) {
54                                if (tableDescription.conditional_formatting_columns) {
55                                    var responsive_rows = detailsRow.find('li');
56                                    var oSettings = wpDataTables[tableDescription.tableId].fnSettings();
57                                    var params = {};
58
59                                    params.thousandsSeparator = tableDescription.number_format == 1 ? '.' : ',';
60                                    params.decimalSeparator = tableDescription.number_format == 1 ? ',' : '.';
61                                    params.dateFormat = tableDescription.datepickFormat;
62                                    params.momentDateFormat = params.dateFormat.replace('dd', 'DD').replace('M', 'MMM').replace('mm', 'MM');
63                                    params.momentTimeFormat = tableDescription.timeFormat.replace('H', 'H').replace('i', 'mm');
64
65                                    for (var i = 0; i < tableDescription.conditional_formatting_columns.length; i++) {
66                                        var column = oSettings.oInstance.api().column(tableDescription.conditional_formatting_columns[i] + ':name', {search: 'applied'});
67                                        var conditionalFormattingRules = oSettings.aoColumns[column.index()].conditionalFormattingRules;
68                                        params.columnType = oSettings.aoColumns[column.index()].wdtType;
69
70                                        for (var j in conditionalFormattingRules) {
71                                            responsive_rows.each(function () {
72                                                $(this).find('.columnValue').contents().filter(function () {
73                                                    if (this.nodeType === 8) {
74                                                        $(this).remove();
75                                                    }
76                                                });
77
78                                                var value_cell = $(this).find('.columnValue').html();
79
80                                                var column_index = $(this).data('column');
81                                                if (column_index == column.index()) {
82                                                    wdtCheckConditionalFormatting(conditionalFormattingRules[j], params, $(this), true);
83                                                }
84                                            });
85                                        }
86                                    }
87                                }
88                            }
89                        });
90                    }
91                    wdtAddOverlay('#' + tableDescription.tableId);
92                }
93                dataTableOptions.fnRowCallback = function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
94                    wpDataTablesResponsiveHelpers[tableDescription.tableId].createExpandIcon(nRow);
95                }
96                if (!tableDescription.editable) {
97                    dataTableOptions.fnDrawCallback = function () {
98                        wpDataTablesResponsiveHelpers[tableDescription.tableId].respond();
99                        wdtRemoveOverlay('#' + tableDescription.tableId);
100                    }
101                }
102            } else {
103                dataTableOptions.fnPreDrawCallback = function () {
104                    wdtAddOverlay('#' + tableDescription.tableId);
105                }
106            }
107
108            if (tableDescription.editable) {
109
110                if (typeof wpDataTablesFunctions[tableDescription.tableId] === 'undefined') {
111                    wpDataTablesFunctions[tableDescription.tableId] = {};
112                }
113
114                wpDataTablesSelRows[tableDescription.tableId] = 
114-1;
115                dataTableOptions.fnDrawCallback = function () {
116                    wdtRemoveOverlay('#' + tableDescription.tableId);
117                    if (tableDescription.responsive) {
118                        wpDataTablesResponsiveHelpers[tableDescription.tableId].respond();
119                    }
120
121                    $('.edit_table[aria-controls="' + tableDescription.tableId + '"]').addClass('disabled');
122                    $('.duplicate_table_entry[aria-controls="' + tableDescription.tableId + '"]').addClass('disabled');
123                    $('.delete_table_entry[aria-controls="' + tableDescription.tableId + '"]').addClass('disabled');
124                    $('.master_detail[aria-controls="' + tableDescription.tableId + '"]').addClass('disabled');
125
126                    if (wpDataTablesSelRows[tableDescription.tableId] == -2) {
127                        // -2 means select first row on "next" page
128                        var sel_row_index = wpDataTables[tableDescription.tableId].fnSettings()._iDisplayLength - 1;
129                        $(tableDescription.selector + ' > tbody > tr').removeClass('selected');
130                        wpDataTablesSelRows[tableDescription.tableId] = wpDataTables[tableDescription.tableId].fnGetPosition($(tableDescription.selector + ' > tbody > tr:eq(' + sel_row_index + ')').get(0));
131                        $(tableDescription.selector + ' > tbody > tr:eq(' + sel_row_index + ')').addClass('selected');
132                    } else if (wpDataTablesSelRows[tableDescription.tableId] == -3) {
133                        var sel_row_index = 0;
134                        $(tableDescription.selector + ' > tbody > tr').removeClass('selected');
135                        wpDataTablesSelRows[tableDescription.tableId] = wpDataTables[tableDescription.tableId].fnGetPosition($(tableDescription.selector + ' > tbody > tr:eq(' + sel_row_index + ')').get(0));
136                        $(tableDescription.selector + ' > tbody > tr:eq(' + sel_row_index + ')').addClass('selected');
137                    }
138
139                    $(tableDescription.selector + '_edit_dialog').parent().removeClass('overlayed');
140
141                    wpDataTablesUpdatingFlags[tableDescription.tableId] = false;
142                };
143
144                /**
145                 * Data apply function for editable tables
146                 * @param data
147                 * @param isDuplicate
148                 * @param applyDuplicate
149                 */
150                wpDataTablesFunctions[tableDescription.tableId].applyData = function (data, isDuplicate = false, applyDuplicate = false) {
151                    $(data).each(function (index, el) {
152                        var $inputElement = $('#' + tableDescription.tableId + '_edit_dialog .editDialogInput:not(.bootstrap-select):eq(' + index + ')');
153
154                        if (el) {
155                            if($inputElement.data("key").toLowerCase() === 'wdt_id' && isDuplicate) {
156                                val = "0"
157                            } else {
158                                var val = el.toString();
159                            }
160                        } else {
161                            var val = '';
162                        }
163                        if (val.indexOf('span') != -1) {
164                            val = val.replace(/<span>/g, '').replace(/<\/span>/g, '');
165                        }
166                        if (val.indexOf('<br/>') != -1 || val.indexOf('<br>') != -1) {
167                            val = val.replace(/<br\s*[\/]?>/g, "\n");
168                        }
169
170                        var inputElementType = $inputElement.data('input_type');
171                        var columnType = $inputElement.data('column_type');
172
173                        if (inputElementType === 'multi-selectbox' || inputElementType === 'selectbox') {
174
175                            if ($inputElement.hasClass('wdt-possible-values-ajax')) {
176
177                                var $selectpickerBlock = $('select#' + tableDescription.tableId + '_' + $inputElement.data('key')).closest('.fg-line').parent();
178
179                                var mandatory = $inputElement.hasClass('mandatory') ? 'mandatory ' : '';
180                                var foreignKeyRule = $inputElement.hasClass('wdt-foreign-key-select') ? 'wdt-foreign-key-select ' : '';
181                                var searchInSelect = $inputElement.hasClass('wdt-search-in-select') ? ' wdt-search-in-select ' : '';
182
183                                // Recreate the selectbox element
184                                $selectpickerBlock.html('<div class="fg-line"><select id="' + tableDescription.tableId + '_' + $inputElement.data('key') + '" title="' + wpdatatables_frontend_strings.nothingSelected + '" data-input_type="' + inputElementType + '" data-key="' + $inputElement.data('key') + '" class="form-control editDialogInput selectpicker ' + mandatory + 'wdt-possible-values-ajax ' + foreignKeyRule + searchInSelect + '" data-live-search="true" data-live-search-placeholder="' + wpdatatables_frontend_strings.search + '" data-column_header="' + $inputElement.data('column_header') + '"></select></div>');
185                                if (inputElementType === 'multi-selectbox')
186                                    $selectpickerBlock.find('select').attr('multiple', 'multiple');
187
188                                // If default value is set, append it to selectbox HTML
189                                if (inputElementType === 'multi-selectbox') {
190                                    var values = val.split(', ');
191
192                                    $.each(values, function (index, value) {
193                                        if (value) {
194                                            $selectpickerBlock.find('select').append('<option selected value="' + value + '">' + value + '</option>');
195                                        }
196                                    });
197                                } else {
198                                    $selectpickerBlock.find('select').append('<option selected value="' + val + '">' + val + '</option>');
199                                }
200
201                                $inputElement = $selectpickerBlock.find('select');
202
203                                // Load possible values on modal open
204                                $inputElement.on('show.bs.select', function (e) {
205                                    jQuery(this).closest('div.editDialogInput').find('.bs-searchbox .form-control').val('').trigger('keyup');
206                                });
207
208                                // Add AJAX to selectbox
209                                $inputElement.selectpicker('refresh')
210                                    .ajaxSelectPicker({
211                                        ajax: {
212                                            url: tableDescription.adminAjaxBaseUrl,
213                                            method: 'POST',
214                                            data: {
215                                                wdtNonce: $('#wdtNonce').val(),
216                                                action: 'wpdatatables_get_column_possible_values',
217                                                tableId: tableDescription.tableWpId,
218                                                originalHeader: $inputElement.data('key')
219                                            }
220                                        },
221                                        cache: false,
222                                        preprocessData: function (data) {
223                                            if ($('.editDialogInput.open').find('select').data('input_type') === 'selectbox') {
224                                                data.unshift({value: ''});
225                                            }
226                                            return data
227                                        },
228                                        preserveSelected: true,
229                                        emptyRequest: true,
230                                        preserveSelectedPosition: 'before',
231                                        locale: {
232                                            emptyTitle: wpdatatables_frontend_strings.nothingSelected,
233                                            statusSearching: wpdatatables_frontend_strings.sLoadingRecords,
234                                            currentlySelected: wpdatatables_frontend_strings.currentlySelected,
235                                            errorText: wpdatatables_frontend_strings.errorText,
236                                            searchPlaceholder: wpdatatables_frontend_strings.search,
237                                            statusInitialized: wpdatatables_frontend_strings.statusInitialized,
238                                            statusNoResults: wpdatatables_frontend_strings.statusNoResults,
239                                            statusTooShort: wpdatatables_frontend_strings.statusTooShort
240                                        }
241                                    });
242                            }
243
244                            if (inputElementType == 'multi-selectbox') {
245                                values = val.split(', ');
246                                $inputElement.selectpicker();
247                                $inputElement.selectpicker('val', values);
248                                $inputElement.selectpicker('refresh');
249                            } else if (inputElementType == 'selectbox') {
250                                $inputElement.selectpicker();
251                                if ($inputElement.hasClass('wdt-foreign-key-select') && val != '') {
252                                    val = typeof $inputElement.find('option[data-label="' + val + '"]').val() !== 'undefined' ?
253                                        $inputElement.find('option[data-label="' + val + '"]').val() : val;
254                                }
255                                if (val == '') {
256                                    val = 'possibleValuesAddEmpty';
257                                }
258                                $inputElement.selectpicker('val', val);
259                                $inputElement.selectpicker('refresh');
260                            }
261
262                            // Hide/Show search box in select/multiselect edit input
263                            if (searchInSelect === ''){
264                                $inputElement.closest('div.editDialogInput').find('.bs-searchbox').hide();
265                            } else {
266                                $inputElement.closest('div.editDialogInput').find('.bs-searchbox').show();
267                            }
268                        } else {
269                            if (inputElementType == 'attachment' || $.inArray(columnType, ['icon']) !== -1) {
270                                columnType = $inputElement.parent().data('column_type') === undefined ? 'link' : $inputElement.parent().data('column_type');
271                                if (isDuplicate && applyDuplicate) {
272                                    val = wpDataTablesFunctions[tableDescription.tableId].transformDataForDuplicate(val, columnType);
273                                }
274                                if (val != '') {
275                                    if ($(val).children('img').first().attr('src') != undefined) {
276                                        val = $(val).children('img').first().attr('src') + '||' + $(val).attr('href');
277                                    } else if ($(val).attr('href') != undefined) {
278                                        val = $(val).attr('href');
279                                    } else if ($(val).attr('src') != undefined) {
280                                        val = $(val).attr('src');
281                                    }
282
283                                    $inputElement.parent().parent().removeClass('fileinput-new').addClass('fileinput-exists');
284                                    if (columnType == 'icon') {
285                                        $inputElement.parent().parent().parent().removeClass('fileinput-new').addClass('fileinput-exists');
286                                        if (val.indexOf('||') != -1) {
287                                            $inputElement.parent().parent().parent().find('.fileinput-preview').html('<img src=' + val.substring(val.indexOf('||') + 2, val.length) + '>');
288                                        } else {
289                                            $inputElement.parent().parent().parent().find('.fileinput-preview').html('<img src=' + val + '>');
290                                        }
291                                    } else {
292                                        $inputElement.parent().parent().find('.fileinput-filename').text(val.split('/').pop());
293                                    }
294                                } else {
295                                    $inputElement.closest('.fileinput').removeClass('fileinput-exists').addClass('fileinput-new');
296                                    $inputElement.closest('.fileinput').find('div.fileinput-exists').removeClass('fileinput-exists').addClass('fileinput-new');
297                                    $inputElement.closest('.fileinput').find('.fileinput-filename').text('');
298                                    $inputElement.closest('.fileinput').find('.fileinput-preview').html('');
299                                }
300                            } else {
301                                if (isDuplicate && applyDuplicate && $.inArray(columnType, ['link', 'int']) !== -1) {
302                                    val = wpDataTablesFunctions[tableDescription.tableId].transformDataForDuplicate(val, columnType);
303                                }
304                                if (val.indexOf('<a ') != -1) {
305                                    if ($.inArray(columnType, ['link', 'email', 'icon']) !== -1) {
306                                        $link = $(val);
307                                        if (applyDuplicate) {
308                                            val = $link.attr('href');
309                                        } else if ($link.attr('href').indexOf($link.html()) === -1) {
310                                            val = $link.attr('href').replace('mailto:', '') + '||' + $link.html();
311                                        } else {
312                                            val = $link.html();
313                                        }
314                                    }
315                                }
316
317                                if (inputElementType == 'mce-editor') {
318                                    tinymce.execCommand('mceRemoveEditor', true, $inputElement.attr('id'));
319                                    tinymce.init({
320                                        selector: '#' + $inputElement.attr('id'),
321                                        init_instance_callback: function (editor) {
322                                            editor.setContent(val);
323                                        },
324                                        menubar: false,
325                                        plugins: 'link image media lists hr colorpicker fullscreen textcolor code',
326                                        toolbar: 'undo redo formatselect bold italic underline strikethrough subscript superscript | alignleft aligncenter alignright al
326ignjustify | bullist numlist outdent indent blockquote | hr fullscreen | link unlink image | forecolor backcolor removeformat | code'
327                                    });
328                                }
329                            }
330                            $inputElement.val(val).css('border', '');
331                        }
332                    });
333                };
334
335                wpDataTablesFunctions[tableDescription.tableId].transformDataForDuplicate = function (val, columnType) {
336                    var transformedVal = val;
337
338                    if (val) {
339                        if (columnType === 'int') {
340                            var thousandsSeparator = tableDescription.number_format == 1 ? '.' : ',';
341                            var decimalSeparator = tableDescription.number_format == 1 ? ',' : '.';
342
343                            transformedVal = wdtFormatNumber(val, 0, decimalSeparator, thousandsSeparator);
344                        } else if (columnType === 'icon') {
345                            val = val.substring(val.lastIndexOf('|') + 1);
346                            transformedVal = "<a href='" + val + "' target='_blank' rel='lightbox[-1]'><img src='" + val + "' /></a>";
347                        } else if (columnType === 'link') {
348                            transformedVal = "<a href='" + val + "' rel='' target='_self'>att</a>";
349                        }
350                    }
351
352                    return transformedVal;
353                }
354
355                /**
356                 * Saving of the table data for frontend
357                 *
358                 * @param forceRedraw
359                 * @param closeDialog
360                 * @returns {boolean}
361                 */
362                wpDataTablesFunctions[tableDescription.tableId].saveTableData = function (forceRedraw, closeDialog, duplicateEntry) {
363                    $(tableDescription.selector + '_edit_dialog').closest('.modal-dialog').find('.wdt-preload-layer').animateFadeIn();
364                    wpDataTablesUpdatingFlags[tableDescription.tableId] = true;
365                    var formdata = {
366                        table_id: tableDescription.tableWpId
367                    };
368                    var aoData = [];
369                    var valid = true;
370                    var validation_message = '';
371                    if (tableDescription.popoverTools) {
372                        $('.wpDataTablesPopover.editTools').hide();
373                    }
374
375                    //Moves tinymce value to hidden initial textarea
376                    if (typeof tinymce != 'undefined') {
377                        tinymce.triggerSave();
378                    }
379                    $(tableDescription.selector + '_edit_dialog .editDialogInput').not('.bootstrap-select').each(function () {
380                        // validation
381                        if ($(this).data('input_type') == 'email') {
382                            if ($(this).val() != '') {
383                                var field_valid = wdtValidateEmail($(this).val());
384                                if (!field_valid) {
385                                    valid = false;
386                                    $(this).addClass('error');
387                                    validation_message += wpdatatables_frontend_strings.invalid_email + ' <b>' + $(this).data('column_header') + '</b><br>';
388                                } else {
389                                    $(this).removeClass('error')
390                                }
391                            }
392                        } else if ($(this).data('input_type') == 'link') {
393                            if ($(this).val() != '') {
394                                field_valid = wdtValidateURL($(this).val());
395                                if (!field_valid) {
396                                    valid = false;
397                                    $(this).addClass('error');
398                                    validation_message += wpdatatables_frontend_strings.invalid_link + ' <b>' + $(this).data('column_header') + '</b><br>';
399                                } else {
400                                    $(this).removeClass('error');
401                                }
402                            }
403                        }
404                        if ($(this).hasClass('mandatory')) {
405                            if ($(this).val() == '' || $(this).val() == null) {
406                                $(this).addClass('error');
407                                valid = false;
408                                validation_message += '<b>' + $(this).data('column_header') + '</b> ' + wpdatatables_frontend_strings.cannot_be_empty + '<br>';
409                            } else {
410                                if (valid) {
411                                    $(this).removeClass('error');
412                                }
413                            }
414                        }
415                        if ($(this).hasClass('datepicker')) {
416                            formdata[$(this).data('key')] = $.datepicker.formatDate(tableDescription.datepickFormat, $.datepicker.parseDate(tableDescription.datepickFormat, $(this).val()));
417                        } else if ($(this).data('input_type') == 'multi-selectbox') {
418                            if ($(this).val()) {
419                                formdata[$(this).data('key')] = $(this).val().join(', ');
420                            } else {
421                                formdata[$(this).data('key')] = '';
422                            }
423                        } else if ($(this).data('column_type') == 'int') {
424                            formdata[$(this).data('key')] = $(this).val().replace(/,/g, '').replace(/\./g, '');
425                        } else {
426                            formdata[$(this).data('key')] = $(this).val();
427                        }
428                        aoData.push(formdata[$(this).data('key')]);
429                    });
430                    if (!valid) {
431                        $(tableDescription.selector + '_edit_dialog').closest('.modal-dialog').find('.wdt-preload-layer').animateFadeOut();
432                        wdtNotify(wpdatatables_edit_strings.error, validation_message, 'danger');
433                        return false;
434                    }
435                    wpDataTablesUpdatingFlags[tableDescription.tableId] = true;
436                    $.ajax({
437                        url: tableDescription.adminAjaxBaseUrl,
438                        type: 'POST',
439                        dataType: 'json',
440                        data: {
441                            action: 'wdt_save_table_frontend',
442                            wdtNonce: $('#wdtNonceFrontendEdit_' + tableDescription.tableWpId).val(),
443                            isDuplicate: duplicateEntry,
444                            formdata: formdata
445                        },
446                        success: function (returnData) {
447                            $(tableDescription.selector + '_edit_dialog').closest('.modal-dialog').find('.wdt-preload-layer').animateFadeOut();
448                            if (returnData.error == '') {
449                                var insert_id = returnData.success;
450                                if (returnData.is_new) {
451                                    forceRedraw = true;
452                                }
453                                if (insert_id) {
454                                    $(tableDescription.selector + '_edit_dialog tr.idRow .editDialogInput').val(insert_id);
455                                    if (forceRedraw) {
456                                        wpDataTables[tableDescription.tableId].fnDraw(false);
457                                        $('.edit_table[aria-controls="' + tableDescription.tableId + '"]').addClass('disabled');
458                                        $('.duplicate_table_entry[aria-controls="' + tableDescription.tableId + '"]').addClass('disabled');
459                                    }
460                                } else {
461                                    wpDataTables[tableDescription.tableId].fnDraw(false);
462                                    $('.edit_table[aria-controls="' + tableDescription.tableId + '"]').addClass('disabled');
463                                    $('.duplicate_table_entry[aria-controls="' + tableDescription.tableId + '"]').addClass('disabled');
464                                }
465
466                                wdtNotify(wpdatatables_edit_strings.success, wpdatatables_edit_strings.dataSaved, 'success');
467                                setTimeout(function () {
468                                    if (closeDialog) {
469                                        $('#wdt-frontend-modal').modal('hide');
470                                    } else {
471                                        $(tableDescription.selector + '_edit_dialog .editDialogInput').val('');
472                                        $(tableDescription.selector + '_edit_dialog .editDialogInput').selectpicker('val', '');
473                                        //Fix for resetting currently selected block in select picker
474                                        $(tableDescription.selector + '_edit_dialog .editDialogInput').trigger('change.abs.preserveSelected').selectpicker('refresh');
475                                        $('.fileinput').removeClass('fileinput-exists').addClass('fileinput-new');
476                                        $('.fileinput').find('div.fileinput-exists').removeClass('fileinput-exists').addClass('fileinput-new');
477                                        $('.fileinput').find('.fileinput-filename').text('');
478                                        $('.fileinput').find('.fileinput-preview').html('');
479                                        if (tinymce.activeEditor)
480                                            tinymce.activeEditor.setContent('');
481
482                                        if (duplicateEntry === true) {
483                                            wpDataTablesFunctions[tableDescription.tableId].applyData(aoData, true, true);
484                                        } else {
485                                            wpDataTablesFunctions[tableDescription.tableId].setPredefinedEditValues();
486                                        }
487                                    }
488                                }, 1000);
489                                if (!returnData.is_new && $(tableDescription.selector + ' > tbody > tr.selected').length) {
490                                    var cursor = wpDataTables[tableDescription.tableId].fnGetPosition($(tableDescription.selector + ' > tbody > tr.selected').get(0));
491                                    wpDataTables[tableDescription.tableId].fnSettings().aoData[cursor]._aData = aoData;
492                                }
493                            } else {
494                                wdtNotify(wpdatatables_edit_strings.error, returnData.error, 'danger');
495                            }
496                        },
497                        error: function (xhr, response) {
498                            $(tableDescription.selector + '_edit_dialog').closest('.modal-dialog').find('.wdt-preload-layer').animateFadeOut();
499                            wdtNotify(wpdatatables_edit_strings.error, wpdatatables_frontend_strings.databaseInsertError, 'danger');
500                        }
501                    });
502                    return true;
503                }
504
505                wpDataTablesFunctions[tableDescription.tableId].setPredefinedEditValues = function () {
506                    for (let i in tableDescription.advancedEditingOptions.aoColumns) {
507
508                        let column = tableDescription.advancedEditingOptions.aoColumns[i];
509                        let defaultValuesArr;
510
511                        // Create selectbox based on "Number of possible values to load" option
512                        if ($.inArray(column.editorInputType, ['selectbox', 'multi-selectbox']) !== -1) {
513                            if (column.possibleValuesAjax !== -1) {
514
515                                var $selectpickerBlock = $('select#' + tableDescription.tableId + '_' + column.origHeader).closest('.fg-line').parent();
516
517                                var mandatory = column.mandatory ? 'mandatory ' : '';
518                                var possibleValuesAjax = (column.possibleValuesAjax) ? 'wdt-possible-values-ajax ' : '';
519                                var foreignKeyRule = column.foreignKeyRule ? 'wdt-foreign-key-select ' : '';
520                                var searchInSelect = column.searchInSelectBoxEditing ? ' wdt-search-in-select ' : '';
521
522                                // Recreate the selectbox element
523                                $selectpickerBlock.html('<div class="fg-line"><select id="' + tableDescription.tableId + '_' + column.origHeader + '" data-input_type="' + column.editorInputType + '" data-key="' + column.origHeader + '" class="form-control editDialogInput selectpicker ' + mandatory + possibleValuesAjax + foreignKeyRule + searchInSelect +'" data-live-search="true" data-live-search-placeholder="' + wpdatatables_frontend_strings.search + '" data-column_header="' + column.displayHeader + '"></select></div>');
524                                if (column.editorInputType === 'multi-selectbox')
525                                    $selectpickerBlock.find('select').attr('multiple', 'multiple');
526
527                                // If default value is set, append it to selectbox HTML
528                                if (column.defaultValue) {
529                                    if (column.editorInputType === 'multi-selectbox') {
530                                        var defaultValues = !Array.isArray(column.defaultValue) ? column.defaultValue.split('|') : column.defaultValue;
531
532                                        $.each(defaultValues, function (index, value) {
533                                            if (value) {
534                                                $selectpickerBlock.find('select').append('<option selected value="' + value + '">' + value + '</option>');
535                                            }
536                                        });
537                                    } else {
538                                        if (typeof column.defaultValue === 'object')
539                                            $selectpickerBlock.find('select').append('<option selected value="' + column.defaultValue.value + '">' + column.defaultValue.text + '</option>');
540                                        else
541                                            $selectpickerBlock.find('select').append('<option selected value="' + column.defaultValue + '">' + column.defaultValue + '</option>');
542                                    }
543                                }
544
545                                // Load possible values on modal open
546                                $('select#' + tableDescription.tableId + '_' + column.origHeader).on('show.bs.select', function (e) {
547                                    jQuery(this).closest('div.editDialogInput').find('.bs-searchbox .form-control').val('').trigger('keyup');
548                                });
549
550                                // Add AJAX to selectbox
551                                $('select#' + tableDescription.tableId + '_' + column.origHeader).selectpicker('refresh').ajaxSelectPicker({
552                                    ajax: {
553                                        url: tableDescription.adminAjaxBaseUrl,
554                                        method: 'POST',
555                                        data: {
556                                            wdtNonce: $('#wdtNonce').val(),
557                                            action: 'wpdatatables_get_column_possible_values',
558                                            tableId: tableDescription.tableWpId,
559                                            originalHeader: column.origHeader
560                                        }
561                                    },
562                                    cache: false,
563                                    preprocessData: function (data) {
564                                        if ($('.editDialogInput.open').find('select').data('input_type') === 'selectbox') {
565                                            data.unshift({value: ''});
566                                        }
567                                        return data
568                                    },
569                                    preserveSelected: true,
570                                    emptyRequest: true,
571                                    preserveSelectedPosition: 'before',
572                                    locale: {
573                                        emptyTitle: wpdatatables_frontend_strings.nothingSelected,
574                                        statusSearching: wpdatatables_frontend_strings.sLoadingRecords,
575                                        currentlySelected: wpdatatables_frontend_strings.currentlySelected,
576                                        errorText: wpdatatables_frontend_strings.errorText,
577                                        searchPlaceholder: wpdatatables_frontend_strings.search,
578                                        statusInitialized: wpdatatables_frontend_strings.statusInitialized,
579                                        statusNoResults: wpdatatables_frontend_strings.statusNoResults,
580                                        statusTooShort: wpdatatables_frontend_strings.statusTooShort
581                                    }
582                                });
583                            }
584                            // Hide/Show search box in select/multiselect edit input
585                            if (column.searchInSelectBoxEditing !== 1){
586                                $('select#' + tableDescription.tableId + '_' + column.origHeader).closest('div.editDialogInput').find('.bs-searchbox').hide();
587                            } else {
588                                $('select#' + tableDescription.tableId + '_' + column.origHeader).closest('div.editDialogInput').find('.bs-searchbox').show();
589                            }
590                        }
591
592                        if (column.defaultValue) {
593                            let columnDefaultValue = column.defaultValue;
594                            if ($.inArray(column.editorInputType, ['selectbox', 'multi-selectbox']) !== -1 ) {
595                                if (typeof columnDefaultValue === 'object') {
596                                    defaultValuesArr = columnDefaultValue.value;
597                                } else {
598                                    defaultValuesArr = column.editorInputType === 'multi-selectbox' && !Array.isArray(columnDefaultValue) ? columnDefaultValue.split('|') : column.defaultValue;
599                                }
600                                $('#wdt-frontend-modal .editDialogInput:not(.bootstrap-select):eq(' + i + ')').selectpicker('val', defaultValuesArr).trigger('change.abs.preserveSelected');
601                            } else if($.inArray(column.editorInputType, ['attachment', 'image']) !== -1 && ($('.fileupload-' + tableDescription.tableId).length)) {
602
603                                //Reset attachment editor
604                                var $fileUploadEl = $('.fileupload-' + tableDescription.tableId);
605                                $($fileUploadEl).each(function () {
606                                    if ($(this).data('column_type') == 'icon') {
607                                        $(this).parent().parent().find('.fileinput-preview').html('<img src=' + columnDefaultValue + '>');
608                                        $(this).parent().removeClass('fileinput-new').addClass('fileinput-exists');
609                                        $(this).parent().parent().removeClass('fileinput-new').addClass('fileinput-exists');
610                                    } else {
611                                        $(this).parent().find('.fileinput-filename').val(columnDefaultValue);
612                                        $(this).parent().removeClass('fileinput-new').addClass('fileinput-exists');
613                                        $(this).parent().find('.fileinput-filename').text((columnDefaultValue).substring((columnDefaultValue).lastIndexOf("/") + 1));
614                                    }
615                                });
616                                $('#wdt-frontend-modal .editDialogInput:not(.bootstrap-select):eq(' + i + ')').val(column.defaultValue);
617
618                            } else if(column.editorInputType === 'mce-editor') {
619                                if (tinymce.activeEditor) {
620                                    $inputElement = $('#' + tableDescription.tableId + '_edit_dialog .editDialogInput:not(.bootstrap-select):eq(' + i + ')');
621                                    tinymce.execCommand('mceRemoveEditor', true, $inputEl
621ement.attr('id'));
622                                    tinymce.init({
623                                        selector: '#' + $inputElement.attr('id'),
624                                        init_instance_callback: function (editor) {
625                                            editor.setContent(column.defaultValue);
626                                        },
627                                        menubar: false,
628                                        plugins: 'link image media lists hr colorpicker fullscreen textcolor code',
629                                        toolbar: 'undo redo formatselect bold italic underline strikethrough subscript superscript | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent blockquote | hr fullscreen | link unlink image | forecolor backcolor removeformat | code'
630                                    });
631                                }
632                            } else {
633                                $('#wdt-frontend-modal .editDialogInput:not(.bootstrap-select):eq(' + i + ')').val(column.defaultValue);
634                            }
635                        }
636                    }
637                }
638
639            }
640
641            /**
642             * Remove overlay if the table is not responsive nor editable
643             */
644            if (!tableDescription.responsive
645                && !tableDescription.editable) {
646                dataTableOptions.fnDrawCallback = function () {
647                    wdtRemoveOverlay('#' + tableDescription.tableId);
648                }
649            }
650            //[<--/ Full version -->]//
651
652            /**
653             * If aggregate functions shortcode exists on the page add that column to the ajax data
654             */
655            if ($('.wdt-column-sum[data-table-id="' + tableDescription.tableWpId + '"]').length) {
656                var sumColumns = [];
657                $('.wdt-column-sum[data-table-id="' + tableDescription.tableWpId + '"]').each(function () {
658                    sumColumns.push($(this).data('column-orig-header'));
659                });
660            }
661
662            if ($('.wdt-column-avg[data-table-id="' + tableDescription.tableWpId + '"]').length) {
663                var avgColumns = [];
664                $('.wdt-column-avg[data-table-id="' + tableDescription.tableWpId + '"]').each(function () {
665                    avgColumns.push($(this).data('column-orig-header'));
666                });
667            }
668
669            if ($('.wdt-column-min[data-table-id="' + tableDescription.tableWpId + '"]').length) {
670                var minColumns = [];
671                $('.wdt-column-min[data-table-id="' + tableDescription.tableWpId + '"]').each(function () {
672                    minColumns.push($(this).data('column-orig-header'));
673                });
674            }
675
676            if ($('.wdt-column-max[data-table-id="' + tableDescription.tableWpId + '"]').length) {
677                var maxColumns = [];
678                $('.wdt-column-max[data-table-id="' + tableDescription.tableWpId + '"]').each(function () {
679                    maxColumns.push($(this).data('column-orig-header'));
680                });
681            }
682
683            if (tableDescription.serverSide) {
684                dataTableOptions.ajax.data = function (data) {
685                    data.sumColumns = sumColumns;
686                    data.avgColumns = avgColumns;
687                    data.minColumns = minColumns;
688                    data.maxColumns = maxColumns;
689                    data.currentUserId = $('#wdt-user-id-placeholder').val();
690                    data.currentUserLogin = $('#wdt-user-login-placeholder').val();
691                    data.currentPostIdPlaceholder = $('#wdt-post-id-placeholder').val();
692                    data.currentUserFirstName = $('#wdt-user-first-name-placeholder').val();
693                    data.currentUserLastName = $('#wdt-user-last-name-placeholder').val();
694                    data.currentUserEmail = $('#wdt-user-email-placeholder').val();
695                    data.currentDate = $('#wdt-date-placeholder').val();
696                    data.currentDateTime = $('#wdt-datetime-placeholder').val();
697                    data.currentTime = $('#wdt-time-placeholder').val();
698                    data.wpdbPlaceholder = $('#wdt-wpdb-placeholder').val();
699                    data.wdtNonce = $('#wdtNonceFrontendEdit_' + tableDescription.tableWpId).val();
700                    data.showAllRows = $('#wdt-show-all-rows').val();
701                };
702            }
703
704            /**
705             * Show after load if configured
706             */
707            if (tableDescription.hideBeforeLoad) {
708                dataTableOptions.fnInitComplete = function () {
709                    $(tableDescription.selector).animateFadeIn();
710                }
711            }
712
713            /**
714             * Init the DataTable itself
715             */
716            wpDataTables[tableDescription.tableId] = $(tableDescription.selector).dataTable(dataTableOptions);
717
718            /**
719             * Remove pagination when "Default rows per page" is set to "All"
720             */
721            if (wpDataTables[tableDescription.tableId].fnSettings()._iDisplayLength >= wpDataTables[tableDescription.tableId].fnSettings().fnRecordsTotal() || dataTableOptions.iDisplayLength === -1) {
722                $('#' +  tableDescription.tableId + '_paginate').hide();
723            }
724
725            $(tableDescription.selector + '_wrapper').addClass('wpDataTableID-' + tableDescription.tableWpId)
726
727            /**
728             * Set pagination alignment classes
729             */
730            if (tableDescription.paginationAlign) {
731                switch (tableDescription.paginationAlign){
732                    case "right":
733                        $(tableDescription.selector + '_wrapper').addClass('wpdt-pagination-right');
734                        $(tableDescription.selector + '_wrapper').removeClass('wpdt-pagination-left');
735                        $(tableDescription.selector + '_wrapper').removeClass('wpdt-pagination-center');
736                        break;
737                    case "left":
738                        $(tableDescription.selector + '_wrapper').addClass('wpdt-pagination-left');
739                        $(tableDescription.selector + '_wrapper').removeClass('wpdt-pagination-right');
740                        $(tableDescription.selector + '_wrapper').removeClass('wpdt-pagination-center');
741                        break;
742                    case "center":
743                        $(tableDescription.selector + '_wrapper').addClass('wpdt-pagination-center');
744                        $(tableDescription.selector + '_wrapper').removeClass('wpdt-pagination-left');
745                        $(tableDescription.selector + '_wrapper').removeClass('wpdt-pagination-right');
746                        break;
747                    default:
748                        $(tableDescription.selector + '_wrapper').addClass('wpdt-pagination-right');
749                        $(tableDescription.selector + '_wrapper').removeClass('wpdt-pagination-left');
750                        $(tableDescription.selector + '_wrapper').removeClass('wpdt-pagination-center');
751                        break;
752                }
753
754            }
755            if (tableDescription.tableSkin) {
756                $(tableDescription.selector + '_wrapper .dt-buttons .DTTT_button_export').on('click', function () {
757                    $('.dt-button-collection').addClass('wdt-skin-' + tableDescription.tableSkin)
758                });
759            }
760
761            /**
762             * Show "Show X entries" dropdown
763             */
764            if (tableDescription.showRowsPerPage){
765                if ( !(jQuery(tableDescription.selector + '_wrapper .dataTables_length .length_menu.bootstrap-select').length))
766                    jQuery(tableDescription.selector + '_wrapper .dataTables_length .length_menu.wdt-selectpicker').selectpicker();
767            }
768
769            /**
770             * Remove pagination when "All" is selected from length menu or
771             * if value length menu is greater than total records
772             */
773            wpDataTables[tableDescription.tableId].fnSettings().aoDrawCallback.push({
774                sName: 'removePaginate',
775                fn: function (oSettings) {
776                    var api = oSettings.oInstance.api();
777
778                    if (typeof (api.page.info()) != 'undefined'){
779                        if (api.page.len() >= api.page.info().recordsDisplay || api.data().page.len() == -1) {
780                            $('#' +  tableDescription.tableId + '_paginate').hide();
781                        } else {
782                            $('#' +  tableDescription.tableId + '_paginate').show();
783                        }
784                    }
785
786                }
787            });
788
789            /**
790             * Enable auto-refresh if defined
791             */
792            if (tableDescription.serverSide) {
793                if (parseInt(tableDescription.autoRefreshInterval) > 0) {
794                    autoRefresh = setInterval(function () {
795                            wpDataTables[tableDescription.tableId].fnDraw(false)
796                        },
797                        parseInt(tableDescription.autoRefreshInterval) * 1000
798                    );
799                } else {
800                    if (typeof autoRefresh !== "undefined") {
801                        clearInterval(autoRefresh);
802                    }
803                }
804            }
805            //[<--/ Full version -->]//
806
807            /**
808             * Add the draw callback
809             * @param callback
810             */
811            wpDataTables[tableDescription.tableId].addOnDrawCallback = function (callback) {
812                if (typeof callback !== 'function') {
813                    return;
814                }
815
816                var index = wpDataTables[tableDescription.tableId].fnSettings().aoDrawCallback.length + 1;
817
818                wpDataTables[tableDescription.tableId].fnSettings().aoDrawCallback.push({
819                    sName: 'user_callback_' + index,
820                    fn: callback
821                });
822
823            };
824
825            //[<-- Full version -->]//
826            /**
827             * SUM, AVG, MIN, MAX functions callback
828             */
829            if (tableDescription.hasSumColumns || tableDescription.hasAvgColumns || tableDescription.hasMinColumns || tableDescription.hasMaxColumns
830                || $('.wdt-column-sum').length || $('.wdt-column-avg').length || $('.wdt-column-min').length || $('.wdt-column-max').length) {
831
832                var sumLabel = tableDescription.sumFunctionsLabel ? tableDescription.sumFunctionsLabel : '&#8721; = ';
833                var avgLabel = tableDescription.avgFunctionsLabel ? tableDescription.avgFunctionsLabel : 'Avg = ';
834                var minLabel = tableDescription.minFunctionsLabel ? tableDescription.minFunctionsLabel : 'Min = ';
835                var maxLabel = tableDescription.maxFunctionsLabel ? tableDescription.maxFunctionsLabel : 'Max = ';
836
837                if (tableDescription.serverSide) {
838                    // Case with server-side table
839                    wpDataTables[tableDescription.tableId].fnSettings().aoDrawCallback.push({
840                        sName: 'updateFooterFunctions',
841                        fn: function (oSettings) {
842                            var api = oSettings.oInstance.api();
843
844                            for (var columnName in api.ajax.json().sumFooterColumns) {
845                                if (tableDescription.hasSumColumns) {
846                                    $('#' + tableDescription.tableId + ' tfoot tr.wdt-sum-row td.wdt-sum-cell[data-column_header="' + columnName + '"]').html(sumLabel + ' ' + api.ajax.json().sumColumnsValues[columnName]);
847                                }
848                            }
849                            for (columnName in api.ajax.json().avgFooterColumns) {
850                                if (tableDescription.hasAvgColumns) {
851                                    $('#' + tableDescription.tableId + ' tfoot tr.wdt-avg-row td.wdt-avg-cell[data-column_header="' + columnName + '"]').html(avgLabel + ' ' + api.ajax.json().avgColumnsValues[columnName]);
852                                }
853                            }
854                            for (columnName in api.ajax.json().minFooterColumns) {
855                                if (tableDescription.hasMinColumns) {
856                                    $('#' + tableDescription.tableId + ' tfoot tr.wdt-min-row td.wdt-min-cell[data-column_header="' + columnName + '"]').html(minLabel + ' ' + api.ajax.json().minColumnsValues[columnName]);
857                                }
858                            }
859                            for (columnName in api.ajax.json().maxFooterColumns) {
860                                if (tableDescription.hasMaxColumns) {
861                                    $('#' + tableDescription.tableId + ' tfoot tr.wdt-max-row td.wdt-max-cell[data-column_header="' + columnName + '"]').html(maxLabel + ' ' + api.ajax.json().maxColumnsValues[columnName]);
862                                }
863                            }
864
865                            if ($('.wdt-column-sum').length) {
866                                $('.wdt-column-sum[data-table-id="' + tableDescription.tableWpId + '"]').each(function () {
867                                    $(this).find('.wdt-column-sum-value').text(api.ajax.json().sumColumnsValues[$(this).data('column-orig-header')]);
868                                })
869                            }
870
871                            if ($('.wdt-column-avg').length) {
872                                $('.wdt-column-avg[data-table-id="' + tableDescription.tableWpId + '"]').each(function () {
873                                    $(this).find('.wdt-column-avg-value').text(api.ajax.json().avgColumnsValues[$(this).data('column-orig-header')]);
874                                })
875                            }
876
877                            if ($('.wdt-column-min').length) {
878                                $('.wdt-column-min[data-table-id="' + tableDescription.tableWpId + '"]').each(function () {
879                                    $(this).find('.wdt-column-min-value').text(api.ajax.json().minColumnsValues[$(this).data('column-orig-header')]);
880                                })
881                            }
882
883                            if ($('.wdt-column-max').length) {
884                                $('.wdt-column-max[data-table-id="' + tableDescription.tableWpId + '"]').each(function () {
885                                    $(this).find('.wdt-column-max-value').text(api.ajax.json().maxColumnsValues[$(this).data('column-orig-header')]);
886                                })
887                            }
888
889                        }
890                    });
891                } else {
892                    // Case with client-side table
893                    wpDataTables[tableDescription.tableId].fnSettings().aoDrawCallback.push({
894                        sName: 'updateFooterFunctions',
895                        fn: function (oSettings) {
896                            var api = oSettings.oInstance.api();
897
898                            var thousandsSeparator = tableDescription.number_format == 1 ? '.' : ',';
899                            var decimalSeparator = tableDescription.number_format == 1 ? ',' : '.';
900
901                            for (var i in tableDescription.sumAvgColumns) {
902
903                                var columnData = api.column(tableDescription.sumAvgColumns[i] + ':name', {search: 'applied'}).data().filter(function (el) {
904                                    return el !== '';
905                                });
906                                var columnType = oSettings.aoColumns[api.column(tableDescription.sumAvgColumns[i] + ':name').index()].wdtType;
907
908                                var sum = wdtCalculateColumnSum(columnData, thousandsSeparator);
909
910                                var nonNullLength = columnData.length;
911
912                                var sumStr = wdtFormatNumberByColumnType(parseFloat(sum), columnType, tableDescription.columnsDecimalPlaces[tableDescription.sumAvgColumns[i]],
913                                    tableDescription.decimalPlaces, decimalSeparator, thousandsSeparator);
914
915                                if (_.contains(tableDescription.sumColumns, tableDescription.sumAvgColumns[i])) {
916                                    $('#' + tableDescription.tableId + ' tfoot tr.wdt-sum-row td.wdt-sum-cell[data-column_header="' + tableDescription.sumAvgColumns[i] + '"]')
917                                        .html(sumLabel + ' ' + sumStr);
918                                }
919
920                                if (_.contains(tableDescription.avgColumns, tableDescription.sumAvgColumns[i])) {
921                                    var avg = sum / nonNullLength;
922
923                                    var avgStr = wdtFormatNumberByColumnType(avg, 'float', tableDescription.columnsDecimalPlaces[tableDescription.sumAvgColumns[i]],
924                                        tableDescription.decimalPlaces, decimalSeparator, thousandsSeparator);
925
926                                    $('#' + tableDescription.tableId + ' tfoot tr.wdt-avg-row td.wdt-avg-cell[data-column_header="' + tableDescription.sumAvgColumns[i] + '"]')
927                                        .html(avgLabel + ' ' + avgStr);
928                                }
929
930                            }
931                            for (i in tableDescription.minColumns) {
932
933                                columnData = api.column(tableDescription.minColumns[i] + ':name', {search: 'applied'}).data().filter(function (el) {
934                                    return el !== '';
935                                });
936                                columnType = oSettings.aoColumns[api.column(tableDescription.minColumns[i] + ':name').index()].wdtType;
937
938                                var min = wdtCalculateColumnMin(columnData, thousandsSeparator);
939
940                                var minStr = wdtFormatNumberByColumnType(parseFloat(min), columnType, tableDescription.columnsDecimalPlaces[tableDescription.minColumns[i]],
941                                    tableDescription.decimalPlaces, decimalSeparator, thousandsSeparator);
942
943                                $('#' + tableDescription.tableId + ' tfoot tr.wdt-min-row td.wdt-min-cell[data-column_header="' + tableDescription.minColumns[i] + '"]')
944                                    .html(minLabel + ' ' + minStr);
945                            }
946                            for (i in tableDescription.maxColumns) {
947
948                                columnData = api.column(tableDescription.maxColumns[i] + ':name', {search: 'applied'}).data().filter(function (el) {
949                                    return el !== '';
950                                });
951                                columnType = oSettings.aoColumns[api.column(tableDescription.maxColumns[i] + ':name').index()].wdtType;
952
953                                var max = wdtCalculateColumnMax(columnData, thousandsSeparator);
954
955                                var maxStr = wdtFormatNumberByColumnType(parseFloat(max), columnType, tableDescription.columnsDecimalPlaces[tableDescription.maxColumns[i]],
956                                    tableDescription.decimalPlaces, decimalSeparator, thousandsSeparator);
957
958                                $('#' + tableDescription.tableId + ' tfoot tr.wdt-max-row td.wdt-max-cell[data-column_header="' + tableDescription.maxColumns[i] + '"]')
959                                    .html(maxLabel + ' ' + maxStr);
960                            }
961
962                            // Update values from wpdatatables_{func} shortcode
963                            if ($('.wdt-column-sum').length) {
964                                $('.wdt-column-sum[data-table-id="' + tableDescription.tableWpId + '"]').each(function () {
965                                    var columnData = api.column($(this).data('column-orig-header') + ':name', {search: 'applied'}).data().filter(function (el) {
966                                        return el !== '';
967                                    });
968                                    var columnType = oSettings.aoColumns[api.column($(this).data('column-orig-header') + ':name').index()].wdtType;
969
970                                    var sum = wdtCalculateColumnSum(columnData, thousandsSeparator);
971
972                                    var sumStr = wdtFormatNumberByColumnType(parseFloat(sum), columnType, tableDescription.columnsDecimalPlaces[$(this).data('column-orig-header')],
973                                        tableDescription.decimalPlaces, decimalSeparator, thousandsSeparator);
974
975                                    $(this).find('.wdt-column-sum-value').text(sumStr);
976                                })
977                            }
978
979                            if ($('.wdt-column-avg').length) {
980                                $('.wdt-column-avg[data-table-id="' + tableDescription.tableWpId + '"]').each(function () {
981                                    var columnData = api.column($(this).data('column-orig-header') + ':name', {search: 'applied'}).data().filter(function (el) {
982                                        return el !== '';
983                                    });
984
985                                    var avg = wdtCalculateColumnSum(columnData, thousandsSeparator) / api.page.info().recordsDisplay;
986
987                                    var avgStr = wdtFormatNumberByColumnType(parseFloat(avg), 'float', tableDescription.columnsDecimalPlaces[$(this).data('column-orig-header')],
988                                        tableDescription.decimalPlaces, decimalSeparator, thousandsSeparator);
989
990                                    $(this).find('.wdt-column-avg-value').text(avgStr);
991                                })
992                            }
993
994                            if ($('.wdt-column-min').length) {
995                                $('.wdt-column-min[data-table-id="' + tableDescription.tableWpId + '"]').each(function () {
996                                    var columnData = api.column($(this).data('column-orig-header') + ':name', {search: 'applied'}).data().filter(function (el) {
997                                        return el !== '';
998                                    });
999                                    var columnType = oSettings.aoColumns[api.column($(this).data('column-orig-header') + ':name').index()].wdtType;
1000
1001                                    var min = wdtCalculateColumnMin(columnData, thousandsSeparator);
1002
1003                                    var minStr = wdtFormatNumberByColumnType(parseFloat(min), columnType, tableDescription.columnsDecimalPlaces[$(this).data('column-orig-header')],
1004                                        tableDescription.decimalPlaces, decimalSeparator, thousandsSeparator);
1005
1006                                    $(this).find('.wdt-column-min-value').text(minStr);
1007                                })
1008                            }
1009
1010                            if ($('.wdt-column-max').length) {
1011                                $('.wdt-column-max[data-table-id="' + tableDescription.tableWpId + '"]').each(function () {
1012                                    var columnData = api.column($(this).data('column-orig-header') + ':name', {search: 'applied'}).data().filter(function (el) {
1013                                        return el !== '';
1014                                    });
1015                                    var columnType = oSettings.aoColumns[api.column($(this).data('column-orig-header') + ':name').index()].wdtType;
1016
1017                                    var max = wdtCalculateColumnMax(columnData, thousandsSeparator);
1018
1019                                    var maxStr = wdtFormatNumberByColumnType(parseFloat(max), columnType, tableDescription.columnsDecimalPlaces[$(this).data('column-orig-header')],
1020                                        tableDescription.decimalPlaces, decimalSeparator, thousandsSeparator);
1021
1022                                    $(this).find('.wdt-column-max-value').text(maxStr);
1023                                })
1024                            }
1025                        }
1026                    });
1027
1028                }
1029            }
1030
1031            /**
1032             * Conditional formatting
1033             */
1034            if (tableDescription.conditional_formatting_columns) {
1035                wpDataTables[tableDescription.tableId].fnSettings().aoDrawCallback.push({
1036                    sName: 'updateConditionalFormatting',
1037                    fn: function (oSettings) {
1038                        for (var i = 0; i < tableDescription.conditional_formatting_columns.length; i++) {
1039                            var params = {};
1040                            var column = oSettings.oInstance.api().column(tableDescription.conditional_formatting_columns[i] + ':name', {search: 'applied'});
1041                            var conditionalFormattingRules = oSettings.aoColumns[column.index()].conditionalFormattingRules;
1042                            params.columnType = oSettings.aoColumns[column.index()].wdtType;
1043                            params.thousandsSeparator = tableDescription.number_format == 1 ? '.' : ',';
1044                            params.decimalSeparator = tableDescription.number_format == 1 ? ',' : '.';
1045                            params.dateFormat = tableDescription.datepickFormat;
1046                            params.momentDateFormat = params.dateFormat.replace('dd', 'DD').replace('M', 'MMM').replace('mm', 'MM').replace('yy', 'YYYY').replace('y', 'YY');
1047                            params.momentTimeFormat = tableDescription.timeFormat.replace('H', 'H').replace('i', 'mm');
1048                            for (var j in conditionalFormattingRules) {
1049                                var nodes = column.nodes();
1050                                column.nodes().to$().each(function () {
1051                                    wdtCheckConditionalFormatting(conditionalFormattingRules[j], params, $(this));
1052                                });
1053                            }
1054                        }
1055                    }
1056                });
1057                if (!tableDescription.serverSide) {
1058                    wpDataTables[tableDescription.tableId].fnDraw();
1059                }
1060            }
1061
1062            /**
1063             * Init the callback for checking if the selected row is first/last in the dataset
1064             */
1065            wpDataTables[tableDescription.tableId].checkSelectedLimits = function () {
1066                if (wpDataTablesUpdatingFlags[tableDescription.tableId]) {
1067                    return;
1068                }
1069                var sel_row_index = $(tableDescription.selector + ' > tbody > tr.selected').index();
1070                if (sel_row_index + wpDataTables[tableDescription.tableId].fnSettings()._iDisplayStart == wpDataTables[tableDescription.tableId].fnSettings()._iRecordsDisplay - 1) {
1071                    $(tableDescription.selector + '_next_edit_dialog').prop('disabled', true)
1072                } else {
1073                    $(tableDescription.selector + '_next_edit_dialog').prop('disabled', false)
1074                }
1075                if ((sel_row_index == 0 && wpDataTables[tableDescription.tableId].fnSettings()._iDisplayStart == 0) || wpDataTables[tableDescription.tableId].fnSettings()._iRecordsDisplay == 0) {
1076                    $(tableDescription.selector + '_prev_edit_dialog').prop('disabled', true)
1077                } else {
1078                    $(tableDescription.selector + '_prev_edit_dialog').prop('disabled', false)
1079                }
1080            };
1081            //[<--/ Full version -->]//
1082
1083            /**
1084             * Init row grouping if enabled
1085             */
1086            if ((tableDescription.columnsFixed == 0) && (tableDescription.groupingEnabled)) {
1087                wpDataTables[tableDescription.tableId].rowGrouping({iGroupingColumnIndex: tableDescription.groupingColumnIndex});
1088            }
1089
1090            //[<-- Full version -->]//
1091            /**
1092             * Init the advanced filtering if enabled
1093             */
1094            if (tableDescription.advancedFilterEnabled) {
1095                $('#' + tableDescription.tableId).dataTable().columnFilter(tableDescription.advancedFilterOptions);
1096                for (var i in wpDataTablesHooks.onRenderFilter) {
1097                    if (!isNaN(i))
1098                        wpDataTablesHooks.onRenderFilter[i](tableDescription);
1099                }
1100            }
1101
1102            if (tableDescription.editable) {
1103
1104                /**
1105                 * Previous button in edit dialog
1106                 */
1107                $(document).on('click', tableDescription.selector + '_prev_edit_dialog', function (e) {
1108                    e.preventDefault();
1109                    e.stopImmediatePropagation();
1110                    var sel_row_index = $(tableDescription.selector + ' > tbody > tr.selected').index();
1111                    if (sel_row_index > 0) {
1112                        $(tableDescription.selector + ' > tbody > tr.selected').removeClass('selected');
1113                        $(tableDescription.selector + ' > tbody > tr:eq(' + (sel_row_index - 1) + ')').addClass('selected', 300);
1114                        wpDataTablesSelRows[tableDescription.tableId] = wpDataTables[tableDescription.tableId].fnGetPosition($(tableDescription.selector + ' > tbody > tr.selected').get(0));
1115                        var data = wpDataTables[tableDescription.tableId].fnGetData(wpDataTablesSelRows[tableDescription.tableId]);
1116                        wpDataTablesFunctions[tableDescription.tableId].applyData(data);
1117                    } else {
1118                        var cur_page = Math.ceil(wpDataTables[tableDescription.tableId].fnSettings()._iDisplayStart / wpDataTables[tableDescription.tableId].fnSettings()._iDisplayLength) + 1;
1119                        if (cur_page == 1)
1120                            return;
1121                        wpDataTablesSelRows[tableDescription.tableId] = -2;
1122                        wpDataTablesUpdatingFlags[tableDescription.tableId] = true;
1123                        wpDataTables[tableDescription.tableId].fnPageChange('previous');
1124                    }
1125                    wpDataTables[tableDescription.tableId].checkSelectedLimits();
1126                });
1127
1128                /**
1129                 * Next button in edit dialog
1130                 */
1131                $(document).on('click', tableDescription.selector + '_next_edit_dialog', function (e) {
1132                    e.preventDefault();
1133                    e.stopImmediatePropagation();
1134                    if (wpDataTables[tableDescription.tableId].fnSettings()._iDisplayLength == -1) {
1135                        wpDataTables[tableDescription.tableId].fnSettings()._iDisplayLength = wpDataTables[tableDescription.tableId].fnSettings()._iRecordsTotal;
1136                    }
1137                    var sel_row_index = $(tableDescription.selector + ' > tbody > tr.selected').index();
1138                    if (sel_row_index < wpDataTables[tableDescription.tableId].fnSettings()._iDisplayLength - 1) {
1139                        $(tableDescription.selector + ' > tbody > tr.selected').removeClass('selected');
1140                        $(tableDescription.selector + ' > tbody > tr:eq(' + (sel_row_index + 1) + ')').addClass('selected', 300);
1141                        wpDataTablesSelRows[tableDescription.tableId] = wpDataTables[tableDescription.tableId].fnGetPosition($(tableDescription.selector + ' > tbody > tr.selected').get(0));
1142                        var data = wpDataTables[tableDescription.tableId].fnGetData(wpDataTablesSelRows[tableDescription.tableId]);
1143                        wpDataTablesFunctions[tableDescription.tableId].applyData(data);
1144                    } else {
1145                        var cur_page = Math.ceil(wpDataTables[tableDescription.tableId].fnSettings()._iDisplayStart / wpDataTables[tableDescription.tableId].fnSettings()._iDisplayLength) + 1;
1146                        var total_pages = Math.ceil(wpDataTables[tableDescription.tableId].fnSettings()._iRecordsTotal / wpDataTables[tableDescription.tableId].fnSettings()._iDisplayLength);
1147                        if (cur_page == total_pages)
1148                            return;
1149                        wpDataTablesSelRows[tableDescription.tableId] = -3;
1150                        wpDataTablesUpdatingFlags[tableDescription.tableId] = true;
1151                        wpDataTables[tableDescription.tableId].fnPageChange('next');
1152                        wpDataTables[tableDescription.tableId].fnDraw(false);
1153                    }
1154                    wpDataTables[tableDescription.tableId].checkSelectedLimits();
1155                });
1156
1157                /**
1158                 * Apply button in edit dialog
1159                 */
1160                $(document).on('click', tableDescription.selector + '_apply_edit_dialog', function (e) {
1161                    e.preventDefault();
1162                    e.stopImmediatePropagation();
1163                    e.preventDefault();
1164                    wpDataTablesFunctions[tableDescription.tableId].saveTableData(true, false, false);
1165                });
1166
1167                /**
1168                 * Duplicate button in edit dialog
1169                 */
1170                $(document).on('click', tableDescription.selector + '_apply_duplicate_dialog', function (e) {
1171                    e.preventDefault();
1172                    e.stopImmediatePropagation();
1173                    e.preventDefault();
1174                    wpDataTablesFunctions[tableDescription.tableId].saveTableData(true, false, true);
1175                });
1176
1177                /**
1178                 * OK button in edit dialog
1179                 */
1180                $(document).on('click', tableDescription.selector + '_ok_edit_dialog', function (e) {
1181                    e.preventDefault();
1182                    e.stopImmediatePropagation();
1183                    e.preventDefault();
1184                    wpDataTablesFunctions[tableDescription.tableId].saveTableData(true, true, false);
1185                });
1186
1187                /**
1188                 * Toggle OK when enter pressed in inputs (but not selectboxes or textareas)
1189                 */
1190                $(document).on('keyup', tableDescription.selector + '_edit_dialog input', function (e) {
1191                    if (e.which == 13) {
1192                        $(tableDescription.selector + '_ok_edit_dialog').click();
1193                    }
1194                });
1195
1196                /**
1197                 * Apply maskmoney for Float column types and apply thousands separator and decimal places
1198                 * based on table description
1199                 */
1200                $(tableDescription.selector + '_edit_dialog input.wdt-maskmoney[data-column_type="float"]').each(function (i) {
1201                    var decimalPlaces = tableDescription.columnsDecimalPlaces[$(this).data('key')] != -1 ?
1202                        tableDescription.columnsDecimalPlaces[$(this).data('key')] :
1203                        parseInt(tableDescription.decimalPlaces);
1204                    $(this).maskMoney({
1205                        thousands: tableDescription.number_format == 1 ? '.' : ',',
1206                        decimal: tableDescription.number_format == 1 ? ',' : '.',
1207                        precision: decimalPlaces,
1208                        allowNegative: true,
1209                        allowEmpty: true,
1210                        allowZero: true
1211                    })
1212                });
1213
1214                /**
1215                 * Apply maskmoney for Input column types
1216                 */
1217                $(tableDescription.selector + '_edit_dialog input.wdt-maskmoney[data-column_type="int"]').each(function (i) {
1218                    var thousandsSeparator = tableDescription.number_format == 1 ? '.' : ',';
1219                    if (tableDescription.columnsThousandsSeparator[$(this).data('key')] == 0) {
1220                        thousandsSeparator = '';
1221                    }
1222                    $(this).maskMoney({
1223                        thousands: thousandsSeparator,
1224                        precision: 0,
1225                        allowNegative: true,
1226                        allowEmpty: true,
1227                        allowZero: true
1228                    });
1229                });
1230
1231                /**
1232                 * Apply fileuploaders
1233                 */
1234                var fileUploadInit = function (selector) {
1235                    if ($('.fileupload-' + selector).length) {
1236
1237                        var attachment = null;
1238                        // Extend the wp.media object
1239                        wdtCustomUploader = wp.media({
1240                            title: wpdatatables_frontend_strings.select_upload_file,
1241                            button: {
1242                                text: wpdatatables_frontend_strings.choose_file
1243                            },
1244                            multiple: false
1245                        });
1246
1247
1248                        $('span.fileupload-' + selector).click(function (e) {
1249                            e.preventDefault();
1250                            var $button = $(this);
1251                            var $relInput = $('#' + $button.data('rel_input'));
1252                            // Fix for inputs in wp media dialog when bs modal is open
1253                            $(document).off('focusin.modal');
1254
1255                            wdtCustomUploader = wp.media({
1256                                title: wpdatatables_frontend_strings.select_upload_file,
1257                                button: {
1258                                    text: wpdatatables_frontend_strings.choose_file
1259                                },
1260                                multiple: false,
1261                                library: {
1262                                    type: $button.data('column_type') == 'icon' ? 'image' : ''
1263                                }
1264                            });
1265                            if ($button.data('column_type') == 'icon') {
1266                                wdtCustomUploader.off('select').on('select', function () {
1267                                    attachment = wdtCustomUploader.state().get('selection').first().toJSON();
1268
1269                                    var val = attachment.url;
1270
1271                                    $relInput.parent().parent().parent().find('.fileinput-preview').html('<img src=' + val + '>');
1272                                    $relInput.parent().parent().parent().removeClass('fileinput-new').addClass('fileinput-exists');
1273                                    $relInput.parent().parent().removeClass('fileinput-new').addClass('fileinput-exists');
1274
1275                                    if (attachment.sizes.thumbnail) {
1276                                        val = attachment.sizes.thumbnail.url + '||' + val;
1277                                    }
1278
1279                                    $relInput.val(val);
1280                                });
1281                            } else {
1282                                // For columns that are not image column type, grab the URL and set it as the text field's value
1283                                wdtCustomUploader.off('select').on('select', function () {
1284                                    var attachment = wdtCustomUploader.state().get('selection').first().toJSON();
1285                                    $relInput.val(attachment.url);
1286                                    $relInput.parent().parent().removeClass('fileinput-new').addClass('fileinput-exists');
1287                                    $relInput.parent().parent().find('.fileinput-filename').text(attachment.filename);
1288                                });
1289                            }
1290                            // Open the uploader dialog
1291                            wdtCustomUploader.open();
1292
1293
1294                        });
1295                    }
1296                };
1297
1298                fileUploadInit(tableDescription.tableId);
1299
1300                /**
1301                 * Show edit dialog
1302                 */
1303                $('.edit_table[aria-controls="' + tableDescription.tableId + '"]').click(function () {
1304                    var modal = $('#wdt-frontend-modal');
1305                    var newSkins = ['dark', 'aqua','purple'];
1306
1307                    if ($(this).hasClass('disabled'))
1308                        return false;
1309
1310                    $('.wpDataTablesPopover.editTools').hide();
1311
1312                    modal.addClass('wdt-skin-' + tableDescription.tableSkin);
1313
1314                    modal.find('.modal-title').html(wpdatatables_frontend_strings.edit_entry);
1315                    modal.find('.modal-body').html('');
1316                    modal.find('.modal-footer').html('');
1317
1318                    var row = $(tableDescription.selector + ' tr.selected').get(0);
1319
1320                    if (['manual', 'mysql'].indexOf(tableDescription.tableType) === -1) {
1321                        if(typeof wpDataTablesEditors[tableDescription.tableType]['edit'] == 'function'){
1322                            if (singleClick === false){
1323                                singleClick = true;
1324                                wpDataTablesEditors[tableDescription.tableType]['edit'](tableDescription, false);
1325                            }
1326                        }
1327                    } else {
1328                        var data = wpDataTables[tableDescription.tableId].fnGetData(row);
1329                        wpDataTablesFunctions[tableDescription.tableId].applyData(data);
1330                        wpDataTables[tableDescription.tableId].checkSelectedLimits();
1331                        modal.find('.modal-body').append($(tableDescription.selector + '_edit_dialog').show());
1332                        modal.find('.modal-footer').append($(tableDescription.selector + '_edit_dialog_buttons').show());
1333
1334                        if (newSkins.includes(tableDescription.tableSkin)){
1335                            modal.find(tableDescription.selector + '_prev_edit_dialog i' ).addClass('wpdt-icon-chevron-left');
1336                            modal.find(tableDescription.selector + '_prev_edit_dialog i' ).removeClass('wpdt-icon-step-backward');
1337                            modal.find(tableDescription.selector + '_next_edit_dialog i' ).addClass('wpdt-icon-chevron-right');
1338                            modal.find(tableDescription.selector + '_next_edit_dialog i' ).removeClass('wpdt-icon-step-forward');
1339                            modal.find(tableDescription.selector + '_apply_edit_dialog i' ).addClass('wpdt-icon-check-circle-full');
1340                            modal.find(tableDescription.selector + '_apply_edit_dialog i' ).removeClass('wpdt-icon-check');
1341                            modal.find(tableDescription.selector + '_ok_edit_dialog i' ).addClass('wpdt-icon-check-circle');
1342                            modal.find(tableDescription.selector + '_ok_edit_dialog i' ).removeClass('wpdt-icon-check-double-reg');
1343                        } else {
1344                            modal.find(tableDescription.selector + '_prev_edit_dialog i' ).removeClass('wpdt-icon-chevron-left');
1345                            modal.find(tableDescription.selector + '_prev_edit_dialog i' ).addClass('wpdt-icon-step-backward');
1346                            modal.find(tableDescription.selector + '_next_edit_dialog i' ).removeClass('wpdt-icon-chevron-right');
1347                            modal.find(tableDescription.selector + '_next_edit_dialog i' ).addClass('wpdt-icon-step-forward');
1348                            modal.find(tableDescription.selector + '_apply_edit_dialog i' ).removeClass('wpdt-icon-check-circle-full');
1349                            modal.find(tableDescription.selector + '_apply_edit_dialog i' ).addClass('wpdt-icon-check');
1350                            modal.find(tableDescription.selector + '_ok_edit_dialog i' ).removeClass('wpdt-icon-check-circle');
1351                            modal.find(tableDescription.selector + '_ok_edit_dialog i' ).addClass('wpdt-icon-check-double-reg');
1352                        }
1353
1354                        $('#wdt-frontend-modal .editDialogInput').each(function (index) {
1355                            if ($(this).data('input_type') == 'mce-editor') {
1356                                if ($(this).siblings().length) {
1357                                    tinymce.execCommand('mceRemoveEditor', true, $(this).attr('id'));
1358                                }
1359                                tinymce.init({
1360                                    selector: '#' + $(this).attr('id'),
1361                                    menubar: false,
1362                                    plugins: 'link image media lists hr colorpicker fullscreen textcolor code',
1363                                    toolbar: 'undo redo formatselect bold italic underline strikethrough subscript superscript | alignleft aligncenter alignright al
1363ignjustify | bullist numlist outdent indent blockquote | hr fullscreen | link unlink image | forecolor backcolor removeformat | code'
1364                                });
1365                            }
1366                        });
1367                        modal.modal('show');
1368                        $('.wdt-apply-edit-button').removeClass('hidden');
1369                        $('.wdt-apply-duplicate-button').addClass('hidden');
1370                    }
1371
1372
1373                    // Show 'No inputs selected' alert
1374                    if (modal.find('.wdt-edit-dialog-fields-block').find('.form-group').length == 0)
1375                        $('#wdt-frontend-modal div.wdt-no-editor-inputs-selected-alert').show();
1376
1377                });
1378
1379                /**
1380                 * Init inline editing
1381                 */
1382                if (tableDescription.inlineEditing) {
1383                    new inlineEditClass(tableDescription, dataTableOptions, $);
1384                }
1385
1386                /**
1387                 * Add new entry dialog
1388                 */
1389                $('.new_table_entry[aria-controls="' + tableDescription.tableId + '"]').click(function () {
1390                    var modal = $('#wdt-frontend-modal');
1391                    var newSkins = ['dark', 'aqua','purple'];
1392
1393                    $('.wpDataTablesPopover.editTools').hide();
1394
1395                    modal.addClass('wdt-skin-' + tableDescription.tableSkin);
1396
1397                    modal.find('.modal-title').html(wpdatatables_frontend_strings.add_new_entry);
1398                    modal.find('.modal-body').html('');
1399                    modal.find('.modal-footer').html('');
1400
1401
1402                    if (['manual', 'mysql'].indexOf(tableDescription.tableType) === -1) {
1403                        if(typeof wpDataTablesEditors[tableDescription.tableType]['new'] == 'function'){
1404                            if (singleClick === false) {
1405                                singleClick = true;
1406                                wpDataTablesEditors[tableDescription.tableType]['new'](tableDescription);
1407                            }
1408                        }
1409                    } else {
1410                        modal.find('.modal-body').append($(tableDescription.selector + '_edit_dialog').show());
1411                        modal.find('.modal-footer').append($(tableDescription.selector + '_edit_dialog_buttons').show());
1412
1413                        if (newSkins.includes(tableDescription.tableSkin)){
1414                            modal.find(tableDescription.selector + '_prev_edit_dialog i' ).addClass('wpdt-icon-chevron-left');
1415                            modal.find(tableDescription.selector + '_prev_edit_dialog i' ).removeClass('wpdt-icon-step-backward');
1416                            modal.find(tableDescription.selector + '_next_edit_dialog i' ).addClass('wpdt-icon-chevron-right');
1417                            modal.find(tableDescription.selector + '_next_edit_dialog i' ).removeClass('wpdt-icon-step-forward');
1418                            modal.find(tableDescription.selector + '_apply_edit_dialog i' ).addClass('wpdt-icon-check-circle-full');
1419                            modal.find(tableDescription.selector + '_apply_edit_dialog i' ).removeClass('wpdt-icon-check');
1420                            modal.find(tableDescription.selector + '_ok_edit_dialog i' ).addClass('wpdt-icon-check-circle');
1421                            modal.find(tableDescription.selector + '_ok_edit_dialog i' ).removeClass('wpdt-icon-check-double-reg');
1422                        } else {
1423                            modal.find(tableDescription.selector + '_prev_edit_dialog i' ).removeClass('wpdt-icon-chevron-left');
1424                            modal.find(tableDescription.selector + '_prev_edit_dialog i' ).addClass('wpdt-icon-step-backward');
1425                            modal.find(tableDescription.selector + '_next_edit_dialog i' ).removeClass('wpdt-icon-chevron-right');
1426                            modal.find(tableDescription.selector + '_next_edit_dialog i' ).addClass('wpdt-icon-step-forward');
1427                            modal.find(tableDescription.selector + '_apply_edit_dialog i' ).removeClass('wpdt-icon-check-circle-full');
1428                            modal.find(tableDescription.selector + '_apply_edit_dialog i' ).addClass('wpdt-icon-check');
1429                            modal.find(tableDescription.selector + '_ok_edit_dialog i' ).removeClass('wpdt-icon-check-circle');
1430                            modal.find(tableDescription.selector + '_ok_edit_dialog i' ).addClass('wpdt-icon-check-double-reg');
1431                        }
1432                        // Reset values in edit modal
1433                        $('#wdt-frontend-modal .editDialogInput').val('').css('border', '');
1434                        $('#wdt-frontend-modal tr.idRow .editDialogInput').val('0');
1435                        $('#wdt-frontend-modal .fileinput').removeClass('fileinput-exists').addClass('fileinput-new');
1436                        $('#wdt-frontend-modal .fileinput').find('div.fileinput-exists').removeClass('fileinput-exists').addClass('fileinput-new');
1437                        $('#wdt-frontend-modal .fileinput').find('.fileinput-filename').text('');
1438                        $('#wdt-frontend-modal .fileinput').find('.fileinput-preview').html('');
1439
1440                        $('#wdt-frontend-modal .editDialogInput').each(function (index) {
1441                            if ($(this).data('input_type') == 'mce-editor') {
1442                                if (tinymce.activeEditor)
1443                                    tinymce.activeEditor.setContent('');
1444                                tinymce.execCommand('mceRemoveEditor', true, $(this).attr('id'));
1445                                tinymce.init({
1446                                    selector: '#' + $(this).attr('id'),
1447                                    menubar: false,
1448                                    plugins: 'link image media lists hr colorpicker fullscreen textcolor code',
1449                                    toolbar: 'undo redo formatselect bold italic underline strikethrough subscript superscript | alignleft aligncenter alignright al
1449ignjustify | bullist numlist outdent indent blockquote | hr fullscreen | link unlink image | forecolor backcolor removeformat | code'
1450                                });
1451                            }
1452                        });
1453
1454                        wpDataTables[tableDescription.tableId].checkSelectedLimits();
1455
1456                        // Reset selectpickers values
1457                        $('#wdt-frontend-modal .selectpicker').selectpicker('deselectAll').selectpicker('refresh');
1458
1459                        wpDataTablesFunctions[tableDescription.tableId].setPredefinedEditValues();
1460
1461                        // Show 'No editor inputs selected' alert
1462                        if (modal.find('.wdt-edit-dialog-fields-block').find('.form-group').length == 0) {
1463                            $('#wdt-frontend-modal div.wdt-no-editor-inputs-selected-alert').show();
1464                        }
1465
1466                        modal.modal('show');
1467                        $('.wdt-apply-edit-button').removeClass('hidden');
1468                        $('.wdt-apply-duplicate-button').addClass('hidden');
1469
1470                    }
1471
1472
1473
1474                });
1475
1476                /**
1477                 * Duplicate entry
1478                 */
1479                $('.duplicate_table_entry[aria-controls="' + tableDescription.tableId + '"]').click(function () {
1480                    var modal = $('#wdt-frontend-modal');
1481                    var newSkins = ['dark', 'aqua','purple'];
1482
1483                    var row = $(tableDescription.selector + ' tr.selected').get(0);
1484
1485                    $('.wpDataTablesPopover.editTools').hide();
1486
1487                    modal.addClass('wdt-skin-' + tableDescription.tableSkin);
1488
1489                    modal.find('.modal-title').html(wpdatatables_frontend_strings.duplicate_entry);
1490                    modal.find('.modal-body').html('');
1491                    modal.find('.modal-footer').html('');
1492
1493
1494                    if (['manual', 'mysql'].indexOf(tableDescription.tableType) === -1) {
1495                        if(typeof wpDataTablesEditors[tableDescription.tableType]['edit'] == 'function'){
1496                            if (singleClick === false) {
1497                                singleClick = true;
1498                                wpDataTablesEditors[tableDescription.tableType]['edit'](tableDescription, true);
1499                            }
1500                        }
1501                    } else {
1502                        var data = wpDataTables[tableDescription.tableId].fnGetData(row);
1503                        wpDataTablesFunctions[tableDescription.tableId].applyData(data, true, false);
1504                        wpDataTables[tableDescription.tableId].checkSelectedLimits();
1505                        modal.find('.modal-body').append($(tableDescription.selector + '_edit_dialog').show());
1506                        modal.find('.modal-footer').append($(tableDescription.selector + '_edit_dialog_buttons').show());
1507
1508                        if (newSkins.includes(tableDescription.tableSkin)){
1509                            modal.find(tableDescription.selector + '_prev_edit_dialog i' ).addClass('wpdt-icon-chevron-left');
1510                            modal.find(tableDescription.selector + '_prev_edit_dialog i' ).removeClass('wpdt-icon-step-backward');
1511                            modal.find(tableDescription.selector + '_next_edit_dialog i' ).addClass('wpdt-icon-chevron-right');
1512                            modal.find(tableDescription.selector + '_next_edit_dialog i' ).removeClass('wpdt-icon-step-forward');
1513                            modal.find(tableDescription.selector + '_apply_edit_dialog i' ).addClass('wpdt-icon-check-circle-full');
1514                            modal.find(tableDescription.selector + '_apply_edit_dialog i' ).removeClass('wpdt-icon-check');
1515                            modal.find(tableDescription.selector + '_ok_edit_dialog i' ).addClass('wpdt-icon-check-circle');
1516                            modal.find(tableDescription.selector + '_ok_edit_dialog i' ).removeClass('wpdt-icon-check-double-reg');
1517                        } else {
1518                            modal.find(tableDescription.selector + '_prev_edit_dialog i' ).removeClass('wpdt-icon-chevron-left');
1519                            modal.find(tableDescription.selector + '_prev_edit_dialog i' ).addClass('wpdt-icon-step-backward');
1520                            modal.find(tableDescription.selector + '_next_edit_dialog i' ).removeClass('wpdt-icon-chevron-right');
1521                            modal.find(tableDescription.selector + '_next_edit_dialog i' ).addClass('wpdt-icon-step-forward');
1522                            modal.find(tableDescription.selector + '_apply_edit_dialog i' ).removeClass('wpdt-icon-check-circle-full');
1523                            modal.find(tableDescription.selector + '_apply_edit_dialog i' ).addClass('wpdt-icon-check');
1524                            modal.find(tableDescription.selector + '_ok_edit_dialog i' ).removeClass('wpdt-icon-check-circle');
1525                            modal.find(tableDescription.selector + '_ok_edit_dialog i' ).addClass('wpdt-icon-check-double-reg');
1526                        }
1527
1528                        $('#wdt-frontend-modal .editDialogInput').each(function (index) {
1529                            if ($(this).data('input_type') == 'mce-editor') {
1530                                if (tinymce.activeEditor)
1531                                    tinymce.activeEditor.setContent('');
1532                                tinymce.execCommand('mceRemoveEditor', true, $(this).attr('id'));
1533                                tinymce.init({
1534                                    selector: '#' + $(this).attr('id'),
1535                                    menubar: false,
1536                                    plugins: 'link image media lists hr colorpicker fullscreen textcolor code',
1537                                    toolbar: 'undo redo formatselect bold italic underline strikethrough subscript superscript | alignleft aligncenter alignright al
1537ignjustify | bullist numlist outdent indent blockquote | hr fullscreen | link unlink image | forecolor backcolor removeformat | code'
1538                                });
1539                            }
1540                        });
1541
1542                        wpDataTables[tableDescription.tableId].checkSelectedLimits();
1543
1544                        // Show 'No editor inputs selected' alert
1545                        if (modal.find('.wdt-edit-dialog-fields-block').find('.form-group').length == 0) {
1546                            $('#wdt-frontend-modal div.wdt-no-editor-inputs-selected-alert').show();
1547                        }
1548
1549                        modal.modal('show');
1550                        $('.wdt-apply-edit-button').addClass('hidden');
1551                        $('.wdt-apply-duplicate-button').removeClass('hidden');
1552
1553                    }
1554                });
1555
1556                /**
1557                 * Hide modal dialog on Esc button
1558                 */
1559                $(document).on('keyup', '#wdt-frontend-modal', function (e) {
1560                    e.preventDefault();
1561                    e.stopImmediatePropagation();
1562                    if (e.which == 27) {
1563                        $('#wdt-frontend-modal').modal('hide').removeClass('wdt-skin-' + tableDescription.tableSkin)
1564                    }
1565                });
1566
1567                /**
1568                 * When the hide instance method has been called append modal to related table( edit modal )
1569                 */
1570                $('#wdt-frontend-modal').on('hidden.bs.modal', function (e) {
1571                    $(tableDescription.selector + '_wrapper').append($(tableDescription.selector + '_edit_dialog').hide());
1572                    $(tableDescription.selector + '_wrapper').append($(tableDescription.selector + '_edit_dialog_buttons').hide());
1573                    $(this).removeClass('wdt-skin-' + tableDescription.tableSkin);
1574                });
1575
1576                /**
1577                 * When the hide instance method has been called append modal to related table( delete modal)
1578                 */
1579                $('#wdt-delete-modal').on('hidden.bs.modal', function (e) {
1580                    $(tableDescription.selector + '_wrapper').append($(tableDescription.selector + '_delete_dialog_buttons').hide());
1581                    $(this).removeClass('wdt-skin-' + tableDescription.tableSkin);
1582                });
1583
1584                /**
1585                 * Delete an entry dialog
1586                 */
1587                $('.delete_table_entry[aria-controls="' + tableDescription.tableId + '"]').click(function (e) {
1588                    e.preventDefault();
1589                    e.stopImmediatePropagation();
1590                    if ($(this).hasClass('disabled')) {
1591                        return false;
1592                    }
1593
1594                    $('.wpDataTablesPopover.editTools').hide();
1595
1596                    var modal =  $('#wdt-delete-modal');
1597
1598                    modal.addClass('wdt-skin-' + tableDescription.tableSkin);
1599
1600                    modal.find('.modal-footer').html('');
1601                    modal.find('.modal-footer').append($(tableDescription.selector + '_delete_dialog_buttons').show());
1602
1603                    modal.modal('show');
1604
1605
1606                    $(tableDescription.selector + '_wdt-browse-delete-button').click(function (e) {
1607                        e.preventDefault();
1608                        e.stopImmediatePropagation();
1609
1610                        if (['manual', 'mysql'].indexOf(tableDescription.tableType) === -1) {
1611                            if(typeof wpDataTablesEditors[tableDescription.tableType]['delete'] == 'function') {
1612                                wpDataTablesEditors[tableDescription.tableType]['delete'](tableDescription);
1613                            }
1614                        } else {
1615                            var row = $(tableDescription.selector + ' tr.selected').get(0);
1616                            var data = wpDataTables[tableDescription.tableId].fnGetData(row);
1617                            var id_val = data[tableDescription.idColumnIndex];
1618                            $.ajax({
1619                                url: tableDescription.adminAjaxBaseUrl,
1620                                type: 'POST',
1621                                dataType: 'json',
1622                                data: {
1623                                    action: 'wdt_delete_table_row',
1624                                    id_key: tableDescription.idColumnKey,
1625                                    id_val: id_val,
1626                                    table_id: tableDescription.tableWpId,
1627                                    wdtNonce: $('#wdtNonceFrontendEdit_' + tableDescription.tableWpId).val()
1628                                },
1629                                success: function (data) {
1630                                    wpDataTables[tableDescription.tableId].fnDraw(false);
1631                                    if (data.error == '') {
1632                                        $('#wdt-delete-modal').modal('hide');
1633                                        wdtNotify(wpdatatables_edit_strings.success, wpdatatables_edit_strings.rowDeleted, 'success');
1634                                    } else {
1635                                        wdtNotify(wpdatatables_edit_strings.error, data.error, 'danger');
1636                                    }
1637                                },
1638                                error: function () {
1639                                    wdtNotify(wpdatatables_edit_strings.error, wpdatatables_edit_strings.databaseDeleteError, 'danger');
1640                                }
1641                            });
1642                        }
1643                    });
1644                });
1645
1646                /**
1647                 * Add a popover that includes edit elements
1648                 */
1649                if (tableDescription.popoverTools) {
1650                    $(tableDescription.selector + '_wrapper').css('position', 'relative');
1651                    $('<div class="wpDataTablesPopover editTools ' + tableDescription.tableId + '"></div>').prependTo(tableDescription.selector + '_wrapper').hide();
1652                    $('.new_table_entry[aria-controls="' + tableDescription.tableId + '"]').prependTo(tableDescription.selector + '_wrapper .wpDataTablesPopover.editTools').css('float', 'right');
1653                    $('.edit_table[aria-controls="' + tableDescription.tableId + '"]').prependTo(tableDescription.selector + '_wrapper .wpDataTablesPopover.editTools').css('float', 'right');
1654                    $('.duplicate_table_entry[aria-controls="' + tableDescription.tableId + '"]').prependTo(tableDescription.selector + '_wrapper .wpDataTablesPopover.editTools').css('float', 'right');
1655                    $('.delete_table_entry[aria-controls="' + tableDescription.tableId + '"]').prependTo(tableDescription.selector + '_wrapper .wpDataTablesPopover.editTools').css('float', 'right');
1656                }
1657
1658                /**
1659                 * Select table row on click
1660                 * @param e
1661                 * @returns {boolean}
1662                 */
1663                var clickEvent = function (e) {
1664
1665                    // Fix if td is URL Link
1666                    if (!$(e.target).is('a') && !$(e.target).is('button')) {
1667                        e.preventDefault();
1668                        e.stopImmediatePropagation();
1669                        e.preventDefault();
1670                    }
1671
1672                    if ($(this).hasClass('group')) {
1673                        return false;
1674                    }
1675                    // Set controls popover position
1676                    var popoverVerticalPosition = $(this).offset().top - $(tableDescription.selector + '_wrapper').offset().top - $('.wpDataTablesPopover.editTools').outerHeight() - 7;
1677                    // Check a cell is edited
1678                    var editedRow = ($(this).children('').hasClass('editing')) ? true : false;
1679
1680                    if ($(this).hasClass('selected')) {
1681                        $(tableDescription.selector + ' tbody tr').removeClass('selected');
1682                        wpDataTablesSelRows[tableDescription.tableId] = -1;
1683                    } else if (!$(this).find('td').hasClass('dataTables_empty') || tableDescription.popoverTools) {
1684                        $(tableDescription.selector + '  tbody tr').removeClass('selected');
1685                        $(this).addClass('selected');
1686                        wpDataTablesSelRows[tableDescription.tableId] = wpDataTables[tableDescription.tableId].fnGetPosition($(tableDescription.selector + ' tbody tr.selected').get(0));
1687                    }
1688                    if ($(tableDescription.selector + ' tbody tr.selected').length > 0) {
1689                        $('.edit_table[aria-controls="' + tableDescription.tableId + '"]').removeClass('disabled');
1690                        $('.duplicate_table_entry[aria-controls="' + tableDescription.tableId + '"]').removeClass('disabled');
1691                        $('.delete_table_entry[aria-controls="' + tableDescription.tableId + '"]').removeClass('disabled');
1692                        $('.master_detail[aria-controls="' + tableDescription.tableId + '"]').removeClass('disabled');
1693                        if (!editedRow) {
1694                            $('.wpDataTablesPopover.editTools.' + tableDescription.tableId + '').show().css('top', popoverVerticalPosition);
1695                        } else {
1696                            return false;
1697                        }
1698                    } else {
1699                        $('.edit_table[aria-controls="' + tableDescription.tableId + '"]').addClass('disabled');
1700                        $('.duplicate_table_entry[aria-controls="' + tableDescription.tableId + '"]').addClass('disabled');
1701                        $('.delete_table_entry[aria-controls="' + tableDescription.tableId + '"]').addClass('disabled');
1702                        $('.master_detail[aria-controls="' + tableDescription.tableId + '"]').addClass('disabled');
1703                        $('.wpDataTablesPopover.editTools.' + tableDescription.tableId + '').hide();
1704
1705                    }
1706                };
1707
1708                var ua = navigator.userAgent,
1709                    event = (ua.match(/iPad/i)) ? "touchstart" : "click";
1710
1711                $(document).off(event, tableDescription.selector + ' tbody tr').on(event, tableDescription.selector + ' tbody tr', clickEvent);
1712
1713                /**
1714                 * Detached the chosen attachment
1715                 */
1716                $(document).on('click', tableDescription.selector + '_edit_dialog a.wdt-detach-attachment-file, a.wdt-detach-attachment-file', function (e) {
1717                    e.preventDefault();
1718                    e.stopImmediatePropagation();
1719                    if ($(this).parent().find('span.fileupload-' + tableDescription.tableId).data('column_type') == 'icon') {
1720                        $(this).parent().find('input.editDialogInput').val('');
1721                        $(this).parent().parent().find('.fileinput-preview').html('');
1722                        $(this).parents('.fileinput-exists').removeClass('fileinput-exists').addClass('fileinput-new');
1723                    } else {
1724                        $(this).parent().find('input.editDialogInput').val('');
1725                        $(this).parent().find('.fileinput-filename').text('');
1726                        $(this).parent().removeClass('fileinput-exists').addClass('fileinput-new');
1727                    }
1728                });
1729
1730            }
1731
1732            /**
1733             * Prevent bootstrap dialog from blocking focusin on Tinymce editor
1734             */
1735            $(document).on('focusin', function(e) {
1736                if ($(e.target).closest(".mce-window").length) {
1737                    e.stopImmediatePropagation();
1738                }
1739            });
1740
1741            /**
1742             * Add some JS hooks for Master-detail add-on
1743             */
1744            if(tableDescription.masterDetail !== undefined && tableDescription.masterDetail){
1745                for (var i in wpDataTablesHooks.onRenderDetails) {
1746                    if (!isNaN(i))
1747                        wpDataTablesHooks.onRenderDetails[i](tableDescription);
1748                }
1749            }
1750
1751            /**
1752             * Show the filter box if enabled in the widget if it is present
1753             */
1754            if (tableDescription.filterInForm == true) {
1755                if ($('#wdt-filter-widget').length) {
1756                    $('.wpDataTablesFilter').appendTo('#wdt-filter-widget');
1757                }
1758            }
1759            //[<--/ Full version -->]//
1760
1761            return wpDataTables[tableDescription.tableId];
1762
1763        };
1764
1765        /**
1766         * Loop through all tables on the page and render the wpDataTables elements
1767         */
1768        $('table.wpDataTable:not(.wpdtSimpleTable)').each(function () {
1769            var tableDescription = JSON.parse($('#' + $(this).data('described-by')).val());
1770            wdtRenderDataTable($(this), tableDescription);
1771        });
1772
1773    });
1774
1775})(jQuery);
1776
1777/**
1778 * Apply cell action for conditional formatting rule
1779 *
1780 * @param $cell
1781 * @param action
1782 * @param setVal
1783 */
1784function wdtApplyCellAction($cell, action, setVal) {
1785    let index = $cell.index() + 1;
1786    let classArr = $cell.attr("class").split(/\s+/);
1787    switch (action) {
1788        case 'setCellColor':
1789            $cell.attr('style', 'background-color: ' + setVal + ' !important');
1790            break;
1791        case 'defaultCellColor':
1792            $cell.attr('style', 'background-color: "" !important');
1793            break;
1794        case 'setCellContent':
1795            if ($cell.children().hasClass('responsiveExpander')){
1796                $cell.html(setVal).prepend('<span class="responsiveExpander"></span>');
1797            } else {
1798                $cell.html(setVal);
1799            }
1800            break;
1801        case 'setCellClass':
1802            $cell.addClass(setVal);
1803            break;
1804        case 'removeCellClass':
1805            $cell.removeClass(setVal);
1806            break;
1807        case 'setRowColor':
1808            $cell.closest('tr').find('td').attr('style', 'background-color: ' + setVal + ' !important');
1809            break;
1810        case 'defaultRowColor':
1811            $cell.closest('tr').find('td').attr('style', 'background-color: "" !important');
1812            break;
1813        case 'setRowClass':
1814            $cell.closest('tr').addClass(setVal);
1815            break;
1816        case 'addColumnClass':
1817            $cell
1818                .closest('table.wpDataTable')
1819                .find('thead th:nth-child(' + index + ')')
1820                .addClass(setVal)
1821                .closest('table.wpDataTable')
1822                .find('tbody td:nth-child(' + index + ')')
1823                .addClass(setVal)
1824                .closest('table.wpDataTable')
1825                .find('tfoot td:nth-child(' + index + ')')
1826                .addClass(setVal);
1827            break;
1828        case 'setColumnColor':
1829            $cell
1830                .closest('table.wpDataTable')
1831                .find('thead th:nth-child(' + index + ')')
1832                .attr('style', 'background-color: ' + setVal + ' !important')
1833                .closest('table.wpDataTable')
1834                .find('tbody td:nth-child(' + index + ')')
1835                .attr('style', 'background-color: ' + setVal + ' !important')
1836                .closest('table.wpDataTable')
1837                .find('tfoot td:nth-child(' + index + ')')
1838                .attr('style', 'background-color: ' + setVal + ' !important');
1839            break;
1840    }
1841}
1842
1843function wdtDialog(str, title) {
1844    var dialogId = Math.floor((Math.random() * 1000) + 1);
1845    var editModal = jQuery('.wdt-frontend-modal').clone();
1846
1847    editModal.attr('id', 'remodal-' + dialogId);
1848    editModal.find('.modal-title').html(title);
1849    editModal.find('.modal-header').append(str);
1850
1851    return editModal;
1852}
1853
1854function wdtAddOverlay(table_selector) {
1855    jQuery(table_selector).addClass('overlayed');
1856}
1857
1858function wdtRemoveOverlay(table_selector) {
1859    jQuery(table_selector).removeClass('overlayed');
1860}
1861
1862/**
1863 * Get cell value cleared from neighbour html tags
1864 * @param element
1865 * @param responsive
1866 * @returns {*}
1867 */
1868function getPurifiedValue(element, responsive) {
1869    if (responsive) {
1870        var cellVal = element.children('.columnValue').html();
1871    } else {
1872        cellVal = element.clone().children().remove().end().html();
1873    }
1874
1875    return cellVal;
1876}
1877
1878/**
1879 * Conditional formatting
1880 * @param conditionalFormattingRules
1881 * @param params
1882 * @param element
1883 * @param responsive
1884 */
1885function wdtCheckConditionalFormatting(conditionalFormattingRules, params, element, responsive) {
1886
1887    var cellVal = '';
1888    var ruleVal = '';
1889    var ruleMatched = false;
1890    if ((params.columnType == 'int') || (params.columnType == 'float')) {
1891        // Process numeric comparison
1892        if (responsive) {
1893            cellVal = element.children('.columnValue').html();
1894        } else {
1895            cellVal = element.clone().html();
1896            if (cellVal.indexOf('<span class="responsiveExpander"></span>') !== -1)
1897                cellVal = cellVal.replace('<span class="responsiveExpander"></span>', '');
1898        }
1899        cellVal = wdtUnformatNumber(cellVal, params.thousandsSeparator, params.decimalSeparator, true);
1900        if (!isNaN(cellVal)) {
1901            cellVal = cellVal === '' ? null : parseFloat(cellVal)
1902        }
1903        ruleVal = conditionalFormattingRules.cellVal;
1904    } else if (params.columnType == 'date') {
1905        cellVal = moment(getPurifiedValue(element, responsive), params.momentDateFormat).toDate();
1906        if (conditionalFormattingRules.cellVal == '%TODAY%') {
1907            ruleVal = moment().startOf('day').toDate();
1908        } else {
1909            ruleVal = moment(conditionalFormattingRules.cellVal, params.momentDateFormat).toDate();
1910        }
1911        if (conditionalFormattingRules.cellVal == '%LAST_WEEK%') {
1912            conditionalFormattingRules.ifClause = '%LAST_WEEK%'
1913            ruleVal = [moment().subtract(1, 'weeks').startOf('isoWeek').toDate(), moment().subtract(1, 'weeks').endOf('isoWeek').toDate()];
1914        }
1915        if (conditionalFormattingRules.cellVal == '%THIS_WEEK%') {
1916            conditionalFormattingRules.ifClause = '%THIS_WEEK%'
1917            ruleVal = [moment().startOf('isoweek').toDate(), moment().endOf('isoweek').toDate()];
1918        }
1919        if (conditionalFormattingRules.cellVal == '%NEXT_WEEK%') {
1920            conditionalFormattingRules.ifClause = '%LAST_WEEK%'
1921            ruleVal = [moment().add(1, 'weeks').startOf('isoWeek').toDate(), moment().add(1, 'weeks').endOf('isoWeek').toDate()];
1922        }
1923        if (conditionalFormattingRules.cellVal == '%LAST_30_DAYS%') {
1924            conditionalFormattingRules.ifClause = '%LAST_30_DAYS%'
1925            ruleVal = [moment().add(-30, 'days').startOf('day').toDate(), moment().toDate()];
1926        }
1927        if (conditionalFormattingRules.cellVal == '%LAST_MONTH%') {
1928            conditionalFormattingRules.ifClause = '%LAST_MONTH%'
1929            ruleVal = [moment().add(-1, 'months').startOf('months').toDate(), moment().startOf('month').toDate()];
1930
1931        }
1932        if (conditionalFormattingRules.cellVal == '%NEXT_MONTH%') {
1933            conditionalFormattingRules.ifClause = '%NEXT_MONTH%'
1934            ruleVal = [moment().add(1, 'months').startOf('months').toDate(), moment().add(2, 'months').startOf('months').toDate()];
1935        }
1936
1937        if (conditionalFormattingRules.cellVal == '%THIS_MONTH%') {
1938            conditionalFormattingRules.ifClause = '%THIS_MONTH%'
1939            ruleVal = [moment().startOf('months').toDate(), moment().endOf('month').toDate()];
1940        }
1941
1942    } else if (params.columnType == 'datetime') {
1943        if (conditionalFormattingRules.cellVal == '%TODAY%') {
1944            cellVal = moment(getPurifiedValue(element, responsive), params.momentDateFormat + ' ' + params.momentTimeFormat).startOf('day').toDate();
1945            ruleVal = moment().startOf('day').toDate();
1946        } else {
1947            cellVal = moment(getPurifiedValue(element, responsive), params.momentDateFormat + ' ' + params.momentTimeFormat).toDate();
1948            ruleVal = moment(conditionalFormattingRules.cellVal, params.momentDateFormat + ' ' + params.momentTimeFormat).toDate();
1949        }
1950        if (conditionalFormattingRules.cellVal == '%LAST_WEEK%') {
1951            conditionalFormattingRules.ifClause = '%LAST_WEEK%'
1952            ruleVal = [moment().subtract(1, 'weeks').startOf('isoWeek').toDate(), moment().subtract(1, 'weeks').endOf('isoWeek').toDate()];
1953        }
1954        if (conditionalFormattingRules.cellVal == '%THIS_WEEK%') {
1955            conditionalFormattingRules.ifClause = '%THIS_WEEK%'
1956            ruleVal = [moment().startOf('isoweek').toDate(), moment().endOf('isoweek').toDate()];
1957        }
1958        if (conditionalFormattingRules.cellVal == '%NEXT_WEEK%') {
1959            conditionalFormattingRules.ifClause = '%LAST_WEEK%'
1960            ruleVal = [moment().add(1, 'weeks').startOf('isoWeek').toDate(), moment().add(1, 'weeks').endOf('isoWeek').toDate()];
1961        }
1962        if (conditionalFormattingRules.cellVal == '%LAST_30_DAYS%') {
1963            conditionalFormattingRules.ifClause = '%LAST_30_DAYS%'
1964            ruleVal = [moment().add(-30, 'days').startOf('day').toDate(), moment().toDate()];
1965        }
1966        if (conditionalFormattingRules.cellVal == '%LAST_MONTH%') {
1967            conditionalFormattingRules.ifClause = '%LAST_MONTH%'
1968            ruleVal = [moment().add(-1, 'months').startOf('months').toDate(), moment().startOf('month').toDate()];
1969
1970        }
1971        if (conditionalFormattingRules.cellVal == '%NEXT_MONTH%') {
1972            conditionalFormattingRules.ifClause = '%NEXT_MONTH%'
1973            ruleVal = [moment().add(1, 'months').startOf('months').toDate(), moment().add(2, 'months').startOf('months').toDate()];
1974        }
1975
1976        if (conditionalFormattingRules.cellVal == '%THIS_MONTH%') {
1977            conditionalFormattingRules.ifClause = '%THIS_MONTH%'
1978            ruleVal = [moment().startOf('months').toDate(), moment().endOf('month').toDate()];
1979        }
1980    } else if (params.columnType == 'time') {
1981        cellVal = moment(getPurifiedValue(element, responsive), params.momentTimeFormat).toDate();
1982        ruleVal = moment(conditionalFormattingRules.cellVal, params.momentTimeFormat).toDate();
1983    } else if (params.columnType == 'link') {
1984        if (responsive) {
1985            cellVal = element.children('.columnValue').html();
1986        } else {
1987            cellVal = element.clone().html();
1988        }
1989        ruleVal = conditionalFormattingRules.cellVal;
1990    } else {
1991        // Process string comparison
1992        if (responsive) {
1993            cellVal = element.children('.columnValue').html();
1994        } else {
1995            cellVal = element.clone().html();
1996        }
1997        ruleVal = conditionalFormattingRules.cellVal;
1998    }
1999
2000    switch (conditionalFormattingRules.ifClause) {
2001        case 'lt':
2002            ruleMatched = cellVal < ruleVal;
2003            break;
2004        case 'lteq':
2005            ruleMatched = cellVal <= ruleVal;
2006            break;
2007        case 'eq':
2008            if (params.columnType == 'date'
2009                || params.columnType == 'datetime'
2010                || params.columnType == 'time') {
2011                cellVal = cellVal != null ? cellVal.getTime() : null;
2012                ruleVal = ruleVal != null ? ruleVal.getTime() : null;
2013            }
2014            ruleMatched = cellVal == ruleVal;
2015            break;
2016        case 'neq':
2017            if (params.columnType == 'date' || params.columnType == 'datetime') {
2018                cellVal = cellVal != null ? cellVal.getTime() : null;
2019                ruleVal = ruleVal != null ? ruleVal.getTime() : null;
2020            }
2021            ruleMatched = cellVal != ruleVal;
2022            break;
2023        case 'gteq':
2024            ruleMatched = cellVal >= ruleVal;
2025            break;
2026        case 'gt':
2027            ruleMatched = cellVal > ruleVal;
2028            break;
2029        case 'contains':
2030            ruleMatched = cellVal.indexOf(ruleVal) !== -1;
2031            break;
2032        case 'contains_not':
2033            ruleMatched = cellVal.indexOf(ruleVal) == -1;
2034            break;
2035        case '%THIS_WEEK%':
2036            ruleMatched = moment(cellVal) >= moment(ruleVal[0]) && moment(cellVal) <= moment(ruleVal[1]);
2037            break;
2038        case '%LAST_WEEK%':
2039            ruleMatched = moment(cellVal) >= moment(ruleVal[0]) && moment(cellVal) <= moment(ruleVal[1]);
2040            break;
2041        case '%NEXT_WEEK%':
2042            ruleMatched = moment(cellVal) >= moment(ruleVal[0]) && moment(cellVal) <= moment(ruleVal[1]);
2043            break;
2044        case '%LAST_30_DAYS%':
2045            ruleMatched = moment(cellVal) >= moment(ruleVal[0]) && moment(cellVal) <= moment(ruleVal[1]);
2046            break;
2047        case '%LAST_MONTH%':
2048            ruleMatched = moment(cellVal) >= moment(ruleVal[0]) && moment(cellVal) < moment(ruleVal[1]);
2049            break;
2050        case '%NEXT_MONTH%':
2051            ruleMatched = moment(cellVal) >= moment(ruleVal[0]) && moment(cellVal) < moment(ruleVal[1]);
2052            break;
2053        case '%THIS_MONTH%':
2054            ruleMatched = moment(cellVal) >= moment(ruleVal[0]) && moment(cellVal) <= moment(ruleVal[1]);
2055            break;
2056    }
2057
2058    if (ruleMatched) {
2059        wdtApplyCellAction(element, conditionalFormattingRules.action, conditionalFormattingRules.setVal);
2060    }
2061}
2062
2063jQuery.fn.dataTableExt.oStdClasses.sWrapper = "wpDataTables wpDataTablesWrapper";
2064jQuery.fn.dataTable.ext.classes.sLengthSelect = 'wdt-selectpicker length_menu';
2065jQuery.fn.dataTable.ext.classes.sFilterInput = 'form-control';

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.