PluginProbe
Stream – Activity Log & Audit Trail / 2.0.2
Stream – Activity Log & Audit Trail v2.0.2
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
stream / ui / js / dashboard.js

dashboard.js in Stream – Activity Log & Audit Trail 2.0.2, at ui/js/dashboard.js

95 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /* globals wp, wp_stream_regenerate_alt_rows */
2 jQuery( function( $ ) {
3
4 /**
5 * Dashboard Live Update
6 */
7 if ( undefined !== wp.heartbeat && undefined !== wp.heartbeat.interval ) {
8 wp.heartbeat.interval( 'fast' );
9 }
10
11 var $widget = $( '#dashboard_stream_activity' ),
12 $list = $widget.find( '.inside ul' );
13
14 // Add alternate classes to initial items
15 $( 'li:even', $list ).addClass( 'alternate');
16
17 // Add Stream widget params to heartbeat API requests
18 $( document ).on( 'heartbeat-send.stream', function( e, data ) {
19 data['wp-stream-heartbeat'] = 'dashboard-update';
20 data['wp-stream-heartbeat-last-time'] = $( 'li:first', $list ).data( 'datetime' ) || 1;
21 });
22
23 // Listen for "heartbeat-tick" on $(document).
24 $( document ).on( 'heartbeat-tick.stream', function( e, data ) {
25 // If this no rows return then we kill the script
26 if ( undefined === typeof data['wp-stream-heartbeat'] || 0 === data['wp-stream-heartbeat'].length ) {
27 return;
28 }
29
30 var $new_items = $( data['wp-stream-heartbeat'] ).filter( 'li' ).removeClass().addClass( 'new-row' );
31
32 // Remove the number of element added to the end of the list table
33 var show_on_screen = data.per_page || 5;
34 var slice_items = show_on_screen - ( $new_items.length + $( 'li', $list ).length );
35
36 if ( slice_items < 0 ) {
37 $( 'li', $list ).slice( slice_items ).remove();
38 }
39
40 // Remove the no items paragraph
41 $widget.find( 'p.no-items' ).remove();
42
43 // Add element to the dom
44 $new_items.slice( 0, data.per_page ).prependTo( $list );
45
46 // Update pagination
47 var total_items_i18n = data.total_items_i18n || '';
48
49 if ( total_items_i18n ) {
50 $( '.total-pages', $widget ).text( data.total_pages_i18n );
51 $( '.pagination-links', $widget ).find( '.next-page, .last-page' ) .toggleClass( 'disabled', data.total_pages === $( '.current-page' ).val() );
52 $( '.pagination-links .last-page', $widget ).attr( 'data-page', data.total_pages ).attr( 'href', data.last_page_link );
53 }
54
55 // Regenerate alternating row classes
56 wp_stream_regenerate_alt_rows( $( 'li', $list ) );
57
58 // Remove background after a certain amount of time
59 setTimeout( function() {
60 $new_items.addClass( 'fadeout' );
61
62 setTimeout( function() {
63 $new_items.removeClass( 'new-row fadeout' );
64 }, 500 );
65
66 }, 3000 );
67
68 });
69
70 // Pagination links
71 $widget.on( 'click', '.pagination-links a', function( e ) {
72 e.preventDefault();
73
74 var data = {
75 'action': 'stream_activity_dashboard_update',
76 'stream-paged': $( this ).data( 'page' )
77 };
78
79 $.ajax({
80 type: 'POST',
81 url: window.ajaxurl,
82 data: data,
83 success: function( response ) {
84 var $inside = $( '.inside', $widget );
85
86 $inside.html( response );
87
88 // Regenerate alternating row classes
89 wp_stream_regenerate_alt_rows( $( 'ul li', $inside ) );
90 }
91 });
92 });
93
94 });
95