utils.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function isObject(o) {
  2. return typeof o === 'object' && o !== null && o.constructor && Object.prototype.toString.call(o).slice(8, -1) === 'Object';
  3. }
  4. function extend(target, src) {
  5. const noExtend = ['__proto__', 'constructor', 'prototype'];
  6. Object.keys(src).filter(key => noExtend.indexOf(key) < 0).forEach(key => {
  7. if (typeof target[key] === 'undefined') target[key] = src[key];else if (isObject(src[key]) && isObject(target[key]) && Object.keys(src[key]).length > 0) {
  8. if (src[key].__swiper__) target[key] = src[key];else extend(target[key], src[key]);
  9. } else {
  10. target[key] = src[key];
  11. }
  12. });
  13. }
  14. function needsNavigation(params) {
  15. if (params === void 0) {
  16. params = {};
  17. }
  18. return params.navigation && typeof params.navigation.nextEl === 'undefined' && typeof params.navigation.prevEl === 'undefined';
  19. }
  20. function needsPagination(params) {
  21. if (params === void 0) {
  22. params = {};
  23. }
  24. return params.pagination && typeof params.pagination.el === 'undefined';
  25. }
  26. function needsScrollbar(params) {
  27. if (params === void 0) {
  28. params = {};
  29. }
  30. return params.scrollbar && typeof params.scrollbar.el === 'undefined';
  31. }
  32. function uniqueClasses(classNames) {
  33. if (classNames === void 0) {
  34. classNames = '';
  35. }
  36. const classes = classNames.split(' ').map(c => c.trim()).filter(c => !!c);
  37. const unique = [];
  38. classes.forEach(c => {
  39. if (unique.indexOf(c) < 0) unique.push(c);
  40. });
  41. return unique.join(' ');
  42. }
  43. export { isObject, extend, needsNavigation, needsPagination, needsScrollbar, uniqueClasses };