MCPcopy
hub / github.com/Splidejs/splide / init

Function init

src/js/test/utils/utils.ts:35–98  ·  view source on GitHub ↗
( options: Options = {}, args: InitArgs = {} )

Source from the content-addressed store, hash-verified

33 * @return A created Splide instance.
34 */
35export function init( options: Options = {}, args: InitArgs = {} ): Splide {
36 const { width = SLIDER_WIDTH, height = 0 } = options;
37 const {
38 id,
39 length = 10,
40 arrows,
41 autoplay,
42 progress,
43 mount = true,
44 html,
45 src,
46 dataSrc,
47 dataSrcset,
48 json,
49 insertHtml,
50 dataInterval,
51 } = args;
52
53 const slideWidth = +width / ( options.perPage || 1 );
54 const slideHeight = +height / ( options.perPage || 1 );
55 const innerHtml = html
56 || buildHtml( { length, arrows, autoplay, progress, src, dataSrc, dataSrcset, json, id, dataInterval } );
57
58 if ( insertHtml ) {
59 if ( ! document.body.innerHTML ) {
60 throw new Error( 'Invalid usage.' );
61 }
62
63 document.body.insertAdjacentHTML( 'beforeend', innerHtml );
64 } else {
65 document.head.innerHTML = '';
66 document.body.innerHTML = innerHtml;
67 }
68
69 const root = id ? document.getElementById( id ) : document.querySelector( `.${ CLASS_ROOT }` );
70 const track = root.querySelector( `.${ CLASS_TRACK }` );
71 const list = root.querySelector<HTMLElement>( `.${ CLASS_LIST }` );
72 const slides = root.querySelectorAll<HTMLElement>( `.${ CLASS_SLIDE }` );
73
74 root.getBoundingClientRect = (): DOMRect => {
75 return assign( {}, DOM_RECT, { width: +width } );
76 };
77
78 track.getBoundingClientRect = (): DOMRect => {
79 return assign( {}, DOM_RECT, { width: +width, right: +width } );
80 };
81
82 list.getBoundingClientRect = (): DOMRect => {
83 return assign( {}, DOM_RECT, {
84 width: +width,
85 ...parseTransform( list ),
86 } );
87 };
88
89 setSlidesRect( Array.from( slides ), list, slideWidth, slideHeight );
90
91 const splide = new Splide( root as HTMLElement, options );
92

Callers 15

nearby.test.tsFile · 0.90
sequential.test.tsFile · 0.90
slide.test.tsFile · 0.90
loop.test.tsFile · 0.90
tab.test.tsFile · 0.90
direction.test.tsFile · 0.90
general.test.tsFile · 0.90
move.test.tsFile · 0.90
general.test.tsFile · 0.90
ltr.test.tsFile · 0.90
rtl.test.tsFile · 0.90

Calls 5

mountMethod · 0.95
buildHtmlFunction · 0.90
assignFunction · 0.90
parseTransformFunction · 0.85
setSlidesRectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…