/* @file * A JavaScript file for implementing slideshows & carousels. * This should be loaded sitewide. */ (function ($, Drupal, window, document, undefined) { // To understand behaviors, see https://drupal.org/node/756722#behaviors Drupal.behaviors.slidersCarousels = { attach: function (context, settings) { // Check if the class exist for owl-carousel to fix the bug related to legislative calendar if ( $( '.owl-carousel' ).length ) { $('.owl-carousel').owlCarousel({ items: 1, nav: true, dots: false, responsiveClass: true, navText: ['Previous Photo', 'Next Photo'], }); } // Add bootstrap carousel classes. $('.view-housegov-slideshow .view-content').addClass('carousel-inner'); $('.view-housegov-slideshow .carousel-item').eq(0).addClass('active'); $('.view-housegov-slideshow .carousel-indicators li').eq(0).addClass('active'); // Add classes and settings for the sliding calendar widget. $('#carousel-calendar .carousel-item').eq(1).addClass('active'); // Initialize slider with the right options $('#carousel-calendar').carousel({ interval: false, keyboard: false }); // Slide to the selected month, account for year differences in Dec/Jan var selectedYear = parseInt($(location).attr('pathname').replace('/legislative-activity', '').replace('/', '').substr(0, 4)); var selectedMonth = parseInt($(location).attr('pathname').replace('/legislative-activity', '').replace('/', '').substr(5, 2)); if (selectedMonth) { var currentYear = new Date().getFullYear(); var currentMonth = new Date().getMonth(); var slideTo = 1; if (selectedYear > currentYear) { slideTo = (selectedMonth + 12) - currentMonth; } else if (selectedYear < currentYear) { slideTo = selectedMonth - currentMonth - 10; } else { slideTo = selectedMonth - currentMonth; } $('#carousel-calendar').carousel(slideTo); } // Hide previous and next control buttons for the first and the last slides $('#carousel-calendar').on('slid.bs.carousel', function() { $('.carousel-control').show(); if ($('.carousel-item:first-of-type').hasClass('active')) { $('.left.carousel-control').hide(); $('.right.carousel-control').focus(); } if ($('.carousel-item:last-of-type').hasClass('active')) { $('.right.carousel-control').hide(); $('.left.carousel-control').focus(); } }); } }; })(jQuery, Drupal, this, this.document);