Repository URL to install this package:
|
Version:
1.1.21 ▾
|
"use strict";
// const Flickity = require('./flickity')
// Flickity.Slide = Slide
// module.exports = Slide
function Slide(parent) {
this.parent = parent;
this.isOriginLeft = parent.originSide == 'left';
this.cells = [];
this.outerWidth = 0;
this.height = 0;
}
var proto = Slide.prototype;
proto.addCell = function (cell) {
this.cells.push(cell);
this.outerWidth += cell.size.outerWidth;
this.height = Math.max(cell.size.outerHeight, this.height); // first cell stuff
if (this.cells.length == 1) {
this.x = cell.x; // x comes from first cell
var beginMargin = this.isOriginLeft ? 'marginLeft' : 'marginRight';
this.firstMargin = cell.size[beginMargin];
}
};
proto.updateTarget = function () {
var endMargin = this.isOriginLeft ? 'marginRight' : 'marginLeft';
var lastCell = this.getLastCell();
var lastMargin = lastCell ? lastCell.size[endMargin] : 0;
var slideWidth = this.outerWidth - (this.firstMargin + lastMargin);
this.target = this.x + this.firstMargin + slideWidth * this.parent.cellAlign;
};
proto.getLastCell = function () {
return this.cells[this.cells.length - 1];
};
proto.select = function () {
this.changeSelectedClass('add');
};
proto.unselect = function () {
this.changeSelectedClass('remove');
};
proto.changeSelectedClass = function (method) {
this.cells.forEach(function (cell) {
cell.element.classList[method]('is-selected');
});
};
proto.getCellElements = function () {
return this.cells.map(function (cell) {
return cell.element;
});
};
module.exports = Slide;
Slide.flickTheBean = Flickity => {
Flickity.Slide = Slide;
};