eu-cookie-law-admin.js
2 years ago
eu-cookie-law.js
1 year ago
form.php
8 months ago
style.css
9 months ago
widget-amp.php
9 months ago
widget.php
9 months ago
eu-cookie-law.js
98 lines
| 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 |