Initial commit
This commit is contained in:
19
assets/sort.css
Normal file
19
assets/sort.css
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* @package ogre-sort
|
||||
* @author cleverogre
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
.ui-sortable tr:hover {
|
||||
cursor: move;
|
||||
}
|
||||
|
||||
.ui-sortable tr.alternate {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.ui-sortable tr.ui-sortable-helper {
|
||||
background-color: #f9f9f9;
|
||||
border-top: 1px solid #dfdfdf;
|
||||
}
|
||||
70
assets/sort.js
Normal file
70
assets/sort.js
Normal file
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* @package ogre-sort
|
||||
* @author cleverogre
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
jQuery(($) => {
|
||||
if (typeof window['ogre_sort'] === 'undefined') return;
|
||||
|
||||
const update = (args) => {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: ogre_sort.ajaxurl,
|
||||
data: args,
|
||||
success: (response, textStatus, jqXHR) => {
|
||||
if (response.success) {
|
||||
console.log('Ogre Sort: Ajax sort request successful');
|
||||
} else if (typeof response.data !== 'undefined' && response.data != '') {
|
||||
console.log('Ogre Sort: Ajax sort error. ' + response.data);
|
||||
} else {
|
||||
console.log('Ogre Sort: Ajax sort error. Unknown sort error.');
|
||||
}
|
||||
},
|
||||
error: (jqXHR, textStatus, errorThrown) => {
|
||||
console.log('Ogre Sort: Ajax sort request failed');
|
||||
},
|
||||
complete: (jqXHR, textStatus) => {
|
||||
console.log('Ogre Sort: Ajax request completed');
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const fixHelper = (e, ui) => {
|
||||
ui.children().children().each(function () {
|
||||
$(this).width($(this).width());
|
||||
});
|
||||
return ui;
|
||||
};
|
||||
|
||||
$('table.posts #the-list, table.pages #the-list').sortable({
|
||||
'items': 'tr',
|
||||
'axis': 'y',
|
||||
'helper': fixHelper,
|
||||
'update': (e, ui) => {
|
||||
const args = {
|
||||
action: 'ogre_sort',
|
||||
relationship: ogre_sort.current_relationship,
|
||||
order: $('#the-list').sortable('serialize'),
|
||||
};
|
||||
if (typeof ogre_sort.term != 'undefined') {
|
||||
args.term = ogre_sort.term;
|
||||
}
|
||||
update(args);
|
||||
},
|
||||
});
|
||||
|
||||
$('table.tags #the-list').sortable({
|
||||
'items': 'tr',
|
||||
'axis': 'y',
|
||||
'helper': fixHelper,
|
||||
'update': (e, ui) => {
|
||||
update({
|
||||
action: 'ogre_sort',
|
||||
relationship: ogre_sort.current_relationship,
|
||||
order: $('#the-list').sortable('serialize'),
|
||||
});
|
||||
},
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user