if (typeof(SDT_DATA) == 'undefined') { var SDT_DATA = {}; } var g_stbServerSideProcessing = false; var g_stbServerSideProcessingIsActive = false; (function(vendor, $, window) { var appName = 'Tables'; var dataTableInstances = []; var ruleJSInstances = []; var extraConfig = {}; if (!(appName in vendor)) { vendor[appName] = {}; vendor[appName].getAppName = (function() { return appName; }); vendor[appName].setExtraConfig = (function(param, value) { extraConfig[param] = value; }); vendor[appName].getParameterByName = (function(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); }); vendor[appName].replaceParameterByName = (function(url, paramName, paramValue) { var pattern = new RegExp('\\b(' + paramName + '=).*?(&|$)'); if (url.search(pattern) >= 0) { return url.replace(pattern, '$1' + paramValue + '$2'); } return url + (url.indexOf('?') > 0 ? '&' : '?') + paramName + '=' + paramValue; }); vendor[appName].getAllTableInstances = (function() { return dataTableInstances; }); vendor[appName].removeAllTableInstances = (function() { dataTableInstances = []; }); vendor[appName].setTableInstance = (function(instance) { dataTableInstances.push(instance); }); vendor[appName].getTableInstanceById = (function(id) { var allTables = this.getAllTableInstances(); for (var i = 0; i < allTables.length; i++) { if (allTables[i].table_id == id) { return allTables[i]; } } return false; }); vendor[appName].getTableInstanceByViewId = (function(viewId) { var allTables = this.getAllTableInstances(); for (var i = 0; i < allTables.length; i++) { if (allTables[i].table_view_id == viewId) { return allTables[i]; } } return false; }); vendor[appName].removeTableInstanceByViewId = (function(viewId) { var allTables = this.getAllTableInstances(); for (var i = 0; i < allTables.length; i++) { if (allTables[i].table_view_id == viewId) { allTables.splice(i, 1); return true; } } return false; }); vendor[appName].getAllRuleJSInstances = (function() { return ruleJSInstances; }); vendor[appName].setRuleJSInstance = (function(table) { var rootElem = table.closest('.supsystic-tables-wrap'), viewId = table.data('view-id'); ruleJSInstances[viewId] = new ruleJS(rootElem.attr('id')); ruleJSInstances[viewId].instanceTable = table; return ruleJSInstances[viewId]; }); vendor[appName].getRuleJSInstance = (function(table) { var allRuleJS = this.getAllRuleJSInstances(), viewId = table.data('view-id'); if (!allRuleJS[viewId]) { this.setRuleJSInstance(table); } return allRuleJS[viewId]; }); vendor[appName].request = (function(route, data) { if (!$.isPlainObject(route) || !('module' in route) || !('action' in route)) { throw new Error('Request route is not specified.'); } if (!$.isPlainObject(data)) { data = {}; } if ('action' in data) { throw new Error('Reserved field "action" used.'); } data.action = 'supsystic-tables'; var url = window.ajaxurl ? window.ajaxurl : ajax_obj.ajaxurl, deferred = $.Deferred(); $.post(url, $.extend({}, { route: route }, data)) .done(function(response, textStatus, jqXHR) { if (response.success) { deferred.resolve(response, textStatus, jqXHR); } else { if (data._maxIter) { retryAjax(deferred, url, route, data, 1, data._maxIter); } else { var message = typeof response.message !== 'undefined' ? response.message : 'There are errors during the request.'; deferred.reject(message, textStatus, jqXHR); } } }).fail(function(jqXHR, textStatus, errorThrown) { if (data._maxIter) { retryAjax(deferred, url, route, data, 1, data._maxIter); } else { deferred.reject(errorThrown, textStatus, jqXHR); } }); function retryAjax(def, url, route, data, curIter, maxIter) { $.post(url, $.extend({}, { route: route }, data)) .done(function(response, textStatus, jqXHR) { if (response.success) { def.resolve(response, textStatus, jqXHR); } else { var message = typeof response.message !== 'undefined' ? response.message : 'There are errors during the request.'; retryErrorHandler(def, url, route, data, curIter, maxIter, message, textStatus, jqXHR); } }).fail(function(jqXHR, textStatus, errorThrown) { retryErrorHandler(def, url, route, data, curIter, maxIter, errorThrown, textStatus, jqXHR); }); } function retryErrorHandler(def, url, route, data, curIter, maxIter, errorThrown, textStatus, jqXHR) { curIter++; if (curIter < maxIter) { retryAjax(def, url, route, data, curIter, maxIter); } else { def.reject(errorThrown, textStatus, jqXHR); } } return deferred.promise(); }); vendor[appName].setTableMobileWidth = (function(isMobile) { $('div .supsystic-tables-wrap').each(function() { isMobile = (typeof(isMobile) == 'undefined' ? true : isMobile); var ssDiv = $(this), widthAttr = ssDiv.data('table-width-' + (isMobile ? 'mobile' : 'fixed')); if (typeof(widthAttr) != 'undefined') { ssDiv.css('display', (widthAttr == 'auto' ? 'inline-block' : '')).css('width', widthAttr); } }); }); vendor[appName].initTablesOnPage = (function(id) { this._initTablesOnPage(id); }); vendor[appName]._initTablesOnPage = (function(id) { var tables = $(typeof id != 'undefined' ? '#supsystic-table-' + id + ':not(.dataTable)' : '.supsystic-table'); if (tables.length == 0) return; if (typeof this._initTablesOnPageWoo === 'function') this._initTablesOnPageWoo(id); var self = this, firstTableId = '', firstTableViewId = '', firstTable = '', firstTableWrapper = '', firstTableFirstRow = ''; if ($(window).width() <= 991) { self.setTableMobileWidth(); } tables.each(function() { self.initializeTable(this, self.showTable, function(table) { // This is used when table is hidden in tabs and can't calculate itself width to adjust on small screens if (table.is(':visible')) { // Fix bug in FF and IE which not supporting max-width 100% for images in td self._calculateImages(table); } else { table.data('isVisible', setInterval(function() { if (table.is(':visible')) { clearInterval(table.data('isVisible')); self._calculateImages(table); } }, 250)); } // Align all tables on page by the columns width depending on the columns width of first table on page if (table.data('align-by-first-table')) { firstTableId = firstTableId || $('.supsystic-table:first').data('id'); firstTable = firstTable || $('#supsystic-table-' + firstTableId); firstTableViewId = firstTable.data('view-id'); firstTableWrapper = firstTableWrapper || firstTable.parents('#supsystic-table-' + firstTableViewId); firstTableFirstRow = firstTable.data('head') ? firstTable.find('thead tr:first-child th') : firstTable.find('tbody tr:first-child td'); if (firstTableViewId != table.data('view-id')) { var currentTableWrapper = table.parents('#supsystic-table-' + table.data('view-id')); currentTableWrapper.css({ width: firstTableWrapper.get(0).style.width }); table.css({ width: firstTable.get(0).style.width }); currentTableWrapper.find('.supsystic-table').each(function() { var curTable = $(this), curTableFirstRow = curTable.data('head') ? curTable.find('thead tr:first-child th') : curTable.find('tbody tr:first-child td'); $.each(curTableFirstRow, function(index, element) { if (firstTableFirstRow[index]) { $(this).width($(firstTableFirstRow[index]).get(0).style.width); } }); }); } } //if row has merged cells no need place header there if (table.data('merged') && table.hasClass('ColWithMergeCellsAlign')) { var mergedData = table.data('merged'); $.each(mergedData, function(index, value) { var rowNumWithMergeCell = value.row; var numForEq = Number(rowNumWithMergeCell) - 1; table.find('tbody tr:eq(' + numForEq + ')').closest('tr').addClass('haveMergedCell'); }); self.setCellAttributes(table.parents('.supsystic-tables-wrap:first').find('.DTFC_LeftWrapper, DTFC_RightWrapper, .dataTables_scrollHead, .dataTables_scrollFoot').find('th, td')); } if (typeof self.getTableInstanceById(table.data('id')).fnAdjustColumnSizing == 'function') { table.trigger('responsive-resize.dt'); setTimeout(function() { table.trigger('responsive-resize.dt'); self.getTableInstanceById(table.data('id')).fnAdjustColumnSizing(false); }, 500); } self.initShortcodesInTable(table); }); //self.initShortcodesInTable($(this)); }); }); vendor[appName].initShortcodesInTable = (function(table) { var tableViewId = table.data('view-id'); //google-maps-easy if (typeof(gmpAllMapsInfo) !== 'undefined' && gmpAllMapsInfo && gmpAllMapsInfo.length) { for (var i = 0; i < gmpAllMapsInfo.length; i++) { var mapData = gmpAllMapsInfo[i], map = $('#' + mapData.view_html_id); if (map.length && map.closest('#supsystic-table-' + tableViewId).length) { var mapViewId = mapData.view_id; setTimeout(function(mapData, mapViewId) { g_gmpAllMaps = $.grep(g_gmpAllMaps, function(value) { if (value.getViewId() == mapViewId) { if (mapData.heatmap && mapData.heatmap.coords) { var coord = [], oldCoord = mapData.heatmap.coords; for (var c = 0; c < oldCoord.length; c++) { var data = oldCoord[c]; coord.push(typeof data == 'object' ? data.join(',') : data); } mapData.heatmap.coords = coord; } if (value._mapParams.simple_slider_id) { $('#' + value._mapParams.simple_slider_id).html(value._mapParams.original_slider_html); } } return value.getViewId() != mapViewId; }); gmpInitMapOnPage(mapData); }, 50, mapData, mapViewId); } } $(document).trigger('gmpAmiVarInited'); } //ultimate-maps if (typeof(umsAllMapsInfo) !== 'undefined' && umsAllMapsInfo && umsAllMapsInfo.length) { for (var i = 0; i < umsAllMapsInfo.length; i++) { var mapData = umsAllMapsInfo[i], map = $('#' + mapData.view_html_id); if (map.length && map.closest('#supsystic-table-' + tableViewId).length) { var mapViewId = mapData.view_id; setTimeout(function(mapData, mapViewId) { g_umsAllMaps = $.grep(g_umsAllMaps, function(value) { if (value.getViewId() == mapViewId) { value._mapObj.remove(); } return value.getViewId() != mapViewId; }); umsInitMapOnPage(mapData); }, 600, mapData, mapViewId); } } $(document).trigger('umsAmiVarInited'); } }); vendor[appName]._getOriginalImageSizes = (function(img) { var tempImage = new Image(), width, height; if ('naturalWidth' in tempImage && 'naturalHeight' in tempImage) { width = img.naturalWidth; height = img.naturalHeight; } else { tempImage.src = img.src; width = tempImage.width; height = tempImage.height; } return { width: width, height: height }; }); vendor[appName]._calculateImages = (function($table) { var self = this, $images = $table.find('img'); if ($images.length > 0 && /firefox|trident|msie/i.test(navigator.userAgent)) { $images.hide(); $.each($images, function(index, el) { var $img = $(this), originalSizes = self._getOriginalImageSizes(this); if ($img.closest('td, th').width() < originalSizes.width) { $img.css('width', '100%'); } }); $images.show(); } }); vendor[appName].createSpinner = (function(elem) { elem = typeof(elem) != 'undefined' ? elem : false; if (elem) { var icon = elem.attr('disabled', true).find('.fa'); if (icon) { icon.data('icon', icon.attr('class')); icon.attr('class', 'fa fa-spinner fa-spin'); } } else { return $('', { class: 'fa fa-spinner fa-spin' }); } }); vendor[appName].deleteSpinner = (function(elem) { var icon = elem.attr('disabled', false).find('.fa'); if (icon) { icon.attr('class', icon.data('icon')); icon.data('icon', ''); } }); vendor[appName].initializeTable = (function(table, callback, finalCallback, reinit, addInstance) { reinit = typeof reinit != 'undefined' ? reinit : {}; addInstance = typeof addInstance != 'undefined' ? addInstance : true; var self = this, $table = (table instanceof $ ? table : $(table)), features = $table.data('features'), config = {}, responsiveMode = $table.data('responsive-mode'), searchingSettings = $table.data('searching-settings'), tableInstance = {}, defaultFeatures = { autoWidth: false, info: false, ordering: false, paging: false, responsive: false, searching: false, stateSave: false, bJQueryUI: true, api: true, retrieve: true, processing: true, initComplete: callback, headerCallback: function(thead, data, start, end, display) { $(thead).closest('thead').find('th').each(function() { self.setStylesToCell(this); }); }, footerCallback: function(tfoot, data, start, end, display) { $(tfoot).closest('tfoot').find('th').each(function() { self.setStylesToCell(this); }); }, // order param disable the default table sorting. // it should be here because of Woocommerce addon: // it has no hidden header for tables without header // and in triggers an error during initializing. // order param should be disabled later during sorting activation order: [] }; g_stbServerSideProcessing = $table.data('server-side-processing') && $table.data('server-side-processing') == 'on'; // Fix for searching by merged cells $table.find('tbody td[data-colspan], tbody td[data-rowspan]').each(function(index, item) { var cell = $(item), cellData = cell.html(); // prevent of copy cell data if it contains tags with id attribute - it must be unique on page if (!cellData.toString().match(/<.*?id=['|"].*?['|"].*?>/g)) { var cellOrValue = cell.data('original-value'), cellFormula = cell.data('formula'), cellOrder = cell.data('order'), table = cell.parents('table:first'), colIndex = cell.index(), rowIndex = cell.parents('tr:first').index(), colspan = cell.data('colspan'), rowspan = cell.data('rowspan'); for (var i = rowIndex + 1; i <= rowIndex + rowspan; i++) { for (var j = colIndex + 1; j <= colIndex + colspan; j++) { var hiddenCell = table.find('tbody tr:nth-child(' + i + ') td:nth-child(' + j + ')'); if (hiddenCell.data('hide') && !$table.data('merged')) { hiddenCell.html(cellData); hiddenCell.data('original-value', cellOrValue); hiddenCell.attr('data-original-value', cellOrValue); hiddenCell.data('order', cellOrder); hiddenCell.attr('data-order', cellOrder); if (cellFormula) { hiddenCell.data('formula', cellFormula); hiddenCell.attr('data-formula', cellFormula); } } } } } }); // Set features $.each(features, function() { var featureName = this.replace(/[-_]([a-z])/g, function(g) { return g[1].toUpperCase(); }); config[featureName] = true; }); if ($table.data('search-value') && !config['searching']) { config['searching'] = true; } if (!config['searching'] && (typeof this.setTableAddSearching === 'function')) { config['searching'] = this.setTableAddSearching($table); } if (toeInArray('searching', features) != -1 && searchingSettings) { if (searchingSettings.minChars > 0 || searchingSettings.resultOnly || searchingSettings.strictMatching ) { $.fn.dataTable.ext.search.push(function(settings, data) { var $searchInput = $(settings.nTableWrapper).find('.dataTables_filter input'), searchValue = $searchInput.val(); if (searchingSettings.resultOnly && searchValue.length === 0) { if (searchingSettings.showTable) { return false; } return false; } if (searchingSettings.strictMatching) { searchValue = $.fn.dataTable.util.escapeRegex(searchValue); var regExp = new RegExp('^' + searchValue, 'i'); for (var i = 0; i < data.length; i++) { var words = data[i].replace(/\s\s+/g, ' ').split(' '); for (var j = 0; j < words.length; j++) { if (words[j].match(regExp)) { return true; } } } return false; } else { return data.join(' ').toLowerCase().indexOf(searchValue.toLowerCase()) !== -1 } }); $table.on('init.dt', function(event, settings) { if (!settings) { return; } var $tableWrapper = $(settings.nTableWrapper), $tableSearchInput = $tableWrapper.find('.dataTables_filter input'), $customInput = $tableSearchInput.clone(); $tableSearchInput.replaceWith($customInput); $customInput.on('input change', function() { if (!searchingSettings.showTable) { if (searchingSettings.resultOnly && searchingSettings.minChars && (this.value.length < searchingSettings.minChars || !this.value.length)) { $table.hide(); $table.parent().find('.dataTables_paginate').hide(); } else { $table.show(); $table.parent().find('.dataTables_paginate').show(); } } if (searchingSettings.minChars && (this.value.length < searchingSettings.minChars && this.value.length !== 0)) { event.preventDefault(); return false; } $table.api().draw(); }); if (searchingSettings.resultOnly && !searchingSettings.showTable) { $table.hide(); $table.parent().find('.dataTables_paginate').hide(); } }); } if (searchingSettings.columnSearch) { var inputTop = (searchingSettings.columnSearchPosition && searchingSettings.columnSearchPosition == 'top'), tPosition = inputTop ? 'thead' : 'tfoot'; if (!$table.find('.stbColumnsSearchWrapper').length) { var headerRow = $table.find('thead tr:first').find('th'); if (headerRow.length) { var searchRow = '', func = inputTop ? 'prepend' : 'append'; for (var i = 0; i < headerRow.length; i++) { var cellItem = $(headerRow[i]), cellClass = '', cellStyle = ''; if (!g_stbServerSideProcessing) { cellStyle = cellItem.is(':visible') ? '' : 'style="display: none;"'; } if (cellItem.hasClass('invisibleCell')) { cellClass = ' class="invisibleCell"' } searchRow += ''; } searchRow += ''; if ($table.find(tPosition).length == 0) { $table.append($('<' + tPosition + '>')); } $table.find(tPosition)[func](searchRow); } } if ($table.data('auto-index') !== 'off') { $('.stbColumnsSearchWrapper th:first-child input').css({ 'visibility': 'hidden' }); } } } if (toeInArray('ordering', features) != -1) { var sortingEnable = ['_all'], sortingDisable = [], aaSorting = [], multipleSorting = $table.data('multiple-sorting'), disableSorting = $table.data('disable-sorting'); if (!$table.data('head')) { sortingDisable = ['_all']; } if (disableSorting && disableSorting.length) { sortingDisable = disableSorting; } if (multipleSorting && multipleSorting.length) { aaSorting = multipleSorting; } else { var columnsCount = $table.find('tr:first th').length, sortColumn = $table.data('sort-column') || 0, sortOrder = $table.data('sort-order') || 'asc', columnNumber = sortColumn - 1; if (columnNumber >= 0 && columnNumber < columnsCount) { aaSorting.push([columnNumber, sortOrder]); } } // config.aoColumnDefs = [ // { type: 'natural-nohtml-ci', targets: '_all' }, // { "sortable": false, "targets": sortingDisable }, // { "sortable": true, "targets": sortingEnable } // ]; config.aoColumnDefs = {}; config.aaSorting = aaSorting; delete defaultFeatures.order; } if ($table.data('pagination-length')) { var paginationLength = String($table.data('pagination-length')); config.aLengthMenu = []; config.aLengthMenu.push(paginationLength.replace('All', -1).split(',').map(Number)); config.aLengthMenu.push(paginationLength.split(',')); } if ($table.data('auto-index') && $table.data('auto-index') !== 'off') { $table.on('draw.dt', function() { var isFirst = true, index = 1; $table.api().column(0).nodes().each(function(cell, i) { var style = window.getComputedStyle(cell); if (isFirst) { index = i + 1; isFirst = false; } if (style.display !== 'none' && !cell.classList.contains('invisibleCell')) { cell.innerHTML = index; index++; } }); }); } // Set responsive mode if (responsiveMode == 0) { // Responsive Mode: Standart Responsive Mode var labelStyles = ''; $table.append(labelStyles); $(window).on('load resize orientationchange', $table, function(event) { event.preventDefault(); clearTimeout($table.data('resizeTimer')); $table.data('resizeTimer', setTimeout(function() { $table.removeClass('oneColumn oneColumnWithLabels'); $table.css('width', '100%'); var tableWidth = $table.width(), wrapperWidth = $table.closest('.supsystic-tables-wrap').width(); if (tableWidth > wrapperWidth || $(window).width() <= 475) { $table.addClass('oneColumn'); if ($table.data('head') == 'on') { $table.addClass('oneColumnWithLabels'); } } }, 150)); if (g_stbServerSideProcessing) { $table.find('td').each(function() { $(this).css({ 'width': '', 'min-width': '' }); }); } }); } else if (responsiveMode === 1) { // Responsive Mode: Automatic Column Hiding config.responsive = { details: { renderer: function(api, rowIdx, columns) { var $table = $(api.table().node()), $subTable = $(''); $.each(columns, function(i, col) { if (col.hidden) { var $cell = $(api.cell(col.rowIndex, col.columnIndex).node()).clone(), markup = ''; if ($table.data('head') == 'on') { var tableHeadTr = $(api.table().header()).find('tr:not(.stbColumnsSearchWrapper)').eq(0); var $headerContent = tableHeadTr.find('th').eq(col.columnIndex).html(); markup += ''; } markup += ''; $cell.after( $('
'; if ($headerContent) { markup += $headerContent; } markup += '
') .addClass('collapsed-cell-holder') .attr('data-cell-row', col.rowIndex) .attr('data-cell-column', col.columnIndex) .hide() ); $subTable.append($(markup).append($cell.addClass('collapsed').show())); } }); return $subTable.is(':empty') ? false : $subTable; } } }; $table.on('responsive-resize.dt', function(event, api, columns) { if (typeof api == 'undefined' || typeof columns == 'undefined') { var tbl = $(this), instance = vendor[appName].getTableInstanceById(tbl.data('id')); if (instance) { api = typeof api != 'undefined' ? api : instance.api(); columns = typeof columns != 'undefined' ? columns : instance.api().columns(); } } var autoHiding = [], searchColumn = $table.find('.stbColumnsSearchWrapper input.search-column'); for (var i = 0, len = columns.length; i < len; i++) { autoHiding[i] = columns[i] ? 1 : 0; } $table.find('th input.search-column').each(function() { var th = $(this).parents('th:first'), i = th.index(); if (columns.length > i) { th.css('display', columns[i] ? '' : 'none'); } }); if (typeof columns[0] == 'boolean') { $table.attr('data-auto-hiding', autoHiding.join()); } if ($table.width() > $table.parent().width()) { $table.css('width', '100%'); $table.css('max-width', '100%'); api.responsive.recalc(); return; } for (var i = 0, len = columns.length; i < len; i++) { if (columns[i]) { $table.find('tr > td.collapsed-cell-holder[data-cell-column="' + i + '"]').each(function(index, el) { var $this = $(this); var $cell = $(api.cell( $this.data('cell-row'), $this.data('cell-column') ).node()); if ($cell.hasClass('collapsed')) { $cell.removeClass('collapsed'); $this.replaceWith($cell); } }); } } if ($table.data('merged')) { // if has merged cells remove them, with autohidding they not working $table.find('td[data-hide]').show(); $table.find('td[data-rowspan]').attr({ 'data-rowspan': 1, rowspan: 1, 'data-colspan': 1, colspan: 1 }); } }); } else if (responsiveMode === 2) { // Responsive Mode: Horizontal Scroll config.scrollX = true; config.bAutoWidth = false; var firstRow = $table.find('tbody tr:first-child td'); if (firstRow.length) { var cntCols = firstRow.length; $table.find('thead tr:first-child th').each(function(i, th) { if (cntCols > i && $(th).css('width')) { firstRow.eq(i).css('width', $(th).css('width')); } }); } } if (responsiveMode === 2 || responsiveMode === 3) { // Responsive Mode: 2 - Horizontal Scroll, 3 - Disable Responsivity var fixedHead = $table.data('head') && $table.data('fixed-head'), fixedFoot = $table.data('foot') && $table.data('fixed-foot'), fixedLeft = $table.data('fixed-left'), fixedRight = $table.data('fixed-right'); // TODO: correct the code to set fixed header and fixed footer in the standard way // TODO: https://datatables.net/extensions/fixedheader/#Features //config.fixedHeader = { // header: false, // footer: false //}; //if (fixedHead) { // config.fixedHeader.header = true; //} //if (fixedFoot) { // config.fixedHeader.footer = true; //} if (fixedHead || fixedFoot) { config.scrollY = $table.data('fixed-height'); config.scrollCollapse = true; } if ($table.data('fixed-cols')) { config.fixedColumns = { leftColumns: fixedLeft ? parseInt(fixedLeft) : 0, rightColumns: fixedRight ? parseInt(fixedRight) : 0 }; config.scrollX = true; } } //$table.find('.invisibleCell').siblings('td').addClass('invisibleCell'); // Add translation var langData = typeof g_stbTblLangData != 'undefined' ? JSON.parse(g_stbTblLangData) : $table.data('translation'), translation = langData || {}, override = $table.data('override'); if (typeof translation != 'object') { translation = {}; // for just to be sure that it is object } $.each(override, function(key, value) { if (value.length) { translation[key] = value; // We need to support old DT format, cuz some languages use it translation['s' + key.charAt(0).toUpperCase() + key.substr(1)] = value; } }); config.language = translation; var ajaxSource = {}; if (g_stbServerSideProcessing) { var nonce = (typeof DTGS_NONCE !== "undefined") ? DTGS_NONCE : DTGS_NONCE_FRONTEND; var route = { "action": "getPageRows", "module": "tables", "nonce": nonce }, loadedRows = [], loadedCells = [], headerRowsCount = ($table.data('head') == 'on' ? $table.data('head-rows-count') : 0), footerRowsCount = ($table.data('foot') == 'on' ? $table.data('foot-custom-rows-count') : 0); ajaxSource = { processing: true, serverSide: true, ajax: { url: window.ajaxurl ? window.ajaxurl : ajax_obj.ajaxurl, type: 'POST', data: { action: "supsystic-tables", route: route, id: $table.data('id'), searchParams: searchingSettings, searchValue: function() { var input = $('#' + $table.attr('id') + '_filter.dataTables_filter').find('input'); return (input.length ? input.val() : ''); }, header: headerRowsCount, footer: footerRowsCount, beforeSend: function() { g_stbServerSideProcessingIsActive = true; } }, dataFilter: function(data) { var json = jQuery.parseJSON(data), rows = $(json.rows).find('tr'), aData = []; loadedRows = []; loadedCells = []; for (var i = 0; i < rows.length; i++) { var row = rows[i]; loadedRows.push(row.attributes); var cells = $(row).find('td'), attrs = [], vals = []; for (var j = 0; j < cells.length; j++) { var cell = cells[j]; attrs.push(cell.attributes); vals.push(cell.innerHTML); } loadedCells.push(attrs); aData.push(vals); } json.rows = ''; json.data = aData; g_stbServerSideProcessingIsActive = false; return JSON.stringify(json); } }, createdRow: function(row, data, dataIndex) { if (typeof(loadedRows[dataIndex]) != 'undefined') { $(loadedRows[dataIndex]).each(function() { $(row).attr(this.name, this.value); }); } } }; if (typeof(config.aoColumnDefs) == 'undefined' || jQuery.isEmptyObject(config.aoColumnDefs)) { config.aoColumnDefs = []; } config.aoColumnDefs.push({ targets: '_all', cellType: 'td', createdCell: function(td, cellData, rowData, row, col) { if (typeof(loadedCells[row][col]) != 'undefined') { var rowspan = 1, colspan = 1; $(loadedCells[row][col]).each(function() { if (this.name == 'data-rowspan' && this.value > 1) { rowspan = this.value; } if (this.name == 'data-colspan' && this.value > 1) { colspan = this.value; } }); if (rowspan > 1 || colspan > 1) { var stopRow = row + parseInt(rowspan), stopCol = col + parseInt(colspan), startRow = colspan > 1 ? row : row + 1, hide; if (stopRow >= loadedCells.length) { stopRow = loadedCells.length; } if (stopCol >= loadedCells[row].length) { stopCol = loadedCells[row].length; } for (i = startRow; i < stopRow; i++) { if (i > row) { hide = document.createAttribute('data-hide'); hide.value = 'true'; loadedCells[i][col].setNamedItem(hide); } for (j = col + 1; j < stopCol; j++) { hide = document.createAttribute('data-hide'); hide.value = 'true'; loadedCells[i][j].setNamedItem(hide); } } } $(loadedCells[row][col]).each(function() { //if(this.name != 'data-formula') { $(td).attr(this.name, this.value); //} }); } } }); } $table.trigger('beforeInitializeTable', $table); var dateFormat = $table.data('date-format'); $table.dataTable.moment(dateFormat); jQuery.fn.dataTable.ext.order.intl(); tableInstance = $table.dataTable($.extend({}, defaultFeatures, config, extraConfig, ajaxSource, reinit));; tableInstance.table_id = $table.data('id'); tableInstance.table_view_id = $table.data('view-id'); tableInstance.fnFakeRowspan(); self._checkOnClickPopups($table); window.table = $table; if ($table.data('remove-rows')) { $(function() { $.contextMenu({ selector: '.dataTable td', animation: { duration: 250, show: 'fadeIn', hide: 'fadeOut' }, callback: function(key, options) { var m = "clicked: " + key; }, items: { "remove_row": { name: "Remove row", callback: function(itemKey, opt, e) { contextMenuAction(this, 'remove_row'); } }, "add_row_before": { name: "Add row before", callback: function(itemKey, opt, e) { contextMenuAction(this, 'add_row', 'before'); } }, "add_row_after": { name: "Add row after", callback: function(itemKey, opt, e) { contextMenuAction(this, 'add_row', 'after'); } }, "sep1": "---------", "quit": { name: "Quit" } } }); function contextMenuAction(e, action, second) { var coltext = e.text(); var colvindex = e.parent().children().index(e); var colindex = $('table.dataTable thead tr th:eq(' + colvindex + ')').data('column-index'); /* Global var for counter */ var giCount = 1; switch (action) { case "remove_row": $table.fnDeleteRow(e.parent('tr')); $table.fnUpdate(); break; case "add_row": var tr = e.parent('tr').clone(true, true); tr.find('td').html('').addClass('menu-injected').addClass('editable').addClass('justCloned'); tr.find('td').data('original-value', '').attr('data-original-value', ''); var order = tr.find('td').data('order'); if (second == 'before') { order = order - 1; tr.find('td').data('order', order).attr('data-order', order); } else { order = order + 1; tr.find('td').data('order', order).attr('data-order', order); } tr.find('td').data('cell-type', 'text').attr('data-cell-type', 'text'); tr.find('td').data('cell-format-type', '').attr('data-cell-format-type', ''); $table.append(tr); $table.fnAddData(tr, true); tr.find('td.justCloned').data('y', '9999').attr('data-y', '9999').removeClass('justCloned'); // $table.fnUpdate(); // $table.trigger('draw.dt'); break; } } }); } if (g_stbServerSideProcessing) { jQuery('.dataTables_processing').css('z-index', '10'); } else { self.setColumnSearch($table); } $table.on('draw.dt', function() { var searching = $table.data('searching-settings'); if (searching && ('columnSearch' in searching) && searching.columnSearch == 'on') { self.setColumnSearch($table); } if (!g_stbServerSideProcessing && $table.data('merged')) { tableInstance.fnResetFakeRowspan(); } self.initShortcodesInTable($table); }); if (responsiveMode === 1) { $table.on('responsive-resize.dt', function(event, api, columns) { if (!g_stbServerSideProcessing && $table.data('merged')) { tableInstance.fnResetFakeRowspan(); } }); } if (typeof $table.data('fixed-cols') !== 'undefined') { tableInstance.api().fixedColumns().update(); } if (addInstance) { this.setTableInstance(tableInstance); } return typeof finalCallback == "function" ? finalCallback(tableInstance) : tableInstance; }); /** Callback for displaying table after initializing * @param {object} settings - DataTables settings object * @param {object} json - JSON data retrieved from the server if the ajax option was set. Otherwise undefined. */ vendor[appName].showTable = (function(settings, json) { var self = vendor[appName], // it is callback so "this" does not equal vendor[appName] object $table = this instanceof $ ? this : settings, // for compatibility with old pro versions $tableWrap = $table.closest('.supsystic-tables-wrap'), tableSelector = '#supsystic-table-' + $table.data('view-id') + ' #supsystic-table-' + $table.data('id'), afterTableLoadedScriptString = $table.attr('data-after-table-loaded-script'), _ruleJS = self.setRuleJSInstance($table), responsiveMode = $table.data('responsive-mode'), fixedHeader = $table.data('fixed-head') == 'on', fixedFooter = $table.data('fixed-foot') == 'on', fixedColumns = $table.data('fixed-right') > 0 || $table.data('fixed-left') > 0, viewId = $table.data('view-id'); // Apply custom CSS styles, which have been set through the table editor $table.find('th, td').each(function() { self.setStylesToCell(this); }); $table.bind('column-visibility.dt draw.dt', function(e) { $(this).find('th, td').each(function() { self.setStylesToCell(this); }); }); // Remove sorting visual elements from the tags if there is no header on table if (!$table.data('head')) { $table.find('th').removeClass('sorting sorting_asc sorting_desc sorting_disabled'); } // Calculate formulas _ruleJS.init(); // Set formats self.formatDataAtTable($table, true); // Apply shortcode param "search" if ($table.data('search-value')) { $table.api().search($table.data('search-value')).draw(); } // Show comments on tap if ('ontouchstart' in window || navigator.msMaxTouchPoints) { $table.parents('.supsystic-tables-wrap:first').find('td, th').on('click', self.applyMobileTableComments); } // Prepare Contact Form by Supsystic buttons $table.parents('.supsystic-tables-wrap:first').find('th, td').each(self._contactFormBtnCellClb); // Page change callback $table.on('page.dt', function() { if (g_stbServerSideProcessing) { g_stbServerSideProcessingIsActive = true; } var table = $(this), tableSelector = '#supsystic-table-' + table.data('view-id') + ' #supsystic-table-' + table.data('id'); self.applyTableEventClb(self.pageEvent, 50, tableSelector); if ($table.data('pagination-scroll') == 'on') { $('html, body').animate({ scrollTop: table.closest('.dataTables_wrapper').offset().top }, 100); } if (typeof(self.setImgLightbox) == 'function') { self.setImgLightbox($table); } }); // Frontend fields if (typeof(self.createEditableFields) == 'function') { // for compatibility with old pro versions var $editableFields = $tableWrap.find('.editable'), $editfileFields = $tableWrap.find('.editfile'), $selectableFields = $tableWrap.find('.selectable'), $tableId = $table.data('id'), useEditableFields = typeof(useEdit) != 'undefined' && typeof(useEdit[$tableId]) != 'undefined' ? useEdit[$tableId] : false; if (useEditableFields || (SDT_DATA.isAdmin && SDT_DATA.isPro)) { if (typeof(self.setFrontendFields) == 'function') { self.setFrontendFields($table); } else if (typeof(self.setAllFields) == 'function') { self.setAllFields($table, $editableFields, $selectableFields); } else { self.createEditableFields($table, $editableFields); self.createEditableFileFields($table, $editfileFields); } $table.on('init.dt', function() { $table.on('responsive-resize.dt responsive-display.dt draw.dt', function() { $editableFields.off('click.sup'); // for compatibility with old pro versions $editfileFields.off('click.sup'); self.updateAfterRedraw($table); }); }); } } if (typeof(self.setImgLightbox) == 'function') { self.setImgLightbox($table); } // apply page.dt event by change table pagination via select var paginationSelect = $tableWrap.find('.dataTables_length select'); if (paginationSelect.length) { paginationSelect.on('change', function() { $table.trigger('page.dt'); }); } self.applyTableEventClb(self.fixHeaderOfHiddenColumns, 50, tableSelector); $table.trigger('beforeShowTable', $table); // Show table $tableWrap.prev('.supsystic-table-loader').hide(); $tableWrap.css('visibility', 'visible'); self.fixSortingForMultipleHeader($table); if (responsiveMode === 2 || fixedHeader || fixedFooter) { // Responsive Mode: Horizontal Scroll $(window).on('load resize orientationchange', $table, function(event) { var tBody = $tableWrap.find('.dataTables_scrollBody'), tBodyTable = tBody.find('.supsystic-table'); if (tBody.width() > tBodyTable.width() || $tableWrap.width() > tBodyTable.width()) { tBody.width(tBodyTable.width()); $tableWrap.find('.dataTables_scrollHead, .dataTables_scrollFoot, .dataTables_scrollBody').width(tBodyTable.width() + 1); /* var scrollTables = $tableWrap.find('.dataTables_scrollHead, .dataTables_scrollFoot'); scrollTables.width(tBodyTable.width() + 1); scrollTables.find('table').width(tBodyTable.width() + 1);*/ } if (tBody.isHorizontallyScrollable()) { tBody.css({ 'border-bottom': 'none' }); } else { tBody.removeStyle('border-bottom'); } var table = self.getTableInstanceById($table.data('id')); if (typeof table.fnAdjustColumnSizing == 'function') { setTimeout(function() { table.fnAdjustColumnSizing(false); }, 350); } }); // need resize twice to get better frontend view var tBody = $tableWrap.find('.dataTables_scrollBody'), tBodyTable = tBody.find('.supsystic-table'); if (tBodyTable.is(":visible")) { setTimeout(function() { $(window).trigger('load'); }, 200); } var $tHeadTable = $tableWrap.find('.dataTables_scrollHead .supsystic-table'); if ($tHeadTable.length) { self.formatDataAtTable($tHeadTable, true); } var $tFootTable = $tableWrap.find('.dataTables_scrollFoot .supsystic-table'); if ($tFootTable.length) { self.formatDataAtTable($tFootTable, true); } } // Correct width of fixed header / footer if (fixedHeader || fixedFooter) { $table.api().fixedHeader.adjust(); var i = 1; setTimeout(function() { var flag = fixedHeader, el = fixedHeader ? $tableWrap.find('.dataTables_scrollHead table thead tr:first-child th') : $tableWrap.find('.dataTables_scrollFoot table tfoot tr:first-child th'); el.each(function() { var thWidth = $tableWrap.find('.dataTables_scrollBody table tbody tr:first-child td:nth-child(' + i + ')'); $(this).css({ 'width': thWidth.outerWidth(), 'min-width': thWidth.outerWidth(), 'box-sizing': 'border-box' }); if (fixedFooter && flag) { var footerEl = $tableWrap.find('.dataTables_scrollFoot table tfoot tr:first-child th:nth-child(' + i + ')'); footerEl.css({ 'width': thWidth.outerWidth(), 'min-width': thWidth.outerWidth(), 'box-sizing': 'border-box' }); } i++; }); }, 200); } // Correct width of fixed columns if (fixedColumns) { $table.api().fixedColumns().relayout(); //var tableCaption = $('.dataTables_scrollHead caption'); // //if(tableCaption.length) { //self._fixTableCaption(tableCaption.height(), viewId, 10); //} } /* Fix for Horizontal scroll responsive mode if table has different width for one column in header and body */ if (!fixedHeader && !fixedFooter && responsiveMode === 2 && toeInArray('auto_width', $table.data('features')) == -1) { $tableWrap.find('.dataTables_scrollBody table thead tr:first-child th').each(function() { var tableWidth = $table.width(), tableWrapWidth = $tableWrap.width(); if (tableWrapWidth > tableWidth) { $tableWrap .find('.dataTables_scrollHeadInner, .dataTables_scrollBody, .dataTables_scrollFootInner') .addClass('fit-content'); } }); } // Load user custom scripts if (afterTableLoadedScriptString !== undefined) { afterTableLoadedScriptString = afterTableLoadedScriptString.substring(1, afterTableLoadedScriptString.length - 1); var afterTableLoadedScript = b64DecodeUnicode(afterTableLoadedScriptString).replace(/"/g, "'"), executeScript = new Function(afterTableLoadedScript); if (typeof executeScript === "function") { setTimeout(function() { executeScript(); }, 1000); } } if (g_stbServerSideProcessing) { $table.on('draw.dt', function(e) { var searching = $table.data('searching-settings'); if (searching && ('columnSearch' in searching) && searching.columnSearch == 'on') { self.setColumnSearch($table); } self.getTableInstanceByViewId(viewId).fnFakeRowspan(); if (responsiveMode === 0 || responsiveMode === 2) { $(window).trigger('load'); } }).trigger('draw.dt'); } var tblEditLink = 'g_stbTblEditLink_' + $table.data('id'), showTblEditLink = eval("typeof " + tblEditLink) !== 'undefined' ? jQuery(window.atob(eval(tblEditLink))) : false; if (showTblEditLink && jQuery(tableSelector).closest('.supsystic-tables-wrap').find('.tblEditLink').length === 0) { jQuery(tableSelector).closest('.supsystic-tables-wrap').append(showTblEditLink); } function b64DecodeUnicode(str) { return decodeURIComponent(Array.prototype.map.call(atob(str), function(c) { return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); }).join('')); } }); vendor[appName].applyTableEventClb = (function(clb, timeout) { // Callback for applying events' actions and other functions to tables with server side processing (SSP) timeout = timeout ? timeout : 0; var self = this, args = Array.from(arguments); if (g_stbServerSideProcessing && g_stbServerSideProcessingIsActive) { setTimeout(function() { self.applyTableEventClb.apply(self, args); }, 50); } else { if (typeof clb == 'function') { args = args.slice(2); setTimeout(function() { clb.apply(self, args); }, timeout); } } }); vendor[appName].pageEvent = (function(tableSelector) { var table = $(tableSelector), tableWrapper = table.parents('.supsystic-tables-wrap:first'); this.getRuleJSInstance(table).init(); this.formatDataAtTable(table, true); this.fixHeaderOfHiddenColumns(table); if ('ontouchstart' in window || navigator.msMaxTouchPoints) { tableWrapper.find('td, th').on('click', this.applyMobileTableComments); } tableWrapper.find('td, th').each(this._contactFormBtnCellClb); this.initShortcodesInTable(table); }); vendor[appName].fixHeaderOfHiddenColumns = (function($table) { $table = $table instanceof $ ? $table : $($table); var tableWrapper = $table.parents('.supsystic-tables-wrap:first'); if (!$table.data('head')) { tableWrapper.find('thead').each(function() { var thead = $(this); thead.find('th').each(function(iter, item) { var th = $(this), itemIndex = iter + 1, columnAllTd = thead.parents('table:first').find('tbody td:nth-child(' + itemIndex + ')'), columnInvTd = columnAllTd.filter('.invisibleCell'), hidden = columnAllTd.length > 0 && columnAllTd.length == columnInvTd.length; if (hidden) { // Fix of correct displaying of tables with hidden rows / columns for tables without headers th.addClass('invisibleCell'); } }); }); } }); vendor[appName].applyMobileTableComments = (function(e) { var $elem = $(this), title = $elem.attr('title'); if (title) { var tableViewId = $elem.parents('table.supsystic-table:first').data('view-id'), cellId = $elem.data('cell-id'), comment = $('.stbMobileComment[data-table="' + tableViewId + '"][data-cell="' + cellId + '"]'); if (!comment.length) { comment = $('