Cropper.js |
|
"use strict";
var CropPane = require('./CropPane.js');
var ImageCanvas = require('./ImageCanvas.js');
var emitter = require('emitter');
var bind = require('bind');
module.exports = Cropper;
|
|
¶ CropperParams
img
Object
Image element to crop
{Object=}
-
Object=
-
options:
|
function Cropper (img, options) {
options = this._defaultOptions(options || {});
this.img = img;
this.cropPane = new CropPane(options);
this.canvas = new ImageCanvas(img);
emitter(this);
this._init();
}
Cropper.prototype = {
_defaultOptions: function (supplied) {
var defaults = {
ratio: 'none',
minWidth: 20,
minHeight: 20,
defaultWidth: 100,
defaultHeight: 100
},
options = supplied;
for (var i in defaults) {
if (defaults.hasOwnProperty(i) && !(i in options)) {
options[i] = defaults[i];
}
}
return options;
},
_init: function () {
this.canvas.draw();
this.cropPane.on('change', bind(this, this._cropChange));
this.cropPane.draw(this.img);
},
_cropChange: function (position) {
this._croppedPosition = position;
|
Change Event |
this.emit('change', position);
this.canvas.drawMask(position);
},
get: function (imageType) {
return this.canvas.toDataUrl(this._croppedPosition, imageType);
},
setRatio: function (ratio) {
this.cropPane.setRatio(ratio);
this.cropPane.refresh();
},
destroy: function () {
this.canvas.destroy();
this.cropPane.destroy();
this.canvas = this.cropPane = null;
}
};
|
Options - container: place inside this element instead of overlaying original image TK - Compare performance of #getBoundingClientRect and #getComputedStyle - Better touch support (ideally multi-touch radness) |
|