In a recent project I had to integrate this module with the Jcrop API so that I could set my own callbacks.

I'm wondering if there is an easy way to do this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

progpapa’s picture

Status: Active » Needs review
FileSize
863 bytes

I was unable to solve the problem in the OP without changing a few lines in imagefield_crop.js. See attached patch.

With the patch applied I can do the following e.g. in a js file in the theme:

(function ($, Drupal, window, document, undefined) {

  Drupal.behaviors.themename = {
    attach: function(context, settings) {

      $('#some-element').click(function(){
        var id = 'id-of-the-imagefield';
        var jcrop_api = Drupal.imagefield_crop.instances[id];
        jcrop_api.setOptions({ aspectRatio: 3 });
        jcrop_api.focus();
      });
    } // attach
  } // behaviors

})(jQuery, Drupal, this, this.document);
joetsuihk’s picture

looks good, adding some comment

progpapa’s picture

Since you are refering to this page in the comments (which makes sense), I thought I'll add a more complete js example:

(function ($, Drupal, window, document, undefined) {

  Drupal.behaviors.themename= {
    attach: function(context, settings) {

      $('#some-element:not(.themename-processed)').click(function(){
       $(this).addClass('themename-processed'); 
        var id = 'id-of-the-imagefield';
        var jcrop_api = Drupal.imagefield_crop.instances[id];
        jcrop_api.setOptions({ aspectRatio: 3 });
        jcrop_api.focus();
      });
    } // attach
  } // behaviors

})(jQuery, Drupal, this, this.document);

this should go into the js file of a theme or module, replace "themename" with the name of the theme or module

joetsuihk’s picture

Please review the patch at #2, thanks!