Skip to content

Commit

Permalink
Merge pull request #3 from dennisinteractive/iclick
Browse files Browse the repository at this point in the history
Looks sound
  • Loading branch information
chriskinch authored Apr 11, 2017
2 parents 2b08e21 + 2bbee93 commit 6afd448
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
31 changes: 30 additions & 1 deletion dist/implied-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,32 @@ if (typeof module !== 'undefined') {
* Launch events on page interaction.
*/
function validateByClick(wrapper) {
wrapper.addEventListener('click', validateByClickHandler);
wrapper.addEventListener('click', validateByClickHandler, {
passive: true
});

document.body.addEventListener('click', icDelegate, {
passive: true
});
}


function icDelegate(e) {
var clickElements = ['A', 'BUTTON', 'INPUT'];

if (clickElements.indexOf(e.target.tagName) >= 0) {
validateByClickHandler(e);
} else {
var parent = e.target;
while (parent.parentNode) {
parent = parent.parentNode;

if (clickElements.indexOf(parent.tagName) >= 0) {
validateByClickHandler({ target: parent });
break;
}
}
}
}

/**
Expand Down Expand Up @@ -513,6 +538,10 @@ if (typeof module !== 'undefined') {
var el = document.getElementById('__ic-notice-container');
el.parentElement.removeChild(el);
ic.status = false;

document.body.removeEventListener('click', icDelegate, {
passive: true
});
}

/**
Expand Down
4 changes: 2 additions & 2 deletions dist/implied-consent.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "implied-consent",
"description": "a Cookie Notice plugin",
"private": true,
"version": "1.1.0",
"version": "1.1.1",
"license": "MIT",
"main": "implied-consent.min.js",
"ignore": [
Expand Down
31 changes: 30 additions & 1 deletion src/implied-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,32 @@
* Launch events on page interaction.
*/
function validateByClick(wrapper) {
wrapper.addEventListener('click', validateByClickHandler);
wrapper.addEventListener('click', validateByClickHandler, {
passive: true
});

document.body.addEventListener('click', icDelegate, {
passive: true
});
}


function icDelegate(e) {
var clickElements = ['A', 'BUTTON', 'INPUT'];

if (clickElements.indexOf(e.target.tagName) >= 0) {
validateByClickHandler(e);
} else {
var parent = e.target;
while (parent.parentNode) {
parent = parent.parentNode;

if (clickElements.indexOf(parent.tagName) >= 0) {
validateByClickHandler({ target: parent });
break;
}
}
}
}

/**
Expand Down Expand Up @@ -242,6 +267,10 @@
var el = document.getElementById('__ic-notice-container');
el.parentElement.removeChild(el);
ic.status = false;

document.body.removeEventListener('click', icDelegate, {
passive: true
});
}

/**
Expand Down

0 comments on commit 6afd448

Please sign in to comment.