123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- /**
- * 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.
- * @param {Object} options - Current options.
- *
- * @return {Object} - The resolver object.
- */
- export default ( Splide, Components, options ) => {
- /**
- * Keep the Elements component.
- *
- * @type {string}
- */
- const Elements = Components.Elements;
- /**
- * Keep the track element.
- *
- * @type {Element}
- */
- const track = Elements.track;
- return {
- /**
- * Margin property name.
- *
- * @type {string}
- */
- marginProp: 'marginBottom',
- /**
- * Init slider styles according to options.
- */
- init() {
- let padding = options.padding;
- if ( padding ) {
- if ( typeof padding !== 'object' ) {
- padding = {
- top : padding,
- bottom: padding,
- }
- }
- applyStyle( track, { paddingTop : unit( padding.top ), paddingBottom: unit( padding.bottom ) } );
- }
- },
- /**
- * 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" must be given in TTB mode.' );
- return toPixel( Splide.root, height );
- },
- /**
- * 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 ) * Components.Slides.total;
- },
- /**
- * Return the slide width in px.
- *
- * @return {number} - The slide width.
- */
- get slideWidth() {
- return toPixel( Splide.root, options.fixedWidth || this.width );
- },
- /**
- * Return the slide height in px.
- *
- * @return {number} - The slide height.
- */
- get slideHeight() {
- let height = options.fixedHeight;
- if ( ! height ) {
- height = ( this.height + this.gap ) / options.perPage - this.gap;
- }
- return toPixel( Splide.root, height );
- },
- /**
- * Return gap in px.
- *
- * @return {Object} - Gap amount in px.
- */
- get gap() {
- const style = getComputedStyle( Elements.slides[ 0 ] );
- return parseFloat( style[ this.marginProp ] ) || 0;
- },
- /**
- * Return padding object.
- *
- * @return {Object} - An object containing padding top and bottom.
- */
- get padding() {
- const style = getComputedStyle( track );
- return {
- top : parseFloat( style.paddingTop ) || 0,
- bottom: parseFloat( style.paddingBottom ) || 0,
- };
- },
- }
- }
|