{"version":3,"file":"data_table-X-mD1wrR.js","sources":["../assets/elementor/js/apex-chart/DataTable.js"],"sourcesContent":["// Class specifically for Data table\nexport default class DataTable {\n constructor() {\n this.tableHandlers = {};\n this.init();\n this.observer = {}; // For IntersectionObserver\n }\n\n // Initialize the class by setting up handlers and events\n init() {\n this.setUpTableHandler();\n this.bindEventHandlers();\n }\n\n // Bind event listeners\n bindEventHandlers() {\n jQuery(window).on('elementor/frontend/init', this.handleElementorWidgetInit.bind(this));\n jQuery(window).on('elementor/editor/init', this.handleElementorWidgetInit.bind(this));\n }\n\n\n handleElementorWidgetInit() {\n elementorFrontend.hooks.addAction('frontend/element_ready/widget', ($scope) => {\n const chartElement = $scope.find('.graphina-jquery-data-table');\n if (chartElement.length > 0) {\n this.initializeTables(chartElement);\n }\n });\n }\n\n initializeTables(chartElement) {\n const chartType = chartElement.data('chart_type');\n if (this.tableHandlers[chartType]) {\n this.tableHandlers[chartType](chartElement);\n }\n }\n\n\n\n setUpTableHandler() {\n this.tableHandlers = {\n data_table_lite: (element) => this.observeTableElement(element, 'data_table_lite'),\n };\n }\n\n // Setup IntersectionObserver to call setupTable when the element is in the viewport\n observeTableElement(element, dataTableType) {\n const elementID = element.data('element_id')\n if (gcfe_public_localize.view_port === 'off') {\n if (!this.observer[elementID]) {\n this.observer[elementID] = new IntersectionObserver((entries) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n // Element is in viewport; initialize the chart\n this.setupTable(jQuery(entry.target), dataTableType);\n // Stop observing the element after initializing the chart\n this.observer[elementID].unobserve(entry.target);\n }\n });\n }, { threshold: 0.1 }); // Trigger when at least 10% of the element is visible\n }\n this.observer[elementID].observe(element[0]); // Start observing the chart element\n } else {\n this.setupTable(element, dataTableType);\n }\n }\n\n getDynamicData(settings, extraData, elementId) {\n let post_id = jQuery(`[data-element_id=\"${elementId}\"]`).closest('[data-elementor-id]').data('elementor-id');\n return new Promise((resolve, reject) => {\n jQuery.ajax({\n url: gcfe_public_localize.ajaxurl,\n type: 'POST',\n dataType: 'json',\n data: {\n action : 'get_jquery_datatable_data',\n nonce : gcfe_public_localize.table_nonce,\n chartType : 'data_table_lite',\n post_id : post_id,\n element_id : elementId,\n series_count: 0,\n settings : JSON.stringify(settings),\n selected_field: []\n },\n success: (response) => {\n jQuery('#data_table_lite_loading_' + elementId).hide();\n jQuery('#data_table_lite_no_data_' + elementId).hide();\n resolve(response);\n },\n error: (error) => {\n console.error('AJAX Error:', error);\n reject(new Error('AJAX request failed.'));\n },\n });\n });\n }\n\n async setupTable(element,dataTableType){\n const element_id = element.data('element_id')\n let chart_data = element.data('chart_data')\n const extraData = element.data('extra_data');\n const settings = element.data('settings');\n\n chart_data.fnInitComplete = () => {\n jQuery('.dataTables_scrollBody').css({\n 'overflow': 'hidden',\n 'border': '0'\n });\n jQuery(`#data_table_lite_${element_id} thead th`).addClass('all graphina-datatable-columns')\n\n jQuery(`#data_table_lite_${element_id} tbody td`).addClass('graphina-datatable-tbody-td')\n\n const tableScrollFoot = jQuery('.dataTables_scrollFoot');\n // Enable TFOOT scroll bars\n tableScrollFoot.css('overflow', 'auto');\n\n // Sync TFOOT scrolling with TBODY\n tableScrollFoot.on('scroll', function () {\n jQuery('.dataTables_scrollBody').scrollLeft(jQuery(this).scrollLeft());\n });\n }\n chart_data.rowCallback = function (row, data, index) {\n if (index % 2 === 0) {\n jQuery(row).addClass('odd');\n } else {\n jQuery(row).addClass('even');\n }\n }\n let datatable = jQuery('.data_table_lite_' + element_id).DataTable(chart_data);\n \n if(extraData.is_dynamic_table){\n const dynamicData = await this.getDynamicData(settings, extraData, element_id);\n let dynamicTableData = {}\n if(dynamicData.data.body.length !== 0 && dynamicData.data.header.length !== 0){\n dynamicTableData.data = dynamicData.data.body;\n dynamicTableData.columns = dynamicData.data.header;\n datatable.destroy();\n jQuery('#data_table_lite_loading_' + element_id).hide();\n datatable = jQuery('#data_table_lite_' + element_id).DataTable(dynamicTableData);;\n }else{\n jQuery('#data_table_lite_loading_' + element_id).show();\n }\n }else{\n if(chart_data.columns.length > 0){\n jQuery('#data_table_lite_loading_' + element_id).hide();\n }\n }\n if (extraData.table_footer) {\n jQuery(`#data_table_lite_${element_id}`).append('