From 9fdf55137599795347fe0f7903622fd8aa91ba6e Mon Sep 17 00:00:00 2001 From: Roger Beaman Date: Tue, 11 Apr 2017 15:41:10 -0400 Subject: [PATCH 1/3] fixing callSuper --- src/mixins/itext_behavior.mixin.js | 1 + src/mixins/object_origin.mixin.js | 7 +++++++ src/util/lang_class.js | 23 ++++++++++++++++++++--- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/mixins/itext_behavior.mixin.js b/src/mixins/itext_behavior.mixin.js index ddd48ae5b74..6f202a3479b 100644 --- a/src/mixins/itext_behavior.mixin.js +++ b/src/mixins/itext_behavior.mixin.js @@ -18,6 +18,7 @@ onDeselect: function() { this.isEditing && this.exitEditing(); this.selected = false; + this.callSuper('onDeselect'); }, /** diff --git a/src/mixins/object_origin.mixin.js b/src/mixins/object_origin.mixin.js index b0bb5c1f98d..19c42cc424f 100644 --- a/src/mixins/object_origin.mixin.js +++ b/src/mixins/object_origin.mixin.js @@ -250,6 +250,13 @@ */ _getLeftTopCoords: function() { return this.translateToOriginPoint(this.getCenterPoint(), 'left', 'top'); + }, + + /** + * Callback; invoked right before object is about to go from active to inactive + */ + onDeselect: function() { + /* NOOP */ } }); diff --git a/src/util/lang_class.js b/src/util/lang_class.js index 9cf6be495e1..dd2d28b8a55 100644 --- a/src/util/lang_class.js +++ b/src/util/lang_class.js @@ -51,10 +51,27 @@ function Subclass() { } function callSuper(methodName) { - var fn = this.constructor.superclass.prototype[methodName]; + var parentMethod; + + // climb prototype chain to find method not equal to callee's method + var currentContext = this; + while (currentContext.constructor.superclass) { + var superClassProto = currentContext.constructor.superclass.prototype; + var superClassMethod = superClassProto[methodName]; + if (currentContext[methodName] !== superClassMethod) { + parentMethod = superClassMethod; + break; + } + currentContext = currentContext.constructor.superclass.prototype; + } + + if (!parentMethod) { + return console.log('tried to callSuper ' + methodName + ', method not found in prototype chain', this); + } + return (arguments.length > 1) - ? fn.apply(this, slice.call(arguments, 1)) - : fn.call(this); + ? parentMethod.apply(this, slice.call(arguments, 1)) + : parentMethod.call(this); } /** From 920a93bfaddea928ea2e7beb4a9c3bcc522e28cc Mon Sep 17 00:00:00 2001 From: Roger Beaman Date: Tue, 11 Apr 2017 15:59:37 -0400 Subject: [PATCH 2/3] fixing lint --- src/util/lang_class.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/util/lang_class.js b/src/util/lang_class.js index dd2d28b8a55..cc970bd6e3e 100644 --- a/src/util/lang_class.js +++ b/src/util/lang_class.js @@ -51,13 +51,12 @@ function Subclass() { } function callSuper(methodName) { - var parentMethod; + var parentMethod = null, + currentContext = this; // climb prototype chain to find method not equal to callee's method - var currentContext = this; while (currentContext.constructor.superclass) { - var superClassProto = currentContext.constructor.superclass.prototype; - var superClassMethod = superClassProto[methodName]; + var superClassMethod = currentContext.constructor.superclass.prototype[methodName]; if (currentContext[methodName] !== superClassMethod) { parentMethod = superClassMethod; break; From 30019ee7ff6b79528daae73c32af9f387f299c5e Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Tue, 18 Apr 2017 12:13:04 +0200 Subject: [PATCH 3/3] fixed unexpected alias for this --- src/util/lang_class.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/util/lang_class.js b/src/util/lang_class.js index cc970bd6e3e..19f72460012 100644 --- a/src/util/lang_class.js +++ b/src/util/lang_class.js @@ -52,16 +52,16 @@ function callSuper(methodName) { var parentMethod = null, - currentContext = this; + _this = this; // climb prototype chain to find method not equal to callee's method - while (currentContext.constructor.superclass) { - var superClassMethod = currentContext.constructor.superclass.prototype[methodName]; - if (currentContext[methodName] !== superClassMethod) { + while (_this.constructor.superclass) { + var superClassMethod = _this.constructor.superclass.prototype[methodName]; + if (_this[methodName] !== superClassMethod) { parentMethod = superClassMethod; break; } - currentContext = currentContext.constructor.superclass.prototype; + _this = _this.constructor.superclass.prototype; } if (!parentMethod) {