| 1 |
( function () { |
| 2 |
function getCookie( name ) { |
| 3 |
var match = document.cookie.match( new RegExp( '(?:^|; )' + name.replace( /[.$?*|{}()[\]\\/+^]/g, '\\$&' ) + '=([^;]*)' ) ); |
| 4 |
return match ? decodeURIComponent( match[1] ) : null; |
| 5 |
} |
| 6 |
function setCookie( name, value, days ) { |
| 7 |
var expires = ''; |
| 8 |
if ( days ) { |
| 9 |
var d = new Date(); |
| 10 |
d.setTime( d.getTime() + days * 86400000 ); |
| 11 |
expires = '; expires=' + d.toUTCString(); |
| 12 |
} |
| 13 |
document.cookie = name + '=' + encodeURIComponent( value ) + expires + '; path=/'; |
| 14 |
} |
| 15 |
|
| 16 |
document.querySelectorAll( '.bkpb-wrap' ).forEach( function ( wrap, idx ) { |
| 17 |
var cookieKey = 'bkpb_closed_' + idx; |
| 18 |
var cookieDays = parseInt( wrap.dataset.cookie, 10 ) || 0; |
| 19 |
|
| 20 |
/* Check if the user dismissed */ |
| 21 |
if ( cookieDays > 0 && getCookie( cookieKey ) === '1' ) { |
| 22 |
wrap.classList.add( 'bkpb-hidden' ); |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
/* Animation */ |
| 27 |
var anim = wrap.dataset.animation || 'none'; |
| 28 |
if ( anim !== 'none' ) { |
| 29 |
wrap.classList.add( 'bkpb-anim-' + anim ); |
| 30 |
} |
| 31 |
|
| 32 |
/* Shift body if fixed top */ |
| 33 |
if ( wrap.classList.contains( 'bkpb-pos-top' ) ) { |
| 34 |
document.body.style.paddingTop = ( parseInt( document.body.style.paddingTop, 10 ) || 0 ) + wrap.offsetHeight + 'px'; |
| 35 |
} |
| 36 |
if ( wrap.classList.contains( 'bkpb-pos-bottom' ) ) { |
| 37 |
document.body.style.paddingBottom = ( parseInt( document.body.style.paddingBottom, 10 ) || 0 ) + wrap.offsetHeight + 'px'; |
| 38 |
} |
| 39 |
|
| 40 |
/* Close button */ |
| 41 |
var btn = wrap.querySelector( '.bkpb-close' ); |
| 42 |
if ( btn ) { |
| 43 |
btn.addEventListener( 'click', function () { |
| 44 |
wrap.classList.add( 'bkpb-hidden' ); |
| 45 |
if ( cookieDays > 0 ) { |
| 46 |
setCookie( cookieKey, '1', cookieDays ); |
| 47 |
} |
| 48 |
} ); |
| 49 |
} |
| 50 |
} ); |
| 51 |
} )(); |
| 52 |
|