first commit

This commit is contained in:
Roman Pyrih
2023-07-24 08:30:51 +02:00
commit c2e100a763
7128 changed files with 1622619 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
( function( $ ) {
// ready event
$( function() {
// Save dismiss state // .is-dismissible
$( '.cn-notice' ).on( 'click', '.notice-dismiss, .cn-notice-dismiss', function( e ) {
if ( $( e.currentTarget ).hasClass( 'cn-approve' ) )
var notice_action = 'approve';
else if ( $( e.currentTarget ).hasClass( 'cn-delay' ) )
var notice_action = 'delay';
else
var notice_action = 'dismiss';
$.ajax( {
url: cnArgsNotice.ajaxURL,
type: 'POST',
dataType: 'json',
data: {
action: 'cn_dismiss_notice',
notice_action: notice_action,
nonce: cnArgsNotice.nonce
}
} );
$( e.delegateTarget ).slideUp( 'fast' );
} );
} );
} )( jQuery );

View File

@@ -0,0 +1,66 @@
( function( $ ) {
// ready event
$( function() {
// cancel deactivation
$( document ).on( 'click', '.cn-deactivate-plugin-cancel', function( e ) {
tb_remove();
return false;
} );
// simple deactivation
$( document ).on( 'click', '.cn-deactivate-plugin-simple', function( e ) {
// display spinner
$( '#cn-deactivation-footer .spinner' ).addClass( 'is-active' );
} );
// deactivation with sending data
$( document ).on( 'click', '.cn-deactivate-plugin-data', function( e ) {
var spinner = $( '#cn-deactivation-footer .spinner' ),
url = $( this ).attr( 'href' );
// display spinner
spinner.addClass( 'is-active' );
// submit data
$.post( ajaxurl, {
action: 'cn-deactivate-plugin',
option_id: $( 'input[name="cn_deactivation_option"]:checked' ).val(),
other: $( 'textarea[name="cn_deactivation_other"]' ).val(),
nonce: cnArgsPlugins.nonce
} ).done( function( response ) {
// deactivate plugin
window.location.href = url;
} ).fail( function() {
// deactivate plugin
window.location.href = url;
} );
return false;
} );
// click on deactivation link
$( document ).on( 'click', '.cn-deactivate-plugin-modal', function( e ) {
var modalBox = $( '#cn-deactivation-container' ).closest( '#TB_window' );
tb_show( cnArgsPlugins.deactivate, '#TB_inline?inlineId=cn-deactivation-modal&modal=false' );
if ( modalBox.length > 0 ) {
$( modalBox ).addClass( 'cn-deactivation-modal' );
$( modalBox ).find( '#TB_closeWindowButton' ).on( 'blur' );
}
return false;
} );
// change radio
$( document ).on( 'change', 'input[name="cn_deactivation_option"]', function( e ) {
if ( $( this ).val() === '6' )
$( '.cn-deactivation-textarea textarea' ).prop( 'disabled', false );
else
$( '.cn-deactivation-textarea textarea' ).prop( 'disabled', true );
} );
} );
} )( jQuery );

View File

