From: Tim Otten Date: Mon, 21 Jun 2021 00:16:24 +0000 (-0700) Subject: crmMonaco - Provide internal access to `$ctrl.editor` / `crmMonaco.editor` instances X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=687bc83446dea39f24f91abb6fcac045ff634a11;p=civicrm-core.git crmMonaco - Provide internal access to `$ctrl.editor` / `crmMonaco.editor` instances --- diff --git a/ang/crmMonaco.js b/ang/crmMonaco.js index 156753a0b7..d232391578 100644 --- a/ang/crmMonaco.js +++ b/ang/crmMonaco.js @@ -7,9 +7,13 @@ angular.module('crmMonaco').directive('crmMonaco', function($timeout, $parse) { return { restrict: 'AE', - require: 'ngModel', + require: ['ngModel', 'crmMonaco'], template: '
', - link: function($scope, $el, $attr, ngModel) { + controller: function() { + this.editor = null; // Filled in by link(). + }, + link: function($scope, $el, $attr, controllers) { + var ngModel = controllers[0], crmMonaco = controllers[1]; var heightPct = 0.70; var editor; require.config({paths: CRM.crmMonaco.paths}); @@ -78,9 +82,12 @@ editor.onDidFocusEditorWidget(bodyScrollSuspend); editor.onDidBlurEditorWidget(bodyScrollRestore); + crmMonaco.editor = editor; + $scope.$on('$destroy', function () { bodyScrollRestore(); if (editor) editor.dispose(); + delete crmMonaco.editor; }); }); }