@pernod-ricard-global-cms/jsutils 2.1.2 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ import { resizeDebouncer } from '../../jsutils';
2
+
3
+ describe('A suite to test resizeDebouncer()', () => {
4
+ // Test coming soon!
5
+ });
File without changes
@@ -0,0 +1,11 @@
1
+ const { defineConfig } = require('cypress')
2
+
3
+ module.exports = defineConfig({
4
+ e2e: {
5
+ // We've imported your old cypress plugins here.
6
+ // You may want to clean this up later by importing these.
7
+ setupNodeEvents(on, config) {
8
+ return require('./cypress/plugins/index.js')(on, config)
9
+ },
10
+ },
11
+ })
package/jsutils.mjs CHANGED
@@ -309,23 +309,37 @@ export function mobileCheck() {
309
309
 
310
310
  /**
311
311
  * Run a function after a window resize event, but only after the alloted time has ended.
312
- * If another resize even occurs it resets the time window.
312
+ * If another resize event occurs it resets the time window.
313
313
  * @param {function} debouncedFunction The function you want to run after a window resize event.
314
314
  * @param {number} time The time in ms.
315
+ * @param {boolean} ignoreVertical Set to true if you only want to listen for horizontal resizing events.
315
316
  */
316
- export function resizeDebouncer(debouncedFunction, time = 250) {
317
+ export function resizeDebouncer(
318
+ debouncedFunction,
319
+ time = 250,
320
+ ignoreVertical = false
321
+ ) {
317
322
  let resizeTimer;
323
+ let screenWidth = window.innerWidth;
318
324
  window.addEventListener("resize", () => {
319
325
  clearTimeout(resizeTimer);
320
326
  resizeTimer = setTimeout(() => {
321
- debouncedFunction();
327
+ if (ignoreVertical) {
328
+ let currentWidth = window.innerWidth;
329
+ if (currentWidth - screenWidth !== 0) {
330
+ debouncedFunction();
331
+ }
332
+ screenWidth = currentWidth;
333
+ } else {
334
+ debouncedFunction();
335
+ }
322
336
  }, time);
323
337
  });
324
338
  }
325
339
 
326
340
  /**
327
341
  * General purpose utility for running a function after a particular event fires on a specified element. The function only fires after the alloted time has ended.
328
- * If another resize even occurs it resets the time window.
342
+ * If another resize event occurs it resets the time window.
329
343
  * @param {htmlElement} element The element that emits the event.
330
344
  * @param {string} eventType The type of event to listen for.
331
345
  * @param {function} debouncedFunction The function to run after the event.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pernod-ricard-global-cms/jsutils",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
4
4
  "description": "Handy collection of Javascript utility functions",
5
5
  "type": "commonjs",
6
6
  "main": "jsutils.mjs",
@@ -24,7 +24,7 @@
24
24
  "swiper": "^8.1.4"
25
25
  },
26
26
  "devDependencies": {
27
- "cypress": "^9.6.1",
27
+ "cypress": "^10.5.0",
28
28
  "jsdoc": "^3.6.7"
29
29
  }
30
30
  }
package/cypress.json DELETED
@@ -1 +0,0 @@
1
- {}