@@ -0,0 +1,841 @@
( function ( $ ) {
// ready event
$( function () {
var btClient = false;
var btCreditCardsInitialized = false;
var btPayPalInitialized = false;
var btInit = function () {
var result = btInitToken();
if ( result !== false && btCreditCardsInitialized === false ) {
// AJAX was successful
result.done( function ( response ) {
// token received
try {
// parse response
data = JSON.parse( response );
// first step, init braintree client
btClient = braintree.client.create( {
authorization: data.token
} );
btInitPaymentMethod( 'credit_card' );
// token failed
} catch ( e ) {
btGatewayFail( 'btInit catch' );
}
// AJAX failed
} ).fail( function () {
btGatewayFail( 'btInit AJAX failed' );
} );
}
}
var btInitToken = function () {
// payment screen?
var payment = $( '.cn-sidebar form[data-action="payment"]' );
// init braintree
if ( payment.length ) {
payment.addClass( 'cn-form-disabled' );
if ( typeof braintree !== 'undefined' ) {
return $.ajax( {
url: cnWelcomeArgs.ajaxURL,
type: 'POST',
dataType: 'html',
data: {
action: 'cn_api_request',
request: 'get_bt_init_token',
nonce: cnWelcomeArgs.nonce
}
} );
} else
return false;
} else
return false;
}
var btInitPaymentMethod = function ( type ) {
// console.log( 'btInitPaymentMethod' );
if ( btClient !== false ) {
if ( type === 'credit_card' && btCreditCardsInitialized === false ) {
$( 'form.cn-form[data-action="payment"]' ).addClass( 'cn-form-disabled' );
btClient.then( btCreditCardsInit ).then( btHostedFieldsInstance ).catch( btGatewayFail );
} else if ( type === 'paypal' && btPayPalInitialized === false ) {
$( 'form.cn-form[data-action="payment"]' ).addClass( 'cn-form-disabled' );
btClient.then( btPaypalCheckoutInit ).then( btPaypalCheckoutSDK ).then( btPaypalCheckoutInstance ).then( btPaypalCheckoutButton ).catch( btGatewayFail );
}
} else
btGatewayFail( 'btInitPaymentMethod btClient is false' );
}
var btCreditCardsInit = function ( clientInstance ) {
// console.log( 'btCreditCardsInit' );
return braintree.hostedFields.create( {
client: clientInstance,
styles: {
'input': {
'font-size': '14px',
'font-family': '-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif',
'color': '#fff'
},
':focus': {
'color': '#fff'
},
"::placeholder": {
'color': '#aaa'
}
},
fields: {
number: {
'selector': '#cn_card_number',
'placeholder': '0000 0000 0000 0000'
},
expirationDate: {
'selector': '#cn_expiration_date',
'placeholder': 'MM / YY'
},
cvv: {
'selector': '#cn_cvv',
'placeholder': '123'
}
}
} );
}
var btHostedFieldsInstance = function ( hostedFieldsInstance ) {
// console.log( 'btHostedFieldsInstance' );
btCreditCardsInitialized = true;
var form = $( 'form.cn-form[data-action="payment"]' );
form.removeClass( 'cn-form-disabled' );
form.on( 'submit', function () {
if ( form.hasClass( 'cn-payment-in-progress' ) )
return false;
form.find( '.cn-form-feedback' ).addClass( 'cn-hidden' );
// spin the spinner, if exists
if ( form.find( '.cn-spinner' ).length )
form.find( '.cn-spinner' ).addClass( 'spin' );
var invalidForm = false;
var state = hostedFieldsInstance.getState();
// check hosted fields
Object.keys( state.fields ).forEach( function ( field ) {
if ( !state.fields[field].isValid ) {
$( state.fields[field].container ).addClass( 'braintree-hosted-fields-invalid' );
invalidForm = true;
}
} );
if ( invalidForm ) {
setTimeout( function () {
cnDisplayError( cnWelcomeArgs.invalidFields, form );
// spin the spinner, if exists
if ( form.find( '.cn-spinner' ).length )
form.find( '.cn-spinner' ).removeClass( 'spin' );
}, 500 );
return false;
}
hostedFieldsInstance.tokenize( function ( err, payload ) {
if ( err ) {
cnDisplayError( cnWelcomeArgs.error );
return false;
} else {
form.addClass( 'cn-payment-in-progress' );
form.find( 'input[name="payment_nonce"]' ).val( payload.nonce );
$( '#cn_submit_paid' ).find( '.cn-screen-button[data-screen="4"]' ).trigger( 'click' );
}
} );
return false;
} );
}
var btPaypalCheckoutInit = function ( clientInstance ) {
// console.log( 'btPaypalCheckoutInit' );
return braintree.paypalCheckout.create( {
client: clientInstance
} );
}
var btPaypalCheckoutSDK = function ( paypalCheckoutInstance ) {
// console.log( 'btPaypalCheckoutSDK' );
return paypalCheckoutInstance.loadPayPalSDK( {
vault: true,
intent: 'tokenize'
} );
}
var btPaypalCheckoutInstance = function ( paypalCheckoutInstance ) {
// console.log( 'btPaypalCheckoutInstance' );
var form = $( 'form.cn-form[data-action="payment"]' );
return paypal.Buttons( {
fundingSource: paypal.FUNDING.PAYPAL,
createBillingAgreement: function () {
// console.log( 'createBillingAgreement' );
form.addClass( 'cn-form-disabled' );
return paypalCheckoutInstance.createPayment( {
flow: 'vault',
intent: 'tokenize',
currency: 'EUR'
} );
},
onApprove: function ( data, actions ) {
// console.log( 'onApprove' );
return paypalCheckoutInstance.tokenizePayment( data ).then( function ( payload ) {
form.addClass( 'cn-payment-in-progress' );
form.find( 'input[name="payment_nonce"]' ).val( payload.nonce );
// console.log( 'onApprove inside' );
// console.log( $( '#cn_submit_paid' ).find( '.cn-screen-button[data-screen="4"]' ) );
$( '#cn_submit_paid' ).find( '.cn-screen-button[data-screen="4"]' ).trigger( 'click' );
} );
},
onCancel: function ( data ) {
// console.log( 'onCancel' );
form.removeClass( 'cn-form-disabled' );
},
onError: function ( err ) {
// console.log( 'onError' );
form.removeClass( 'cn-form-disabled' );
}
} ).render( '#cn_paypal_button' );
}
var btPaypalCheckoutButton = function () {
// console.log( 'btPaypalCheckoutButton' );
btPayPalInitialized = true;
$( 'form.cn-form[data-action="payment"]' ).removeClass( 'cn-form-disabled' );
}
var btGatewayFail = function ( error ) {
// console.log( 'btGatewayFail' );
if ( typeof error !== 'undefined' )
console.log( error );
cnDisplayError( cnWelcomeArgs.error );
}
var cnDisplayError = function ( message, form ) {
if ( typeof form === 'undefined' )
form = $( 'form.cn-form[data-action="payment"]' );
form.find( '.cn-form-feedback' ).html( '<p class="cn-error">' + message + '</p>' ).removeClass( 'cn-hidden' );
}
var cnWelcomeScreen = function ( e ) {
var screen = $( e.target ).data( 'screen' );
var steps = [ 1, 2, 3, 4 ];
var sidebars = [ 'login', 'register', 'configure', 'payment' ];
// continue with screen loading
var requestData = {
action: 'cn_welcome_screen',
nonce: cnWelcomeArgs.nonce
};
if ( $.inArray( screen, steps ) != -1 ) {
var container = $( '.cn-welcome-wrap' );
requestData.screen = screen;
} else if ( $.inArray( screen, sidebars ) != -1 ) {
var container = $( '.cn-sidebar' );
requestData.screen = screen;
} else
return false;
// add loading overlay
$( container ).addClass( 'cn-loading' );
$.ajax( {
url: cnWelcomeArgs.ajaxURL,
type: 'POST',
dataType: 'html',
data: requestData
} ).done( function ( response ) {
$( container ).replaceWith( response );
} ).fail( function ( jqXHR, textStatus, errorThrown ) {
//
} ).always( function ( response ) {
// remove spinner
$( container ).removeClass( 'cn-loading' );
// trigger event
var event = $.Event( 'screen-loaded' );
$( document ).trigger( event );
} );
return this;
};
var cnWelcomeForm = function ( form ) {
var formAction = $( form[0] ).data( 'action' );
var formResult = null;
var formData = {
action: 'cn_api_request',
nonce: cnWelcomeArgs.nonce
};
// clear feedback
$( form[0] ).find( '.cn-form-feedback' ).addClass( 'cn-hidden' );
// build request data
formData.request = formAction;
// convert form data to object
$( form[0] ).serializeArray().map( function ( x ) {
// exception for checkboxes
if ( x.name === 'cn_laws' ) {
var arrayVal = typeof formData[x.name] !== 'undefined' ? formData[x.name] : [ ];
arrayVal.push( x.value );
formData[x.name] = arrayVal;
} else {
formData[x.name] = x.value;
}
} );
formResult = $.ajax( {
url: cnWelcomeArgs.ajaxURL,
type: 'POST',
dataType: 'json',
data: formData
} );
return formResult;
};
// handle screen loading
$( document ).on( 'click', '.cn-screen-button', function ( e ) {
var form = $( e.target ).closest( 'form' );
var result = false;
// spin the spinner, if exists
if ( $( e.target ).find( '.cn-spinner' ).length )
$( e.target ).find( '.cn-spinner' ).addClass( 'spin' );
// no form?
if ( form.length === 0 )
return cnWelcomeScreen( e );
var formData = { };
var formDataset = $( form[0] ).data();
var formAction = formDataset.hasOwnProperty( 'action' ) ? formDataset.action : '';
// get form data
$( form[0] ).serializeArray().map( function ( x ) {
// exception for checkboxes
if ( x.name === 'cn_laws' ) {
var arrayVal = typeof formData[x.name] !== 'undefined' ? formData[x.name] : [ ];
arrayVal.push( x.value );
formData[x.name] = arrayVal;
} else {
formData[x.name] = x.value;
}
} );
// console.log( form[0] );
// console.log( formData );
// console.log( formAction );
// payment?
if ( formAction === 'payment' ) {
if ( formData.plan !== 'free' ) {
// only credit cards
if ( $( form[0] ).find( 'input[name="payment_nonce"]' ).val() === '' ) {
form.trigger( 'submit' );
return false;
}
} else {
// load screen
cnWelcomeScreen( e );
return false;
}
} else
e.preventDefault();
// get form and process it
result = cnWelcomeForm( form );
result.done( function ( response ) {
// error
if ( response.hasOwnProperty( 'error' ) ) {
cnDisplayError( response.error, $( form[0] ) );
return false;
// message
} else if ( response.hasOwnProperty( 'message' ) ) {
cnDisplayError( response.message, $( form[0] ) );
return false;
// all good
} else {
switch ( formAction ) {
// logged in, go to success or billing
case 'login' :
// register complete, go to success or billing
case 'register' :
var accountPlan = formData.hasOwnProperty( 'plan' ) ? formData.plan : 'free';
// trigger payment
var accordionItem = $( form[0] ).closest( '.cn-accordion-item' );
// collapse account
$( accordionItem ).addClass( 'cn-collapsed cn-disabled' );
// show billing
$( accordionItem ).next().removeClass( 'cn-disabled' ).removeClass( 'cn-collapsed' );
$( accordionItem ).find( 'form' ).removeClass( 'cn-form-disabled' );
// init braintree after payment screen is loaded via AJAX
btInit();
break;
case 'configure' :
default :
// load screen
cnWelcomeScreen( e );
break;
}
}
} );
result.always( function ( response ) {
if ( $( e.target ).find( '.cn-spinner' ).length )
$( e.target ).find( '.cn-spinner' ).removeClass( 'spin' );
// after invalid payment?
if ( formAction === 'payment' ) {
$( form[0] ).removeClass( 'cn-payment-in-progress' );
$( form[0] ).find( 'input[name="payment_nonce"]' ).val( '' );
}
} );
return result;
} );
//
$( document ).on( 'screen-loaded', function () {
var configureFields = $( '#cn-form-configure' ).serializeArray() || [ ];
var frame = window.frames[ 'cn_iframe_id' ];
if ( configureFields.length > 0 ) {
$( configureFields ).each( function ( index, field ) {
} );
}
} );
// change payment method
$( document ).on( 'change', 'input[name="method"]', function () {
var input = $( this );
$( '#cn_payment_method_credit_card, #cn_payment_method_paypal' ).toggle();
input.closest( 'form' ).find( '.cn-form-feedback' ).addClass( 'cn-hidden' );
// init payment method if needed
btInitPaymentMethod( input.val() );
} );
//
$( document ).on( 'click', '.cn-accordion > .cn-accordion-item .cn-accordion-button', function () {
var accordionItem = $( this ).closest( '.cn-accordion-item' );
var activeItem = $( this ).closest( '.cn-accordion' ).find( '.cn-accordion-item:not(.cn-collapsed)' );
if ( $( accordionItem ).hasClass( 'cn-collapsed' ) ) {
$( activeItem ).addClass( 'cn-collapsed' );
$( accordionItem ).removeClass( 'cn-collapsed' );
}
return false;
} );
// live preview
$( document ).on( 'change', 'input[name="cn_position"]', function () {
var val = $( this ).val();
var frame = window.frames['cn_iframe_id'];
frame.contentWindow.postMessage( { call: 'position', value: val } );
} );
$( document ).on( 'change', 'input[name="cn_laws"]', function () {
var val = [ ];
$( 'input[name="cn_laws"]:checked' ).each( function () {
val.push( $( this ).val() );
} );
var frame = window.frames['cn_iframe_id'];
frame.contentWindow.postMessage( { call: 'laws', value: val } );
} );
$( document ).on( 'change', 'input[name="cn_naming"]', function () {
var val = [ ];
$( 'input[name="cn_naming"]:checked' ).each( function () {
val.push( $( this ).val() );
} );
var frame = window.frames['cn_iframe_id'];
frame.contentWindow.postMessage( { call: 'naming', value: val } );
} );
$( document ).on( 'change', 'input[name="cn_privacy_paper"]', function () {
var val = $( this ).prop( 'checked' );
var frame = window.frames['cn_iframe_id'];
frame.contentWindow.postMessage( { call: 'privacy_paper', value: val } );
} );
$( document ).on( 'change', 'input[name="cn_privacy_contact"]', function () {
var val = $( this ).prop( 'checked' );
var frame = window.frames['cn_iframe_id'];
frame.contentWindow.postMessage( { call: 'privacy_contact', value: val } );
} );
$( document ).on( 'change', 'input[name="cn_color_primary"]', function () {
var val = $( this ).val();
var frame = window.frames['cn_iframe_id'];
frame.contentWindow.postMessage( { call: 'color_primary', value: val } );
} );
$( document ).on( 'change', 'input[name="cn_color_background"]', function () {
var val = $( this ).val();
var frame = window.frames['cn_iframe_id'];
frame.contentWindow.postMessage( { call: 'color_background', value: val } );
} );
$( document ).on( 'change', 'input[name="cn_color_border"]', function () {
var val = $( this ).val();
var frame = window.frames['cn_iframe_id'];
frame.contentWindow.postMessage( { call: 'color_border', value: val } );
} );
$( document ).on( 'change', 'input[name="cn_color_text"]', function () {
var val = $( this ).val();
var frame = window.frames['cn_iframe_id'];
frame.contentWindow.postMessage( { call: 'color_text', value: val } );
} );
$( document ).on( 'change', 'input[name="cn_color_heading"]', function () {
var val = $( this ).val();
var frame = window.frames['cn_iframe_id'];
frame.contentWindow.postMessage( { call: 'color_heading', value: val } );
} );
$( document ).on( 'change', 'input[name="cn_color_button_text"]', function () {
var val = $( this ).val();
var frame = window.frames['cn_iframe_id'];
frame.contentWindow.postMessage( { call: 'color_button_text', value: val } );
} );
// plan selection
$( document ).on( 'change', 'input[name="plan"]', function () {
var availablePlans = [ 'free', 'monthly', 'yearly' ];
var input = $( this ),
inputVal = input.val();
inputVal = availablePlans.indexOf( inputVal ) != -1 ? inputVal : 'free';
if ( inputVal === 'free' ) {
$( '#cn_submit_free' ).removeClass( 'cn-hidden' );
$( '#cn_submit_paid' ).addClass( 'cn-hidden' );
} else {
$( '#cn_submit_free' ).addClass( 'cn-hidden' );
$( '#cn_submit_paid' ).removeClass( 'cn-hidden' );
}
$( document ).find( '.cn-pricing-item input[value="' + inputVal + '"' ).prop( 'checked', true );
} );
// highlight form
$( document ).on( 'click', 'input[name="cn_pricing_plan"]', function () {
$( '.cn-accordion .cn-accordion-item:first-child:not(.cn-collapsed)' ).focus();
} );
// select plan
$( document ).on( 'change', 'input[name="cn_pricing_plan"]', function () {
var availablePlans = [ 'free', 'monthly', 'yearly' ];
var input = $( this ),
inputVal = input.val();
inputVal = availablePlans.indexOf( inputVal ) != -1 ? inputVal : 'free';
if ( inputVal === 'free' ) {
$( '#cn_submit_free' ).removeClass( 'cn-hidden' );
$( '#cn_submit_paid' ).addClass( 'cn-hidden' );
} else {
$( '#cn_submit_free' ).addClass( 'cn-hidden' );
$( '#cn_submit_paid' ).removeClass( 'cn-hidden' );
}
$( document ).find( '#cn_field_plan_' + inputVal ).prop( 'checked', true );
} );
// color picker
initSpectrum();
// init welcome modal
if ( cnWelcomeArgs.initModal == true )
initModal();
} );
$( document ).on( 'ajaxComplete', function () {
// color picker
initSpectrum();
} );
function initSpectrum() {
$( '.cn-color-picker' ).spectrum( {
showInput: true,
showInitial: true,
allowEmpty: false,
showAlpha: false
} );
}
function initModal() {
var progressbar,
timerId,
modal = $( "#cn-modal-trigger" );
if ( modal ) {
$( "#cn-modal-trigger" ).modaal( {
content_source: cnWelcomeArgs.ajaxURL + '?action=cn_welcome_screen' + '&nonce=' + cnWelcomeArgs.nonce + '&screen=1',
type: 'ajax',
width: 1600,
custom_class: 'cn-modal',
// is_locked: true
ajax_success: function () {
progressbar = $( document ).find( '.cn-progressbar' );
if ( progressbar ) {
timerId = initProgressBar( progressbar );
}
},
before_close: function () {
clearInterval( timerId );
var currentStep = $( '.cn-welcome-wrap' );
// reload if on success screen
if ( currentStep.length > 0 ) {
if ( $( currentStep[0] ).hasClass( 'cn-welcome-step-4' ) === true )
window.location.reload( true );
}
},
after_close: function () {
progressbar = $( document ).find( '.cn-progressbar' );
$( progressbar ).progressbar( "destroy" );
}
} );
$( modal ).trigger( 'click' );
$( document ).on( 'click', '.cn-skip-button', function ( e ) {
$( '#modaal-close' ).trigger( 'click' );
} );
}
}
function initProgressBar( progressbar ) {
var progressbarObj,
progressLabel = $( document ).find( '.cn-progress-label' ),
complianceResults = $( document ).find( '.cn-compliance-results' ),
currentProgress = 0,
timerId;
if ( progressbar ) {
$( document ).on( 'click', '.cn-screen-button', function ( e ) {
e.preventDefault();
// console.log( e );
clearInterval( timerId );
} );
$( progressbar ).progressbar( {
value: 5,
max: 100,
create: function ( event, ui ) {
// console.log( event );
timerId = setInterval( function () {
// increment progress bar
currentProgress += 5;
// console.log( currentProgress );
// update progressbar
progressbar.progressbar( 'value', currentProgress );
var lastItem = $( complianceResults ).find( 'div:visible' ).last(),
lastItemText = $( lastItem ).find( '.cn-compliance-status' ).text();
$( lastItem ).find( '.cn-compliance-status' ).text( lastItemText + ' .' );
switch ( currentProgress ) {
case 25:
$( lastItem ).find( '.cn-compliance-status' ).addClass( 'cn-passed' ).text( cnWelcomeArgs.statusPassed );
$( lastItem ).next().slideDown( 200 );
break;
case 50:
if ( cnWelcomeArgs.complianceStatus === 'active' ) {
$( lastItem ).find( '.cn-compliance-status' ).addClass( 'cn-passed' ).text( cnWelcomeArgs.statusPassed );
} else {
$( lastItem ).find( '.cn-compliance-status' ).addClass( 'cn-failed' ).text( cnWelcomeArgs.statusFailed );
}
$( lastItem ).next().slideDown( 200 );
break;
case 75:
if ( cnWelcomeArgs.complianceStatus === 'active' ) {
$( lastItem ).find( '.cn-compliance-status' ).addClass( 'cn-passed' ).text( cnWelcomeArgs.statusPassed );
} else {
$( lastItem ).find( '.cn-compliance-status' ).addClass( 'cn-failed' ).text( cnWelcomeArgs.statusFailed );
}
$( lastItem ).next().slideDown( 200 );
break;
case 100:
if ( cnWelcomeArgs.complianceStatus === 'active' ) {
$( lastItem ).find( '.cn-compliance-status' ).addClass( 'cn-passed' ).text( cnWelcomeArgs.statusPassed );
} else {
$( lastItem ).find( '.cn-compliance-status' ).addClass( 'cn-failed' ).text( cnWelcomeArgs.statusFailed );
}
break;
}
// complete
if ( currentProgress >= 100 ) {
clearInterval( timerId );
}
}, 300 );
},
change: function ( event, ui ) {
// console.log( event );
progressLabel.text( progressbar.progressbar( 'value' ) + '%' );
},
complete: function ( event, ui ) {
// console.log( event );
setTimeout( function () {
if ( cnWelcomeArgs.complianceStatus )
$( '.cn-compliance-check' ).find( '.cn-compliance-feedback' ).html( '<p class="cn-message">' + cnWelcomeArgs.compliancePassed + '</p>' ).removeClass( 'cn-hidden' );
else
$( '.cn-compliance-check' ).find( '.cn-compliance-feedback' ).html( '<p class="cn-error">' + cnWelcomeArgs.complianceFailed + '</p>' ).removeClass( 'cn-hidden' );
}, 500 );
// $( progressbar ).progressbar( "destroy" );
}
} );
progressbarObj = $( progressbar ).progressbar( "instance" );
return timerId;
}
}
$( document ).on( 'click', '.cn-run-upgrade, .cn-run-welcome', function ( e ) {
e.preventDefault();
// console.log( e );
// modal
initModal();
} );
$( document ).ready( function () {
var welcome = false;
welcome = cnGetUrlParam( 'welcome' );
if ( welcome ) {
// modal
initModal();
}
} );
$( document ).on( 'click', '.cn-sign-up', function ( e ) {
e.preventDefault();
$( '.cn-screen-button' ).trigger( 'click' );
} );
var cnGetUrlParam = function cnGetUrlParam( parameter ) {
var pageURL = window.location.search.substring( 1 ),
urlVars = pageURL.split( '&' ),
parameterName,
i;
for ( i = 0; i < urlVars.length; i++ ) {
parameterName = urlVars[i].split( '=' );
if ( parameterName[0] === parameter ) {
return typeof parameterName[1] === undefined ? true : decodeURIComponent( parameterName[1] );
}
}
return false;
};
} )( jQuery );

