posts_list.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. Template.postsList.onRendered(function () {
  2. this.find('.wrapper')._uihooks = {
  3. moveElement: function (node, next) {
  4. var $node = $(node);
  5. var $next = $(next);
  6. var oldTop = $node.offset().top;
  7. var height = $node.outerHeight(true);
  8. var $inBetween = $next.nextUntil(node);
  9. // This was in the wrong direction, try the other way..
  10. if ($inBetween.length === 0) {
  11. $inBetween = $node.nextUntil(next);
  12. }
  13. // Now put node into place
  14. $node.insertBefore(next);
  15. // Measure new top.
  16. var newTop = $node.offset().top;
  17. // Move node "back" to where it was before.
  18. $node
  19. .removeClass('animate')
  20. .css('top', oldTop - newTop);
  21. // Push every other element down (or up) to put them back.
  22. $inBetween
  23. .removeClass('animate')
  24. .css('top', oldTop < newTop ? height : -1 * height);
  25. // Force a redraw.
  26. $node.offset();
  27. // Reset everything to 0, animated.
  28. $node.addClass('animate').css('top', 0);
  29. $inBetween.addClass('animate').css('top', 0);
  30. }
  31. };
  32. });