jCrop, an unusual requirement, and strange behaviour

jCrop, an unusual requirement, and strange behaviour

jQuery 1.4.4, jCrop 0.9.8

I'm trying to make it so that I can have sort of a "floating" aspect ratio, in that the final image width is fixed, but the height may be between 2 values. I also need to avoid increasing the size of the cropped image so I'm using the minSize option. I thought that I might try setting the maxSize depending on the current aspect ratio, although I'm unsure whether changing that value is possible on the fly. I've been trying to determine that but have been stalled on something for the past couple of days. I hope someone can point out the problem that has thus far has eluded me.

The code below causes things to act very strangely. When I drag, the selection isn't released from the mouse. That is, I can let go the mouse button and the selection will continue to follow the mouse indefinitely. The only way to get that to stop, short of reloading, is to click on the image again.

  1. var api;
  2. var min_w = 950;
  3. var min_h = 72;
  4. var max_h = 410;
  5. var max_aspect_ratio = min_w / min_h;
  6. var min_aspect_ratio = min_w / max_h;
  7. $(function()
  8. {
  9.     api = $('#crop_src img').Jcrop({
  10.         minSize: [min_w, min_h],
  11.         onChange: updateBounds,
  12.         onSelect: updateCoords  // sets form values, not shown
  13.     });
  14.    
  15.     // debug
  16.     $('#min_aspect_ratio span').text(min_aspect_ratio);
  17.     $('#max_aspect_ratio span').text(max_aspect_ratio);
  18. });
  19. function updateBounds(coords)
  20. {   
  21.     var new_aspect_ratio = coords.w / coords.h;
  22.    
  23.     // debug
  24.     $('#new_aspect_ratio span').text(new_aspect_ratio);
  25.        
  26.     if (new_aspect_ratio >= max_aspect_ratio)
  27.     {
  28.         /* allow change height only
  29.          */
  30.          api.setOptions({
  31.              maxSize: [coords.w, 0],
  32.             onChange: updateBounds,
  33.             onSelect: updateCoords
  34.          });
  35.     }
  36.     else if (new_aspect_ratio <= min_aspect_ratio)
  37.     {
  38.         /* allow change width only
  39.          */
  40.          api.setOptions({
  41.              maxSize: [0, coords.h],
  42.             onChange: updateBounds,
  43.             onSelect: updateCoords
  44.          });
  45.     }
  46.     else
  47.     {
  48.          api.setOptions({
  49.              maxSize: [0, 0],
  50.             onChange: updateBounds,
  51.             onSelect: updateCoords
  52.          });
  53.     }
  54.    
  55.     updateCoords(coords);
  56. }
I've set breakpoints at the calls to api.setOptions() and they're triggered. But, when I remove those and place one at Jcrop.setOptions() it's never triggered.

Can anyone suggest what's going on?