Skip to content

Commit 61e61be

Browse files
Bug Fix: Relative units for the fixedWidth/fixedHeight option didn't work(#97).
1 parent fa183d6 commit 61e61be

File tree

8 files changed

+1779
-3542
lines changed

8 files changed

+1779
-3542
lines changed

dist/js/splide.esm.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* Splide.js
3-
* Version : 2.4.9
3+
* Version : 2.4.10
44
* License : MIT
55
* Copyright: 2020 Naotoshi Fujita
66
*/
@@ -2290,10 +2290,12 @@ var UID_NAME = 'uid';
22902290
* Initialization.
22912291
*/
22922292
init: function init() {
2293+
var _this2 = this;
2294+
22932295
collect();
22942296
addClass(root, getClasses());
2295-
Elements.slides.forEach(function (slide, index) {
2296-
Elements.register(slide, index, -1);
2297+
this.slides.forEach(function (slide, index) {
2298+
_this2.register(slide, index, -1);
22972299
});
22982300
},
22992301

@@ -3120,6 +3122,7 @@ var abs = Math.abs;
31203122

31213123

31223124

3125+
31233126
/**
31243127
* The component for cloning some slides for "loop" mode of the track.
31253128
*
@@ -3161,10 +3164,15 @@ var abs = Math.abs;
31613164
* Called when the component is mounted.
31623165
*/
31633166
mount: function mount() {
3167+
var _this = this;
3168+
31643169
if (Splide.is(LOOP)) {
31653170
init();
31663171
Splide.on('refresh', init).on('resize', function () {
31673172
if (cloneCount !== getCloneCount()) {
3173+
// Destroy before refresh not to collect clones by the Elements component.
3174+
_this.destroy();
3175+
31683176
Splide.refresh();
31693177
}
31703178
});
@@ -3215,32 +3223,31 @@ var abs = Math.abs;
32153223

32163224

32173225
function generateClones(count) {
3218-
var length = Elements.length;
3226+
var length = Elements.length,
3227+
register = Elements.register;
32193228

3220-
if (!length) {
3221-
return;
3222-
}
3223-
3224-
var slides = Elements.slides;
3229+
if (length) {
3230+
var slides = Elements.slides;
32253231

3226-
while (slides.length < count) {
3227-
slides = slides.concat(slides);
3228-
} // Clones after the last element.
3232+
while (slides.length < count) {
3233+
slides = slides.concat(slides);
3234+
} // Clones after the last element.
32293235

32303236

3231-
slides.slice(0, count).forEach(function (elm, index) {
3232-
var clone = cloneDeeply(elm);
3233-
append(Elements.list, clone);
3234-
clones.push(clone);
3235-
Elements.register(clone, index + length, index % length);
3236-
}); // Clones before the first element.
3237+
slides.slice(0, count).forEach(function (elm, index) {
3238+
var clone = cloneDeeply(elm);
3239+
append(Elements.list, clone);
3240+
clones.push(clone);
3241+
register(clone, index + length, index % length);
3242+
}); // Clones before the first element.
32373243

3238-
slides.slice(-count).forEach(function (elm, index) {
3239-
var clone = cloneDeeply(elm);
3240-
before(clone, slides[0]);
3241-
clones.push(clone);
3242-
Elements.register(clone, index - count, (length + index - count % length) % length);
3243-
});
3244+
slides.slice(-count).forEach(function (elm, index) {
3245+
var clone = cloneDeeply(elm);
3246+
before(clone, slides[0]);
3247+
clones.push(clone);
3248+
register(clone, index - count, (length + index - count % length) % length);
3249+
});
3250+
}
32443251
}
32453252
/**
32463253
* Return half count of clones to be generated.
@@ -3264,7 +3271,7 @@ var abs = Math.abs;
32643271

32653272
var baseCount = options.autoWidth || options.autoHeight ? Elements.length : options.perPage;
32663273
var dimension = options.direction === TTB ? 'Height' : 'Width';
3267-
var fixedSize = options["fixed" + dimension];
3274+
var fixedSize = toPixel(Splide.root, options["fixed" + dimension]);
32683275

32693276
if (fixedSize) {
32703277
// Roughly calculate the count. This needs not to be strict.

dist/js/splide.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* Splide.js
3-
* Version : 2.4.9
3+
* Version : 2.4.10
44
* License : MIT
55
* Copyright: 2020 Naotoshi Fujita
66
*/
@@ -2280,10 +2280,12 @@ var UID_NAME = 'uid';
22802280
* Initialization.
22812281
*/
22822282
init: function init() {
2283+
var _this2 = this;
2284+
22832285
collect();
22842286
addClass(root, getClasses());
2285-
Elements.slides.forEach(function (slide, index) {
2286-
Elements.register(slide, index, -1);
2287+
this.slides.forEach(function (slide, index) {
2288+
_this2.register(slide, index, -1);
22872289
});
22882290
},
22892291

@@ -3110,6 +3112,7 @@ var abs = Math.abs;
31103112

31113113

31123114

3115+
31133116
/**
31143117
* The component for cloning some slides for "loop" mode of the track.
31153118
*
@@ -3151,10 +3154,15 @@ var abs = Math.abs;
31513154
* Called when the component is mounted.
31523155
*/
31533156
mount: function mount() {
3157+
var _this = this;
3158+
31543159
if (Splide.is(LOOP)) {
31553160
init();
31563161
Splide.on('refresh', init).on('resize', function () {
31573162
if (cloneCount !== getCloneCount()) {
3163+
// Destroy before refresh not to collect clones by the Elements component.
3164+
_this.destroy();
3165+
31583166
Splide.refresh();
31593167
}
31603168
});
@@ -3205,32 +3213,31 @@ var abs = Math.abs;
32053213

32063214

32073215
function generateClones(count) {
3208-
var length = Elements.length;
3216+
var length = Elements.length,
3217+
register = Elements.register;
32093218

3210-
if (!length) {
3211-
return;
3212-
}
3213-
3214-
var slides = Elements.slides;
3219+
if (length) {
3220+
var slides = Elements.slides;
32153221

3216-
while (slides.length < count) {
3217-
slides = slides.concat(slides);
3218-
} // Clones after the last element.
3222+
while (slides.length < count) {
3223+
slides = slides.concat(slides);
3224+
} // Clones after the last element.
32193225

32203226

3221-
slides.slice(0, count).forEach(function (elm, index) {
3222-
var clone = cloneDeeply(elm);
3223-
append(Elements.list, clone);
3224-
clones.push(clone);
3225-
Elements.register(clone, index + length, index % length);
3226-
}); // Clones before the first element.
3227+
slides.slice(0, count).forEach(function (elm, index) {
3228+
var clone = cloneDeeply(elm);
3229+
append(Elements.list, clone);
3230+
clones.push(clone);
3231+
register(clone, index + length, index % length);
3232+
}); // Clones before the first element.
32273233

3228-
slides.slice(-count).forEach(function (elm, index) {
3229-
var clone = cloneDeeply(elm);
3230-
before(clone, slides[0]);
3231-
clones.push(clone);
3232-
Elements.register(clone, index - count, (length + index - count % length) % length);
3233-
});
3234+
slides.slice(-count).forEach(function (elm, index) {
3235+
var clone = cloneDeeply(elm);
3236+
before(clone, slides[0]);
3237+
clones.push(clone);
3238+
register(clone, index - count, (length + index - count % length) % length);
3239+
});
3240+
}
32343241
}
32353242
/**
32363243
* Return half count of clones to be generated.
@@ -3254,7 +3261,7 @@ var abs = Math.abs;
32543261

32553262
var baseCount = options.autoWidth || options.autoHeight ? Elements.length : options.perPage;
32563263
var dimension = options.direction === TTB ? 'Height' : 'Width';
3257-
var fixedSize = options["fixed" + dimension];
3264+
var fixedSize = toPixel(Splide.root, options["fixed" + dimension]);
32583265

32593266
if (fixedSize) {
32603267
// Roughly calculate the count. This needs not to be strict.

dist/js/splide.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/splide.min.js.gz

8 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)