Skip to content

Commit

Permalink
Feat: add cookie_table_caption option (close #485)
Browse files Browse the repository at this point in the history
  • Loading branch information
orestbida committed Mar 26, 2023
1 parent 0b1d14a commit bdfe84e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ A __lightweight__ & __gdpr compliant__ cookie consent plugin written in plain ja
accept_all_btn: 'Accept all',
reject_all_btn: 'Reject all',
close_btn_label: 'Close',
// cookie_table_caption: 'Cookie list',
cookie_table_headers: [
{col1: 'Name'},
{col2: 'Domain'},
Expand Down
2 changes: 1 addition & 1 deletion dist/cookieconsent.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cookieconsent.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/cookieconsent.css
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,14 @@ CookieConsent settings modal
overflow: hidden;
}

#s-bl caption {
display: block;
padding: 0.5rem 1rem;
font-size: .9em;
border-top: 1px solid var(--cc-cookie-table-border);
font-weight: 600;
}

#s-bl td,
#s-bl th {
padding: 0.8em 0.625em;
Expand Down
13 changes: 11 additions & 2 deletions src/cookieconsent.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

/**
* Global user configuration object
* @type {import('../types/types')}
*/
user_config,

Expand Down Expand Up @@ -616,12 +617,13 @@
new_settings_blocks = _createNode('div');
new_settings_blocks.id = 's-bl';
}

// Add label to close button
settings_close_btn.setAttribute('aria-label', user_config.languages[lang]['settings_modal']['close_btn_label'] || 'Close');

all_blocks = user_config.languages[lang]['settings_modal']['blocks'];
all_table_headers = user_config.languages[lang]['settings_modal']['cookie_table_headers'];
var table_caption = user_config.languages[lang]['settings_modal']['cookie_table_caption'];

var n_blocks = all_blocks.length;

Expand Down Expand Up @@ -810,8 +812,15 @@
var thead = _createNode('thead');
thead.appendChild(tr_tmp);

// append header to table
var block_table = _createNode('table');

if(table_caption) {
var caption = _createNode('caption');
caption.innerHTML = table_caption;
block_table.appendChild(caption);
}

// append header to table
block_table.appendChild(thead);

var tbody_fragment = document.createDocumentFragment();
Expand Down
1 change: 1 addition & 0 deletions types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ declare global {
title: string
description: string
toggle?: ToggleSetting
cookie_table_caption?: string,
cookie_table_headers?: Record<string, string>[]
cookie_table?: Record<string, string | boolean>[]
}
Expand Down

0 comments on commit bdfe84e

Please sign in to comment.