@pernod-ricard-global-cms/jsutils 1.6.5 → 2.0.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.
- package/jsutils.js +37 -15
- package/package.json +28 -28
package/jsutils.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
/* eslint-disable consistent-return */
|
|
2
2
|
/* eslint-disable no-console */
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Function for check whether the code is running within the Wordpress admin page. Checks for wp-admin class.
|
|
6
|
+
* @returns {Boolean}
|
|
7
|
+
*/
|
|
8
|
+
export function isWpAdmin() {
|
|
9
|
+
return document.body.classList.contains('wp-admin') ? true : false;
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
/**
|
|
5
13
|
* This function accepts an html element and returns the position of that element on the page.
|
|
6
14
|
*
|
|
@@ -223,21 +231,13 @@ export function footerIntersection(entries, element) {
|
|
|
223
231
|
* Dynamically retrieves the swiper css and js and returns a resolved promise when they have both been successfully fetched.
|
|
224
232
|
* @returns {promise}
|
|
225
233
|
*/
|
|
226
|
-
export function
|
|
234
|
+
export function getSwiperAssetsV2(options = { css: 'bundle' }) {
|
|
227
235
|
const getSwiperJs = () =>
|
|
228
|
-
import(/* webpackChunkName: 'swiper' */ '
|
|
229
|
-
|
|
230
|
-
const getSwiperCss = () =>
|
|
231
|
-
import(
|
|
232
|
-
/* webpackChunkName: 'swiper' */
|
|
233
|
-
'../../swiper/swiper-bundle.min.css'
|
|
234
|
-
);
|
|
236
|
+
import(/* webpackChunkName: 'swiper' */ 'NodeModules/swiper/swiper.esm');
|
|
235
237
|
|
|
236
|
-
const promisedJs = Promise.all([getSwiperJs()
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
);
|
|
238
|
+
const promisedJs = Promise.all([getSwiperJs()]).then((values) => {
|
|
239
|
+
return values;
|
|
240
|
+
});
|
|
241
241
|
return promisedJs;
|
|
242
242
|
}
|
|
243
243
|
|
|
@@ -564,6 +564,27 @@ export function checkIosVersion() {
|
|
|
564
564
|
return 0;
|
|
565
565
|
}
|
|
566
566
|
|
|
567
|
+
/**
|
|
568
|
+
* Function for adding a link tag with preconnect to the head of the document. Very useful if you need to add this dynamically.
|
|
569
|
+
* @param {string} domain The domain you wish to preconnect to.
|
|
570
|
+
* @returns {void} The preconnect will be appended to the head tag.
|
|
571
|
+
*/
|
|
572
|
+
export function appendPreconnect(domain) {
|
|
573
|
+
try {
|
|
574
|
+
if (!domain) {
|
|
575
|
+
console.log('The domain was missing or broken...');
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
const link = document.createElement('link');
|
|
579
|
+
link.rel = 'preconnect';
|
|
580
|
+
link.href = domain;
|
|
581
|
+
document.head.appendChild(link);
|
|
582
|
+
return;
|
|
583
|
+
} catch (error) {
|
|
584
|
+
console.error(error);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
|
|
567
588
|
const api = {
|
|
568
589
|
copyToClipboard,
|
|
569
590
|
checkDevice,
|
|
@@ -571,9 +592,9 @@ const api = {
|
|
|
571
592
|
eventListenerDebouncer,
|
|
572
593
|
footerIntersection,
|
|
573
594
|
getPosition,
|
|
574
|
-
getSwiperAssets,
|
|
575
595
|
getGsap,
|
|
576
596
|
getJquery,
|
|
597
|
+
getSwiperAssetsV2,
|
|
577
598
|
inCriticalCssConfig,
|
|
578
599
|
injectYouTubeIframeScript,
|
|
579
600
|
isEmailValid,
|
|
@@ -587,6 +608,7 @@ const api = {
|
|
|
587
608
|
waitForLoad,
|
|
588
609
|
getElementStyles,
|
|
589
610
|
getPercent,
|
|
590
|
-
checkIosVersion
|
|
611
|
+
checkIosVersion,
|
|
612
|
+
appendPreconnect
|
|
591
613
|
};
|
|
592
614
|
export default api;
|
package/package.json
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
2
|
+
"name": "@pernod-ricard-global-cms/jsutils",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Handy collection of Javascript utility functions",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "jsutils.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "jasmine"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/Chivas-Brothers/jsUtils.git"
|
|
13
|
+
},
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/Chivas-Brothers/jsUtils/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/Chivas-Brothers/jsUtils#readme",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"gsap": "^3.7.1",
|
|
22
|
+
"jquery": "^3.6.0",
|
|
23
|
+
"prettier": "^2.5.1",
|
|
24
|
+
"swiper": "^8.1.4"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"jasmine": "^3.9.0",
|
|
28
|
+
"jsdoc": "^3.6.7"
|
|
29
|
+
}
|
|
30
30
|
}
|