PageSourceSearch

https://www.minnesotaalumni.org/files/component/imagecmp/scripts/public.gallery.js

js minnesotaalumni.org collected 2026-09-24 20:38:17 UTC 4,963 bytes, 172 lines download raw bytes

1(function($) {
2
3  var Gallery = function(gallery, overrides) {
4    this.gallery = gallery;
5    this.defaults = {
6      includeCount: true,
7      imageAdvance: true,
8      callbacks: {
9        ready: function(gallery) {},
10        beforeChange: function(gallery, index) {},
11        afterChange: function(gallery, index) {}
12      }
13    };
14    this.overrides = (typeof overrides !== 'undefined' ? overrides : {});
15    
16    this.init = function() {
17      this.gallery.data('gallery', this);
18      this.settings = $.extend(true, this.defaults, (typeof Webe.galleryConfig !== "undefined" ? Webe.galleryConfig : {}), this.overrides);
19      
20      delete this.overrides;
21      delete this.defaults;
22
23      this.structure();
24
25      return this;
26    };
27
28    this.structure = function() {
29      var gallery = this.gallery,
30        settings = this.settings;
31
32      gallery.attr('data-gallery-state', 'loading');
33
34      this.slides = $('.subcomponent-imagechild', gallery);
35      this.slides.first().addClass('is-active');
36
37      this.controls = $('<div class="gallery-controls" />');
38      if (settings.includeCount) {
39        this.controls.append('<div class="gallery-controls-count"><span class="count">1</span> <span class="count-of">of</span> <span class="total">' + this.slides.length + '</span></div>');
40      }
41      this.controls.append('<a class="gallery-controls-arrow gallery-controls-prev" data-direction="-1" href="#prev">Previous</a><a class="gallery-controls-arrow gallery-controls-next" data-direction="1" href="#next">Next</a>');
42      
43      gallery.append(this.controls);
44      gallery.wrapInner('<div class="gallery-wrap" />');
45
46      this.gallery.trigger('galleryBuilt');
47      this.bind();
48
49      return this;
50    };
51    
52    this.update = function() {
53      var that = this,
54        gallery = this.gallery,
55        index = parseInt(this.count.text(), 10);
56
57      that.slides = $('.subcomponent-imagechild', gallery);
58      
59      that.total = $('.gallery-controls-count .total', that.controls);
60      that.total.text(that.slides.length);
61      
62      that.jumpTo(index - 1);
63
64      return that;
65    };
66
67    this.bind = function() {
68      var that = this,
69        gallery = this.gallery,
70        settings = this.settings;
71      
72      that.count = $('.gallery-controls-count .count', that.controls);
73      
74      that.controls.on('mousedown', '.gallery-controls-arrow', function(e) {
75        e.preventDefault();
76        e.stopPropagation();
77      });
78
79      that.controls.on('click', '.gallery-controls-arrow', function(e) {
80        e.preventDefault();
81        var direction = parseInt($(this).attr('data-direction'), 10),
82          active = that.slides.filter('.is-active'),
83          next = null;
84
85        if (direction < 0) {
86          next = active.prev('.subcomponent-imagechild');
87          if (!next.length) {
88            next = that.slides.length - 1;
89          }
90        } else if (direction > 0) {
91          next = active.next('.subcomponent-imagechild');
92          if (!next.length) {
93            next = 0;
94          }
95        }
96  
97        next = (next === parseInt(next, 10) ? next : that.slides.index(next));
98        that.jumpTo(next);
99      });
100
101      if (settings.imageAdvance && !$('body').hasClass('page-storybuilder')) {
102        gallery.on('click', 'img', function() {
103          that.jumpTo(parseInt(that.count.text(), 10));
104        });
105      }
106
107      if (typeof settings.callbacks.ready === 'function') {
108        settings.callbacks.ready(that.gallery);
109      }
110      gallery.attr('data-gallery-state', 'ready');
111
112      return that;
113    };
114
115    this.jumpTo = function(index, active) {
116      var that = this,
117        settings = this.settings,
118        next;
119
120      if (index >= that.slides.length) {
121        index = 0;
122      } else if (index < 0) {
123        index = that.slides.length - 1;
124      }
125      
126      active = (typeof active === 'undefined' ? that.slides.filter('.is-active') : active);
127      next = that.slides.eq(index);
128
129      if (typeof settings.callbacks.beforeChange === 'function') {
130        settings.callbacks.beforeChange(that.gallery, index);
131      }
132
133      if (settings.includeCount) {
134        that.count.text(index + 1);
135      }
136
137      active.removeClass('is-active');
138      next.addClass('is-active');
139
140      if (typeof settings.callbacks.afterChange === 'function') {
141        settings.callbacks.afterChange(that.gallery, index);
142      }
143
144      return that;
145    };
146
147    this.destroy = function() {
148      var active = this.slides.filter('.is-active');
149      active.removeClass('is-active');
150
151      this.gallery.trigger('galleryDestroyed');
152      this.gallery.removeAttr('data-gallery-state');
153      $('.gallery-wrap > *', this.gallery).unwrap();
154      this.controls.remove();
155
156      return this;
157    };
158
159
160    return this;
161  };
162
163
164  Webe.ImgGallery = Gallery;
165
166
167  // auto-construct and -init galleries
168  $('.component-imagecmp.type-gallery').each(function() {
169    new Webe.ImgGallery($(this)).init();
170  });
171
172})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.