calendar_overlap.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Create the splitter, set the viewport size, and set the position of the scrollbar to the first item.
  3. */
  4. (function($){
  5. Drupal.behaviors.calendarSetScroll = {
  6. attach: function(context) {
  7. // Make multi-day resizable - stolen/borrowed from textarea.js
  8. $('.header-body-divider:not(.header-body-divider-processed)').each(function() {
  9. var divider = $(this).addClass('header-body-divider-processed');
  10. var start_y = divider.offset().top;
  11. // Add the grippie icon
  12. $(this).prepend('<div class="grippie"></div>').mousedown(startDrag);
  13. function startDrag(e) {
  14. start_y = divider.offset().top;
  15. $(document).mousemove(performDrag).mouseup(endDrag);
  16. return false;
  17. }
  18. function performDrag(e) {
  19. var offset = e.pageY - start_y;
  20. var mwc = $('#multi-day-container');
  21. var sdc = $('#single-day-container');
  22. var mwc_height = mwc.height();
  23. var sdc_height = sdc.height();
  24. var max_height = mwc_height + sdc_height;
  25. mwc.height(Math.min(max_height,Math.max(0,mwc_height + offset)));
  26. sdc.height(Math.min(max_height,Math.max(0,sdc_height - offset)));
  27. start_y = divider.offset().top;
  28. return false;
  29. }
  30. function endDrag(e) {
  31. $(document).unbind("mousemove", performDrag).unbind("mouseup", endDrag);
  32. }
  33. });
  34. $('.single-day-footer:not(.single-day-footer-processed)').each(function() {
  35. var divider = $(this).addClass('single-day-footer-processed');
  36. var start_y = divider.offset().top;
  37. // Add the grippie icon
  38. $(this).prepend('<div class="grippie"></div>').mousedown(startDrag);
  39. function startDrag(e) {
  40. start_y = divider.offset().top;
  41. $(document).mousemove(performDrag).mouseup(endDrag);
  42. return false;
  43. }
  44. function performDrag(e) {
  45. var offset = e.pageY - start_y;
  46. var sdc = $('#single-day-container');
  47. sdc.height(Math.max(0,sdc.height() + offset));
  48. start_y = divider.offset().top;
  49. return false;
  50. }
  51. function endDrag(e) {
  52. $(document).unbind("mousemove", performDrag).unbind("mouseup", endDrag);
  53. }
  54. });
  55. // Size the window
  56. calendar_resizeViewport($);
  57. }
  58. };
  59. })(jQuery);
  60. // Scroll the viewport to the first item
  61. function calendar_scrollToFirst($) {
  62. if ($('div.first_item').size() > 0 ) {
  63. var y = $('div.first_item').offset().top - $('#single-day-container').offset().top ;
  64. $('#single-day-container').scrollTop(y);
  65. }
  66. }
  67. // Size the single day view
  68. function calendar_resizeViewport($) {
  69. // Size of the browser window
  70. var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
  71. var top = $('#single-day-container').offset().top;
  72. // Give it a 20 pixel margin at the bottom
  73. $('#single-day-container').height(viewportHeight - top - 20);
  74. }