| 1 |
|
| 2 |
( function( $ ) { |
| 3 |
|
| 4 |
$( document ).ready( function() { |
| 5 |
|
| 6 |
var tables = $( '.posts-data-table' ); |
| 7 |
var adminBarVisible = $( '#wpadminbar' ).length; |
| 8 |
|
| 9 |
tables.each( function() { |
| 10 |
|
| 11 |
var config = { |
| 12 |
responsive: true, |
| 13 |
processing: true // display 'processing' indicator when loading |
| 14 |
}; |
| 15 |
|
| 16 |
// Set language - defaults to English if not specified |
| 17 |
if ( ( typeof posts_data_table !== 'undefined' ) && posts_data_table.langurl ) { |
| 18 |
config.language = { url: posts_data_table.langurl }; |
| 19 |
} |
| 20 |
|
| 21 |
// Initialise DataTable |
| 22 |
var table = $( this ).DataTable( config ); |
| 23 |
|
| 24 |
// If scroll offset defined, animate back to top of table on next/previous page event |
| 25 |
$( this ).on( 'page.dt', function() { |
| 26 |
if ( $( this ).data( 'scroll-offset' ) !== false ) { |
| 27 |
var tableOffset = $( this ).parent().offset().top - $( this ).data( 'scroll-offset' ); |
| 28 |
if ( adminBarVisible ) { // Adjust offset for WP admin bar |
| 29 |
tableOffset -= 32; |
| 30 |
} |
| 31 |
$( 'html,body' ).animate( { scrollTop: tableOffset }, 300 ); |
| 32 |
} |
| 33 |
} ); |
| 34 |
|
| 35 |
// If 'search on click' feature enabled then add click handler for links in category and author columns. |
| 36 |
// When a category or author is clicked, the table will filter by that value |
| 37 |
if ( $( this ).data( 'click-filter' ) ) { |
| 38 |
table.columns( ['category:name', 'author:name'] ).nodes().to$().each( function() { |
| 39 |
$( this ).children( 'a' ).on( 'click', function() { |
| 40 |
table.search( $( this ).text() ).draw(); |
| 41 |
return false; |
| 42 |
} ); |
| 43 |
} ); |
| 44 |
} |
| 45 |
|
| 46 |
} ); // each table |
| 47 |
|
| 48 |
} ); // end document.ready |
| 49 |
|
| 50 |
} )( jQuery ); |