PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
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 16.3-a.1, at modules/widgets/eu-cookie-law/eu-cookie-law.js

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