This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Omphaloskepsis/plugins/jetpack/modules/custom-post-types/js/nova-drag-drop.js
2018-03-21 18:19:20 +00:00

50 lines
1.1 KiB
JavaScript

/* jshint onevar: false, smarttabs: true */
/* global _novaDragDrop */
(function($){
var list;
function init() {
list = $('#the-list');
dragMenus();
addNonce();
addSubmitButton();
}
function dragMenus() {
list.sortable({
cancel: '.no-items',
stop: function( event, ui ) {
if ( ui.item.is(':first-child') ) {
return list.sortable('cancel');
}
//
reOrder();
}
});
}
function reOrder() {
list.find('.menu-label-row').each(function() {
var term_id = $(this).data('term_id');
$(this).nextUntil('.menu-label-row').each(function(i) {
var row = $(this);
row.find('.menu-order-value').val(i);
row.find('.nova-menu-term').val(term_id);
});
});
}
function addSubmitButton() {
$('.tablenav').prepend('<input type="submit" class="button-primary button-reorder alignright" value="' + _novaDragDrop.reorder + '" name="' + _novaDragDrop.reorderName + '" />');
}
function addNonce() {
$('#posts-filter').append('<input type="hidden" name="' + _novaDragDrop.nonceName + '" value="' + _novaDragDrop.nonce + '" />');
}
// do it
$(document).ready(init);
})(jQuery);