addClasses.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. function prepareClasses(entries, prefix) {
  2. const resultClasses = [];
  3. entries.forEach(item => {
  4. if (typeof item === 'object') {
  5. Object.keys(item).forEach(classNames => {
  6. if (item[classNames]) {
  7. resultClasses.push(prefix + classNames);
  8. }
  9. });
  10. } else if (typeof item === 'string') {
  11. resultClasses.push(prefix + item);
  12. }
  13. });
  14. return resultClasses;
  15. }
  16. export default function addClasses() {
  17. const swiper = this;
  18. const {
  19. classNames,
  20. params,
  21. rtl,
  22. $el,
  23. device,
  24. support
  25. } = swiper; // prettier-ignore
  26. const suffixes = prepareClasses(['initialized', params.direction, {
  27. 'pointer-events': !support.touch
  28. }, {
  29. 'free-mode': swiper.params.freeMode && params.freeMode.enabled
  30. }, {
  31. 'autoheight': params.autoHeight
  32. }, {
  33. 'rtl': rtl
  34. }, {
  35. 'grid': params.grid && params.grid.rows > 1
  36. }, {
  37. 'grid-column': params.grid && params.grid.rows > 1 && params.grid.fill === 'column'
  38. }, {
  39. 'android': device.android
  40. }, {
  41. 'ios': device.ios
  42. }, {
  43. 'css-mode': params.cssMode
  44. }, {
  45. 'centered': params.cssMode && params.centeredSlides
  46. }], params.containerModifierClass);
  47. classNames.push(...suffixes);
  48. $el.addClass([...classNames].join(' '));
  49. swiper.emitContainerClasses();
  50. }