You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

64 lines
1.6 KiB

  1. // Jcrop jQuery plugin function
  2. $.fn.Jcrop = function(options,callback){
  3. options = options || {};
  4. var first = this.eq(0).data('Jcrop');
  5. var args = Array.prototype.slice.call(arguments);
  6. // Return API if requested
  7. if (options == 'api') { return first; }
  8. // Allow calling API methods (with arguments)
  9. else if (first && (typeof options == 'string')) {
  10. // Call method if it exists
  11. if (first[options]) {
  12. args.shift();
  13. first[options].apply(first,args);
  14. return first;
  15. }
  16. // Unknown input/method does not exist
  17. return false;
  18. }
  19. // Otherwise, loop over selected elements
  20. this.each(function(){
  21. var t = this, $t = $(this);
  22. var exists = $t.data('Jcrop');
  23. var obj;
  24. // If Jcrop already exists on this element only setOptions()
  25. if (exists)
  26. exists.setOptions(options);
  27. else {
  28. if (!options.stageConstructor)
  29. options.stageConstructor = $.Jcrop.stageConstructor;
  30. options.stageConstructor(this,options,function(stage,options){
  31. var selection = options.setSelect;
  32. if (selection) delete(options.setSelect);
  33. var obj = $.Jcrop.attach(stage.element,options);
  34. if (typeof stage.attach == 'function')
  35. stage.attach(obj);
  36. $t.data('Jcrop',obj);
  37. if (selection) {
  38. obj.newSelection();
  39. obj.setSelect(selection);
  40. }
  41. if (typeof callback == 'function')
  42. callback.call(obj);
  43. });
  44. }
  45. return this;
  46. });
  47. };