-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from iamapinan/dev
fixed bugs
- Loading branch information
Showing
14 changed files
with
237 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) => { | ||
|
@@ -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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.