scottcheng / cropit

A "customizable crop and zoom" jQuery plugin.
http://scottcheng.github.io/cropit/
MIT License
874 stars 305 forks source link

cropit in ES6 #195

Open nielszwart opened 8 years ago

nielszwart commented 8 years ago

Im trying to get this to work with ES6 but I'm getting the following error message:

Uncaught TypeError: (0 , _jquery2.default)(...).cropit is not a function

So I've done the 'npm install cropit' and then I created a cropit.js which looks like this (based on the basic image cropper demo):

import $ from 'jquery'
import cropit from 'cropit'

export function initCropit() {
  $.fn.cropit = cropit
  $('#image-cropper').cropit()
  $('.download-btn').click(function() {
    var imageData = $('#image-cropper').cropit('export');
    window.open(imageData);
  });
}

And this is ofcourse included in the main.js. Now when opening the page I get the above error message saying it is not a function (which is correct, if I console.log this it tells me its an empty object)

Does anyone have an idea about what I am doing wrong in my ES6 cropit setup?

charles-passille-smartnets commented 7 years ago

@nielszwart Hey, just a thought, I'm using pugjs not es6 but, are you initializing the script on document ready? https://learn.jquery.com/using-jquery-core/document-ready/

May need to wrap your function somehow and call it after the document is done loading.

riteshdalal commented 7 years ago

@nielszwart - did you find an answer for this issue?

emimarz commented 6 years ago

same issue here