Skip to content

Commit

Permalink
Merge pull request #18 from iamapinan/dev
Browse files Browse the repository at this point in the history
fixed bugs
  • Loading branch information
iamapinan authored May 28, 2020
2 parents 19ff8d5 + 0e499e3 commit f36ab3b
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 154 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ You can edit the term page and publish on your website with elegant and powerful

### Changelogs

### 1.0.8
* Fixed WP Super Cache issue.
* Fixed consent not display on some website.
* Add template for user privacy & consent screen.
* Improve performance issue.

#### 1.0.7
* Fixed guest cookie

Expand Down
2 changes: 2 additions & 0 deletions assets/axios.min.js

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

1 change: 1 addition & 0 deletions assets/axios.min.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions assets/pdpa-consent-user.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
flex-direction: row;
background: rgb(170,34,195);
background: linear-gradient(0deg, rgba(170,34,195,1) 0%, rgba(253,45,121,1) 100%);
height: 150px;
padding: 10px;
padding: 20px 10px;
margin-bottom: 25px;
margin-top: 25px;
border-radius: 8px;
Expand All @@ -43,8 +42,9 @@
justify-content: flex-start;
padding-left: 25px;
}
.profile-header-top .user_title h3{
.profile-header-top .user_title h3 {
margin-bottom: 10px;
margin-top: 15px;
color: #fff;
}
.profile-header-top .user_title p {
Expand Down
8 changes: 5 additions & 3 deletions assets/pdpa-consent-user.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
(()=>{

})
document.addEventListener("DOMContentLoaded", function () {
document.getElementById('pdpa-status-reset').addEventListener("click", (e) => {
pdpa_consent_call('pdpa-reset');
})
});
73 changes: 31 additions & 42 deletions assets/pdpa-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,40 @@
* Package: pdpa-consent
* (c) Apinan Woratrakun <[email protected]>
*/
if (pdpa_ajax.consent_enable == 'yes') {
document.addEventListener("DOMContentLoaded", function () {
var allow_button = document.getElementById("PDPAAllow")
var not_allow_button = document.getElementById("PDPANotAllow")
var consent_win = document.getElementById("pdpa_screen")

not_allow_button.addEventListener("click", () => {
pdpa_ajax_call('pdpa-not-allow');
consent_win.style.display = 'none'
document.addEventListener("DOMContentLoaded", function () {
if (pdpa_ajax.consent_enable === "yes") {
document.getElementById("PDPANotAllow").addEventListener("click", function() {
pdpa_consent_call('pdpa-not-allow');
document.getElementById("pdpa_screen").style.display = 'none'
});

allow_button.addEventListener("click", () => {
pdpa_ajax_call('pdpa-allow');
consent_win.style.display = 'none'
});
})
}

const pdpa_ajax_call = (action_require) => {
// Guest process.
if(pdpa_ajax.current_user == 'guest') {
var the_date = new Date();
cookie_expire = the_date.setDate(the_date.getDate() + 30)
cookie_process({
type: action_require == 'pdpa-allow' ? 'user_allow' : 'user_not_allow',
cookie_name: 'pdpa_accepted',
cookie_expire: new Date(cookie_expire),
cookie_domain: window.location.hostname
document.getElementById("PDPAAllow").addEventListener("click", function() {
pdpa_consent_call('pdpa-allow');
document.getElementById("pdpa_screen").style.display = 'none'
});

return ;
}
})

var xhr = new XMLHttpRequest();
var fd = new FormData();

xhr.open("POST", pdpa_ajax.ajax_url, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var json = JSON.parse(xhr.responseText);
cookie_process(json);
}
};
const pdpa_consent_call = (action_require) => {
var pdpa_request_data = new FormData();
pdpa_request_data.append("action", "pdpa_action");
pdpa_request_data.append("set_status", action_require);
pdpa_request_data.append("security", pdpa_ajax.pdpa_nonce);

fd.append("action", "pdpa_action");
fd.append("set_status", action_require);
fd.append("security", pdpa_ajax.pdpa_nonce);
xhr.send(fd);
axios({
method: 'POST',
url: pdpa_ajax.ajax_url,
data: pdpa_request_data
})
.then(function (response) {
//handle success
cookie_process(response.data);
})
.catch(function (response) {
//handle error
console.log(response);
});
}

const cookie_process = (d) => {
Expand All @@ -58,8 +44,11 @@ const cookie_process = (d) => {
cookie_string = d.cookie_name + "=1; expires=" + d.cookie_expire + "; domain=" + d.cookie_domain + "; path=/";
} else if (d.type == 'user_not_allow') {
cookie_string = d.cookie_name + "=0; expires=" + d.cookie_expire + "; domain=" + d.cookie_domain + "; path=/";
} else if(d.type == 'reset') {
cookie_string = d.cookie_name + "=0; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=" + d.cookie_domain + "; path=/";
window.location.reload()
} else {
console.log("error.")
console.log("error.", d)
}
document.cookie = cookie_string;
}
Expand Down
9 changes: 6 additions & 3 deletions includes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ public function pdpa_admin_option()
.admin-page form th {
text-align: right;
}
.admin-page form h2 {
font-size: 18pt;
margin-top: 10px;
}
</style>
<?php settings_errors(); ?>
<div class="admin-page">
Expand Down Expand Up @@ -306,8 +310,7 @@ public function is_enable_callback()
public function regenerate_callback()
{
printf(
'<input type="checkbox" name="pdpa_option[regenerate]" id="is_enable" value="1" %s>',
!isset($this->options['regenerate']) ? 'checked' : ''
'<input type="checkbox" name="pdpa_option[regenerate]" id="is_enable" value="1">'
);
}
public function allow_user_reset_callback()
Expand Down Expand Up @@ -429,7 +432,7 @@ public function custom_css_callback()
.pdpa-admin-table {
border: 1px solid #eee;
padding: 0px;
background-color: #fff;
background-color: #fdf8ea;
}
.pdpa-admin-table tr td:first-child {
color: #a23a08;
Expand Down
Loading

0 comments on commit f36ab3b

Please sign in to comment.