0
0
0348raven2018-02-21 23:05:31
JavaScript
0348raven, 2018-02-21 23:05:31

How to detect an initialized plugin (croppie or whatever)?

I am using croppie to edit images before sending to server. The task is to initialize and stop the plugin on demand:

$('#someID').croppie({
   viewport: {
      width: 128,
      height: 128
   }
});
$('#someID').croppie('bind', {
   url: 'some base64 encoded image'
});


Then the plugin needs to be hidden:

$('#someID').toggle();
$('#someID').croppie('bind');


Then I need the croppie again, and the first part of the js code will work again, so the consoles are visible:

croppie.min.js:1 Uncaught Error: Croppie: Can't initialize croppie more than once


And obviously I'm just checking the initialized plugin for the current element now or not. What I found:

// it supposed to be the answer, however it doesn't work correctly for me.    
if (!jQuery().fn.croppie) {

       $('#someID').croppie({
           viewport: {
                width: 128,
                height: 128
           }
       });

    }


I found this solution here and here

But it did not help me, because the plugin always returns something if it is connected to the page.
How to be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tyzberd, 2018-02-22
@tyzberd

check class https://codepen.io/anon/pen/wyXqQL?q=Croppie&limit...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question