plugin.js
1.6 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
// Jcrop jQuery plugin function
$.fn.Jcrop = function(options,callback){
options = options || {};
var first = this.eq(0).data('Jcrop');
var args = Array.prototype.slice.call(arguments);
// Return API if requested
if (options == 'api') { return first; }
// Allow calling API methods (with arguments)
else if (first && (typeof options == 'string')) {
// Call method if it exists
if (first[options]) {
args.shift();
first[options].apply(first,args);
return first;
}
// Unknown input/method does not exist
return false;
}
// Otherwise, loop over selected elements
this.each(function(){
var t = this, $t = $(this);
var exists = $t.data('Jcrop');
var obj;
// If Jcrop already exists on this element only setOptions()
if (exists)
exists.setOptions(options);
else {
if (!options.stageConstructor)
options.stageConstructor = $.Jcrop.stageConstructor;
options.stageConstructor(this,options,function(stage,options){
var selection = options.setSelect;
if (selection) delete(options.setSelect);
var obj = $.Jcrop.attach(stage.element,options);
if (typeof stage.attach == 'function')
stage.attach(obj);
$t.data('Jcrop',obj);
if (selection) {
obj.newSelection();
obj.setSelect(selection);
}
if (typeof callback == 'function')
callback.call(obj);
});
}
return this;
});
};