(function ($, Drupal, settings) { "use strict"; Drupal.behaviors.frontNews1 = { attach: function (context) { $(context) .find(".front-news1 .carouel-common").once("front-news1").each(function (){ var owlSetting = $(this).data('settings'); if(!owlSetting){ return } var responsive = {} if(owlSetting.xs){ responsive[0] = { items: owlSetting.xs, } } if(owlSetting.sm){ responsive[750] = { items: owlSetting.sm, } } if(owlSetting.md){ responsive[1024] = { items: owlSetting.md, } } if(owlSetting.lg){ responsive[1200] = { items: owlSetting.lg, margin: 20, } } if(owlSetting.xl){ responsive[1400] = { items: owlSetting.xl, margin: 30, } } var owl = $('.front-news1 .owl-carousel').owlCarousel({ loop: Boolean(owlSetting.loop), autoplayTimeout:owlSetting.autoplayTimeout, autoplay: Boolean(owlSetting.autoPlay), dotsEach: 1, navRewind: false, nav: Boolean(owlSetting.nav), dots:Boolean(owlSetting.dots), margin: 15, autoplayHoverPause:true, responsive: responsive, }); $('.front-news1 .left-btn').on('click', function () { owl.trigger('prev.owl.carousel'); }); $('.front-news1 .right-btn').on('click', function () { owl.trigger('next.owl.carousel'); }); }) } }; Drupal.behaviors.front_news_tab1 = { attach: function (context) { $(context) .find(".front-news1 .owl_news_tab").once("owl_news_tab").each(function (){ var owl = $('.front-news1 .owl_news_tab').owlCarousel({ items: 1, margin: 10, loop: true, autoplay: false, dotsEach: 1, navRewind: false, nav: false, dots:false, }); $('.front-news1 .front_news_tab_menu li').click(function (){ var index = $(this).index(); owl.trigger('to.owl.carousel',index); $('.front-news1 .front_news_tab_menu li').removeClass('active-bg-color border-color'); $(this).addClass('active-bg-color border-color'); }) owl.on('translated.owl.carousel', function (event) { // var index = (event.item.index-1)%(event.item.count) -1; var index = $(context).find(".front-news1 .owl_news_tab").find('.owl-item.active').data('id'); $('.front-news1 .front_news_tab_menu li').removeClass('active-bg-color border-color'); $('.front-news1 .front_news_tab_menu li').eq(index-1).addClass('active-bg-color border-color'); }) }) } }; Drupal.behaviors.front_news_ajax1 = { attach: function (context) { $(context) .find(".block-frontnews1 .view-shouyexinwendaifenlei").once("front_news_ajax1").each(function (){ var selectVal = $(".block-frontnews1 .view-shouyexinwendaifenlei .select-wrapper select").val(); $('.block-frontnews1 .view-shouyexinwendaifenlei .front-news_term li').each(function () { if ($(this).data('id') == selectVal) { $(this).addClass('isActive active-bg-color border-color').siblings().removeClass('isActive active-bg-color border-color'); } }); // 首页新闻Tabs切换逻辑 $(document).on('click', '.block-frontnews1 .view-shouyexinwendaifenlei .front-news_term li', function () { var $id = $(this).data('id'); $('.block-frontnews1 .view-shouyexinwendaifenlei .select-wrapper .form-select').val($id); $('.block-frontnews1 .view-shouyexinwendaifenlei .form-actions .js-form-submit').trigger('click'); //销毁动画事件 }); }) } }; }) (jQuery, Drupal, drupalSettings);