0
|| $js_options['datatables_colreorder_fixright'] > 0
) {
// Register the JS files.
$url = plugins_url( "js/dataTables.colReorder.js", __FILE__ );
wp_enqueue_script( 'tablepress-datatables-colreorder', $url, array( 'tablepress-datatables' ), self::$version, true );
$needJS = TRUE;
}
if ( $js_options['datatables_colresize'] != ''
|| $js_options['datatables_colresize_minwidth'] > 0
|| $js_options['datatables_colresize_scrolly'] > 0
|| $js_options['datatables_colresize_resizetable'] != ''
) {
// Register the JS files.
$url = plugins_url( "js/dataTables.colResize.js", __FILE__ );
wp_enqueue_script( 'tablepress-datatables-colresize', $url, array( 'tablepress-datatables' ), self::$version, true );
$needJS = TRUE;
}
// Add the common filter that adds JS for all calls on the page.
if ( $needJS && ! has_filter( 'tablepress_all_datatables_commands', array( __CLASS__, 'all_datatables_commands' ) )
) {
add_filter( 'tablepress_all_datatables_commands', array( __CLASS__, 'all_datatables_commands' ) );
}
return $js_options;
}
/**
* Evaluate JS parameters and convert them to DataTables parameters.
*
* @since 0.1
*
* @param array $parameters DataTables parameters.
* @param string $table_id Table ID.
* @param string $html_id HTML ID of the table.
* @param array $js_options JS options for DataTables.
* @return array Extended DataTables parameters.
*/
public static function datatables_parameters( $parameters, $table_id, $html_id, $js_options ) {
// Construct the DataTables ColReorder config parameter.
$parameters['colReorder'] = array();
if ($js_options['datatables_colreorder_realtime'] != '') {
$parameters['colReorder'][] = "\"realtime\":{$js_options['datatables_colreorder_realtime']}";
}
if ($js_options['datatables_colreorder_fixleft'] > 0) {
$parameters['colReorder'][] = "\"fixedColumnsLeft\":{$js_options['datatables_colreorder_fixleft']}";
}
if ($js_options['datatables_colreorder_fixright'] > 0) {
$parameters['colReorder'][] = "\"fixedColumnsRight\":{$js_options['datatables_colreorder_fixright']}";
}
if (empty($parameters['colReorder'])) {
if ($js_options['datatables_colreorder'] != ''
&& $js_options['datatables_colreorder'] != 'false')
{
$parameters['colReorder'] = '"colReorder":true';
} else {
unset($parameters['colReorder']);
}
} else {
$parameters['colReorder'] = '"colReorder":{' . implode(',', $parameters['colReorder']) . '}';
}
// Construct the DataTables ColResize config parameter.
$parameters['colResize'] = array();
if ($js_options['datatables_colresize_minwidth'] > 0) {
$parameters['colResize'][] = "\"minColumnWidth\":{$js_options['datatables_colresize_minwidth']}";
}
if ($js_options['datatables_colresize_scrolly'] > 0) {
$parameters['colResize'][] = "\"scrollY\":{$js_options['datatables_colresize_scrolly']}";
}
if ($js_options['datatables_colresize_resizetable'] != '') {
if ($js_options['datatables_colresize_resizetable'] != 'false') {
$parameters['colResize'][] = "\"resizeTable\":true";
} else {
$parameters['colResize'][] = "\"resizeTable\":false";
}
}
if (empty($parameters['colResize'])) {
if ($js_options['datatables_colresize'] != ''
&& ($js_options['datatables_colresize'] != 'false'))
{
$parameters['colResize'] = '"colResize":true';
} else {
unset($parameters['colResize']);
}
} else {
$parameters['colResize'] = '"colResize":{' . implode(',', $parameters['colResize']) . '}';
}
if (isset($parameters['colResize'])) {
$parameters['autoWidth'] = '"autoWidth":false';
$parameters['scrollX'] = '"scrollX":false';
}
return $parameters;
}
/**
* Add jQuery code that adds the necessary CSS for the Extension, instead of loading that CSS from a file on all pages.
*
* @since 0.1
*
* @param array $commands The JS commands for the DataTables JS library.
* @return array Modified JS commands for the DataTables JS library.
*/
public static function all_datatables_commands( $commands ) {
// First the ColReorder CSS
$commands = "$('head').append('');\n" . $commands;
// Now the ColResize CSS
$commands = "$('head').append('