backdrop-contrib / focal_point

Allows you to specify the portion of an image that is most important so it doesn't get cropped
GNU General Public License v2.0
1 stars 2 forks source link

Not working with JQuery 3 #5

Closed robertgarrigos closed 2 weeks ago

robertgarrigos commented 9 months ago

This module is not working with JQuery 3. It does with JQuery 1. Editing a node with an image field which uses focal point triggers this error:

jquery.js?v=3.7.1:2 Uncaught TypeError: Cannot read properties of undefined (reading 'indexOf')
    at ce.fn.load (jquery.js?v=3.7.1:2:82864)
    at HTMLImageElement.<anonymous> (focal_point.js:44:23)
    at Function.each (jquery.js?v=3.7.1:2:3129)
    at ce.fn.init.each (jquery.js?v=3.7.1:2:1594)
    at focal_point.js:42:14
laryn commented 5 months ago

I think this is working on the latest code -- please reopen if not.

robertgarrigos commented 3 months ago

Still, I'm getting this error in the web console with jQuery 3 and the latest code.

With jQuery 3 the cross in the image always appears in the top-left corner of the image. Only when I switch to jquery 1 the cross appears where you left it the last time.

Edita_Notícia_Dia_Internacional_d_Acció_per_a_la_Salut_de_les_Dones___Ona_Codinenca_-_Vivaldi

robertgarrigos commented 3 months ago

I think I've found the problem here: https://blog.jquery.com/2015/07/13/jquery-3-0-and-jquery-compat-3-0-alpha-versions-released/

I've fixed this problem by changing this code:

setTimeout(function() {
          $img.one('load', function(){
            focalPointSetIndicator($indicator, $(this), $field);
          }).each(function() {
            if (this.complete) {
              $(this).load();
            }
          });
        }, 0);

to this:

setTimeout(function () {
          $img.one('load', function () {
            focalPointSetIndicator($indicator, $(this), $field);
          }).each(function () {
            if (this.complete) {
              $(this).trigger('load'); // Trigger the load event manually if the image is already loaded
            }
          });
        }, 0);
robertgarrigos commented 3 months ago

Done a PR which addresses this problem.

laryn commented 1 month ago

@robertgarrigos Is this working for you with the latest version? At some point the same change you suggest must have been added -- it doesn't seem like your PR changes anything substantial.

robertgarrigos commented 2 weeks ago

@laryn yes, latest version works with jQuery 3. Thanks