Files
image-editor/src/extend-fabric-functionality.js
T

65 lines
1.7 KiB
JavaScript

'use strict';
/* globals $, fabric */
var Draggable = require('./Draggable');
var util = require('./util');
function ExtendFabricFunctionality() {
// Set default values for the fabric canvas
$.extend(fabric.Object.prototype, {
cornerSize: 0,
hasBorders: false,
hasControls: false,
padding: 0,
selectable: false,
strokeWidth: 0,
addTo: function(canvas) {
canvas.add(this);
return this;
},
});
util.setProperties(fabric.Image.prototype, {
drag: {
get: function() {
return this.__draggable || (this.__draggable = new Draggable(this));
}
}
});
$.extend(fabric.Rect.prototype, {
/**
* Gets the inner bounds of this fabric.Rect
* @return {Object}
*/
getInsideBoundingRect: function() {
var bounds = this.getBoundingRect();
var returnValue = {
left: bounds.left + this.strokeWidth,
top: bounds.top + this.strokeWidth,
width: bounds.width - this.strokeWidth * 2,
height: bounds.height - this.strokeWidth * 2
};
returnValue.right = returnValue.left + returnValue.width;
returnValue.bottom = returnValue.top + returnValue.height;
returnValue.min = {
left: returnValue.left,
top: returnValue.top
};
returnValue.max = {
left: returnValue.left + returnValue.width,
top: returnValue.top + returnValue.height
};
return returnValue;
}
});
}
module.exports = ExtendFabricFunctionality;