Projet

Général

Profil

Paste
Télécharger (2,82 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / calendar / js / calendar_overlap.js @ 76df55b7

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

    
12
      // Add the grippie icon
13
      $(this).prepend('<div class="grippie"></div>').mousedown(startDrag);
14

    
15
      function startDrag(e) {
16
        start_y = divider.offset().top;
17
        $(document).mousemove(performDrag).mouseup(endDrag);
18
        return false;
19
      }
20

    
21
      function performDrag(e) {
22
        var offset = e.pageY - start_y;
23
        var mwc = $('#multi-day-container');
24
        var sdc = $('#single-day-container');
25
        var mwc_height = mwc.height();
26
        var sdc_height = sdc.height();
27
        var max_height = mwc_height + sdc_height;
28
        mwc.height(Math.min(max_height,Math.max(0,mwc_height + offset)));
29
        sdc.height(Math.min(max_height,Math.max(0,sdc_height - offset)));
30
        start_y = divider.offset().top;
31
        return false;
32
      }
33

    
34
      function endDrag(e) {
35
        $(document).unbind("mousemove", performDrag).unbind("mouseup", endDrag);
36
      }
37
     });
38

    
39
    $('.single-day-footer:not(.single-day-footer-processed)').each(function() {
40
      var divider = $(this).addClass('single-day-footer-processed');
41
      var start_y = divider.offset().top;
42

    
43
      // Add the grippie icon
44
      $(this).prepend('<div class="grippie"></div>').mousedown(startDrag);
45

    
46
      function startDrag(e) {
47
        start_y = divider.offset().top;
48
        $(document).mousemove(performDrag).mouseup(endDrag);
49
        return false;
50
      }
51

    
52
      function performDrag(e) {
53
        var offset = e.pageY - start_y;
54
        var sdc = $('#single-day-container');
55
        sdc.height(Math.max(0,sdc.height() + offset));
56
        start_y = divider.offset().top;
57
        return false;
58
      }
59

    
60
      function endDrag(e) {
61
        $(document).unbind("mousemove", performDrag).unbind("mouseup", endDrag);
62
      }
63
     });
64

    
65
     // Size the window
66
     calendar_resizeViewport($);
67
  }
68
};
69
})(jQuery);
70

    
71
// Scroll the viewport to the first item
72
function calendar_scrollToFirst($) {
73
   if ($('div.first_item').size() > 0 ) {
74
      var y = $('div.first_item').offset().top - $('#single-day-container').offset().top ;
75
      $('#single-day-container').scrollTop(y);
76
   }
77
}
78

    
79
// Size the single day view
80
function calendar_resizeViewport($) {
81
  // Size of the browser window
82
  var viewportHeight = window.innerHeight ? window.innerHeight : $(window).height();
83
  var top = $('#single-day-container').offset().top;
84

    
85
  // Give it a 20 pixel margin at the bottom
86
  //$('#single-day-container').height(viewportHeight - top - 20);
87
}