tapmodo / Jcrop

Jcrop - The Javascript Image Cropping Engine
https://jcrop.com
Other
4.31k stars 939 forks source link

Events Touch are not initialized after we destroyed a JCrop instance #186

Open mikael1611 opened 9 years ago

mikael1611 commented 9 years ago

Hi, I noticed Events Touch are not initialized after we destroyed and recreated a JCrop instance. Try it yourself with your Mobile or Chrome Emulating Touch Mode

To solve it temporary, I use this command after destroy() instruction $.Jcrop.component.DragState.prototype.touch = null;

Try with Jcrop basic.html demo page and call the following instruction:

function destroyAndRecreate()
{

    $('#target').Jcrop("api").destroy();

    //Uncomment next line to force events touch init after destroy
    //$.Jcrop.component.DragState.prototype.touch = null;  

    $('#target').Jcrop({
      setSelect: [ 175, 100, 400, 300 ]
    });     

}
crystoy commented 8 years ago

+1

ZaneCEO commented 8 years ago

You are definitely my hero for the week. I spent 3 full days looking for a solution to this problem. I was blaming my coding (as I always do), so I was miles away from the real issue.

$.Jcrop.component.DragState.prototype.touch = null; works perfectly.... and I would NEVER have found it without you. THANKS SO, SO, SO much!!!!!!!!!

quisse commented 8 years ago

+1

woodcockjosh commented 8 years ago

+1 OMFG . I literally spent 6 hours f*cking around with this until I started to believe the lib was broke. Thanks for the workaround!

alexsasharegan commented 7 years ago

This hasn't been solved in the lib yet, has it? The check made here must be the offending section necessitating the null reset: JcropTouch.js (lines: 27-32)

I'm just diving into using this on a project, so I'm not familiar with the code yet. Can this kind of reset be performed on $(selector).Jcrop('api').destroy()? Given that the fix manipulates the prototype, maybe there's a better instance check for initializing touch events?

shehzadshafi42 commented 7 years ago

You can also try this code. It works for me.

function destroyAndRecreate() { $("#target").data('Jcrop').destroy(); $('#target').Jcrop({ setSelect: [ 175, 100, 400, 300 ] }); }