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