PluginProbe
Posts Table with Search & Sort / 1.0.6
Posts Table with Search & Sort v1.0.6
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.0.6, at assets/js/posts-data-table.js

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