PluginProbe
Posts Table with Search & Sort / 1.1.5
Posts Table with Search & Sort v1.1.5
1.4.13 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2 1.3 1.3.1 1.3.1-v2 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 40 releases
posts-data-table / assets / js / posts-data-table.js

posts-data-table.js in Posts Table with Search & Sort 1.1.5, at assets/js/posts-data-table.js

50 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 );