-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththe-taxonomy-sort.js
61 lines (56 loc) · 1.57 KB
/
the-taxonomy-sort.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
jQuery( document ).ready( function( $ )
{
// if it is taxonomy page
if( adminpage == 'edit-tags-php' )
{
// make table rows sortable
$( '.wp-list-table.tags tbody' ).sortable({
items: 'tr:not(.inline-edit-row)',
cursor: 'move',
axis: 'y',
containment: 'table.widefat',
scrollSensitivity: 40,
stop: function( event, ui ) {
// array for the ids and positions
var rows = new Array([]),
taxonomy_name = $( 'input[name="taxonomy"]' ).val();
// show "activity" with spinner
thets_activity_spinner( true );
$( '.wp-list-table.tags tbody tr:not(.inline-edit-row)' ).each( function( i, e ) {
var rowID = parseInt( $( e ).attr( 'id' ).substr( 4 ) );
rows[i] = rowID;
} );
// post rows for sorting
$.post( ajaxurl, {
'rows' : rows,
'taxonomy_name' : taxonomy_name,
'action' : 'get_inline_boxes'
}, function(response) {
// stop activity spinner
thets_activity_spinner( false );
});
}
});
}
/**
* Adds, shows or hides the activity status spinner
*
* @param {boolean} status To show (true) or hide (false) the spinner
* @return {void}
*/
function thets_activity_spinner( status ) {
var actions_table = $( '.tablenav .actions' );
if( actions_table.find( '.spinner' ).length === 0 && status === true ) {
// add spinner
actions_table.prepend( '<div class="spinner" style="display: inline;" />' );
}
else if ( status === true ) {
// show spinner
actions_table.find( '.spinner' ).show();
}
else {
// hide spinner
actions_table.find( '.spinner' ).hide();
}
}
} );