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 10, 2021
1 parent 8fc0f08 commit 7d9b67e
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 7d9b67e

Please sign in to comment.