[Tiny fix] Fix a couple small bugs from DisplayAd clean up (#14846)

* Clean up and fix DisplayAd click JS

* Fix double use of variable
This commit is contained in:
Ben Halpern 2021-09-28 15:51:30 -04:00 committed by GitHub
parent 5678fb77f5
commit 647573dcad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View file

@ -143,10 +143,10 @@ function trackCustomImpressions() {
&& windowBigEnough
&& checkUserLoggedIn()) {
var csrfToken = tokenMeta.getAttribute('content');
[].forEach.call(displayAds, function(unit) {
displayAds.forEach(unit => {
trackAdImpression(csrfToken, unit);
unit.removeEventListener('click', trackAdClick, false );
unit.addEventListener('click', function(e) { trackAdClick(csrfToken, e) });
unit.addEventListener('click', function(e) { trackAdClick(csrfToken, e.target) });
});
}
}, 1800)
@ -221,7 +221,8 @@ function trackAdImpression(token, adBox) {
})
}
function trackAdClick(token, adBox) {
function trackAdClick(token, clickedElement) {
var adBox = clickedElement.closest('[data-display-unit]');
if (!adClicked) {
var dataBody = {
display_ad_event: {

View file

@ -44,9 +44,9 @@ module Html
next if allowed_image_host?(src)
if synchronous_detail_detection && img
width, height = image_width_height(img)
img["width"] = width
img["height"] = height
attribute_width, attribute_height = image_width_height(img)
img["width"] = attribute_width
img["height"] = attribute_height
end
img["loading"] = "lazy"