Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
<customClass/> | ||
<contentAuthor>xwiki:XWiki.Admin</contentAuthor> | ||
<creationDate>1450093299000</creationDate> | ||
<date>1450108239000</date> | ||
<date>1450188859000</date> | ||
<contentUpdateDate>1450108212000</contentUpdateDate> | ||
<version>1.1</version> | ||
<title>SyntaxHighlighting</title> | ||
|
@@ -119,15 +119,15 @@ | |
<className>XWiki.JavaScriptExtension</className> | ||
<guid>ae324f77-9a39-4a22-b789-fb02e302d54f</guid> | ||
<property> | ||
<cache>long</cache> | ||
<cache>default</cache> | ||
</property> | ||
<property> | ||
<code>#includeMacros('Macros') | ||
|
||
## 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; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Enygma2002
|
||
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; | ||
This comment has been minimized.
Sorry, something went wrong.
Enygma2002
|
||
$('<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() { | ||
This comment has been minimized.
Sorry, something went wrong.
Enygma2002
|
||
initSingleCodeMirror(textarea, codeMirrorMode); | ||
$(this).remove(); | ||
window.localStorage['XWiki.extension.SyntaxHighlighting.disable'] = 0; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
}); | ||
} | ||
|
||
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; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
}); | ||
|
||
// Track this new instance by adding it to the list of instances. | ||
codeMirrors.push(codeMirror); | ||
}, function (err) { | ||
|
What do you want to achieve with this? With the current code, you are setting this preference per user's browser. However, you are enabling/disabling it below per-element, but using the same key, so the effect is that each enable/disable you do does not target the particular element the checkbox is attached to, but the entire page (browser preference actually).