瀏覽代碼

Expose the `check` method to manually check whether to load near images.

Naotoshi Fujita 2 年之前
父節點
當前提交
2586acd529

+ 5 - 4
dist/js/splide.cjs.js

@@ -1,6 +1,6 @@
 /*!
 /*!
  * Splide.js
  * Splide.js
- * Version  : 4.0.9
+ * Version  : 4.0.11
  * License  : MIT
  * License  : MIT
  * Copyright: 2022 Naotoshi Fujita
  * Copyright: 2022 Naotoshi Fujita
  */
  */
@@ -2410,7 +2410,7 @@ function LazyLoad(Splide2, Components2, options) {
     if (options.lazyLoad) {
     if (options.lazyLoad) {
       init();
       init();
       on(EVENT_REFRESH, init);
       on(EVENT_REFRESH, init);
-      isSequential || on(events, observe);
+      isSequential || on(events, check);
     }
     }
   }
   }
 
 
@@ -2433,7 +2433,7 @@ function LazyLoad(Splide2, Components2, options) {
     isSequential && loadNext();
     isSequential && loadNext();
   }
   }
 
 
-  function observe() {
+  function check() {
     entries = entries.filter(function (data) {
     entries = entries.filter(function (data) {
       var distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
       var distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
       return data[1].isWithin(Splide2.index, distance) ? load(data) : true;
       return data[1].isWithin(Splide2.index, distance) ? load(data) : true;
@@ -2472,7 +2472,8 @@ function LazyLoad(Splide2, Components2, options) {
 
 
   return {
   return {
     mount: mount,
     mount: mount,
-    destroy: apply(empty, entries)
+    destroy: apply(empty, entries),
+    check: check
   };
   };
 }
 }
 
 

+ 5 - 4
dist/js/splide.esm.js

@@ -4,7 +4,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
 
 
 /*!
 /*!
  * Splide.js
  * Splide.js
- * Version  : 4.0.9
+ * Version  : 4.0.11
  * License  : MIT
  * License  : MIT
  * Copyright: 2022 Naotoshi Fujita
  * Copyright: 2022 Naotoshi Fujita
  */
  */
@@ -2405,7 +2405,7 @@ function LazyLoad(Splide2, Components2, options) {
     if (options.lazyLoad) {
     if (options.lazyLoad) {
       init();
       init();
       on(EVENT_REFRESH, init);
       on(EVENT_REFRESH, init);
-      isSequential || on(events, observe);
+      isSequential || on(events, check);
     }
     }
   }
   }
 
 
@@ -2428,7 +2428,7 @@ function LazyLoad(Splide2, Components2, options) {
     isSequential && loadNext();
     isSequential && loadNext();
   }
   }
 
 
-  function observe() {
+  function check() {
     entries = entries.filter(function (data) {
     entries = entries.filter(function (data) {
       var distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
       var distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
       return data[1].isWithin(Splide2.index, distance) ? load(data) : true;
       return data[1].isWithin(Splide2.index, distance) ? load(data) : true;
@@ -2467,7 +2467,8 @@ function LazyLoad(Splide2, Components2, options) {
 
 
   return {
   return {
     mount: mount,
     mount: mount,
-    destroy: apply(empty, entries)
+    destroy: apply(empty, entries),
+    check: check
   };
   };
 }
 }
 
 

+ 5 - 4
dist/js/splide.js

@@ -4,7 +4,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
 
 
 /*!
 /*!
  * Splide.js
  * Splide.js
- * Version  : 4.0.8
+ * Version  : 4.0.11
  * License  : MIT
  * License  : MIT
  * Copyright: 2022 Naotoshi Fujita
  * Copyright: 2022 Naotoshi Fujita
  */
  */
@@ -2403,7 +2403,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
       if (options.lazyLoad) {
       if (options.lazyLoad) {
         init();
         init();
         on(EVENT_REFRESH, init);
         on(EVENT_REFRESH, init);
-        isSequential || on(events, observe);
+        isSequential || on(events, check);
       }
       }
     }
     }
 
 
@@ -2426,7 +2426,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
       isSequential && loadNext();
       isSequential && loadNext();
     }
     }
 
 
-    function observe() {
+    function check() {
       entries = entries.filter(function (data) {
       entries = entries.filter(function (data) {
         var distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
         var distance = options.perPage * ((options.preloadPages || 1) + 1) - 1;
         return data[1].isWithin(Splide2.index, distance) ? load(data) : true;
         return data[1].isWithin(Splide2.index, distance) ? load(data) : true;
@@ -2465,7 +2465,8 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
 
 
     return {
     return {
       mount: mount,
       mount: mount,
-      destroy: apply(empty, entries)
+      destroy: apply(empty, entries),
+      check: check
     };
     };
   }
   }
 
 

File diff suppressed because it is too large
+ 0 - 0
dist/js/splide.min.js


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


File diff suppressed because it is too large
+ 0 - 0
dist/js/splide.min.js.map


+ 2 - 0
dist/types/index.d.ts

@@ -189,6 +189,8 @@ interface KeyboardComponent extends BaseComponent {
  * @since 3.0.0
  * @since 3.0.0
  */
  */
 interface LazyLoadComponent extends BaseComponent {
 interface LazyLoadComponent extends BaseComponent {
+    /** @internal */
+    check(): void;
 }
 }
 
 
 /**
 /**

+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
 {
   "name": "@splidejs/splide",
   "name": "@splidejs/splide",
-  "version": "4.0.10",
+  "version": "4.0.11",
   "lockfileVersion": 2,
   "lockfileVersion": 2,
   "requires": true,
   "requires": true,
   "packages": {
   "packages": {
     "": {
     "": {
       "name": "@splidejs/splide",
       "name": "@splidejs/splide",
-      "version": "4.0.10",
+      "version": "4.0.11",
       "license": "MIT",
       "license": "MIT",
       "devDependencies": {
       "devDependencies": {
         "@babel/core": "^7.18.13",
         "@babel/core": "^7.18.13",

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "@splidejs/splide",
   "name": "@splidejs/splide",
-  "version": "4.0.10",
+  "version": "4.0.11",
   "description": "Splide is a lightweight, flexible and accessible slider/carousel. No dependencies, no Lighthouse errors.",
   "description": "Splide is a lightweight, flexible and accessible slider/carousel. No dependencies, no Lighthouse errors.",
   "author": "Naotoshi Fujita",
   "author": "Naotoshi Fujita",
   "license": "MIT",
   "license": "MIT",

+ 7 - 4
src/js/components/LazyLoad/LazyLoad.ts

@@ -34,11 +34,13 @@ import { IMAGE_SELECTOR, SRC_DATA_ATTRIBUTE, SRCSET_DATA_ATTRIBUTE } from './con
  * @since 3.0.0
  * @since 3.0.0
  */
  */
 export interface LazyLoadComponent extends BaseComponent {
 export interface LazyLoadComponent extends BaseComponent {
+  /** @internal */
+  check(): void;
 }
 }
 
 
 /**
 /**
  * The type for each entry.
  * The type for each entry.
- * Use tuple for better compression.
+ * Use a tuple for better compression.
  *
  *
  * @since 4.0.0
  * @since 4.0.0
  */
  */
@@ -72,7 +74,7 @@ export function LazyLoad( Splide: Splide, Components: Components, options: Optio
     if ( options.lazyLoad ) {
     if ( options.lazyLoad ) {
       init();
       init();
       on( EVENT_REFRESH, init );
       on( EVENT_REFRESH, init );
-      isSequential || on( events, observe );
+      isSequential || on( events, check );
     }
     }
   }
   }
 
 
@@ -106,7 +108,7 @@ export function LazyLoad( Splide: Splide, Components: Components, options: Optio
    * Checks how close each image is from the active slide, and determines whether to start loading or not.
    * Checks how close each image is from the active slide, and determines whether to start loading or not.
    * The last `+1` is for the current page.
    * The last `+1` is for the current page.
    */
    */
-  function observe(): void {
+  function check(): void {
     entries = entries.filter( data => {
     entries = entries.filter( data => {
       const distance = options.perPage * ( ( options.preloadPages || 1 ) + 1 ) - 1;
       const distance = options.perPage * ( ( options.preloadPages || 1 ) + 1 ) - 1;
       return data[ 1 ].isWithin( Splide.index, distance ) ? load( data ) : true;
       return data[ 1 ].isWithin( Splide.index, distance ) ? load( data ) : true;
@@ -116,7 +118,7 @@ export function LazyLoad( Splide: Splide, Components: Components, options: Optio
   }
   }
 
 
   /**
   /**
-   * Starts loading the image in the data.
+   * Starts loading the image in the provided data.
    *
    *
    * @param data - A LazyLoadEntry object.
    * @param data - A LazyLoadEntry object.
    */
    */
@@ -163,5 +165,6 @@ export function LazyLoad( Splide: Splide, Components: Components, options: Optio
   return {
   return {
     mount,
     mount,
     destroy: apply( empty, entries ),
     destroy: apply( empty, entries ),
+    check,
   };
   };
 }
 }

Some files were not shown because too many files changed in this diff