浏览代码

Optimize code.

NaotoshiFujita 5 年之前
父节点
当前提交
cf9d816fdd
共有 7 个文件被更改,包括 111 次插入92 次删除
  1. 38 32
      dist/js/splide.esm.js
  2. 38 32
      dist/js/splide.js
  3. 0 0
      dist/js/splide.min.js
  4. 二进制
      dist/js/splide.min.js.gz
  5. 2 2
      src/js/components/controller/index.js
  6. 22 22
      src/js/components/track/index.js
  7. 11 4
      src/js/constants/defaults.js

+ 38 - 32
dist/js/splide.esm.js

@@ -1100,7 +1100,7 @@ var DEFAULTS = {
    * Fix height of slides. CSS format is allowed such as 10em, 80vh but % unit is not accepted.
    * heightRatio option will be ignored when this option is falsy.
    *
-   * @type {number}
+   * @type {number|string}
    */
   fixedHeight: 0,
 
@@ -1375,15 +1375,22 @@ var DEFAULTS = {
   throttle: 100,
 
   /**
-   * Breakpoints definitions.
+   * Whether to destroy a slider or not.
+   *
+   * @type {boolean}
+   */
+  destroy: false,
+
+  /**
+   * Options for specific breakpoints.
    *
    * @example
    * {
-   *   '1000': {
+   *   1000: {
    *     perPage: 3,
    *     gap: 20
    *   },
-   *   '600': {
+   *   600: {
    *     perPage: 1,
    *     gap: 5,
    *   }
@@ -2488,7 +2495,7 @@ var controller_floor = Math.floor;
      *
      * @param {string} control - A control target pattern.
      *
-     * @return {string|number} - A parsed target.
+     * @return {number} - A parsed target.
      */
     parse: function parse(control) {
       var index = Splide.index;
@@ -2544,7 +2551,7 @@ var controller_floor = Math.floor;
     /**
      * Compute page number from the given slide index.
      *
-     * @param index - Slide index.
+     * @param {number} index - Slide index.
      *
      * @return {number} - A computed page number.
      */
@@ -3036,8 +3043,6 @@ var controller_floor = Math.floor;
      * @param {boolean} silently  - If true, suppress emitting events.
      */
     go: function go(destIndex, newIndex, silently) {
-      var _this2 = this;
-
       var newPosition = getTrimmedPosition(destIndex);
       var prevIndex = Splide.index;
 
@@ -3047,39 +3052,17 @@ var controller_floor = Math.floor;
 
       if (Math.abs(newPosition - currPosition) >= 1 || isFade) {
         Components.Transition.start(destIndex, newIndex, prevIndex, this.toCoord(newPosition), function () {
-          _this2.end(destIndex, newIndex, prevIndex, silently);
+          onTransitionEnd(destIndex, newIndex, prevIndex, silently);
         });
       } else {
         if (destIndex !== prevIndex && Splide.options.trimSpace === 'move') {
           Components.Controller.go(destIndex + destIndex - prevIndex, silently);
         } else {
-          this.end(destIndex, newIndex, prevIndex, silently);
+          onTransitionEnd(destIndex, newIndex, prevIndex, silently);
         }
       }
     },
 
-    /**
-     * Called whenever slides arrive at a destination.
-     *
-     * @param {number}  destIndex - A destination index.
-     * @param {number}  newIndex  - A new index.
-     * @param {number}  prevIndex - A previous index.
-     * @param {boolean} silently  - If true, suppress emitting events.
-     */
-    end: function end(destIndex, newIndex, prevIndex, silently) {
-      applyStyle(list, {
-        transition: ''
-      });
-
-      if (!isFade) {
-        this.jump(newIndex);
-      }
-
-      if (!silently) {
-        Splide.emit('moved', newIndex, prevIndex, destIndex);
-      }
-    },
-
     /**
      * Move the track to the specified index.
      *
@@ -3140,12 +3123,35 @@ var controller_floor = Math.floor;
     }
 
   }, isVertical ? vertical(Splide, Components) : horizontal(Splide, Components));
+  /**
+   * Called whenever slides arrive at a destination.
+   *
+   * @param {number}  destIndex - A destination index.
+   * @param {number}  newIndex  - A new index.
+   * @param {number}  prevIndex - A previous index.
+   * @param {boolean} silently  - If true, suppress emitting events.
+   */
+
+  function onTransitionEnd(destIndex, newIndex, prevIndex, silently) {
+    applyStyle(list, {
+      transition: ''
+    });
+
+    if (!isFade) {
+      Track.jump(newIndex);
+    }
+
+    if (!silently) {
+      Splide.emit('moved', newIndex, prevIndex, destIndex);
+    }
+  }
   /**
    * Convert index to the trimmed position.
    *
    * @return {number} - Trimmed position.
    */
 
+
   function getTrimmedPosition(index) {
     return Track.trim(Track.toPosition(index));
   }

+ 38 - 32
dist/js/splide.js

@@ -1090,7 +1090,7 @@ var DEFAULTS = {
    * Fix height of slides. CSS format is allowed such as 10em, 80vh but % unit is not accepted.
    * heightRatio option will be ignored when this option is falsy.
    *
-   * @type {number}
+   * @type {number|string}
    */
   fixedHeight: 0,
 
@@ -1365,15 +1365,22 @@ var DEFAULTS = {
   throttle: 100,
 
   /**
-   * Breakpoints definitions.
+   * Whether to destroy a slider or not.
+   *
+   * @type {boolean}
+   */
+  destroy: false,
+
+  /**
+   * Options for specific breakpoints.
    *
    * @example
    * {
-   *   '1000': {
+   *   1000: {
    *     perPage: 3,
    *     gap: 20
    *   },
-   *   '600': {
+   *   600: {
    *     perPage: 1,
    *     gap: 5,
    *   }
@@ -2478,7 +2485,7 @@ var controller_floor = Math.floor;
      *
      * @param {string} control - A control target pattern.
      *
-     * @return {string|number} - A parsed target.
+     * @return {number} - A parsed target.
      */
     parse: function parse(control) {
       var index = Splide.index;
@@ -2534,7 +2541,7 @@ var controller_floor = Math.floor;
     /**
      * Compute page number from the given slide index.
      *
-     * @param index - Slide index.
+     * @param {number} index - Slide index.
      *
      * @return {number} - A computed page number.
      */
@@ -3026,8 +3033,6 @@ var controller_floor = Math.floor;
      * @param {boolean} silently  - If true, suppress emitting events.
      */
     go: function go(destIndex, newIndex, silently) {
-      var _this2 = this;
-
       var newPosition = getTrimmedPosition(destIndex);
       var prevIndex = Splide.index;
 
@@ -3037,39 +3042,17 @@ var controller_floor = Math.floor;
 
       if (Math.abs(newPosition - currPosition) >= 1 || isFade) {
         Components.Transition.start(destIndex, newIndex, prevIndex, this.toCoord(newPosition), function () {
-          _this2.end(destIndex, newIndex, prevIndex, silently);
+          onTransitionEnd(destIndex, newIndex, prevIndex, silently);
         });
       } else {
         if (destIndex !== prevIndex && Splide.options.trimSpace === 'move') {
           Components.Controller.go(destIndex + destIndex - prevIndex, silently);
         } else {
-          this.end(destIndex, newIndex, prevIndex, silently);
+          onTransitionEnd(destIndex, newIndex, prevIndex, silently);
         }
       }
     },
 
-    /**
-     * Called whenever slides arrive at a destination.
-     *
-     * @param {number}  destIndex - A destination index.
-     * @param {number}  newIndex  - A new index.
-     * @param {number}  prevIndex - A previous index.
-     * @param {boolean} silently  - If true, suppress emitting events.
-     */
-    end: function end(destIndex, newIndex, prevIndex, silently) {
-      applyStyle(list, {
-        transition: ''
-      });
-
-      if (!isFade) {
-        this.jump(newIndex);
-      }
-
-      if (!silently) {
-        Splide.emit('moved', newIndex, prevIndex, destIndex);
-      }
-    },
-
     /**
      * Move the track to the specified index.
      *
@@ -3130,12 +3113,35 @@ var controller_floor = Math.floor;
     }
 
   }, isVertical ? vertical(Splide, Components) : horizontal(Splide, Components));
+  /**
+   * Called whenever slides arrive at a destination.
+   *
+   * @param {number}  destIndex - A destination index.
+   * @param {number}  newIndex  - A new index.
+   * @param {number}  prevIndex - A previous index.
+   * @param {boolean} silently  - If true, suppress emitting events.
+   */
+
+  function onTransitionEnd(destIndex, newIndex, prevIndex, silently) {
+    applyStyle(list, {
+      transition: ''
+    });
+
+    if (!isFade) {
+      Track.jump(newIndex);
+    }
+
+    if (!silently) {
+      Splide.emit('moved', newIndex, prevIndex, destIndex);
+    }
+  }
   /**
    * Convert index to the trimmed position.
    *
    * @return {number} - Trimmed position.
    */
 
+
   function getTrimmedPosition(index) {
     return Track.trim(Track.toPosition(index));
   }

文件差异内容过多而无法显示
+ 0 - 0
dist/js/splide.min.js


二进制
dist/js/splide.min.js.gz


+ 2 - 2
src/js/components/controller/index.js

@@ -72,7 +72,7 @@ export default ( Splide, Components ) => {
 		 *
 		 * @param {string} control - A control target pattern.
 		 *
-		 * @return {string|number} - A parsed target.
+		 * @return {number} - A parsed target.
 		 */
 		parse( control ) {
 			let index = Splide.index;
@@ -131,7 +131,7 @@ export default ( Splide, Components ) => {
 		/**
 		 * Compute page number from the given slide index.
 		 *
-		 * @param index - Slide index.
+		 * @param {number} index - Slide index.
 		 *
 		 * @return {number} - A computed page number.
 		 */

+ 22 - 22
src/js/components/track/index.js

@@ -93,37 +93,17 @@ export default ( Splide, Components ) => {
 
 			if ( Math.abs( newPosition - currPosition ) >= 1 || isFade ) {
 				Components.Transition.start( destIndex, newIndex, prevIndex, this.toCoord( newPosition ), () => {
-					this.end( destIndex, newIndex, prevIndex, silently );
+					onTransitionEnd( destIndex, newIndex, prevIndex, silently );
 				} );
 			} else {
 				if ( destIndex !== prevIndex && Splide.options.trimSpace === 'move' ) {
 					Components.Controller.go( destIndex + destIndex - prevIndex, silently );
 				} else {
-					this.end( destIndex, newIndex, prevIndex, silently );
+					onTransitionEnd( destIndex, newIndex, prevIndex, silently );
 				}
 			}
 		},
 
-		/**
-		 * Called whenever slides arrive at a destination.
-		 *
-		 * @param {number}  destIndex - A destination index.
-		 * @param {number}  newIndex  - A new index.
-		 * @param {number}  prevIndex - A previous index.
-		 * @param {boolean} silently  - If true, suppress emitting events.
-		 */
-		end( destIndex, newIndex, prevIndex, silently ) {
-			applyStyle( list, { transition: '' } );
-
-			if ( ! isFade ) {
-				this.jump( newIndex );
-			}
-
-			if ( ! silently ) {
-				Splide.emit( 'moved', newIndex, prevIndex, destIndex );
-			}
-		},
-
 		/**
 		 * Move the track to the specified index.
 		 *
@@ -182,6 +162,26 @@ export default ( Splide, Components ) => {
 		},
 	}, isVertical ? Vertical( Splide, Components ) : Horizontal( Splide, Components ) );
 
+	/**
+	 * Called whenever slides arrive at a destination.
+	 *
+	 * @param {number}  destIndex - A destination index.
+	 * @param {number}  newIndex  - A new index.
+	 * @param {number}  prevIndex - A previous index.
+	 * @param {boolean} silently  - If true, suppress emitting events.
+	 */
+	function onTransitionEnd( destIndex, newIndex, prevIndex, silently ) {
+		applyStyle( list, { transition: '' } );
+
+		if ( ! isFade ) {
+			Track.jump( newIndex );
+		}
+
+		if ( ! silently ) {
+			Splide.emit( 'moved', newIndex, prevIndex, destIndex );
+		}
+	}
+
 	/**
 	 * Convert index to the trimmed position.
 	 *

+ 11 - 4
src/js/constants/defaults.js

@@ -68,7 +68,7 @@ export const DEFAULTS = {
 	 * Fix height of slides. CSS format is allowed such as 10em, 80vh but % unit is not accepted.
 	 * heightRatio option will be ignored when this option is falsy.
 	 *
-	 * @type {number}
+	 * @type {number|string}
 	 */
 	fixedHeight: 0,
 
@@ -343,15 +343,22 @@ export const DEFAULTS = {
 	throttle: 100,
 
 	/**
-	 * Breakpoints definitions.
+	 * Whether to destroy a slider or not.
+	 *
+	 * @type {boolean}
+	 */
+	destroy: false,
+
+	/**
+	 * Options for specific breakpoints.
 	 *
 	 * @example
 	 * {
-	 *   '1000': {
+	 *   1000: {
 	 *     perPage: 3,
 	 *     gap: 20
 	 *   },
-	 *   '600': {
+	 *   600: {
 	 *     perPage: 1,
 	 *     gap: 5,
 	 *   }

部分文件因为文件数量过多而无法显示