diff --git a/platform/commonUI/dialog/src/OverlayService.js b/platform/commonUI/dialog/src/OverlayService.js index 043f638700..5faba5dcf6 100644 --- a/platform/commonUI/dialog/src/OverlayService.js +++ b/platform/commonUI/dialog/src/OverlayService.js @@ -47,9 +47,16 @@ define( * @constructor */ function OverlayService($document, $compile, $rootScope) { - this.$document = $document; this.$compile = $compile; - this.$rootScope = $rootScope; + + // Don't include $document and $rootScope directly; + // avoids https://docs.angularjs.org/error/ng/cpws + this.findBody = function () { + return $document.find('body'); + }; + this.newScope = function () { + return $rootScope.$new(); + }; } /** @@ -67,7 +74,7 @@ define( */ OverlayService.prototype.createOverlay = function (key, overlayModel) { // Create a new scope for this overlay - var scope = this.$rootScope.$new(), + var scope = this.newScope(), element; // Stop showing the overlay; additionally, release the scope @@ -86,7 +93,7 @@ define( // Create the overlay element and add it to the document's body element = this.$compile(TEMPLATE)(scope); - this.$document.find('body').prepend(element); + this.findBody().prepend(element); return { dismiss: dismiss diff --git a/platform/commonUI/edit/src/representers/EditToolbarRepresenter.js b/platform/commonUI/edit/src/representers/EditToolbarRepresenter.js index 059b5e13f8..daf3645b69 100644 --- a/platform/commonUI/edit/src/representers/EditToolbarRepresenter.js +++ b/platform/commonUI/edit/src/representers/EditToolbarRepresenter.js @@ -91,8 +91,22 @@ define( } } + // Avoid attaching scope to this; + // http://errors.angularjs.org/1.2.26/ng/cpws + this.setSelection = function (s) { + scope.selection = s; + }; + this.clearExposedToolbar = function () { + // Clear exposed toolbar state (if any) + if (attrs.toolbar) { + delete scope.$parent[attrs.toolbar]; + } + }; + this.exposeToolbar = function () { + scope.$parent[self.attrs.toolbar] = self.toolbarObject; + }; + this.commit = commit; - this.scope = scope; this.attrs = attrs; this.updateSelection = updateSelection; this.toolbar = undefined; @@ -127,24 +141,21 @@ define( // Initialize toolbar object self.toolbar = new EditToolbar(definition, self.commit); // Ensure toolbar state is exposed - self.scope.$parent[self.attrs.toolbar] = self.toolbarObject; + self.exposeToolbar(); } } // Expose the toolbar object to the parent scope initialize(definition); // Create a selection scope - this.scope.selection = new EditToolbarSelection(); + this.setSelection(new EditToolbarSelection()); // Initialize toolbar to an empty selection this.updateSelection([]); }; // Destroy; remove toolbar object from parent scope EditToolbarRepresenter.prototype.destroy = function () { - // Clear exposed toolbar state (if any) - if (this.attrs.toolbar) { - delete this.scope.$parent[this.attrs.toolbar]; - } + this.clearExposedToolbar(); }; return EditToolbarRepresenter;