// "crmMonaco" is a basic skeletal directive.
// Example usage: <div crm-monaco ng-model="my.content"></div>
- angular.module('crmMonaco').directive('crmMonaco', function($timeout) {
+ // Example usage: <div crm-monaco="{readOnly: true}" ng-model="my.content"></div>
+ angular.module('crmMonaco').directive('crmMonaco', function($timeout, $parse) {
return {
restrict: 'AE',
require: 'ngModel',
var editor;
require.config({paths: CRM.crmMonaco.paths});
require(['vs/editor/editor.main'], function() {
- var editorEl = $el.find('.crm-monaco-container');
- editorEl.css({height: Math.round(heightPct * $(window).height())});
- editor = monaco.editor.create(editorEl[0], {
- value: ngModel.$modelValue,
+ var options = {
+ readOnly: false,
language: 'html',
// theme: 'vs-dark',
- theme: 'vs',
+ theme: 'vs'
+ };
+ if ($attr.crmMonaco) {
+ angular.extend(options, $parse($attr.crmMonaco)($scope));
+ }
+ angular.extend(options, {
+ value: ngModel.$modelValue,
minimap: {
enabled: false
},
}
});
+ var editorEl = $el.find('.crm-monaco-container');
+ editorEl.css({height: Math.round(heightPct * $(window).height())});
+ editor = monaco.editor.create(editorEl[0], options);
+
editor.onDidChangeModelContent(_.debounce(function () {
$scope.$apply(function () {
ngModel.$setViewValue(editor.getValue());