lib
7 years ago
addon-licenses.js
7 years ago
admin-compat.js
7 years ago
admin-fields.js
7 years ago
admin-form.js
7 years ago
admin-global.js
7 years ago
admin-order.js
7 years ago
custom-spinner.js
7 years ago
help.js
7 years ago
rating-edit.js
7 years ago
view-category-filter.js
7 years ago
views.js
7 years ago
admin-order.js
129 lines
| 1 | /** |
| 2 | * Admin list order |
| 3 | * Strong Testimonials |
| 4 | */ |
| 5 | |
| 6 | // set cell widths to prevent shrinkage |
| 7 | function setCellWidths() { |
| 8 | jQuery('td, th', 'table.posts').each(function () { |
| 9 | var cell = jQuery(this); |
| 10 | cell.width(cell.width()); |
| 11 | }); |
| 12 | }; |
| 13 | |
| 14 | // reset cell widths |
| 15 | function resetCellWidths(reset) { |
| 16 | jQuery('td, th', 'table.posts').each(function () { |
| 17 | var cell = jQuery(this); |
| 18 | cell.width(''); |
| 19 | }).promise().done(setCellWidths); |
| 20 | }; |
| 21 | |
| 22 | // Returns a function, that, as long as it continues to be invoked, will not |
| 23 | // be triggered. The function will be called after it stops being called for |
| 24 | // N milliseconds. If `immediate` is passed, trigger the function on the |
| 25 | // leading edge, instead of the trailing. |
| 26 | // Thanks http://davidwalsh.name/javascript-debounce-function |
| 27 | function debounce(func, wait, immediate) { |
| 28 | var timeout; |
| 29 | return function () { |
| 30 | var context = this, args = arguments; |
| 31 | var later = function () { |
| 32 | timeout = null; |
| 33 | if (!immediate) func.apply(context, args); |
| 34 | }; |
| 35 | var callNow = immediate && !timeout; |
| 36 | clearTimeout(timeout); |
| 37 | timeout = setTimeout(later, wait); |
| 38 | if (callNow) func.apply(context, args); |
| 39 | }; |
| 40 | }; |
| 41 | |
| 42 | // window resize listener |
| 43 | var myEfficientFn = debounce(resetCellWidths, 100); |
| 44 | window.addEventListener('resize', myEfficientFn); |
| 45 | |
| 46 | |
| 47 | jQuery(document).ready(function ($) { |
| 48 | |
| 49 | $.fn.strongSort = function (options) { |
| 50 | |
| 51 | var $this = this; |
| 52 | var $handles = $(options.handles); |
| 53 | |
| 54 | var toggleReorder = function () { |
| 55 | $this.sortable("enable"); |
| 56 | $handles.show(); |
| 57 | } |
| 58 | |
| 59 | this.sortable({ |
| 60 | disabled: true, // initially disabled |
| 61 | items: 'tr', |
| 62 | axis: 'y', |
| 63 | handle: options.handles, |
| 64 | forcePlaceholderSize: true, |
| 65 | placeholder: "sortable-placeholder", |
| 66 | start: function (e, ui) { |
| 67 | // set height of placeholder to match current dragged element |
| 68 | ui.placeholder.height(ui.helper.height()); |
| 69 | ui.helper.css("cursor", "move"); |
| 70 | }, |
| 71 | helper: function (e, ui) { |
| 72 | var $originals = ui.children(); |
| 73 | var $helper = ui.clone(); |
| 74 | $helper.children().each(function (index) { |
| 75 | // set helper cell sizes to match the original sizes |
| 76 | $(this).width($originals.eq(index).width()); |
| 77 | }); |
| 78 | return $helper; |
| 79 | }, |
| 80 | update: function (e, ui) { |
| 81 | ui.item.find(".column-handle").addClass("refresh"); |
| 82 | $.post(ajaxurl, { |
| 83 | action: 'update-menu-order', |
| 84 | order: $('#the-list').sortable('serialize'), |
| 85 | }, |
| 86 | function (data) { |
| 87 | // update menu order shown |
| 88 | var $orders = $(".menu-order"); |
| 89 | var obj = JSON.parse(data); |
| 90 | var orderArray = $.map(obj, function (val, i) { |
| 91 | $orders.eq(i).html(val); |
| 92 | }); |
| 93 | }) |
| 94 | .done(function () { |
| 95 | // update zebra striping |
| 96 | $("#the-list").find("tr:even").removeClass("alternate"); |
| 97 | ui.item.effect('highlight', {}, 2000); |
| 98 | ui.item.find(".column-handle").removeClass("refresh"); |
| 99 | }) |
| 100 | |
| 101 | } |
| 102 | }); |
| 103 | |
| 104 | toggleReorder(); |
| 105 | |
| 106 | return this; |
| 107 | } |
| 108 | |
| 109 | // Init |
| 110 | |
| 111 | setCellWidths(); |
| 112 | |
| 113 | $("#screen-meta").on("change", ".metabox-prefs", resetCellWidths); |
| 114 | |
| 115 | $("#the-list").strongSort({ |
| 116 | handles: 'td.column-handle' |
| 117 | }); |
| 118 | |
| 119 | $("td.column-handle").hover( |
| 120 | function () { |
| 121 | $(this).closest("tr").addClass("reorder-hover"); |
| 122 | }, |
| 123 | function () { |
| 124 | $(this).closest("tr").removeClass("reorder-hover"); |
| 125 | } |
| 126 | ); |
| 127 | |
| 128 | }); |
| 129 |