slide.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // /**
  2. // * The sub component for handling each slide.
  3. // *
  4. // * @author Naotoshi Fujita
  5. // * @copyright Naotoshi Fujita. All rights reserved.
  6. // */
  7. //
  8. // import { find, addClass, removeClass, hasClass } from '../../utils/dom';
  9. // import { SLIDE } from '../../constants/types';
  10. // import { STATUS_CLASSES } from '../../constants/classes';
  11. // import { each } from "../../utils/object";
  12. //
  13. //
  14. // /**
  15. // * The sub component for handling each slide.
  16. // *
  17. // * @param {number} index - An unique slide index.
  18. // * @param {number} realIndex - Clones should pass a real slide index.
  19. // * @param {Element} slide - A slide element.
  20. // * @param {Splide} Splide - A Splide instance.
  21. // *
  22. // * @return {Object} - The sub component object.
  23. // */
  24. // export default ( index, realIndex, slide, Splide ) => {
  25. // /**
  26. // * Events when the slide status is updated.
  27. // * Append a namespace to remove listeners later.
  28. // *
  29. // * @type {string}
  30. // */
  31. // const statusUpdateEvents = [
  32. // 'mounted', 'updated', 'resize', Splide.options.updateOnMove ? 'move' : 'moved',
  33. // ].join( '.slide ' ).trim();
  34. //
  35. // /**
  36. // * Slide sub component object.
  37. // *
  38. // * @type {Object}
  39. // */
  40. // const Slide = {
  41. // /**
  42. // * Slide element.
  43. // *
  44. // * @type {Element}
  45. // */
  46. // slide,
  47. //
  48. // /**
  49. // * Slide index.
  50. // *
  51. // * @type {number}
  52. // */
  53. // index,
  54. //
  55. // /**
  56. // * Real index for clones.
  57. // *
  58. // * @type {number}
  59. // */
  60. // realIndex,
  61. //
  62. // /**
  63. // * Container element if available.
  64. // *
  65. // * @type {Element|null}
  66. // */
  67. // container: find( slide, `.${ Splide.classes.container }` ),
  68. //
  69. // /**
  70. // * Whether this is clone or not.
  71. // *
  72. // * @type {boolean}
  73. // */
  74. // isClone: realIndex > -1,
  75. //
  76. // /**
  77. // * Called when the component is mounted.
  78. // */
  79. // mount() {
  80. // if ( ! this.isClone ) {
  81. // const number = index + 1;
  82. // slide.id = `${ Splide.root.id }-slide${ number < 10 ? '0' + number : number }`;
  83. // }
  84. //
  85. // Splide.on( statusUpdateEvents, () => this.update() );
  86. // },
  87. //
  88. // /**
  89. // * Destroy.
  90. // */
  91. // destroy() {
  92. // Splide.off( statusUpdateEvents );
  93. // each( STATUS_CLASSES, className => { removeClass( slide, className ) } );
  94. // },
  95. //
  96. // /**
  97. // * Update active and visible status.
  98. // */
  99. // update() {
  100. // update( this.isActive(), false );
  101. // update( this.isVisible(), true );
  102. // },
  103. //
  104. // /**
  105. // * Check whether this slide is active or not.
  106. // *
  107. // * @return {boolean} - True if the slide is active or false if not.
  108. // */
  109. // isActive() {
  110. // return Splide.index === index;
  111. // },
  112. //
  113. // /**
  114. // * Check whether this slide is visible or not.
  115. // *
  116. // * @return {boolean} - True if the slide is visible or false if not.
  117. // */
  118. // isVisible() {
  119. // const { focus, trimSpace } = Splide.options;
  120. // const { index: activeIndex, length } = Splide;
  121. // const isCenter = 'center' === focus;
  122. // const numInView = Splide.Components.Layout.numInView;
  123. // const offset = isCenter ? numInView / 2 : parseInt( focus ) || 0;
  124. //
  125. // if ( trimSpace && Splide.is( SLIDE ) ) {
  126. // if ( activeIndex < offset ) {
  127. // return index < numInView;
  128. // } else if ( activeIndex >= length - ( numInView - offset ) ) {
  129. // return index >= length - numInView;
  130. // }
  131. // }
  132. //
  133. // const min = activeIndex - offset + ( isCenter && numInView % 2 === 0 ? 1 : 0 );
  134. //
  135. // return min <= index && index < activeIndex + numInView - offset;
  136. // },
  137. //
  138. // /**
  139. // * Calculate how far this slide is from another slide and
  140. // * return true if the distance is within the given number.
  141. // *
  142. // * @param {number} from - Index of a target slide.
  143. // * @param {number} within - True if the slide is within this number.
  144. // *
  145. // * @return {boolean} - True if the slide is within this number or false otherwise.
  146. // */
  147. // isWithin( from, within ) {
  148. // let diff = Math.abs( from - index );
  149. //
  150. // if ( ! Splide.is( SLIDE ) && ! this.isClone ) {
  151. // diff = Math.min( diff, Splide.length - diff );
  152. // }
  153. //
  154. // return diff < within;
  155. // },
  156. // };
  157. //
  158. //
  159. // /**
  160. // * Update classes for activity or visibility.
  161. // *
  162. // * @param {boolean} active - Is active/visible or not.
  163. // * @param {boolean} forVisibility - Toggle classes for activity or visibility.
  164. // */
  165. // function update( active, forVisibility ) {
  166. // const type = forVisibility ? 'visible' : 'active';
  167. // const className = STATUS_CLASSES[ type ];
  168. //
  169. // if ( active ) {
  170. // addClass( slide, className );
  171. // Splide.emit( `${ type }`, Slide );
  172. // } else {
  173. // if ( hasClass( slide, className ) ) {
  174. // removeClass( slide, className );
  175. // Splide.emit( `${ forVisibility ? 'hidden' : 'inactive' }`, Slide );
  176. // }
  177. // }
  178. // }
  179. //
  180. // return Slide;
  181. // }