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.
 
 
 
 
 
 

96 lines
2.7 KiB

  1. // Jcrop static functions
  2. $.extend(Jcrop,{
  3. component: { },
  4. filter: { },
  5. stage: { },
  6. registerComponent: function(name,component){
  7. Jcrop.component[name] = component;
  8. },
  9. registerFilter: function(name,filter){
  10. Jcrop.filter[name] = filter;
  11. },
  12. registerStageType: function(name,stage){
  13. Jcrop.stage[name] = stage;
  14. },
  15. // attach: function(element,opt){{{
  16. attach: function(element,opt){
  17. var obj = new $.Jcrop(element,opt);
  18. return obj;
  19. },
  20. // }}}
  21. // imgCopy: function(imgel){{{
  22. imgCopy: function(imgel){
  23. var img = new Image;
  24. img.src = imgel.src;
  25. return img;
  26. },
  27. // }}}
  28. // imageClone: function(imgel){{{
  29. imageClone: function(imgel){
  30. return $.Jcrop.supportsCanvas?
  31. Jcrop.canvasClone(imgel):
  32. Jcrop.imgCopy(imgel);
  33. },
  34. // }}}
  35. // canvasClone: function(imgel){{{
  36. canvasClone: function(imgel){
  37. var canvas = document.createElement('canvas'),
  38. ctx = canvas.getContext('2d');
  39. $(canvas).width(imgel.width).height(imgel.height),
  40. canvas.width = imgel.naturalWidth;
  41. canvas.height = imgel.naturalHeight;
  42. ctx.drawImage(imgel,0,0,imgel.naturalWidth,imgel.naturalHeight);
  43. return canvas;
  44. },
  45. // }}}
  46. // propagate: function(plist,config,obj){{{
  47. propagate: function(plist,config,obj){
  48. for(var i=0,l=plist.length;i<l;i++)
  49. if (config.hasOwnProperty(plist[i]))
  50. obj[plist[i]] = config[plist[i]];
  51. },
  52. // }}}
  53. // getLargestBox: function(ratio,w,h){{{
  54. getLargestBox: function(ratio,w,h){
  55. if ((w/h) > ratio)
  56. return [ h * ratio, h ];
  57. else return [ w, w / ratio ];
  58. },
  59. // }}}
  60. // stageConstructor: function(el,options,callback){{{
  61. stageConstructor: function(el,options,callback){
  62. // Get a priority-ordered list of available stages
  63. var stages = [];
  64. $.each(Jcrop.stage,function(i,e){
  65. stages.push(e);
  66. });
  67. stages.sort(function(a,b){ return a.priority - b.priority; });
  68. // Find the first one that supports this element
  69. for(var i=0,l=stages.length;i<l;i++){
  70. if (stages[i].isSupported(el,options)){
  71. stages[i].create(el,options,function(obj,opt){
  72. if (typeof callback == 'function') callback(obj,opt);
  73. });
  74. break;
  75. }
  76. }
  77. },
  78. // }}}
  79. // supportsColorFade: function(){{{
  80. supportsColorFade: function(){
  81. return $.fx.step.hasOwnProperty('backgroundColor');
  82. },
  83. // }}}
  84. // wrapFromXywh: function(xywh){{{
  85. wrapFromXywh: function(xywh){
  86. var b = { x: xywh[0], y: xywh[1], w: xywh[2], h: xywh[3] };
  87. b.x2 = b.x + b.w;
  88. b.y2 = b.y + b.h;
  89. return b;
  90. }
  91. // }}}
  92. });