crmMonaco - Provide internal access to `$ctrl.editor` / `crmMonaco.editor` instances
authorTim Otten <totten@civicrm.org>
Mon, 21 Jun 2021 00:16:24 +0000 (17:16 -0700)
committerTim Otten <totten@civicrm.org>
Tue, 6 Jul 2021 21:34:18 +0000 (14:34 -0700)
ang/crmMonaco.js

index 156753a0b773e2368aac518b1358d7aa680c8c52..d23239157844605732e6eaea46e2750d4f7bd091 100644 (file)
@@ -7,9 +7,13 @@
   angular.module('crmMonaco').directive('crmMonaco', function($timeout, $parse) {
     return {
       restrict: 'AE',
-      require: 'ngModel',
+      require: ['ngModel', 'crmMonaco'],
       template: '<div class="crm-monaco-container"></div>',
-      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});
           editor.onDidFocusEditorWidget(bodyScrollSuspend);
           editor.onDidBlurEditorWidget(bodyScrollRestore);
 
+          crmMonaco.editor = editor;
+
           $scope.$on('$destroy', function () {
             bodyScrollRestore();
             if (editor) editor.dispose();
+            delete crmMonaco.editor;
           });
         });
       }