!function($, window, document, undefined)
{
XenForo.FatSortable = function ($container)
{
var sortUrl = $container.data('sort-url'),
itemSelector = 'li.listItem';
console.log('sortable init start');
if (!sortUrl) {
console.log('data-sort-url for .sortable not found');
return;
}
var config = {
forcePlaceholderSize: true,
items: itemSelector
};
var eventConfig = {
'sortupdate': function(e) {
var order = [];
$container.find('[data-item-id]').each(function(i){
var $this = $(this),
itemId = $this.data('item-id'),
parentId = $this.parent().data('parent-id');
if (parentId !== undefined) {
order[i] = [itemId, parentId];
}
else {
order[i] = itemId;
}
});
// moving across groups can trigger this multiple times
if ($container.data('sort-timer')) {
clearTimeout($container.data('sort-timer'));
}
$container.data('sort-timer', setTimeout(function () {
XenForo.ajax(
sortUrl,
{ order: order },
function (e) {
// ajax progress complete, execute display order update
console.info('ajax request complete');
}
);
}, 100));
}
};
$container.sortable(config).bind(eventConfig);
var editor = XenForo.getEditorInForm($missingElement.closest('form'), ':not(.NoAttachment)');
editor.$editor.on('AttachmentsChanged', function(e)
{
console.log(e);
console.log('attachChanged fired');
$container.sortable(config).bind(eventConfig);
});
};
XenForo.register('.fat_sortable', 'XenForo.FatSortable');
}
(jQuery, this, document);