View File

@@ -0,0 +1,94 @@
( function( $ ) {
// ready event
$( function() {
// initialize color picker
$( '.cn_color' ).wpColorPicker();
$( '#cn_app_purge_cache a' ).on( 'click', function( e ) {
e.preventDefault();
var el = this;
$( el ).parent().addClass( 'loading' ).append( '<span class="spinner is-active" style="float: none;"></span>' );
$.ajax( {
url: cnArgs.ajaxURL,
type: 'POST',
dataType: 'json',
data: {
action: 'cn_purge_cache',
nonce: cnArgs.nonce
}
} )
.done ( function ( result ) {
console.log( result );
} )
.always ( function ( result ) {
$( el ).parent().find( '.spinner' ).remove();
} );
} );
// refuse option
$( '#cn_refuse_opt' ).on( 'change', function() {
if ( $( this ).is( ':checked' ) )
$( '#cn_refuse_opt_container' ).slideDown( 'fast' );
else
$( '#cn_refuse_opt_container' ).slideUp( 'fast' );
} );
// revoke option
$( '#cn_revoke_cookies' ).on( 'change', function() {
if ( $( this ).is( ':checked' ) )
$( '#cn_revoke_opt_container' ).slideDown( 'fast' );
else
$( '#cn_revoke_opt_container' ).slideUp( 'fast' );
} );
// privacy policy option
$( '#cn_see_more' ).on( 'change', function() {
if ( $( this ).is( ':checked' ) )
$( '#cn_see_more_opt' ).slideDown( 'fast' );
else
$( '#cn_see_more_opt' ).slideUp( 'fast' );
} );
// on scroll option
$( '#cn_on_scroll' ).on( 'change', function() {
if ( $( this ).is( ':checked' ) )
$( '#cn_on_scroll_offset' ).slideDown( 'fast' );
else
$( '#cn_on_scroll_offset' ).slideUp( 'fast' );
} );
// privacy policy link
$( '#cn_see_more_link-custom, #cn_see_more_link-page' ).on( 'change', function() {
if ( $( '#cn_see_more_link-custom:checked' ).val() === 'custom' ) {
$( '#cn_see_more_opt_page' ).slideUp( 'fast', function() {
$( '#cn_see_more_opt_link' ).slideDown( 'fast' );
} );
} else if ( $( '#cn_see_more_link-page:checked' ).val() === 'page' ) {
$( '#cn_see_more_opt_link' ).slideUp( 'fast', function() {
$( '#cn_see_more_opt_page' ).slideDown( 'fast' );
} );
}
} );
$( '#cn_refuse_code_fields' ).find( 'a' ).on( 'click', function( e ) {
e.preventDefault();
$( '#cn_refuse_code_fields' ).find( 'a' ).removeClass( 'nav-tab-active' );
$( '.refuse-code-tab' ).removeClass( 'active' );
var id = $( this ).attr( 'id' ).replace( '-tab', '' );
$( '#' + id ).addClass( 'active' );
$( this ).addClass( 'nav-tab-active' );
} );
} );
$( document ).on( 'click', 'input#reset_cookie_notice_options', function() {
return confirm( cnArgs.resetToDefaults );
} );
} )( jQuery );

