eu-cookie-law-admin.js
5 years ago
eu-cookie-law.js
5 years ago
form.php
2 years ago
style.css
6 years ago
widget-amp.php
5 years ago
widget.php
4 years ago
eu-cookie-law.js
98 lines
| 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 |