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