浏览代码

Remove Slides component.

NaotoshiFujita 5 年之前
父节点
当前提交
1afc2df3da
共有 2 个文件被更改,包括 0 次插入323 次删除
  1. 0 142
      src/js/components/slides/index.js
  2. 0 181
      src/js/components/slides/slide.js

+ 0 - 142
src/js/components/slides/index.js

@@ -1,142 +0,0 @@
-/**
- * The component for handling all slides including clones.
- *
- * @author    Naotoshi Fujita
- * @copyright Naotoshi Fujita. All rights reserved.
- */
-
-import Slide from './slide';
-
-
-/**
- * The component for handling all slides including clones.
- *
- * @param {Splide} Splide     - A Splide instance.
- * @param {Object} Components - An object containing components.
- *
- * @return {Object} - The component object.
- */
-export default ( Splide, Components ) => {
-	/**
-	 * Store slide elements.
-	 *
-	 * @type {Array}
-	 */
-	let slides = [];
-
-	/**
-	 * Store Slide objects.
-	 *
-	 * @type {Array}
-	 */
-	let SlideObjects = [];
-
-	/**
-	 * Slides component object.
-	 *
-	 * @type {Object}
-	 */
-	const Slides = {
-		/**
-		 * Called when the component is mounted.
-		 */
-		mount() {
-			init();
-
-			Splide.on( 'refresh', () => {
-				this.destroy();
-				init();
-			} );
-		},
-
-		/**
-		 * Destroy.
-		 */
-		destroy() {
-			SlideObjects.forEach( Slide => { Slide.destroy() } );
-			SlideObjects = [];
-		},
-
-		/**
-		 * Register a slide to create a Slide object and handle its behavior.
-		 *
-		 * @param {number}  index     - A unique index.
-		 * @param {number}  realIndex - A real index for clones. Set -1 for real slides.
-		 * @param {Element} slide     - A slide element.
-		 */
-		register( index, realIndex, slide ) {
-			const SlideObject = Slide( index, realIndex, slide, Splide );
-			SlideObject.mount();
-			SlideObjects.push( SlideObject );
-		},
-
-		/**
-		 * Return the Slide object designated by the index.
-		 * Note that "find" is not supported by IE.
-		 *
-		 * @return {Object|undefined} - A Slide object if available. Undefined if not.
-		 */
-		getSlide( index ) {
-			return SlideObjects.filter( Slide => Slide.index === index )[0];
-		},
-
-		/**
-		 * Return slide elements.
-		 *
-		 * @param {boolean} includeClones - Whether to include cloned slides or not.
-		 * @param {boolean} objects       - Whether to return elements or Slide objects
-		 *
-		 * @return {Object[]|Element[]} - Slide objects or elements.
-		 */
-		getSlides( includeClones, objects ) {
-			if ( objects ) {
-				return includeClones ? SlideObjects : SlideObjects.filter( Slide => ! Slide.isClone );
-			}
-
-			return includeClones ? SlideObjects.map( Slide => Slide.slide ) : slides;
-		},
-
-		/**
-		 * Return Slide objects belonging to the given page.
-		 *
-		 * @param {number} page - A page number.
-		 *
-		 * @return {Object[]} - An array containing Slide objects.
-		 */
-		getSlidesByPage( page ) {
-			const idx     = Components.Controller.toIndex( page );
-			const options = Splide.options;
-			const max     = options.focus !== false ? 1 : options.perPage;
-
-			return SlideObjects.filter( ( { index } ) => idx <= index && index < idx + max );
-		},
-
-		/**
-		 * Return slides length without clones.
-		 *
-		 * @return {number} - Slide length.
-		 */
-		get length() {
-			return slides.length;
-		},
-
-		/**
-		 * Return "SlideObjects" length including clones.
-		 *
-		 * @return {number} - Slide length including clones.
-		 */
-		get total() {
-			return SlideObjects.length;
-		},
-	};
-
-	/**
-	 * Initialization.
-	 */
-	function init() {
-		slides = Components.Elements.slides;
-		slides.forEach( ( slide, index ) => { Slides.register( index, -1, slide ) } );
-	}
-
-	return Slides;
-}

+ 0 - 181
src/js/components/slides/slide.js

