PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.3.2
Jetpack – WP Security, Backup, Speed, & Growth v12.3.2
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
jetpack / modules / widgets / eu-cookie-law / eu-cookie-law.js

eu-cookie-law.js in Jetpack – WP Security, Backup, Speed, & Growth 12.3.2, at modules/widgets/eu-cookie-law/eu-cookie-law.js

98 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function () {
2 var cookieValue = document.cookie.replace(
3 /(?:(?:^|.*;\s*)eucookielaw\s*\=\s*([^;]*).*$)|^.*$/,
4 '$1'
5 ),
6 overlay = document.getElementById( 'eu-cookie-law' ),
7 widget = document.querySelector( '.widget_eu_cookie_law_widget' ),
8 inCustomizer = widget && widget.hasAttribute( 'data-customize-widget-id' ),
9 getScrollTop,
10 initialScrollPosition,
11 scrollFunction;
12
13 if ( null === widget || null === overlay ) {
14 return;
15 }
16
17 /**
18 * Gets the amount that the window is scrolled.
19 *
20 * @return int The distance from the top of the document.
21 */
22 getScrollTop = function () {
23 return Math.abs( document.body.getBoundingClientRect().y );
24 };
25
26 if ( overlay.classList.contains( 'top' ) ) {
27 widget.classList.add( 'top' );
28 }
29
30 if ( overlay.classList.contains( 'ads-active' ) ) {
31 var adsCookieValue = document.cookie.replace(
32 /(?:(?:^|.*;\s*)personalized-ads-consent\s*\=\s*([^;]*).*$)|^.*$/,
33 '$1'
34 );
35 if ( '' !== cookieValue && '' !== adsCookieValue && ! inCustomizer ) {
36 overlay.parentNode.removeChild( overlay );
37 }
38 } else if ( '' !== cookieValue && ! inCustomizer ) {
39 overlay.parentNode.removeChild( overlay );
40 }
41
42 document.body.appendChild( widget );
43 overlay.querySelector( 'form' ).addEventListener( 'submit', accept );
44
45 if ( overlay.classList.contains( 'hide-on-scroll' ) ) {
46 initialScrollPosition = getScrollTop();
47 scrollFunction = function () {
48 if ( Math.abs( getScrollTop() - initialScrollPosition ) > 50 ) {
49 accept();
50 }
51 };
52 window.addEventListener( 'scroll', scrollFunction );
53 } else if ( overlay.classList.contains( 'hide-on-time' ) ) {
54 setTimeout( accept, overlay.getAttribute( 'data-hide-timeout' ) * 1000 );
55 }
56
57 var accepted = false;
58 function accept( event ) {
59 if ( accepted ) {
60 return;
61 }
62 accepted = true;
63
64 if ( event && event.preventDefault ) {
65 event.preventDefault();
66 }
67
68 if ( overlay.classList.contains( 'hide-on-scroll' ) ) {
69 window.removeEventListener( 'scroll', scrollFunction );
70 }
71
72 var expireTime = new Date();
73 expireTime.setTime(
74 expireTime.getTime() + overlay.getAttribute( 'data-consent-expiration' ) * 24 * 60 * 60 * 1000
75 );
76
77 document.cookie =
78 'eucookielaw=' + expireTime.getTime() + ';path=/;expires=' + expireTime.toGMTString();
79 if (
80 overlay.classList.contains( 'ads-active' ) &&
81 overlay.classList.contains( 'hide-on-button' )
82 ) {
83 document.cookie =
84 'personalized-ads-consent=' +
85 expireTime.getTime() +
86 ';path=/;expires=' +
87 expireTime.toGMTString();
88 }
89
90 overlay.classList.add( 'hide' );
91 setTimeout( function () {
92 overlay.parentNode.removeChild( overlay );
93 var widgetSection = document.querySelector( '.widget.widget_eu_cookie_law_widget' );
94 widgetSection.parentNode.removeChild( widgetSection );
95 }, 400 );
96 }
97 } )();
98