diff --git a/jquery.poptrox.js b/jquery.poptrox.js index 215a8c9..1878538 100644 --- a/jquery.poptrox.js +++ b/jquery.poptrox.js @@ -619,6 +619,14 @@ }); + function createImageOnClickHandler(index) { + return function(e) { + e.preventDefault(); + e.stopPropagation(); + $popup.trigger('poptrox_open', [index]); + }; + } + $this.find(settings.selector).each(function(index) { var x, tmp, a = $(this), i = a.find('img'), data = a.data('poptrox'); @@ -855,14 +863,7 @@ a .attr('href', '') .css('outline', 0) - .on('click', function(e) { - - e.preventDefault(); - e.stopPropagation(); - - $popup.trigger('poptrox_open', [index]); - - }); + .on('click', createImageOnClickHandler(queue.length-1)); }); @@ -870,4 +871,4 @@ }; -})(jQuery); \ No newline at end of file +})(jQuery);