From 7d9b67e68aa842979c71e68aa0d860c4095bb968 Mon Sep 17 00:00:00 2001 From: Bernhard Pottler Date: Sat, 9 Oct 2021 17:37:37 +0200 Subject: [PATCH] feature: add onClickHandler only if needed 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. --- src/pig.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pig.js b/src/pig.js index beafd5d..57a3113 100644 --- a/src/pig.js +++ b/src/pig.js @@ -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 @@ -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(); }