mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-04-27 00:44:41 +00:00
Initialize fabric.IText canvas handlers only once. Closes #1076
Qunit additions
This commit is contained in:
parent
0fc31d09c5
commit
da0866429a
3 changed files with 21 additions and 14 deletions
|
|
@ -1106,6 +1106,14 @@
|
|||
fabric.Canvas.prototype._setCursorFromEvent = function() { };
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if canvas handlers are initialized for fabric.IText objects
|
||||
* @static
|
||||
* @memberof fabric.Canvas
|
||||
* @type Boolean
|
||||
*/
|
||||
fabric.Canvas._hasITextHandlers = false;
|
||||
|
||||
/**
|
||||
* @class fabric.Element
|
||||
* @alias fabric.Canvas
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@
|
|||
_this.selected = true;
|
||||
}, 100);
|
||||
|
||||
if (!this._hasCanvasHandlers) {
|
||||
if (this.canvas && !fabric.Canvas._hasITextHandlers) {
|
||||
this._initCanvasHandlers();
|
||||
this._hasCanvasHandlers = true;
|
||||
fabric.Canvas._hasITextHandlers = true;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
@ -36,25 +36,18 @@
|
|||
* @private
|
||||
*/
|
||||
_initCanvasHandlers: function() {
|
||||
var _this = this;
|
||||
|
||||
this.canvas.on('selection:cleared', function(options) {
|
||||
|
||||
// do not exit editing if event fired
|
||||
// when clicking on an object again (in editing mode)
|
||||
if (options.e && _this.canvas.containsPoint(options.e, _this)) return;
|
||||
|
||||
_this.exitEditing();
|
||||
this.canvas.on('selection:cleared', function() {
|
||||
fabric.IText.prototype.exitEditingOnOthers.call();
|
||||
});
|
||||
|
||||
this.canvas.on('mouse:up', function() {
|
||||
this.getObjects('i-text').forEach(function(obj) {
|
||||
fabric.IText.instances.forEach(function(obj) {
|
||||
obj.__isMousedown = false;
|
||||
});
|
||||
});
|
||||
|
||||
this.canvas.on('object:selected', function() {
|
||||
fabric.IText.prototype.exitEditingOnOthers.call(_this);
|
||||
this.canvas.on('object:selected', function(options) {
|
||||
fabric.IText.prototype.exitEditingOnOthers.call(options.target);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -1042,6 +1042,12 @@
|
|||
return new fabric.IText(object.text, clone(object));
|
||||
};
|
||||
|
||||
/**
|
||||
* Contains all fabric.IText objects that have been created
|
||||
* @static
|
||||
* @memberof fabric.IText
|
||||
* @type Array
|
||||
*/
|
||||
fabric.IText.instances = [ ];
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue