Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vanilla JS to avoid issues because of jquery versions #96

Merged
merged 3 commits into from
Sep 21, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions views/js/overrideAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
* International Registered Trademark & Property of PrestaShop SA
*/

$(window).load(function() {
let addressShipping = $('#addressShipping');
addressShipping.empty();
addressShipping.append('<p>'+psgdprNoAddresses+'</p>');
addressShipping.css("visibility", "visible");

let addressInvoice = $('#addressInvoice');
addressInvoice.empty();
addressInvoice.append('<p>'+psgdprNoAddresses+'</p>');
addressInvoice.css("visibility", "visible");
document.addEventListener('DOMContentLoaded', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using $(document).on('ready')

Most browsers provide similar functionality in the form of a DOMContentLoaded event. However, jQuery's .ready() method differs in an important and useful way: If the DOM becomes ready and the browser fires DOMContentLoaded before the code calls .ready( handler ), the function handler will still be executed. In contrast, a DOMContentLoaded event listener added after the event fires is never executed.

from the jQuery doc

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @V4LUX wanted to avoid using jQuery.
He did it because the current code does not work well with 1.7.7, and the bug comes from our update of jQuery version.

Since psgdpr module is supposed to work on multiple PS 1.7 versions, I think he chose a "no jQuery" solution to make sure it works on all PS versions.

let addressShipping = document.getElementById('addressShipping');
if (addressShipping) {
addressShipping.innerHTML = '<p>'+psgdprNoAddresses+'</p>';
addressShipping.style.visibility = "visible";
}

let addressInvoice = document.getElementById('addressInvoice');
if (addressInvoice) {
addressInvoice.innerHTML = '<p>'+psgdprNoAddresses+'</p>';
addressInvoice.style.visibility = "visible";
}
});