Skip to content

Commit

Permalink
feature: add onClickHandler only if needed
Browse files Browse the repository at this point in the history
Changed default value of onClickHandler setting to null and added click
handler to ProgressiveImage element only, if there is an onClickHandler.
This way no unused click handler is added to image.
  • Loading branch information
BePo65 committed Oct 9, 2021
1 parent c63fafc commit 34b02f7
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/pig.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,7 @@
*
* @param {string} filename - The filename property of the image.
*/
onClickHandler: function(filename) {
},
onClickHandler: null,

/**
* Get the minimum required aspect ratio for a valid row of images. The
Expand Down Expand Up @@ -864,7 +863,11 @@
if (!this.element) {
this.element = document.createElement(this.pig.settings.figureTagName);
this.element.className = this.classNames.figure;
this.element.addEventListener("click", function (){ this.pig.settings.onClickHandler(this.filename); }.bind(this) );
if (this.pig.settings.onClickHandler !== null) {
this.element.addEventListener('click', function() {
this.pig.settings.onClickHandler(this.filename);
}.bind(this) );
}
this._updateStyles();
}

Expand Down

0 comments on commit 34b02f7

Please sign in to comment.