This commit is contained in:
emmymayo
2025-02-05 23:15:46 +01:00
commit 7269c99357
16995 changed files with 3389680 additions and 0 deletions
@@ -0,0 +1,32 @@
/* eslint no-var: 0 */
( function ( $ ) {
var $document = $( document );
$document.ready( function () {
var maybeShowNotice = function ( e, policyUrl ) {
var $policyUrl = $( policyUrl || this ).closest( '.eu-cookie-law-widget-policy-url' );
if ( $policyUrl.find( 'input[type="radio"][value="default"]' ).is( ':checked' ) ) {
$policyUrl.find( '.notice.default-policy' ).css( 'display', 'block' );
$policyUrl.find( '.notice.custom-policy' ).hide();
} else {
$policyUrl.find( '.notice.default-policy' ).hide();
$policyUrl.find( '.notice.custom-policy' ).css( 'display', 'block' );
}
};
$document.on(
'click',
'.eu-cookie-law-widget-policy-url input[type="radio"]',
maybeShowNotice
);
$document.on( 'widget-updated widget-added', function ( e, widget ) {
var widgetId = $( widget ).attr( 'id' );
if ( widgetId && widgetId.indexOf( 'eu_cookie_law_widget' ) !== -1 ) {
maybeShowNotice( null, $( '#' + widgetId + ' .eu-cookie-law-widget-policy-url' ) );
}
} );
$( '.eu-cookie-law-widget-policy-url' ).each( maybeShowNotice );
} );
} )( jQuery );
@@ -0,0 +1,97 @@
( function () {
var overlay = document.getElementById( 'eu-cookie-law' ),
widget = document.querySelector( '.widget_eu_cookie_law_widget' );
if ( null === widget || null === overlay ) {
return;
}
var cookieValue = document.cookie.replace(
/(?:(?:^|.*;\s*)eucookielaw\s*=\s*([^;]*).*$)|^.*$/,
'$1'
),
inCustomizer = widget && widget.hasAttribute( 'data-customize-widget-id' ),
getScrollTop,
initialScrollPosition,
scrollFunction;
/**
* Gets the amount that the window is scrolled.
*
* @return int The distance from the top of the document.
*/
getScrollTop = function () {
return Math.abs( document.body.getBoundingClientRect().y );
};
if ( overlay.classList.contains( 'top' ) ) {
widget.classList.add( 'top' );
}
if ( overlay.classList.contains( 'ads-active' ) ) {
var adsCookieValue = document.cookie.replace(
/(?:(?:^|.*;\s*)personalized-ads-consent\s*=\s*([^;]*).*$)|^.*$/,
'$1'
);
if ( '' !== cookieValue && '' !== adsCookieValue && ! inCustomizer ) {
overlay.parentNode.removeChild( overlay );
}
} else if ( '' !== cookieValue && ! inCustomizer ) {
overlay.parentNode.removeChild( overlay );
}
document.body.appendChild( widget );
overlay.querySelector( 'form' ).addEventListener( 'submit', accept );
if ( overlay.classList.contains( 'hide-on-scroll' ) ) {
initialScrollPosition = getScrollTop();
scrollFunction = function () {
if ( Math.abs( getScrollTop() - initialScrollPosition ) > 50 ) {
accept();
}
};
window.addEventListener( 'scroll', scrollFunction );
} else if ( overlay.classList.contains( 'hide-on-time' ) ) {
setTimeout( accept, overlay.getAttribute( 'data-hide-timeout' ) * 1000 );
}
var accepted = false;
function accept( event ) {
if ( accepted ) {
return;
}
accepted = true;
if ( event && event.preventDefault ) {
event.preventDefault();
}
if ( overlay.classList.contains( 'hide-on-scroll' ) ) {
window.removeEventListener( 'scroll', scrollFunction );
}
var expireTime = new Date();
expireTime.setTime(
expireTime.getTime() + overlay.getAttribute( 'data-consent-expiration' ) * 24 * 60 * 60 * 1000
);
document.cookie =
'eucookielaw=' + expireTime.getTime() + ';path=/;expires=' + expireTime.toGMTString();
if (
overlay.classList.contains( 'ads-active' ) &&
overlay.classList.contains( 'hide-on-button' )
) {
document.cookie =
'personalized-ads-consent=' +
expireTime.getTime() +
';path=/;expires=' +
expireTime.toGMTString();
}
overlay.classList.add( 'hide' );
setTimeout( function () {
overlay.parentNode.removeChild( overlay );
widget.parentNode.removeChild( widget );
}, 400 );
}
} )();
@@ -0,0 +1,301 @@
<?php
/**
* EU Cookie Law Widget form.
*
* @html-template Jetpack_EU_Cookie_Law_Widget::form
* @package automattic/jetpack
*/
use Automattic\Jetpack\Redirect;
// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- HTML template, let Phan handle it.
?>
<p>
<strong>
<?php esc_html_e( 'Banner text', 'jetpack' ); ?>
</strong>
<ul>
<li>
<label>
<input
<?php checked( $instance['text'], 'default' ); ?>
name="<?php echo esc_attr( $this->get_field_name( 'text' ) ); ?>"
type="radio"
value="default"
/>
<?php esc_html_e( 'Default', 'jetpack' ); ?>
</label>
</li>
<li>
<label>
<input
<?php checked( $instance['text'], 'custom' ); ?>
name="<?php echo esc_attr( $this->get_field_name( 'text' ) ); ?>"
type="radio"
value="custom"
/>
<?php esc_html_e( 'Custom:', 'jetpack' ); ?>
</label>
</li>
</ul>
<textarea
class="widefat"
name="<?php echo esc_attr( $this->get_field_name( 'customtext' ) ); ?>"
placeholder="<?php echo esc_attr( $instance['default-text'] ); ?>"
><?php echo esc_html( $instance['customtext'] ); ?></textarea>
</p>
<hr />
<p>
<strong>
<?php esc_html_e( 'Privacy Policy Link', 'jetpack' ); ?>
</strong>
<ul class="eu-cookie-law-widget-policy-url">
<li>
<label>
<input
<?php checked( $instance['policy-url'], 'default' ); ?>
name="<?php echo esc_attr( $this->get_field_name( 'policy-url' ) ); ?>"
type="radio"
value="default"
/>
<?php esc_html_e( 'Default', 'jetpack' ); ?>
</label>
</li>
<li>
<label>
<input
<?php checked( $instance['policy-url'], 'custom' ); ?>
name="<?php echo esc_attr( $this->get_field_name( 'policy-url' ) ); ?>"
type="radio"
value="custom"
/>
<?php esc_html_e( 'Custom URL:', 'jetpack' ); ?>
</label>
<input
class="widefat"
name="<?php echo esc_attr( $this->get_field_name( 'custom-policy-url' ) ); ?>"
placeholder="<?php echo esc_url( $instance['default-policy-url'] ); ?>"
style="margin-top: .5em;"
type="text"
value="<?php echo esc_url( $instance['custom-policy-url'] ); ?>"
/>
<span class="notice notice-warning default-policy" style="display: none;">
<span style="display: block; margin: .5em 0;">
<strong><?php esc_html_e( 'Caution:', 'jetpack' ); ?></strong>
<?php esc_html_e( 'The default policy URL only covers cookies set by Jetpack. If youre running other plugins, custom cookies, or third-party tracking technologies, you should create and link to your own cookie statement.', 'jetpack' ); ?>
</span>
</span>
<?php if ( Jetpack::is_module_active( 'wordads' ) ) : ?>
<span class="notice notice-warning custom-policy" style="display: none;">
<span style="display: block; margin: .5em 0;">
<strong><?php esc_html_e( 'Caution:', 'jetpack' ); ?></strong>
<?php
printf(
wp_kses(
/* Translators: %s is the URL to a Jetpack support article. */
__( 'For GDPR compliance, please make sure your policy contains <a href="%s" target="_blank">privacy information relating to WordAds</a>.', 'jetpack' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
),
)
),
esc_url( Redirect::get_url( 'jetpack-support-ads', array( 'anchor' => 'privacy' ) ) )
);
?>
</span>
</span>
<?php endif; ?>
</li>
</ul>
</p>
<p>
<strong>
<?php esc_html_e( 'Link text', 'jetpack' ); ?>
</strong>
<label>
<input
class="widefat"
name="<?php echo esc_attr( $this->get_field_name( 'policy-link-text' ) ); ?>"
type="text"
value="<?php echo esc_attr( $instance['policy-link-text'] ); ?>"
/>
</label>
</p>
<hr />
<p>
<strong>
<?php esc_html_e( 'Button text', 'jetpack' ); ?>
</strong>
<label>
<input
class="widefat"
name="<?php echo esc_attr( $this->get_field_name( 'button' ) ); ?>"
type="text"
value="<?php echo esc_attr( $instance['button'] ); ?>"
/>
</label>
</p>
<hr />
<p>
<strong>
<?php esc_html_x( 'Capture consent & hide the banner', 'action', 'jetpack' ); ?>
</strong>
<ul>
<li>
<label>
<input
<?php checked( $instance['hide'], 'button' ); ?>
name="<?php echo esc_attr( $this->get_field_name( 'hide' ) ); ?>"
type="radio"
value="button"
<?php echo Jetpack::is_module_active( 'wordads' ) ? 'disabled' : ''; ?>
/>
<?php esc_html_e( 'after the user clicks the dismiss button', 'jetpack' ); ?>
</label>
</li>
<li>
<label>
<input
<?php checked( $instance['hide'], 'scroll' ); ?>
name="<?php echo esc_attr( $this->get_field_name( 'hide' ) ); ?>"
type="radio"
value="scroll"
<?php echo Jetpack::is_module_active( 'wordads' ) ? 'disabled' : ''; ?>
/>
<?php esc_html_e( 'after the user scrolls the page', 'jetpack' ); ?>
</label>
</li>
<li>
<label>
<input
<?php checked( $instance['hide'], 'time' ); ?>
name="<?php echo esc_attr( $this->get_field_name( 'hide' ) ); ?>"
type="radio"
value="time"
<?php echo Jetpack::is_module_active( 'wordads' ) ? 'disabled' : ''; ?>
/>
<?php esc_html_e( 'after this amount of time', 'jetpack' ); ?>
</label>
<input
max="1000"
min="3"
name="<?php echo esc_attr( $this->get_field_name( 'hide-timeout' ) ); ?>"
style="padding: 3px 5px; width: 3em;"
type="number"
value="<?php echo esc_attr( $instance['hide-timeout'] ); ?>"
/>
<?php esc_html_e( 'seconds', 'jetpack' ); ?>
</li>
</ul>
<?php if ( Jetpack::is_module_active( 'wordads' ) ) : ?>
<span class="notice notice-warning" style="display: block;">
<span style="display: block; margin: .5em 0;">
<?php esc_html_e( 'Visitors must provide consent by clicking the dismiss button when WordAds is turned on.', 'jetpack' ); ?>
</span>
</span>
<?php endif; ?>
</p>
<hr />
<p>
<strong>
<?php esc_html_x( 'Consent expires after', 'action', 'jetpack' ); ?>
</strong>
<ul>
<li>
<input
max="365"
min="1"
name="<?php echo esc_attr( $this->get_field_name( 'consent-expiration' ) ); ?>"
style="padding: 3px 5px; width: 3.75em;"
type="number"
value="<?php echo esc_attr( $instance['consent-expiration'] ); ?>"
/>
<?php esc_html_e( 'days', 'jetpack' ); ?>
</li>
</ul>
</p>
<hr />
<p>
<strong>
<?php esc_html_e( 'Color scheme', 'jetpack' ); ?>
</strong>
<ul>
<li>
<label>
<input
<?php checked( $instance['color-scheme'], 'default' ); ?>
name="<?php echo esc_attr( $this->get_field_name( 'color-scheme' ) ); ?>"
type="radio"
value="default"
/>
<?php esc_html_e( 'Light', 'jetpack' ); ?>
</label>
</li>
<li>
<label>
<input
<?php checked( $instance['color-scheme'], 'negative' ); ?>
name="<?php echo esc_attr( $this->get_field_name( 'color-scheme' ) ); ?>"
type="radio"
value="negative"
/>
<?php esc_html_e( 'Dark', 'jetpack' ); ?>
</label>
</li>
</ul>
</p>
<hr />
<p>
<strong>
<?php esc_html_e( 'Position', 'jetpack' ); ?>
</strong>
<ul>
<li>
<label>
<input
<?php checked( $instance['position'], 'bottom' ); ?>
name="<?php echo esc_attr( $this->get_field_name( 'position' ) ); ?>"
type="radio"
value="bottom"
/>
<?php esc_html_e( 'Bottom', 'jetpack' ); ?>
</label>
</li>
<li>
<label>
<input
<?php checked( $instance['position'], 'top' ); ?>
name="<?php echo esc_attr( $this->get_field_name( 'position' ) ); ?>"
type="radio"
value="top"
/>
<?php esc_html_e( 'Top', 'jetpack' ); ?>
</label>
</li>
</ul>
</p>
<hr />
<p class="small">
<?php esc_html_e( 'It is your own responsibility to ensure that your site complies with the relevant laws.', 'jetpack' ); ?>
<a href="<?php echo esc_url( Redirect::get_url( 'jetpack-support-extra-sidebar-widgets-eu-cookie-law-widget' ) ); ?>">
<?php esc_html_e( 'Click here for more information', 'jetpack' ); ?>
</a>
</p>
@@ -0,0 +1,134 @@
.widget_eu_cookie_law_widget {
animation: fadeIn 800ms;
border: none;
bottom: 1em;
left: 1em;
margin: 0;
padding: 0;
position: fixed;
right: 1em;
width: auto;
z-index: 50001;
}
@keyframes fadeIn {
from { opacity: 0; visibility: hidden; }
to { opacity: 1; visibility: visible; }
}
.widget_eu_cookie_law_widget.widget.top {
bottom: auto;
top: 1em;
}
.admin-bar .widget_eu_cookie_law_widget.widget.top {
top: 3em;
}
amp-consent.widget_eu_cookie_law_widget.widget.top {
top: 1em;
margin: 0;
}
.admin-bar amp-consent.widget_eu_cookie_law_widget.widget.top {
top: 0;
margin-top: 3em;
}
#eu-cookie-law {
background-color: #fff;
border: 1px solid #dedede;
color: #2e4467;
font-size: 12px;
line-height: 1.5;
overflow: hidden;
padding: 6px 6px 6px 15px;
position: relative;
}
#eu-cookie-law a,
#eu-cookie-law a:active,
#eu-cookie-law a:visited {
color: inherit;
cursor: inherit;
text-decoration: underline;
}
#eu-cookie-law a:hover {
cursor: pointer;
text-decoration: none;
}
#eu-cookie-law.negative {
background-color: #000;
border: none;
color: #fff;
}
#eu-cookie-law.hide {
opacity: 0;
visibility: hidden;
transition: opacity 400ms, visibility 400ms;
}
/**
* Using a highly-specific rule to make sure that certain form styles
* will be reset
*/
#eu-cookie-law form {
margin-bottom: 0;
position: static;
}
/**
* Using a highly-specific rule to make sure that all button styles
* will be reset
*/
#eu-cookie-law input,
#eu-cookie-law input:hover,
#eu-cookie-law input:focus {
background: #f3f3f3;
border: 1px solid #dedede;
border-radius: 4px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
color: #2e4453;
cursor: pointer;
display: inline;
float: right;
font-family: inherit;
font-size: 14px;
font-weight: inherit;
line-height: inherit;
margin: 0 0 0 5%;
padding: 8px 12px;
position: static;
text-transform: none;
}
#eu-cookie-law.negative input,
#eu-cookie-law.negative input:hover,
#eu-cookie-law.negative input:focus {
background: #282828;
border-color: #535353;
color: #fff;
}
@media ( max-width: 600px ) {
#eu-cookie-law {
padding-bottom: 55px;
}
#eu-cookie-law input.accept {
bottom: 8px;
position: absolute;
right: 8px;
}
}
/**
* Tweak position of the Customizer edit button to make it more obvious this
* is an editable widget rather than a normal accept cookies banner.
*/
.widget_eu_cookie_law_widget .customize-partial-edit-shortcut > button {
left: 0;
}
@@ -0,0 +1,42 @@
<?php
/**
* AMP Widget for Cookies and Consent.
*
* @html-template Jetpack_EU_Cookie_Law_Widget::widget
* @package automattic/jetpack
*/
// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- HTML template, let Phan handle it.
?>
<amp-consent id="eu-cookie-consent" layout="nodisplay" class="widget widget_eu_cookie_law_widget<?php echo esc_attr( ! empty( $instance['position'] ) && 'top' === $instance['position'] ? ' top' : '' ); ?>">
<script type="application/json">
{
"consentInstanceId": "eu-cookie-consent",
"consentRequired": true,
"promptUI": "eu-cookie-consent-prompt"
}
</script>
<div class="popupOverlay" id="eu-cookie-consent-prompt">
<div class="consentPopup<?php echo esc_attr( ! empty( $instance['color-scheme'] ) && 'negative' === $instance['color-scheme'] ? ' negative' : '' ); ?>" id="eu-cookie-law">
<form>
<input type="button" on="tap:eu-cookie-consent.accept" class="accept" value="<?php echo esc_attr( $instance['button'] ); ?>" />
</form>
<?php
if ( 'default' === $instance['text'] || empty( $instance['customtext'] ) ) {
echo wp_kses_post( nl2br( $instance['default-text'] ) );
} else {
echo esc_html( $instance['customtext'] );
}
$is_default_policy = 'default' === $instance['policy-url'] || empty( $instance['custom-policy-url'] );
$policy_link_url = $is_default_policy ? $instance['default-policy-url'] : $instance['custom-policy-url'];
$policy_link_rel = $is_default_policy ? 'nofollow' : '';
?>
<a href="<?php echo esc_url( $policy_link_url ); ?>" rel="<?php echo esc_attr( $policy_link_rel ); ?>">
<?php echo esc_html( $instance['policy-link-text'] ); ?>
</a>
</div>
</div>
</amp-consent>
@@ -0,0 +1,39 @@
<?php
/**
* Widget for Cookies and Consent.
*
* @html-template Jetpack_EU_Cookie_Law_Widget::widget
* @package automattic/jetpack
*/
// phpcs:disable VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable -- HTML template, let Phan handle it.
?>
<div
class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"
data-hide-timeout="<?php echo (int) $instance['hide-timeout']; ?>"
data-consent-expiration="<?php echo (int) $instance['consent-expiration']; ?>"
id="eu-cookie-law"
>
<form method="post" id="jetpack-eu-cookie-law-form">
<input type="submit" value="<?php echo esc_attr( $instance['button'] ); ?>" class="accept" />
</form>
<?php
if ( 'default' === $instance['text'] || empty( $instance['customtext'] ) ) {
echo nl2br( esc_html( $instance['default-text'] ) );
} else {
echo nl2br( esc_html( $instance['customtext'] ) );
}
?>
<?php
$is_default_policy = 'default' === $instance['policy-url'] || empty( $instance['custom-policy-url'] );
$policy_link_url = $is_default_policy ? $instance['default-policy-url'] : $instance['custom-policy-url'];
$policy_link_rel = $is_default_policy ? 'nofollow' : '';
?>
<a href="<?php echo esc_url( $policy_link_url ); ?>" rel="<?php echo esc_attr( $policy_link_rel ); ?>">
<?php echo esc_html( $instance['policy-link-text'] ); ?>
</a>
</div>