View File

@@ -0,0 +1,5 @@
(function($){$(function(){$('.cn_color').wpColorPicker();$('#cn_app_purge_cache a').on('click',function(e){e.preventDefault();var el=this;$(el).parent().addClass('loading').append('<span class="spinner is-active" style="float: none;"></span>');$.ajax({url:cnArgs.ajaxURL,type:'POST',dataType:'json',data:{action:'cn_purge_cache',nonce:cnArgs.nonce}}).done(function(result){console.log(result)}).always(function(result){$(el).parent().find('.spinner').remove()})});$('#cn_refuse_opt').on('change',function(){if($(this).is(':checked'))
$('#cn_refuse_opt_container').slideDown('fast');else $('#cn_refuse_opt_container').slideUp('fast')});$('#cn_revoke_cookies').on('change',function(){if($(this).is(':checked'))
$('#cn_revoke_opt_container').slideDown('fast');else $('#cn_revoke_opt_container').slideUp('fast')});$('#cn_see_more').on('change',function(){if($(this).is(':checked'))
$('#cn_see_more_opt').slideDown('fast');else $('#cn_see_more_opt').slideUp('fast')});$('#cn_on_scroll').on('change',function(){if($(this).is(':checked'))
$('#cn_on_scroll_offset').slideDown('fast');else $('#cn_on_scroll_offset').slideUp('fast')});$('#cn_see_more_link-custom, #cn_see_more_link-page').on('change',function(){if($('#cn_see_more_link-custom:checked').val()==='custom'){$('#cn_see_more_opt_page').slideUp('fast',function(){$('#cn_see_more_opt_link').slideDown('fast')})}else if($('#cn_see_more_link-page:checked').val()==='page'){$('#cn_see_more_opt_link').slideUp('fast',function(){$('#cn_see_more_opt_page').slideDown('fast')})}});$('#cn_refuse_code_fields').find('a').on('click',function(e){e.preventDefault();$('#cn_refuse_code_fields').find('a').removeClass('nav-tab-active');$('.refuse-code-tab').removeClass('active');var id=$(this).attr('id').replace('-tab','');$('#'+id).addClass('active');$(this).addClass('nav-tab-active')})});$(document).on('click','input#reset_cookie_notice_options',function(){return confirm(cnArgs.resetToDefaults)})})(jQuery)

