summaryrefslogtreecommitdiff
path: root/modules/slideshow/js/slideshow.js
blob: 1dffbf5a97c6cbf31be753ae995cee912dc0ffff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
(function($) {
  $.gallery_slideshow = {
    interval: 4000,
    timer: null,
    images: [],
    current: -1,
    init: function(data) {
      var self = this;
      var size = $.gallery_get_viewport_size();
      $("body").append(
        '<div id="gSlideshowOverlay" class="ui-dialog-overlay"></div>' +
        '<div class="gLoadingLarge" style="z-index; 2005; width:100%; height:100%">&nbsp</div>' +
        '<div id="gSlideshowButtonPanel"><div class="ui-corner-all">' +
        '<a id="gSlideshowPrevious" href="javascript: $.gallery_slideshow.previous()" />' +
        '<a id="gSlideshowPause" href="javascript: $.gallery_slideshow.pause()" />' +
        '<a id="gSlideshowResume" href="javascript: $.gallery_slideshow.resume()" />' +
        '<a id="gSlideshowNext" href="javascript: $.gallery_slideshow.next()" />' +
        '<a id="gSlideshowClose" href="javascript: $.gallery_slideshow.close()" />' +
        '</div></div>' +
        '<div id="gSlideShowImages"></div>');
      $().bind("mousemove", $.gallery_slideshow._mouse_over);

      // array of {url: xxx, width: nnn, height: nnn}
      for (var i=0; i < data.length; i++) {
        $("#gSlideShowImages").append(
            '<img id="img_' + i + '" src="' + data[i].url + '" width="' + data[i].width + 'px" ' +
            'height="' + data[i].height + 'px"  />');
        $("#gSlideShowImages #img_" + i).load(function() {
          $.gallery_slideshow.images.push("#" +$(this).attr("id"));
          if ($.gallery_slideshow.images.length == 1) {
            $.gallery_slideshow._show_image(null);
            setTimeout(function() {$("#gSlideshowButtonPanel").hide();},
                       $.gallery_slideshow.interval);
          }
        });
      };
      $(window).resize(function() {
        var size = $.gallery_get_viewport_size();
        $("#gSlideshowOverlay").width(size.width()).height(size.height());
        var current = $(".gSlideCurrent");
        var position = $.gallery_auto_fit_window(current.width(), current.height());
        $($.gallery_slideshow.images[$.gallery_slideshow.current].replace("img", "clone"))
          .height(position.height).width(position.width).css({
            top: position.top,
            left: position.left
          });
        });
      },

    close: function(event) {
      $.gallery_slideshow.pause();
      $($.gallery_slideshow.images[$.gallery_slideshow.current].replace("img", "clone")).remove();
      $("#gSlideshowOverlay").remove();
      $("#gSlideShowImages").remove();
      $("#gSlideshowButtonPanel").remove();
      $().unbind("mousemove", $.gallery_slideshow._mouse_over);
    },

    previous: function() {
      $.gallery_slideshow.pause();
      $.gallery_slideshow.current--;

      $.gallery_slideshow.current = --$.gallery_slideshow.current < 0 ?
        $.gallery_slideshow.images.length - 1 : $.gallery_slideshow.current;
      var next_image = $($.gallery_slideshow.images[$.gallery_slideshow.current]);
      $.gallery_slideshow._show_image(next_image);
    },

    next: function() {
      $.gallery_slideshow.pause();
      $.gallery_slideshow.current = ++$.gallery_slideshow.current % $.gallery_slideshow.images.length;
      var next_image = $($.gallery_slideshow.images[$.gallery_slideshow.current]);
      $.gallery_slideshow._show_image(next_image);
    },

    pause: function() {
      if ($.gallery_slideshow.timer) {
        $("#gSlideshowPause").toggle();
        $("#gSlideshowResume").toggle();
        clearTimeout($.gallery_slideshow.timer);
        $.gallery_slideshow.timer = null;
      }
    },

    resume: function() {
      $("#gSlideshowPause").toggle();
      $("#gSlideshowResume").toggle();
      $.gallery_slideshow._show_image(null);
    },

    _mouse_over: function(event) {
      var size = $.gallery_get_viewport_size();
      if (event.pageY < size.height() && size.height() - 100 <= event.pageY) {
        $("#gSlideshowButtonPanel").show();
      } else {
        $("#gSlideshowButtonPanel").hide();
      }
    },

    // If next_image is not null, then this a call from prev or next
    _show_image: function(next_image) {
      var reset_timer = false;
      var previous = $.gallery_slideshow.current;
      if (next_image == null) {
        $.gallery_slideshow.current = ++$.gallery_slideshow.current % $.gallery_slideshow.images.length;
        next_image = $($.gallery_slideshow.images[$.gallery_slideshow.current]);
        reset_timer = true;
      }
      var zIndex = parseInt(next_image.css("zIndex"));
      var position = $.gallery_auto_fit_window(next_image.width(), next_image.height());
      var clone = next_image.clone();

      clone.attr("id", next_image.attr("id").replace("img", "clone"));
      clone.height(position.height).width(position.width).css({
        marginTop: 0, marginLeft: 0, marginBottom: 0, marginRight: 0,
        display: "none",
        position: "absolute",
        zIndex: zIndex + 1,
        top: position.top + "px",
        left: position.left + "px"
      });

      $("body").append(clone);
      clone.fadeIn("slow", function() {
        if (previous >= 0) {
          $($.gallery_slideshow.images[previous].replace("img", "clone")).remove();
        }
        clone.css("zIndex", zIndex);
        if (reset_timer) {
          $.gallery_slideshow.timer =
            setTimeout(function() {$.gallery_slideshow._show_image(null);},
                       $.gallery_slideshow.interval);
        }
      });
    }
  };
})(jQuery);

$(document).ready(function() {
  $("#gSlideshowLink").click(function(event) {
    event.preventDefault();
    $.get($(event.currentTarget).attr("href"), {}, $.gallery_slideshow.init, "json");
    return false;
  });
});