diff --git a/editor-tool-highlighting/src/main/resources/SyntaxHighlighting/SyntaxHighlighting.xml b/editor-tool-highlighting/src/main/resources/SyntaxHighlighting/SyntaxHighlighting.xml
index 9302193..d71fbc1 100644
--- a/editor-tool-highlighting/src/main/resources/SyntaxHighlighting/SyntaxHighlighting.xml
+++ b/editor-tool-highlighting/src/main/resources/SyntaxHighlighting/SyntaxHighlighting.xml
@@ -32,7 +32,7 @@
#includeMacros('Macros')
@@ -127,7 +127,7 @@
## Only do work if the extension is enabled.
#if ($configuration.getValue('enabled') == 1)
-define([], function () {
+define(['jquery'], function ($) {
var codeMirrors = [];
/* Initialize the CodeMirror library and then start registering the extra modules. */
@@ -172,12 +172,18 @@ define([], function () {
//
// Attach codeMirrors to all the elements matched with the propertyPattern.
//
+ var codeMirrorState = window.localStorage['XWiki.extension.SyntaxHighlighting.disable'] || 0;
var textareas = $$(propertyPattern);
for (var i = 0; i<textareas.length; ++i) {
var textarea = textareas[i];
// If the textarea is not visible, like the object editor's textareas are when they are not expanded, delay the initialization
if (textarea.offsetWidth > 0 || textarea.offsetHeight > 0) {
- initSingleCodeMirror(textarea, codeMirrorMode);
+ if(codeMirrorState === '1') {
+ displayEnableCheckbox(textarea, codeMirrorMode);
+ }
+ else {
+ initSingleCodeMirror(textarea, codeMirrorMode);
+ }
} else {
var objectDiv = textarea.up('.xobject');
if (!objectDiv) {
@@ -197,6 +203,16 @@ define([], function () {
}
}
+ // Add a checkbox to enable CodeMirror for the user
+ var displayEnableCheckbox = function (textarea, codeMirrorMode) {
+ var openInstances = $('.enableCodeMirror').length;
+ $('<div class="meta-versionSummary enableCodeMirror"><input type="checkbox" class="SHcheckbox" id="enableCodeMirror'+openInstances+'"/> <label for="enableCodeMirror'+openInstances+'">Allow Syntax Highlighting</label></div>').insertAfter(textarea).on('click',function() {
+ initSingleCodeMirror(textarea, codeMirrorMode);
+ $(this).remove();
+ window.localStorage['XWiki.extension.SyntaxHighlighting.disable'] = 0;
+ });
+ }
+
var initSingleCodeMirror = function (textarea, codeMirrorMode) {
// FIXME: Until a better way comes up, we`ll just reuse the xwiki 2.1 syntax mode for 2.0 as well.
if (codeMirrorMode == 'xwiki/2.0') {
@@ -328,6 +344,16 @@ define([], function () {
// console.log('CodeMirror instance initialized for mode: ' + codeMirrorMode);
+ // Add a checkbox to disable CodeMirror for the user
+ var openInstances = jQuery('.disableCodeMirror').length;
+ var codeMirrorDiv = jQuery(textarea).siblings('.CodeMirror');
+jQuery('<div class="meta-versionSummary disableCodeMirror"><input type="checkbox" checked="checked" class="SHcheckbox" id="disableCodeMirror'+openInstances+'"/> <label for="disableCodeMirror'+openInstances+'" >Allow Syntax Highlighting</label></div>').insertAfter(codeMirrorDiv).on('click',function() {
+ codeMirror.toTextArea();
+ displayEnableCheckbox(textarea, codeMirrorMode);
+ $(this).remove();
+ window.localStorage['XWiki.extension.SyntaxHighlighting.disable'] = 1;
+ });
+
// Track this new instance by adding it to the list of instances.
codeMirrors.push(codeMirror);
}, function (err) {