multiselect.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @name Multiselect Module
  3. * @description Select multiple albums or photos.
  4. * @author Tobias Reich
  5. * @copyright 2014 by Tobias Reich
  6. */
  7. multiselect = {
  8. position: {
  9. top: null,
  10. right: null,
  11. bottom: null,
  12. left: null
  13. },
  14. show: function(e) {
  15. if ($('.album:hover, .photo:hover').length!=0) return false;
  16. if (visible.multiselect()) $('#multiselect').remove();
  17. multiselect.position.top = e.pageY;
  18. multiselect.position.right = -1 * (e.pageX - $(document).width());
  19. multiselect.position.bottom = -1 * (multiselect.position.top - $(window).height());
  20. multiselect.position.left = e.pageX;
  21. $('body').append(build.multiselect(multiselect.position.top, multiselect.position.left));
  22. $(document).on('mousemove', multiselect.resize);
  23. },
  24. resize: function(e) {
  25. var mouse_x = e.pageX,
  26. mouse_y = e.pageY,
  27. newHeight,
  28. newWidth;
  29. if (multiselect.position.top===null||
  30. multiselect.position.right===null||
  31. multiselect.position.bottom===null||
  32. multiselect.position.left===null) return false;
  33. if (mouse_y>=multiselect.position.top) {
  34. // Do not leave the screen
  35. newHeight = e.pageY - multiselect.position.top;
  36. if ((multiselect.position.top+newHeight)>=$(document).height())
  37. newHeight -= (multiselect.position.top + newHeight) - $(document).height() + 2;
  38. $('#multiselect').css({
  39. top: multiselect.position.top,
  40. bottom: 'inherit',
  41. height: newHeight
  42. });
  43. } else {
  44. $('#multiselect').css({
  45. top: 'inherit',
  46. bottom: multiselect.position.bottom,
  47. height: multiselect.position.top - e.pageY
  48. });
  49. }
  50. if (mouse_x>=multiselect.position.left) {
  51. // Do not leave the screen
  52. newWidth = e.pageX - multiselect.position.left;
  53. if ((multiselect.position.left+newWidth)>=$(document).width())
  54. newWidth -= (multiselect.position.left + newWidth) - $(document).width() + 2;
  55. $('#multiselect').css({
  56. right: 'inherit',
  57. left: multiselect.position.left,
  58. width: newWidth
  59. });
  60. } else {
  61. $('#multiselect').css({
  62. right: multiselect.position.right,
  63. left: 'inherit',
  64. width: multiselect.position.left - e.pageX
  65. });
  66. }
  67. },
  68. close: function() {
  69. $(document).off('mousemove');
  70. multiselect.position.top = null;
  71. multiselect.position.right = null;
  72. multiselect.position.bottom = null;
  73. multiselect.position.left = null;
  74. lychee.animate('#multiselect', "fadeOut");
  75. setTimeout(function() {
  76. $('#multiselect').remove();
  77. }, 300);
  78. }
  79. }