posts_list.js 1.3 KB

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