"use strict"; (function ($) { $.fn.extend({ /** * @param { String } containerClassName - swiper-container盒子类名 * @param { Object } - swiper内置属性 * */ createSwiper: function createSwiper(containerClassName) { var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, _ref$autoplay = _ref.autoplay, autoplay = _ref$autoplay === void 0 ? false : _ref$autoplay, _ref$loop = _ref.loop, loop = _ref$loop === void 0 ? false : _ref$loop, _ref$slidesPerGroup = _ref.slidesPerGroup, slidesPerGroup = _ref$slidesPerGroup === void 0 ? 1 : _ref$slidesPerGroup, _ref$slidesPerView = _ref.slidesPerView, slidesPerView = _ref$slidesPerView === void 0 ? [4, 3, 1.1] : _ref$slidesPerView, _ref$spaceBetween = _ref.spaceBetween, spaceBetween = _ref$spaceBetween === void 0 ? [28, 32, 18] : _ref$spaceBetween, _ref$paginationType = _ref.paginationType, paginationType = _ref$paginationType === void 0 ? 'fraction' : _ref$paginationType; var moduleClassName = $(this).attr('class'); var valid = $(this).autoToggleClassName(containerClassName); if (!valid) return false; return new Swiper(".".concat(moduleClassName, " .").concat(containerClassName), { autoplay: autoplay, loop: loop, slidesPerGroup: slidesPerGroup, breakpoints: { 320: { slidesPerView: slidesPerView[2], spaceBetween: spaceBetween[2] }, 768: { slidesPerView: slidesPerView[1], spaceBetween: spaceBetween[1] }, 1460: { slidesPerView: slidesPerView[0], spaceBetween: spaceBetween[0] } }, navigation: { nextEl: ".".concat(moduleClassName, " .swiper-button-prev"), prevEl: ".".concat(moduleClassName, " .swiper-button-prev") }, pagination: { el: ".".concat(moduleClassName, " .swiper-pagination"), type: paginationType } }); }, //自动添加删除swiper-wrapper, swiper-slide类名, 默认添加 autoToggleClassName: function autoToggleClassName(containerName) { var flag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; var moduleName = $(this).attr('class'); var wrap = $(".".concat(moduleName, " .").concat(containerName)).children()[0]; if (!wrap) return false; var slides = $(wrap).children(); if (!slides) return false; if (flag && !$(wrap).hasClass('swiper-wrapper')) { $(wrap).addClass('swiper-wrapper'); } else if (!flag) { $(wrap).removeClass('swiper-wrapper'); } $(slides).each(function () { if (flag && !$(this).hasClass('swiper-slide')) { $(this).addClass('swiper-slide'); } else if (!flag) { $(this).removeClass('swiper-slide'); } }); return flag; } }); })(jQuery); //添加需要响应浏览器窗口大小改变的方法, 第一个参数为width var resWidthObj = { fnMap: new Map(), debounceFn: [], hasNewFn: false, hasDelFn: false, add: function add(fn) { if (!this.fnMap.has(fn)) { this.fnMap.set(fn, true); this.hasNewFn = true; this.start(fn); } else { console.log('has already function' + fn); } }, delete: function _delete(fn) { if (this.fnMap.has(fn)) { this.fnMap.delete(fn); this.hasDelFn = true; this.start(); } }, start: function start() { var _this = this; var addFn = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {}; var width = $(window).width(); if (this.hasNewFn || this.hasDelFn) { this.debounceFn = []; addFn(width); this.fnMap.forEach(function (key, fn) { _this.debounceFn.push(_this.debounce(fn, 1000)); }); this.hasNewFn = false; this.hasDelFn = false; } //有添加或者删除方法时 重新生成防抖函数组 $(window).resize(function () { width = $(window).width(); _this.debounceFn.forEach(function (fn) { fn(width); }); }); }, debounce: function debounce(fn, delay) { var timer = null; return function () { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } clearTimeout(timer); timer = setTimeout(function () { fn.apply(void 0, args); }, delay); }; } };