index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import $ from 'jquery';
  2. import Sortable from 'sortablejs';
  3. import PageFilters, { Instance as PageFiltersInstance } from './filter';
  4. import Page from './page';
  5. const pad = (n, s) => (`000${n}`).substr(-s);
  6. // Pages Ordering
  7. let Ordering = null;
  8. let orderingElement = $('#ordering');
  9. if (orderingElement.length) {
  10. Ordering = new Sortable(orderingElement.get(0), {
  11. filter: '.ignore',
  12. onUpdate: function() {
  13. /* Old single page index behavior
  14. let item = $(event.item);
  15. let index = orderingElement.children().index(item) + 1;
  16. $('[data-order]').val(index);
  17. */
  18. let indexes = [];
  19. const children = orderingElement.children();
  20. const padZero = (children.length + '').split('').length;
  21. children.each((index, item) => {
  22. item = $(item);
  23. indexes.push(item.data('id'));
  24. item.find('.page-order').text(`${pad(index + 1, padZero)}.`);
  25. });
  26. $('[data-order]').val(indexes.join(','));
  27. }
  28. });
  29. $(document).on('input', '[name="data[folder]"]', (event) => {
  30. const target = $(event.currentTarget);
  31. const activeOrder = $('[data-id][data-active-id]');
  32. activeOrder.data('id', target.val());
  33. Ordering.options.onUpdate();
  34. });
  35. }
  36. export default {
  37. Ordering,
  38. Page,
  39. PageFilters: {
  40. PageFilters,
  41. Instance: PageFiltersInstance
  42. }
  43. };