Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sort.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. var sortableTable;
  2. $(function () {
  3. // tips/notes:
  4. // In HTML add data-sorter="false" to table headings (TH) that should not be sorted
  5. // or add data-sorter="myParser" to THs that require a custom parser
  6. // sorts dates placed in the title attribute of a td
  7. $.tablesorter.addParser({
  8. id: 'relativeTime',
  9. is: function (s) {
  10. return false;
  11. },
  12. format: function (str, table, td) {
  13. return td.title;
  14. },
  15. type: 'text'
  16. });
  17. // sort to ignore (English) articles
  18. // add data-sorter="ignoreArticles" to THs
  19. $.tablesorter.addParser({
  20. id: 'ignoreArticles',
  21. $format: $.tablesorter.getParserById('text').format,
  22. articlesRegEx: /^(?:the\s|a\s|an\s)/i,
  23. is: function () {
  24. return false;
  25. },
  26. format: function (s, table) {
  27. return this.$format((s || '').replace(this.articlesRegEx, ''), table);
  28. },
  29. type: 'text'
  30. });
  31. sortableTable = {
  32. container: $('#manage_collage_table'),
  33. form: $('#drag_drop_collage_form'),
  34. serialInput: $('#drag_drop_collage_sort_order'),
  35. check: $('#check_all'),
  36. counter: function () {
  37. var x = 10;
  38. $('input.sort_numbers').each(function () {
  39. this.value = x;
  40. x += 10;
  41. });
  42. this.serializer();
  43. },
  44. color: function () {
  45. // noop - handled by CSS
  46. },
  47. serializer: function () {
  48. this.serialInput.val(this.container.sortable('serialize'));
  49. },
  50. save: function () {
  51. sortableTable.form.submit();
  52. },
  53. widthFix: function (e, row) {
  54. row.children('td').each(function () {
  55. $(this).width($(this).width());
  56. });
  57. return row;
  58. },
  59. init: function () {
  60. $('.drag_drop_save').removeClass('hidden');
  61. this.noteToggle();
  62. this.draggable();
  63. this.tableSorter();
  64. if (this.check.length !== 0) {
  65. this.checks();
  66. } else {
  67. $('.save_sortable_collage').click(sortableTable.save);
  68. }
  69. },
  70. draggable: function () {
  71. this.container.sortable({
  72. items: '.drag',
  73. axis: 'y',
  74. containment: '.thin',
  75. forcePlaceholderSize: true,
  76. helper: sortableTable.widthFix,
  77. stop: sortableTable.postSort
  78. });
  79. },
  80. tableSorter: function () {
  81. this.container.tablesorter({
  82. cssHeader: 'headerSort',
  83. cssDesc: 'headerSortUp',
  84. cssAsc: 'headerSortDown',
  85. textExtraction: sortableTable.extractor
  86. }).on('sortEnd', sortableTable.postSort);
  87. },
  88. extractor: function (node) {
  89. return node.textContent || node.innerText;
  90. },
  91. postSort: function () {
  92. sortableTable.color();
  93. sortableTable.counter();
  94. },
  95. noteToggle: function () {
  96. var span = $('<a href="#" class="brackets tooltip" title="Toggle note">Hide</a>').click(function (e) {
  97. e.preventDefault();
  98. $('#drag_drop_textnote > :first-child').toggle();
  99. var $this = $(this);
  100. $this.text($this.text() === 'Hide' ? 'Show' : 'Hide');
  101. });
  102. $('#sorting_head').append(' ', span);
  103. },
  104. checks: function () {
  105. this.check.on('click', 'input', function () {
  106. var s = this.checked ?
  107. 'td.center :checkbox:not(:checked)' :
  108. 'td.center :checked';
  109. $(s).click();
  110. }).find('span').html('<input type="checkbox" />');
  111. this.container.on('click', 'td > :checkbox', function () {
  112. $(this).parents('tr').toggleClass('row_checked');
  113. }).on('dblclick', 'tr.drag', function () {
  114. $(this).find(':checkbox').click();
  115. });
  116. }
  117. };
  118. sortableTable.init();
  119. });