@@ -1,181 +0,0 @@
-// /**
-//  * The sub component for handling each slide.
-//  *
-//  * @author    Naotoshi Fujita
-//  * @copyright Naotoshi Fujita. All rights reserved.
-//  */
-//
-// import { find, addClass, removeClass, hasClass } from '../../utils/dom';
-// import { SLIDE } from '../../constants/types';
-// import { STATUS_CLASSES } from '../../constants/classes';
-// import { each } from "../../utils/object";
-//
-//
-// /**
-//  * The sub component for handling each slide.
-//  *
-//  * @param {number}  index     - An unique slide index.
-//  * @param {number}  realIndex - Clones should pass a real slide index.
-//  * @param {Element} slide     - A slide element.
-//  * @param {Splide}  Splide    - A Splide instance.
-//  *
-//  * @return {Object} - The sub component object.
-//  */
-// export default ( index, realIndex, slide, Splide ) => {
-// 	/**
-// 	 * Events when the slide status is updated.
-// 	 * Append a namespace to remove listeners later.
-// 	 *
-// 	 * @type {string}
-// 	 */
-// 	const statusUpdateEvents = [
-// 		'mounted', 'updated', 'resize', Splide.options.updateOnMove ? 'move' : 'moved',
-// 	].join( '.slide ' ).trim();
-//
-// 	/**
-// 	 * Slide sub component object.
-// 	 *
-// 	 * @type {Object}
-// 	 */
-// 	const Slide = {
-// 		/**
-// 		 * Slide element.
-// 		 *
-// 		 * @type {Element}
-// 		 */
-// 		slide,
-//
-// 		/**
-// 		 * Slide index.
-// 		 *
-// 		 * @type {number}
-// 		 */
-// 		index,
-//
-// 		/**
-// 		 * Real index for clones.
-// 		 *
-// 		 * @type {number}
-// 		 */
-// 		realIndex,
-//
-// 		/**
-// 		 * Container element if available.
-// 		 *
-// 		 * @type {Element|null}
-// 		 */
-// 		container: find( slide, `.${ Splide.classes.container }` ),
-//
-// 		/**
-// 		 * Whether this is clone or not.
-// 		 *
-// 		 * @type {boolean}
-// 		 */
-// 		isClone: realIndex > -1,
-//
-// 		/**
-// 		 * Called when the component is mounted.
-// 		 */
-// 		mount() {
-// 			if ( ! this.isClone ) {
-// 				const number = index + 1;
-// 				slide.id = `${ Splide.root.id }-slide${ number < 10 ? '0' + number : number }`;
-// 			}
-//
-// 			Splide.on( statusUpdateEvents, () => this.update() );
-// 		},
-//
-// 		/**
-// 		 * Destroy.
-// 		 */
-// 		destroy() {
-// 			Splide.off( statusUpdateEvents );
-// 			each( STATUS_CLASSES, className => { removeClass( slide, className ) } );
-// 		},
-//
-// 		/**
-// 		 * Update active and visible status.
-// 		 */
-// 		update() {
-// 			update( this.isActive(), false );
-// 			update( this.isVisible(), true );
-// 		},
-//
-// 		/**
-// 		 * Check whether this slide is active or not.
-// 		 *
-// 		 * @return {boolean} - True if the slide is active or false if not.
-// 		 */
-// 		isActive() {
-// 			return Splide.index === index;
-// 		},
-//
-// 		/**
-// 		 * Check whether this slide is visible or not.
-// 		 *
-// 		 * @return {boolean} - True if the slide is visible or false if not.
-// 		 */
-// 		isVisible() {
-// 			const { focus, trimSpace }  = Splide.options;
-// 			const { index: activeIndex, length } = Splide;
-// 			const isCenter  = 'center' === focus;
-// 			const numInView = Splide.Components.Layout.numInView;
-// 			const offset    = isCenter ? numInView / 2 : parseInt( focus ) || 0;
-//
-// 			if ( trimSpace && Splide.is( SLIDE ) ) {
-// 				if ( activeIndex < offset ) {
-// 					return index < numInView;
-// 				} else if ( activeIndex >= length - ( numInView - offset ) ) {
-// 					return index >= length - numInView;
-// 				}
-// 			}
-//
-// 			const min = activeIndex - offset + ( isCenter && numInView % 2 === 0 ? 1 : 0 );
-//
-// 			return min <= index && index < activeIndex + numInView - offset;
-// 		},
-//
-// 		/**
-// 		 * Calculate how far this slide is from another slide and
-// 		 * return true if the distance is within the given number.
-// 		 *
-// 		 * @param {number} from   - Index of a target slide.
-// 		 * @param {number} within - True if the slide is within this number.
-// 		 *
-// 		 * @return {boolean} - True if the slide is within this number or false otherwise.
-// 		 */
-// 		isWithin( from, within ) {
-// 			let diff = Math.abs( from - index );
-//
-// 			if ( ! Splide.is( SLIDE ) && ! this.isClone ) {
-// 				diff = Math.min( diff, Splide.length - diff );
-// 			}
-//
-// 			return diff < within;
-// 		},
-// 	};
-//
-//
-// 	/**
-// 	 * Update classes for activity or visibility.
-// 	 *
-// 	 * @param {boolean} active        - Is active/visible or not.
-// 	 * @param {boolean} forVisibility - Toggle classes for activity or visibility.
-// 	 */
-// 	function update( active, forVisibility ) {
-// 		const type      = forVisibility ? 'visible' : 'active';
-// 		const className = STATUS_CLASSES[ type ];
-//
-// 		if ( active ) {
-// 			addClass( slide, className );
-// 			Splide.emit( `${ type }`, Slide );
-// 		} else {
-// 			if ( hasClass( slide, className ) ) {
-// 				removeClass( slide, className );
-// 				Splide.emit( `${ forVisibility ? 'hidden' : 'inactive' }`, Slide );
-// 			}
-// 		}
-// 	}
-//
-// 	return Slide;
-// }