View File

@@ -0,0 +1,461 @@
( function( $ ) {
// ready event
$( function() {
var cnHiddenElements = {};
// listen for the load
document.addEventListener( 'load.hu', function( e ) {
// set widget text strings
hu.setTexts( cnFrontWelcome.textStrings );
} );
// listen for the reload
document.addEventListener( 'reload.hu', function( e ) {
var container = $( '#hu' );
var customOptions = { config: {
dontSellLink: true,
privacyPolicyLink: true,
privacyPaper: true,
privacyContact: true
} };
// set widget options
hu.setOptions( customOptions );
} );
// listen for the display
document.addEventListener( 'display.hu', function( e ) {
var val = [],
container = $( '#hu' );
var customOptions = { config: {
// make it empty
} };
$( parent.document ).find( 'input[name="cn_laws"]:checked' ).each( function() {
val.push( $( this ).val() );
} );
// hide paper and contact
if ( $( parent.document ).find( 'input[name="cn_privacy_paper"]' ).prop( 'checked' ) === true ) {
$( container ).find( '#hu-cookies-paper' ).show();
} else {
$( container ).find( '#hu-cookies-paper' ).hide();
}
if ( $( parent.document ).find( 'input[name="cn_privacy_contact"]' ).prop( 'checked' ) === true ) {
$( container ).find( '#hu-cookies-contact' ).show();
} else {
$( container ).find( '#hu-cookies-contact' ).hide();
}
if ( $.inArray( 'ccpa', val ) !== -1 ) {
var htmlElement = $( $( container ).find( '#hu-cookies-notice-dontsell-btn' ) );
if ( htmlElement.length === 0 ) {
$( '#hu-policy-links' ).append( cnHiddenElements.ccpa );
delete cnHiddenElements.ccpa;
}
$.extend( customOptions.config, { dontSellLink: true } );
} else {
var htmlElement = $( $( container ).find( '#hu-cookies-notice-dontsell-btn' ) );
// add to hidden elements
if ( htmlElement ) {
cnHiddenElements['ccpa'] = htmlElement;
// remove el
$( htmlElement ).remove();
}
$.extend( customOptions.config, { dontSellLink: false } );
}
if ( $.inArray( 'gdpr', val ) !== -1 ) {
var htmlElement = $( $( container ).find( '#hu-cookies-notice-privacy-btn' ) );
if ( htmlElement.length === 0 ) {
$( '#hu-policy-links' ).prepend( cnHiddenElements.gdpr );
delete cnHiddenElements.gdpr;
}
$.extend( customOptions.config, { privacyPolicyLink: true } );
} else {
var htmlElement = $( $( container ).find( '#hu-cookies-notice-privacy-btn' ) );
// add to hidden elements
if ( htmlElement ) {
cnHiddenElements['gdpr'] = htmlElement;
// remove el
$( htmlElement ).remove();
}
$.extend( customOptions.config, { privacyPolicyLink: false } );
}
// console.log( customOptions );
// set widget options
hu.setOptions( customOptions );
} );
// listen for the parent
window.addEventListener( 'message', function( event ) {
var iframe = $( parent.document ).find( '#cn_iframe_id' ),
form = $( parent.document ).find( '#cn-form-configure' );
// console.log( iframe );
// add spinner
$( iframe ).closest( '.has-loader' ).addClass( 'cn-loading' ).append( '<span class="cn-spinner"></span>' );
// lock options
$( form ).addClass( 'cn-form-disabled' );
// emit loader
window.setTimeout( function() {
if ( typeof event.data == 'object' ) {
var container = $( '#hu' ),
option = event.data.call,
customOptions = {},
customTexts = {};
// console.log( option );
switch ( option ) {
case 'position':
$( container ).removeClass( 'hu-position-bottom hu-position-top hu-position-left hu-position-right hu-position-center' );
$( container ).addClass( 'hu-position-' + event.data.value );
customOptions = { design: { position: event.data.value } }
break;
case 'naming':
var level1 = $( '.hu-cookies-notice-consent-choices-1' ),
level2 = $( '.hu-cookies-notice-consent-choices-2' ),
level3 = $( '.hu-cookies-notice-consent-choices-3' );
var text1 = cnFrontWelcome.levelNames[event.data.value][1],
text2 = cnFrontWelcome.levelNames[event.data.value][2],
text3 = cnFrontWelcome.levelNames[event.data.value][3];
// apply text to dom elements
$( level1 ).find( '.hu-toggle-label' ).text( text1 );
$( level2 ).find( '.hu-toggle-label' ).text( text2 );
$( level3 ).find( '.hu-toggle-label' ).text( text3 );
// apply text to text strings
customTexts = {
levelNameText_1: text1,
levelNameText_2: text2,
levelNameText_3: text3
}
break;
case 'laws':
customOptions.config = {}
if ( $.inArray( 'ccpa', event.data.value ) !== -1 ) {
var htmlElement = $( container ).find( '#hu-cookies-notice-dontsell-btn' );
if ( htmlElement.length === 0 ) {
$( '#hu-policy-links' ).append( cnHiddenElements.ccpa );
delete cnHiddenElements.ccpa;
}
$.extend( customOptions.config, { dontSellLink: true } );
} else {
var htmlElement = $( container ).find( '#hu-cookies-notice-dontsell-btn' );
// add to hidden elements
if ( htmlElement && ! cnHiddenElements.hasOwnProperty( 'ccpa' ) ) {
cnHiddenElements['ccpa'] = htmlElement;
// remove el
$( htmlElement ).remove();
}
$.extend( customOptions.config, { dontSellLink: false } );
}
if ( $.inArray( 'gdpr', event.data.value ) !== -1 ) {
var htmlElement = $( container ).find( '#hu-cookies-notice-privacy-btn' );
if ( htmlElement.length === 0 ) {
$( '#hu-policy-links' ).prepend( cnHiddenElements.gdpr );
delete cnHiddenElements.gdpr;
}
$.extend( customOptions.config, { privacyPolicyLink: true } );
} else {
var htmlElement = $( container ).find( '#hu-cookies-notice-privacy-btn' );
// add to hidden elements
if ( htmlElement && ! cnHiddenElements.hasOwnProperty( 'gdpr' ) ) {
cnHiddenElements['gdpr'] = htmlElement;
// remove el
$( htmlElement ).remove();
}
$.extend( customOptions.config, { privacyPolicyLink: false } );
}
// console.log( customOptions );
break;
case 'privacy_paper':
var value = event.data.value === true;
var htmlElement = $( container ).find( '#hu-cookies-paper' );
if ( value )
$( htmlElement ).show();
else
$( htmlElement ).hide();
$.extend( customOptions.config, { privacyPaper: value } );
break;
case 'privacy_contact':
var value = event.data.value === true;
var htmlElement = $( container ).find( '#hu-cookies-contact');
if ( value )
$( htmlElement ).show();
else
$( htmlElement ).hide();
$.extend( customOptions.config, { privacyContact: value } );
break;
case 'color_primary':
var iframeContents = $( iframe ).contents()[0];
iframeContents.documentElement.style.setProperty( '--hu-primaryColor', event.data.value );
customOptions = { design: { primaryColor: event.data.value } }
break;
case 'color_background':
var iframeContents = $( iframe ).contents()[0];
iframeContents.documentElement.style.setProperty( '--hu-bannerColor', event.data.value );
customOptions = { design: { bannerColor: event.data.value } }
break;
case 'color_border':
var iframeContents = $( iframe ).contents()[0];
iframeContents.documentElement.style.setProperty( '--hu-borderColor', event.data.value );
customOptions = { design: { borderColor: event.data.value } }
break;
case 'color_text':
var iframeContents = $( iframe ).contents()[0];
iframeContents.documentElement.style.setProperty( '--hu-textColor', event.data.value );
customOptions = { design: { textColor: event.data.value } }
break;
case 'color_heading':
var iframeContents = $( iframe ).contents()[0];
iframeContents.documentElement.style.setProperty( '--hu-headingColor', event.data.value );
customOptions = { design: { headingColor: event.data.value } }
break;
case 'color_button_text':
var iframeContents = $( iframe ).contents()[0];
iframeContents.documentElement.style.setProperty( '--hu-btnTextColor', event.data.value );
customOptions = { design: { btnTextColor: event.data.value } }
break;
}
// set widget options
hu.setOptions( customOptions );
// set widget texts
hu.setTexts( customTexts );
// console.log( hu.options );
}
// remove spinner
$( iframe ).closest( '.has-loader' ).find( '.cn-spinner' ).remove();
$( iframe ).closest( '.has-loader' ).removeClass( 'cn-loading' );
// unlock options
$( form ).removeClass( 'cn-form-disabled' );
}, 500 );
}, false );
// is it iframe?
if ( document !== parent.document && typeof cnFrontWelcome !== 'undefined' && cnFrontWelcome.previewMode ) {
// $( parent.document ).find( '#cn_test' ).val( $( document ).find( '.site-title' ).text() );
var iframe = $( parent.document ).find( '#cn_iframe_id' );
// inject links into initial document
$( document.body ).find( 'a[href], area[href]' ).each( function() {
cnAddPreviewModeToLink( this, iframe );
} );
// inject links into initial document
$( document.body ).find( 'form' ).each( function() {
cnAddPreviewModeToForm( this, iframe );
} );
// inject links for new elements added to the page
if ( typeof MutationObserver !== 'undefined' ) {
var observer = new MutationObserver( function( mutations ) {
_.each( mutations, function( mutation ) {
$( mutation.target ).find( 'a[href], area[href]' ).each( function() {
cnAddPreviewModeToLink( this, iframe );
} );
$( mutation.target ).find( 'form' ).each( function() {
cnAddPreviewModeToForm( this, iframe );
} );
} );
} );
observer.observe( document.documentElement, {
childList: true,
subtree: true
} );
} else {
// If mutation observers aren't available, fallback to just-in-time injection.
$( document.documentElement ).on( 'click focus mouseover', 'a[href], area[href]', function() {
cnAddPreviewModeToLink( this, iframe );
} );
}
// remove spinner
$( iframe ).closest( '.has-loader' ).find( '.cn-spinner' ).remove();
$( iframe ).closest( '.has-loader' ).removeClass( 'cn-loading' );
}
} );
/**
* Inject preview mode parameter into specific links on the frontend.
*/
function cnAddPreviewModeToLink( element, iframe ) {
var params, $element = $( element );
// skip elements with no href attribute
if ( ! element.hasAttribute( 'href' ) )
return;
// skip links in admin bar
if ( $element.closest( '#wpadminbar' ).length )
return;
// ignore links with href="#", href="#id", or non-HTTP protocols (e.g. javascript: and mailto:)
if ( '#' === $element.attr( 'href' ).substr( 0, 1 ) || ! /^https?:$/.test( element.protocol ) )
return;
// make sure links in preview use HTTPS if parent frame uses HTTPS.
// if ( api.settings.channel && 'https' === api.preview.scheme.get() && 'http:' === element.protocol && -1 !== api.settings.url.allowedHosts.indexOf( element.host ) )
// element.protocol = 'https:';
// ignore links with special class
if ( $element.hasClass( 'wp-playlist-caption' ) )
return;
// check special links
if ( ! cnIsLinkPreviewable( element ) )
return;
$( element ).on( 'click', function() {
$( iframe ).closest( '.has-loader' ).addClass( 'cn-loading' );
} );
// parse query string
params = cnParseQueryString( element.search.substring( 1 ) );
// set preview mode
params.cn_preview_mode = 1;
element.search = $.param( params );
}
/**
* Inject preview mode parameter into specific forms on the frontend.
*/
function cnAddPreviewModeToForm( element, iframe ) {
var input = document.createElement( 'input' );
input.setAttribute( 'type', 'hidden' );
input.setAttribute( 'name', 'cn_preview_mode' );
input.setAttribute( 'value', 1 );
element.appendChild( input );
}
/**
* Parse query string.
*/
function cnParseQueryString( string ) {
var params = {};
_.each( string.split( '&' ), function( pair ) {
var parts, key, value;
parts = pair.split( '=', 2 );
if ( ! parts[0] )
return;
key = decodeURIComponent( parts[0].replace( /\+/g, ' ' ) );
key = key.replace( / /g, '_' );
if ( _.isUndefined( parts[1] ) )
value = null;
else
value = decodeURIComponent( parts[1].replace( /\+/g, ' ' ) );
params[ key ] = value;
} );
return params;
}
/**
* Whether the supplied link is previewable.
*/
function cnIsLinkPreviewable( element ) {
var matchesAllowedUrl, parsedAllowedUrl, elementHost;
if ( 'javascript:' === element.protocol )
return true;
// only web URLs can be previewed
if ( element.protocol !== 'https:' && element.protocol !== 'http:' )
return false;
elementHost = element.host.replace( /:(80|443)$/, '' );
parsedAllowedUrl = document.createElement( 'a' );
matchesAllowedUrl = ! _.isUndefined( _.find( cnFrontWelcome.allowedURLs, function( allowedUrl ) {
parsedAllowedUrl.href = allowedUrl;
return parsedAllowedUrl.protocol === element.protocol && parsedAllowedUrl.host.replace( /:(80|443)$/, '' ) === elementHost && 0 === element.pathname.indexOf( parsedAllowedUrl.pathname.replace( /\/$/, '' ) );
} ) );
if ( ! matchesAllowedUrl )
return false;
// skip wp login and signup pages
if ( /\/wp-(login|signup)\.php$/.test( element.pathname ) )
return false;
// allow links to admin ajax as faux frontend URLs
if ( /\/wp-admin\/admin-ajax\.php$/.test( element.pathname ) )
return false;
// disallow links to admin, includes, and content
if ( /\/wp-(admin|includes|content)(\/|$)/.test( element.pathname ) )
return false;
return true;
};
} )( jQuery );

