get-params.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 events = {};
  12. const passedParams = {};
  13. extend(params, Swiper.defaults);
  14. extend(params, Swiper.extendedDefaults);
  15. params._emitClasses = true;
  16. params.init = false;
  17. const rest = {};
  18. const allowedParams = paramsList.map(key => key.replace(/_/, ''));
  19. Object.keys(obj).forEach(key => {
  20. if (allowedParams.indexOf(key) >= 0) {
  21. if (isObject(obj[key])) {
  22. params[key] = {};
  23. passedParams[key] = {};
  24. extend(params[key], obj[key]);
  25. extend(passedParams[key], obj[key]);
  26. } else {
  27. params[key] = obj[key];
  28. passedParams[key] = obj[key];
  29. }
  30. } else if (key.search(/on[A-Z]/) === 0 && typeof obj[key] === 'function') {
  31. events[`${key[2].toLowerCase()}${key.substr(3)}`] = obj[key];
  32. } else {
  33. rest[key] = obj[key];
  34. }
  35. });
  36. ['navigation', 'pagination', 'scrollbar'].forEach(key => {
  37. if (params[key] === true) params[key] = {};
  38. if (params[key] === false) delete params[key];
  39. });
  40. return {
  41. params,
  42. passedParams,
  43. rest,
  44. events
  45. };
  46. }
  47. export { getParams };