diff --git a/init.js b/init.js index 4b1cd04..ce95737 100644 --- a/init.js +++ b/init.js @@ -74,6 +74,16 @@ jQuery(function() { } } }, + nativeeditor: { + default_: '0', + callback: function(value) { + if (!cm && value === '0') { + initCodeMirror(); + } else if (cm && value === '1') { + destroyCodeMirror(); + } + } + }, syntax: { default_: '1', callback: function(value) { @@ -105,9 +115,21 @@ jQuery(function() { initMode(); initHooks(); initSettingsMenu(); - initCodeMirror(); + + if (getSetting('nativeeditor') === '0') { + initCodeMirror(); + } + + function destroyCodeMirror() { + var selection = window.DWgetSelection(textarea.get(0)); + cm.toTextArea(); + cm = null; + window.DWsetSelection(selection); + textarea.focus(); + } function initCodeMirror() { + var selection = window.DWgetSelection(textarea.get(0)); cm = CodeMirror.fromTextArea(textarea.get(0), {mode: 'null'}); cm.setOption('lineWrapping', textarea.prop('wrap') !== 'off'); cm.setOption('readOnly', textarea.prop('readonly')); @@ -126,9 +148,12 @@ jQuery(function() { cm.setOption('scrollbarStyle', 'overlay'); cm.setSize(null, textarea.css('height')); jQuery.each(settings, function(name, setting) { - var value = getSetting(name); - setting.callback(value); + if (name !== 'nativeeditor') { + var value = getSetting(name); + setting.callback(value); + } }); + window.DWsetSelection(selection); } function initMode() { @@ -285,6 +310,8 @@ jQuery(function() { 'activeline', 'matchbrackets', 'syntax', + '-', + 'nativeeditor', ]; jQuery.each(items, function(index, name) { @@ -300,6 +327,7 @@ jQuery(function() { var item = jQuery('
  • '); var link = jQuery('').html(title); var value = getSetting(name); + var disabled = getSetting('nativeeditor') === '1'; if (setting.choices) { // Choice setting @@ -332,6 +360,10 @@ jQuery(function() { link.append(icon); } + if (disabled && name !== 'nativeeditor') { + item.addClass('ui-state-disabled'); + } + item.append(link); menu.append(item); }); @@ -374,6 +406,14 @@ jQuery(function() { } } + if (name === 'nativeeditor') { + if (value === '1') { + ui.item.siblings().addClass('ui-state-disabled'); + } else { + ui.item.siblings().removeClass('ui-state-disabled'); + } + } + setSetting(name, value); }); diff --git a/lang/ca/lang.php b/lang/ca/lang.php index 177ab55..b4c3fa3 100644 --- a/lang/ca/lang.php +++ b/lang/ca/lang.php @@ -6,5 +6,6 @@ $lang['js']['setting_keymap'] = 'Mapa de tecles'; $lang['js']['setting_linenumbers'] = 'Mostra els números de línia'; $lang['js']['setting_matchbrackets'] = 'Ressalta els parèntesis concordants'; +$lang['js']['setting_nativeeditor'] = 'Editor natiu de DokuWiki'; $lang['js']['setting_syntax'] = 'Ressalta la sintaxi'; $lang['js']['setting_theme'] = 'Tema de colors'; diff --git a/lang/en/lang.php b/lang/en/lang.php index aec61b6..b80b730 100644 --- a/lang/en/lang.php +++ b/lang/en/lang.php @@ -6,5 +6,6 @@ $lang['js']['setting_keymap'] = 'Key map'; $lang['js']['setting_linenumbers'] = 'Display line numbers'; $lang['js']['setting_matchbrackets'] = 'Highlight matching brackets'; +$lang['js']['setting_nativeeditor'] = 'Native DokuWiki editor'; $lang['js']['setting_syntax'] = 'Highlight syntax'; $lang['js']['setting_theme'] = 'Color theme';