|
@@ -5,8 +5,9 @@
|
|
|
* @copyright Naotoshi Fujita. All rights reserved.
|
|
|
*/
|
|
|
|
|
|
-import { LOOP } from '../../constants/types';
|
|
|
import { addClass, removeAttribute, append, before, remove } from '../../utils/dom';
|
|
|
+import { LOOP } from '../../constants/types';
|
|
|
+import { TTB } from "../../constants/directions";
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -80,7 +81,7 @@ export default ( Splide, Components ) => {
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Generate and append clones.
|
|
|
+ * Generate and append/prepend clones.
|
|
|
*/
|
|
|
function generateClones() {
|
|
|
const length = Elements.length;
|
|
@@ -96,6 +97,7 @@ export default ( Splide, Components ) => {
|
|
|
slides = slides.concat( slides );
|
|
|
}
|
|
|
|
|
|
+ // Clones after the last element.
|
|
|
slides.slice( 0, count ).forEach( ( elm, index ) => {
|
|
|
const clone = cloneDeeply( elm );
|
|
|
append( Elements.list, clone );
|
|
@@ -104,6 +106,7 @@ export default ( Splide, Components ) => {
|
|
|
Elements.register( clone, index + length, index % length );
|
|
|
} );
|
|
|
|
|
|
+ // Clones before the first element.
|
|
|
slides.slice( -count ).forEach( ( elm, index ) => {
|
|
|
const clone = cloneDeeply( elm );
|
|
|
before( clone, slides[0] );
|
|
@@ -116,6 +119,8 @@ export default ( Splide, Components ) => {
|
|
|
/**
|
|
|
* Return half count of clones to be generated.
|
|
|
* Clone count is determined by:
|
|
|
+ * - "clones" value in the options.
|
|
|
+ * - Number of slides that can be placed in a view in "fixed" mode.
|
|
|
* - Max pages a flick action can move.
|
|
|
* - Whether the slide length is enough for perPage.
|
|
|
*
|
|
@@ -124,11 +129,22 @@ export default ( Splide, Components ) => {
|
|
|
function getCloneCount() {
|
|
|
const options = Splide.options;
|
|
|
|
|
|
- if ( options.autoWidth ) {
|
|
|
- return Elements.length;
|
|
|
+ if ( options.clones ) {
|
|
|
+ return options.clones;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Use the slide length in autoWidth mode because the number candnot be calculated.
|
|
|
+ let baseCount = options.autoWidth ? Elements.length : options.perPage;
|
|
|
+
|
|
|
+ const dimension = options.direction === TTB ? 'Height' : 'Width';
|
|
|
+ const fixedSize = options[ `fixed${ dimension }` ];
|
|
|
+
|
|
|
+ if ( fixedSize ) {
|
|
|
+ // Roughly determine the count. This needs not to be strict.
|
|
|
+ baseCount = Math.ceil( Elements.track[ `client${ dimension }` ] / fixedSize );
|
|
|
}
|
|
|
|
|
|
- return options.perPage * ( options.drag ? options.flickMaxPages + 1 : 1 );
|
|
|
+ return baseCount * ( options.drag ? options.flickMaxPages + 1 : 1 );
|
|
|
}
|
|
|
|
|
|
/**
|