multiselect.js 3.8 KB

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