123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- /**
- * The resolver component for vertical layout.
- *
- * @author Naotoshi Fujita
- * @copyright Naotoshi Fujita. All rights reserved.
- */
- import { applyStyle } from "../../../utils/dom";
- import { toPixel, unit } from "../../../utils/utils";
- import { exist } from "../../../utils/error";
- /**
- * The resolver component for vertical layout.
- *
- * @param {Splide} Splide - A Splide instance.
- * @param {Object} Components - An object containing components.
- *
- * @return {Object} - The resolver object.
- */
- export default ( Splide, Components ) => {
- /**
- * Keep the Elements component.
- *
- * @type {string}
- */
- const Elements = Components.Elements;
- /**
- * Keep the root element.
- *
- * @type {Element}
- */
- const root = Splide.root;
- /**
- * Keep the track element.
- *
- * @type {Element}
- */
- let track;
- /**
- * Keep the latest options.
- *
- * @type {Element}
- */
- let options;
- return {
- /**
- * Margin property name.
- *
- * @type {string}
- */
- margin: 'marginBottom',
- /**
- * Init slider styles according to options.
- */
- init() {
- options = Splide.options;
- track = Elements.track;
- this.gap = toPixel( root, options.gap );
- const padding = options.padding;
- const { top = padding, bottom = padding } = padding;
- this.padding = {
- top : toPixel( root, top ),
- bottom: toPixel( root, bottom ),
- };
- applyStyle( track, {
- paddingTop : unit( top ),
- paddingBottom: unit( bottom ),
- } );
- },
- /**
- * Return the slide width in px.
- *
- * @return {number} - The slide width.
- */
- slideWidth() {
- return toPixel( root, options.fixedWidth || this.width );
- },
- /**
- * Return the slide height in px.
- *
- * @return {number} - The slide height.
- */
- slideHeight() {
- const height = options.fixedHeight || ( this.height + this.gap ) / options.perPage - this.gap;
- return toPixel( root, height );
- },
- /**
- * Return slider width without padding.
- *
- * @return {number} - Current slider width.
- */
- get width() {
- return track.clientWidth;
- },
- /**
- * Return slide height without padding.
- *
- * @return {number} - Slider height.
- */
- get height() {
- const height = options.height || this.width * options.heightRatio;
- exist( height, '"height" or "heightRatio" is missing.' );
- return toPixel( root, height ) - this.padding.top - this.padding.bottom;
- },
- /**
- * Return list width.
- *
- * @return {number} - Current list width.
- */
- get listWidth() {
- return this.width;
- },
- /**
- * Return list height.
- *
- * @return {number} - Current list height.
- */
- get listHeight() {
- return ( this.slideHeight() + this.gap ) * Elements.total;
- },
- }
- }
|