PageSourceSearch

https://rare.org/wp-content/themes/rare/js/scripts.js?ver=2.0.7

js rare.org collected 2026-09-24 18:00:17 UTC 10,101 bytes, 320 lines download raw bytes

1// Custom scripts file
2
3jQuery( document ).ready(function( $ ) {
4  'use strict';
5
6  // Listen for clicks to translate button
7  (function(translateButtons) {
8    function isChildOf(className, node) {
9      let cur = node;
10
11      do {
12        if (cur.classList.contains(className)) {
13          return true;
14        }
15      } while (cur = cur.parentElement)
16
17      return false;
18    }
19
20    let currentlyDisplayWidget = false;
21
22    function setWidgetVisibility(parent) {
23      const selectWidget = document.querySelector('.translator');
24
25      if (parent) {
26        const domRect = parent.getBoundingClientRect();
27        selectWidget.style.left = (domRect.x - 54) + 'px';
28        selectWidget.style.top = (domRect.y + 2) + 'px';
29      }
30
31      selectWidget.style.display = currentlyDisplayWidget ? 'block' : 'none';
32
33      // Focus on next paint
34      setTimeout(function() { document.querySelector('.gt_selector').focus() }, 0);
35    }
36
37    translateButtons.forEach(function(translateButton) { translateButton.addEventListener('click', function(e) {
38      if (isChildOf('translator', e.target)) {
39        return;
40      }
41
42      currentlyDisplayWidget = !currentlyDisplayWidget;
43      setWidgetVisibility(translateButton);
44    })});
45
46    document.addEventListener('click', function(e) {
47      if (isChildOf('translate-label', e.target) || isChildOf('translator', e.target)) {
48        return;
49      }
50      currentlyDisplayWidget = false;
51      setWidgetVisibility();
52    });
53
54    document.querySelector('.gt_selector')
55    .addEventListener('change', function() {
56      currentlyDisplayWidget = false;
57      setWidgetVisibility();
58    });
59
60    setWidgetVisibility();
61  })(document.querySelectorAll('.translate-label'));
62
63  // Generic function that runs on window resize.
64  function resizeStuff() {
65  }
66
67  // gravity forms function to position the legend
68  // correctly below the form instead of above
69  if ( $('.rare-gform-legend').length ) {
70    let legend = $('.rare-gform-legend');
71    let form = legend.parent().parent('.gform_heading').next('form');
72    form.find('.gform_body.gform-body').after(legend);
73
74  }
75
76  // Runs function once on window resize.
77  var TO = false;
78  $(window).resize(function () {
79    if (TO !== false) {
80      clearTimeout(TO);
81    }
82
83    // 200 is time in miliseconds.
84    TO = setTimeout(resizeStuff, 200);
85  }).resize();
86  /*
87  $(window).setBreakpoints({
88    // use only largest available vs use all available
89      distinct: true,
90    // array of widths in pixels where breakpoints
91    // should be triggered
92      breakpoints: [
93        0,
94        600,
95        980
96      ]
97    });
98
99    $(window).bind('enterBreakpoint0',function() {
100
101      $('.overlay-block').next().css('padding-top', "30px");
102      $('.hero-bg-image:not(.hero-bg-image--no-img)').next().css('margin-top', 0);
103    });
104
105    $(window).bind('enterBreakpoint600',function() {
106      var $overlay_padding = $('.overlay-block').height();
107      $overlay_padding = $overlay_padding + 30;
108
109      var $hero_padding = $('.hero-bg-image:not(.hero-bg-image--no-img)').height();
110      $hero_padding = $hero_padding - 30;
111
112      $('.overlay-block').next().css('padding-top', "30px");
113      $('.hero-bg-image:not(.hero-bg-image--no-img)').next().css('margin-top', $hero_padding);
114    });
115
116    $(window).bind('enterBreakpoint980',function() {
117      var $overlay_padding = $('.overlay-block').height();
118      $overlay_padding = $overlay_padding + 30;
119
120      var $hero_padding = $('.hero-bg-image:not(.hero-bg-image--no-img)').height();
121      $hero_padding = $hero_padding - 30;
122
123      $('.overlay-block').next().css('padding-top', $overlay_padding);
124      $('.hero-bg-image:not(.hero-bg-image--no-img)').next().css('margin-top', $hero_padding);;
125    });
126  */
127
128  // Wowjs, animate.css init
129  new WOW().init();
130  $('.homepage .l-header').removeClass('l-header--fixed');
131
132  $(window).scroll(function() {
133    var scroll = $(window).scrollTop();
134
135    if (scroll >= 150) {
136        $('.has-hero:not(.archive) .l-header').addClass('l-header--fixed');
137        $('.has-no-hero .l-header').addClass('l-header--fixed');
138    } else {
139        $('.has-hero:not(.archive) .l-header').removeClass('l-header--fixed');
140        $('.has-no-hero .l-header').removeClass('l-header--fixed');
141    }
142
143    if (scroll >= 150) {
144      $('.homepage .l-header').addClass('l-header--fixed');
145    } else {
146        $('.homepage .l-header').removeClass('l-header--fixed');
147    }
148
149    if (scroll >= 350) {
150      $('.menu--sidebar').addClass('menu--fixed');
151    } else {
152        $('.menu--sidebar').removeClass('menu--fixed');
153    }
154  });
155
156  $('.accordion-item__title').click(function() {
157    $(this).next().slideToggle();
158    $(this).toggleClass('is-open');
159  });
160
161  $('.facets__toggle').on('click', function() {
162    var isExpanded = $(this).attr('aria-expanded') === 'true';
163    $(this).attr('aria-expanded', String(!isExpanded));
164  });
165
166  $('.leadership-grid:not(.board-grid) .content-grid-item').on('click', function(e) {
167
168    $('.content-grid-item').not($(this)).removeClass('is-open').addClass('is-closed').find('.content-grid-item__quote').slideUp();
169
170
171    $(this).find('.content-grid-item__quote').slideToggle();
172
173    $(this).toggleClass('is-open is-closed');
174
175    e.stopPropagation();
176    e.preventDefault();
177
178  });
179
180  $('.leadership-grid:not(.board-grid) .content-grid-item .button').on('click', function(e){
181    // stop the event from bubbling.
182      e.stopPropagation();
183  });
184
185  //$('.leadership-grid:not(.board-grid) .content-grid-item .button').unbind('click');
186
187  $('html').click(function(){
188    if( !$(event.target).hasClass('.content-grid-item.is-open') ){
189        $('.content-grid-item.is-open').find('.content-grid-item__quote').slideUp();
190        $('.content-grid-item.is-open').toggleClass('is-closed is-open');
191    }
192  });
193
194  $('.contact-countries .contact-item:first-child').addClass('is-active');
195
196  $('.contact__content .contact__details:first-child').addClass('is-active');
197
198  $('.contact-countries .contact-item').click(function() {
199
200    $('.contact-countries .contact-item').removeClass('is-active');
201    $('.contact__content .contact__details').removeClass('is-active');
202
203    $(this).each(function() {
204      var $country = $(this).attr('data-country-name');
205
206      $(this).toggleClass('is-active');
207
208      $('.contact__content').find('[data-country="' + $country + '"]').addClass('is-active');
209    });
210  });
211
212  //$('.l-sidebar__sidebar .menu--sidebar').scrollspy({ offset: -140, activeClass: 'is-active', animate: true });
213
214  /*$('.menu--sidebar .menu__link').click(function() {
215      $('.menu--sidebar .menu__link').removeClass('is-active');
216      $(this).toggleClass('is-active');
217  });*/
218
219  $('.owl-carousel.overlay-cards__content').owlCarousel({
220    responsiveClass: true,
221    nav: true,
222    loop: true,
223    margin: 10,
224    responsive:{
225        0:{
226            items: 1
227        },
228        600:{
229            items: 3
230        },
231        1000:{
232          items: 4
233        }
234    }
235  });
236
237  $('.owl-carousel.testimonials__content').owlCarousel({
238    loop: true,
239    margin: 0,
240    nav: true,
241    items: 1,
242    autoHeight: true
243  });
244
245  // Carousel — split layout (image left / text right)
246  var $imageCarousel = $('.owl-carousel.image-carousel__slides');
247  $imageCarousel.owlCarousel({
248    rewind: true,
249    margin: 0,
250    nav: true,
251    navText: [
252      '<div class="screen-reader-text">Previous</div><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" style="transform:scale
252X(-1)"><path fill="currentColor" d="M12.6 12L8.7 8.1q-.275-.275-.275-.7t.275-.7t.7-.275t.7.275l4.6 4.6q.15.15.213.325t.062.375t-.062.375t-.213.325l-4.6 4.6q-.275.275-.7.275t-.7-.275t-.275-.7t.275-.7z"/></svg>',
253      '<div class="screen-reader-text">Next</div><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><path fill="currentColor" d="M12.6 12L8.7 8.1q-.275-.275-.275-.7t.275-.7t.7-.275t.7.275l4.6 4.6q.15.15.213.325t.062.375t-.062.375t-.213.325l-4.6 4.6q-.275.275-.7.275t-.7-.275t-.275-.7t.275-.7z"/></svg>'
254    ],
255    keyboard: true,
256    dots: true,
257    items: 1,
258    autoHeight: false
259  });
260
261  // Keyboard navigation: arrow keys when focused within the carousel
262  $imageCarousel.closest('.image-carousel').on('keydown', function (e) {
263    if (e.key === 'ArrowLeft') {
264      $imageCarousel.trigger('prev.owl.carousel');
265      e.preventDefault();
266    } else if (e.key === 'ArrowRight') {
267      $imageCarousel.trigger('next.owl.carousel');
268      e.preventDefault();
269    }
270  });
271
272  //Sticky sidebar menu
273  var $sticky = $('.menu--fixed');
274  var $stickyrStopper = $('.l-footer');
275  if (!!$sticky.offset()) { // make sure ".menu--fixed" element exists
276
277    var generalSidebarHeight = $sticky.innerHeight();
278    var stickyTop = $sticky.offset().top;
279    var stickOffset = 0;
280    var stickyStopperPosition = $stickyrStopper.offset().top;
281    var stopPoint = stickyStopperPosition - generalSidebarHeight - stickOffset;
282    var diff = stopPoint + stickOffset;
283
284    $(window).scroll(function(){ // scroll event
285      var windowTop = $(window).scrollTop(); // returns number
286
287      if (stopPoint < windowTop) {
288          $sticky.css({ position: 'absolute', top: diff });
289      } else if (stickyTop < windowTop+stickOffset) {
290          $sticky.css({ position: 'fixed', top: stickOffset });
291      } else {
292          $sticky.css({position: 'absolute', top: 'initial'});
293      }
294    });
295  }
296
297  /**
298   * Hide empty <p> in WYSIWYG block
299   */
300  if ( $('.wysiwyg__content').length ) {
301    $('.wysiwyg__content').find('.wysiwyg--content').each(function(i, e) {
302      $(e).children('p').each(function(n, p) {
303        if($.trim($(this).text()) == '' && $(this).children().length == 0){
304          console.log('hiding', $(this));
305          $(this).hide();
306          }
307      })
308    });
309  }
310
311  $('.wysiwyg__content').find('.wysiwyg--content').find('.gform_footer.top_label').hide();
312
313  // Scroll to gform after it has been submitted
314  if ($('.gform_confirmation_wrapper').length) {
315    $('html, body').animate({
316      scrollTop: $('.gform_confirmation_wrapper').offset().top - 300
317    }, 500);
318  }
319
320});

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.