Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2014
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. !function($, window, document, undefined)
  2. {
  3. XenForo.FatSortable = function ($container)
  4. {
  5. var sortUrl = $container.data('sort-url'),
  6. itemSelector = 'li.listItem';
  7.  
  8. console.log('sortable init start');
  9.  
  10. if (!sortUrl) {
  11. console.log('data-sort-url for .sortable not found');
  12. return;
  13. }
  14.  
  15. var config = {
  16. forcePlaceholderSize: true,
  17. items: itemSelector
  18. };
  19.  
  20. var eventConfig = {
  21. 'sortupdate': function(e) {
  22. var order = [];
  23.  
  24. $container.find('[data-item-id]').each(function(i){
  25. var $this = $(this),
  26. itemId = $this.data('item-id'),
  27. parentId = $this.parent().data('parent-id');
  28.  
  29. if (parentId !== undefined) {
  30. order[i] = [itemId, parentId];
  31. }
  32. else {
  33. order[i] = itemId;
  34. }
  35. });
  36.  
  37. // moving across groups can trigger this multiple times
  38. if ($container.data('sort-timer')) {
  39. clearTimeout($container.data('sort-timer'));
  40. }
  41.  
  42. $container.data('sort-timer', setTimeout(function () {
  43. XenForo.ajax(
  44. sortUrl,
  45. { order: order },
  46. function (e) {
  47. // ajax progress complete, execute display order update
  48. console.info('ajax request complete');
  49. }
  50. );
  51. }, 100));
  52. }
  53. };
  54.  
  55. $container.sortable(config).bind(eventConfig);
  56.  
  57. var editor = XenForo.getEditorInForm($missingElement.closest('form'), ':not(.NoAttachment)');
  58.  
  59. editor.$editor.on('AttachmentsChanged', function(e)
  60. {
  61. console.log(e);
  62. console.log('attachChanged fired');
  63. $container.sortable(config).bind(eventConfig);
  64. });
  65. };
  66.  
  67. XenForo.register('.fat_sortable', 'XenForo.FatSortable');
  68. }
  69. (jQuery, this, document);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement