get-params.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import Swiper from 'swiper';
  2. import { isObject, extend } from './utils.js';
  3. import { paramsList } from './params-list.js';
  4. function getParams(obj) {
  5. if (obj === void 0) {
  6. obj = {};
  7. }
  8. const params = {
  9. on: {}
  10. };
  11. const passedParams = {};
  12. extend(params, Swiper.defaults);
  13. extend(params, Swiper.extendedDefaults);
  14. params._emitClasses = true;
  15. params.init = false;
  16. const rest = {};
  17. const allowedParams = paramsList.map(key => key.replace(/_/, ''));
  18. Object.keys(obj).forEach(key => {
  19. if (allowedParams.indexOf(key) >= 0) {
  20. if (isObject(obj[key])) {
  21. params[key] = {};
  22. passedParams[key] = {};
  23. extend(params[key], obj[key]);
  24. extend(passedParams[key], obj[key]);
  25. } else {
  26. params[key] = obj[key];
  27. passedParams[key] = obj[key];
  28. }
  29. } else if (key.search(/on[A-Z]/) === 0 && typeof obj[key] === 'function') {
  30. params.on[`${key[2].toLowerCase()}${key.substr(3)}`] = obj[key];
  31. } else {
  32. rest[key] = obj[key];
  33. }
  34. });
  35. ['navigation', 'pagination', 'scrollbar'].forEach(key => {
  36. if (params[key] === true) params[key] = {};
  37. if (params[key] === false) delete params[key];
  38. });
  39. return {
  40. params,
  41. passedParams,
  42. rest
  43. };
  44. }
  45. export { getParams };