multiselect.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 (mobileBrowser()) return false;
  16. if (lychee.publicMode) return false;
  17. if ($('.album:hover, .photo:hover').length!=0) return false;
  18. if (visible.multiselect()) $('#multiselect').remove();
  19. multiselect.position.top = e.pageY;
  20. multiselect.position.right = -1 * (e.pageX - $(document).width());
  21. multiselect.position.bottom = -1 * (multiselect.position.top - $(window).height());
  22. multiselect.position.left = e.pageX;
  23. $('body').append(build.multiselect(multiselect.position.top, multiselect.position.left));
  24. $(document).on('mousemove', multiselect.resize);
  25. },
  26. resize: function(e) {
  27. var mouse_x = e.pageX,
  28. mouse_y = e.pageY,
  29. newHeight,
  30. newWidth;
  31. if (multiselect.position.top===null||
  32. multiselect.position.right===null||
  33. multiselect.position.bottom===null||
  34. multiselect.position.left===null) return false;
  35. if (mouse_y>=multiselect.position.top) {
  36. // Do not leave the screen
  37. newHeight = e.pageY - multiselect.position.top;
  38. if ((multiselect.position.top+newHeight)>=$(document).height())
  39. newHeight -= (multiselect.position.top + newHeight) - $(document).height() + 2;
  40. $('#multiselect').css({
  41. top: multiselect.position.top,
  42. bottom: 'inherit',
  43. height: newHeight
  44. });
  45. } else {
  46. $('#multiselect').css({
  47. top: 'inherit',
  48. bottom: multiselect.position.bottom,
  49. height: multiselect.position.top - e.pageY
  50. });
  51. }
  52. if (mouse_x>=multiselect.position.left) {
  53. // Do not leave the screen
  54. newWidth = e.pageX - multiselect.position.left;
  55. if ((multiselect.position.left+newWidth)>=$(document).width())
  56. newWidth -= (multiselect.position.left + newWidth) - $(document).width() + 2;
  57. $('#multiselect').css({
  58. right: 'inherit',
  59. left: multiselect.position.left,
  60. width: newWidth
  61. });
  62. } else {
  63. $('#multiselect').css({
  64. right: multiselect.position.right,
  65. left: 'inherit',
  66. width: multiselect.position.left - e.pageX
  67. });
  68. }
  69. },
  70. stopResize: function() {
  71. $(document).off('mousemove');
  72. },
  73. getSize: function() {
  74. if (!visible.multiselect()) return false;
  75. return {
  76. top: $('#multiselect').offset().top,
  77. left: $('#multiselect').offset().left,
  78. width: parseInt($('#multiselect').css('width').replace('px', '')),
  79. height: parseInt($('#multiselect').css('height').replace('px', ''))
  80. }
  81. },
  82. getSelection: function(e) {
  83. var tolerance = 150,
  84. id,
  85. ids = [],
  86. offset,
  87. size = multiselect.getSize();
  88. if (visible.contextMenu()) return false;
  89. if (!visible.multiselect()) return false;
  90. $('.photo, .album').each(function() {
  91. offset = $(this).offset();
  92. if (offset.top>=(size.top-tolerance)&&
  93. offset.left>=(size.left-tolerance)&&
  94. (offset.top+206)<=(size.top+size.height+tolerance)&&
  95. (offset.left+206)<=(size.left+size.width+tolerance)) {
  96. id = $(this).data('id');
  97. if (id!=='0'&&id!==0&&id!=='f'&&id!=='s'&&id!==null&id!==undefined) {
  98. ids.push(id);
  99. $(this).addClass('active');
  100. }
  101. }
  102. });
  103. if (ids.length!=0&&visible.album()) contextMenu.photoMulti(ids, e);
  104. else if (ids.length!=0&&visible.albums()) contextMenu.albumMulti(ids, e);
  105. else multiselect.close();
  106. },
  107. close: function() {
  108. multiselect.stopResize();
  109. multiselect.position.top = null;
  110. multiselect.position.right = null;
  111. multiselect.position.bottom = null;
  112. multiselect.position.left = null;
  113. lychee.animate('#multiselect', 'fadeOut');
  114. setTimeout(function() {
  115. $('#multiselect').remove();
  116. }, 300);
  117. }
  118. }