View File

@@ -0,0 +1,458 @@
// CustomEvent polyfil for IE support
( function () {
if ( typeof window.CustomEvent === "function" )
return false;
function CustomEvent( event, params ) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
return evt;
}
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
} )();
// ClassList polyfil for IE/Safari support
( function () {
var regExp = function ( name ) {
return new RegExp( '(^| )' + name + '( |$)' );
};
var forEach = function ( list, fn, scope ) {
for ( var i = 0; i < list.length; i++ ) {
fn.call( scope, list[i] );
}
};
function ClassList( element ) {
this.element = element;
}
ClassList.prototype = {
add: function () {
forEach( arguments, function ( name ) {
if ( !this.contains( name ) ) {
this.element.className += this.element.className.length > 0 ? ' ' + name : name;
}
}, this );
},
remove: function () {
forEach( arguments, function ( name ) {
this.element.className =
this.element.className.replace( regExp( name ), '' );
}, this );
},
toggle: function ( name ) {
return this.contains( name )
? ( this.remove( name ), false ) : ( this.add( name ), true );
},
contains: function ( name ) {
return regExp( name ).test( this.element.className );
},
// bonus..
replace: function ( oldName, newName ) {
this.remove( oldName ), this.add( newName );
}
};
// IE8/9, Safari
if ( !( 'classList' in Element.prototype ) ) {
Object.defineProperty( Element.prototype, 'classList', {
get: function () {
return new ClassList( this );
}
} );
}
if ( window.DOMTokenList && DOMTokenList.prototype.replace == null )
DOMTokenList.prototype.replace = ClassList.prototype.replace;
} )();
// cookieNotice
( function ( window, document, undefined ) {
var cookieNotice = new function () {
// cookie status
this.cookiesAccepted = null;
// notice container
this.noticeContainer = null;
// set cookie value
this.setStatus = function ( cookieValue ) {
var _this = this;
// remove listening to scroll event
if ( cnArgs.onScroll === '1' )
window.removeEventListener( 'scroll', this.handleScroll );
var date = new Date(),
laterDate = new Date();
// set cookie type and expiry time in seconds
if ( cookieValue === 'accept' ) {
cookieValue = 'true';
laterDate.setTime( parseInt( date.getTime() ) + parseInt( cnArgs.cookieTime ) * 1000 );
} else {
cookieValue = 'false';
laterDate.setTime( parseInt( date.getTime() ) + parseInt( cnArgs.cookieTimeRejected ) * 1000 );
}
// set cookie
document.cookie = cnArgs.cookieName + '=' + cookieValue + ';expires=' + laterDate.toUTCString() + ';' + ( !!cnArgs.cookieDomain ? 'domain=' + cnArgs.cookieDomain + ';' : '' ) + ( !!cnArgs.cookiePath ? 'path=' + cnArgs.cookiePath + ';' : '' ) + ( cnArgs.secure === '1' ? 'secure;' : '' );
// update global status
this.cookiesAccepted = cookieValue === 'true';
// trigger custom event
var event = new CustomEvent(
'setCookieNotice',
{
detail: {
value: cookieValue,
time: date,
expires: laterDate,
data: cnArgs
}
}
);
document.dispatchEvent( event );
this.setBodyClass( [ 'cookies-set', cookieValue === 'true' ? 'cookies-accepted' : 'cookies-refused' ] );
this.hideCookieNotice();
// show revoke notice if enabled
if ( cnArgs.revokeCookiesOpt === 'automatic' ) {
// show cookie notice after the revoke is hidden
this.noticeContainer.addEventListener( 'animationend', function handler() {
_this.noticeContainer.removeEventListener( 'animationend', handler );
_this.showRevokeNotice();
} );
this.noticeContainer.addEventListener( 'webkitAnimationEnd', function handler() {
_this.noticeContainer.removeEventListener( 'webkitAnimationEnd', handler );
_this.showRevokeNotice();
} );
}
// redirect?
if ( cnArgs.redirection === '1' && ( ( cookieValue === 'true' && this.cookiesAccepted === null ) || ( cookieValue !== this.cookiesAccepted && this.cookiesAccepted !== null ) ) ) {
var url = window.location.protocol + '//',
hostname = window.location.host + '/' + window.location.pathname;
// enabled cache?
if ( cnArgs.cache === '1' ) {
url = url + hostname.replace( '//', '/' ) + ( window.location.search === '' ? '?' : window.location.search + '&' ) + 'cn-reloaded=1' + window.location.hash;
window.location.href = url;
} else {
url = url + hostname.replace( '//', '/' ) + window.location.search + window.location.hash;
window.location.reload( true );
}
return;
}
};
// get cookie value
this.getStatus = function ( bool ) {
var value = "; " + document.cookie,
parts = value.split( '; cookie_notice_accepted=' );
if ( parts.length === 2 ) {
var val = parts.pop().split( ';' ).shift();
if ( bool )
return val === 'true';
else
return val;
} else
return null;
};
// display cookie notice
this.showCookieNotice = function () {
var _this = this;
// trigger custom event
var event = new CustomEvent(
'showCookieNotice',
{
detail: {
data: cnArgs
}
}
);
document.dispatchEvent( event );
this.noticeContainer.classList.remove( 'cookie-notice-hidden' );
this.noticeContainer.classList.add( 'cn-animated' );
this.noticeContainer.classList.add( 'cookie-notice-visible' );
// detect animation
this.noticeContainer.addEventListener( 'animationend', function handler() {
_this.noticeContainer.removeEventListener( 'animationend', handler );
_this.noticeContainer.classList.remove( 'cn-animated' );
} );
this.noticeContainer.addEventListener( 'webkitAnimationEnd', function handler() {
_this.noticeContainer.removeEventListener( 'webkitAnimationEnd', handler );
_this.noticeContainer.classList.remove( 'cn-animated' );
} );
};
// hide cookie notice
this.hideCookieNotice = function () {
var _this = this;
// trigger custom event
var event = new CustomEvent(
'hideCookieNotice',
{
detail: {
data: cnArgs
}
}
);
document.dispatchEvent( event );
this.noticeContainer.classList.add( 'cn-animated' );
this.noticeContainer.classList.remove( 'cookie-notice-visible' );
// detect animation
this.noticeContainer.addEventListener( 'animationend', function handler() {
_this.noticeContainer.removeEventListener( 'animationend', handler );
_this.noticeContainer.classList.remove( 'cn-animated' );
_this.noticeContainer.classList.add( 'cookie-notice-hidden' );
} );
this.noticeContainer.addEventListener( 'webkitAnimationEnd', function handler() {
_this.noticeContainer.removeEventListener( 'webkitAnimationEnd', handler );
_this.noticeContainer.classList.remove( 'cn-animated' );
_this.noticeContainer.classList.add( 'cookie-notice-hidden' );
} );
};
// display revoke notice
this.showRevokeNotice = function () {
var _this = this;
// trigger custom event
var event = new CustomEvent(
'showRevokeNotice',
{
detail: {
data: cnArgs
}
}
);
document.dispatchEvent( event );
this.noticeContainer.classList.remove( 'cookie-revoke-hidden' );
this.noticeContainer.classList.add( 'cn-animated' );
this.noticeContainer.classList.add( 'cookie-revoke-visible' );
// detect animation
this.noticeContainer.addEventListener( 'animationend', function handler() {
_this.noticeContainer.removeEventListener( 'animationend', handler );
_this.noticeContainer.classList.remove( 'cn-animated' );
} );
this.noticeContainer.addEventListener( 'webkitAnimationEnd', function handler() {
_this.noticeContainer.removeEventListener( 'webkitAnimationEnd', handler );
_this.noticeContainer.classList.remove( 'cn-animated' );
} );
};
// hide revoke notice
this.hideRevokeNotice = function () {
var _this = this;
// trigger custom event
var event = new CustomEvent(
'hideRevokeNotice',
{
detail: {
data: cnArgs
}
}
);
document.dispatchEvent( event );
this.noticeContainer.classList.add( 'cn-animated' );
this.noticeContainer.classList.remove( 'cookie-revoke-visible' );
// detect animation
this.noticeContainer.addEventListener( 'animationend', function handler() {
_this.noticeContainer.removeEventListener( 'animationend', handler );
_this.noticeContainer.classList.remove( 'cn-animated' );
_this.noticeContainer.classList.add( 'cookie-revoke-hidden' );
} );
this.noticeContainer.addEventListener( 'webkitAnimationEnd', function handler() {
_this.noticeContainer.removeEventListener( 'webkitAnimationEnd', handler );
_this.noticeContainer.classList.remove( 'cn-animated' );
_this.noticeContainer.classList.add( 'cookie-revoke-hidden' );
} );
};
// change body classes
this.setBodyClass = function ( classes ) {
// remove body classes
document.body.classList.remove( 'cookies-revoke' );
document.body.classList.remove( 'cookies-accepted' );
document.body.classList.remove( 'cookies-refused' );
document.body.classList.remove( 'cookies-set' );
document.body.classList.remove( 'cookies-not-set' );
// add body classes
for ( var i = 0; i < classes.length; i++ ) {
document.body.classList.add( classes[i] );
}
};
// handle mouse scrolling
this.handleScroll = function () {
var scrollTop = window.pageYOffset || ( document.documentElement || document.body.parentNode || document.body ).scrollTop
// accept cookie
if ( scrollTop > parseInt( cnArgs.onScrollOffset ) )
this.setStatus( 'accept' );
};
// cross browser compatible closest function
this.getClosest = function ( elem, selector ) {
// element.matches() polyfill
if ( !Element.prototype.matches ) {
Element.prototype.matches =
Element.prototype.matchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector ||
Element.prototype.oMatchesSelector ||
Element.prototype.webkitMatchesSelector ||
function ( s ) {
var matches = ( this.document || this.ownerDocument ).querySelectorAll( s ),
i = matches.length;
while ( --i >= 0 && matches.item( i ) !== this ) {
}
return i > -1;
};
}
// get the closest matching element
for ( ; elem && elem !== document; elem = elem.parentNode ) {
if ( elem.matches( selector ) )
return elem;
}
return null;
};
// initialize
this.init = function () {
var _this = this;
this.cookiesAccepted = this.getStatus( true );
this.noticeContainer = document.getElementById( 'cookie-notice' );
var cookieButtons = document.getElementsByClassName( 'cn-set-cookie' ),
revokeButtons = document.getElementsByClassName( 'cn-revoke-cookie' ),
closeIcon = document.getElementById( 'cn-close-notice' );
// add effect class
this.noticeContainer.classList.add( 'cn-effect-' + cnArgs.hideEffect );
// check cookies status
if ( this.cookiesAccepted === null ) {
// handle on scroll
if ( cnArgs.onScroll === '1' )
window.addEventListener( 'scroll', function ( e ) {
_this.handleScroll();
} );
// handle on click
if ( cnArgs.onClick === '1' )
window.addEventListener( 'click', function ( e ) {
var outerContainer = _this.getClosest( e.target, '#cookie-notice' );
// accept notice if clicked element is not inside the container
if ( outerContainer === null )
_this.setStatus( 'accept' );
}, true );
this.setBodyClass( [ 'cookies-not-set' ] );
// show cookie notice
this.showCookieNotice();
} else {
this.setBodyClass( [ 'cookies-set', this.cookiesAccepted === true ? 'cookies-accepted' : 'cookies-refused' ] );
// show revoke notice if enabled
if ( cnArgs.revokeCookies === '1' && cnArgs.revokeCookiesOpt === 'automatic' )
this.showRevokeNotice();
}
// handle cookie buttons click
for ( var i = 0; i < cookieButtons.length; i++ ) {
cookieButtons[i].addEventListener( 'click', function ( e ) {
e.preventDefault();
// Chrome double click event fix
e.stopPropagation();
_this.setStatus( this.dataset.cookieSet );
} );
}
// handle close icon
if ( closeIcon !== 'null' ) {
closeIcon.addEventListener( 'click', function ( e ) {
e.preventDefault();
// Chrome double click event fix
e.stopPropagation();
_this.setStatus( 'reject' );
} );
}
// handle revoke buttons click
for ( var i = 0; i < revokeButtons.length; i++ ) {
revokeButtons[i].addEventListener( 'click', function ( e ) {
e.preventDefault();
// hide revoke notice
if ( _this.noticeContainer.classList.contains( 'cookie-revoke-visible' ) ) {
_this.hideRevokeNotice();
// show cookie notice after the revoke is hidden
_this.noticeContainer.addEventListener( 'animationend', function handler() {
_this.noticeContainer.removeEventListener( 'animationend', handler );
_this.showCookieNotice();
} );
_this.noticeContainer.addEventListener( 'webkitAnimationEnd', function handler() {
_this.noticeContainer.removeEventListener( 'webkitAnimationEnd', handler );
_this.showCookieNotice();
} );
// show cookie notice
} else if ( _this.noticeContainer.classList.contains( 'cookie-notice-hidden' ) && _this.noticeContainer.classList.contains( 'cookie-revoke-hidden' ) ) {
_this.showCookieNotice();
}
} );
}
};
}
// initialize plugin
window.addEventListener( 'load', function () {
cookieNotice.init();
}, false );
} )( window, document, undefined );

File diff suppressed because one or more lines are too long