From 02afc31ff183d5c5c3a64bf6eb9de096da6c2212 Mon Sep 17 00:00:00 2001 From: jlmitch5 Date: Fri, 15 Jul 2016 14:08:53 -0400 Subject: [PATCH] allow readOnly to be passed to CodeMirror --- lib/AngularCodeMirror.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/AngularCodeMirror.js b/lib/AngularCodeMirror.js index 4550897..2ef0ad4 100644 --- a/lib/AngularCodeMirror.js +++ b/lib/AngularCodeMirror.js @@ -30,7 +30,7 @@ angular.module('AngularCodeMirrorModule', []) .factory('AngularCodeMirror', [ function() { - return function() { + return function(readOnly) { var fn = function() { this.myCodeMirror = null; @@ -68,6 +68,15 @@ angular.module('AngularCodeMirrorModule', []) // Initialize CodeMirror self.modes[mode].value = scope[model]; + + // if readOnly is passed to AngularCodeMirror, set the + // options for all modes to be readOnly + if (readOnly) { + Object.keys(self.modes).forEach(function(val) { + self.modes[val].readOnly = true; + }); + } + self.myCodeMirror = CodeMirror(document.getElementById('cm-' + model + '-container'), self.modes[mode]); // Adjust the height