Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Commit

Permalink
New setting for switching to native editor (fixes #14, fixes #26)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertgasset committed May 3, 2015
1 parent b8cf727 commit f0ee0c5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
46 changes: 43 additions & 3 deletions init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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'));
Expand All @@ -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() {
Expand Down Expand Up @@ -285,6 +310,8 @@ jQuery(function() {
'activeline',
'matchbrackets',
'syntax',
'-',
'nativeeditor',
];

jQuery.each(items, function(index, name) {
Expand All @@ -300,6 +327,7 @@ jQuery(function() {
var item = jQuery('<li>');
var link = jQuery('<a>').html(title);
var value = getSetting(name);
var disabled = getSetting('nativeeditor') === '1';

if (setting.choices) {
// Choice setting
Expand Down Expand Up @@ -332,6 +360,10 @@ jQuery(function() {
link.append(icon);
}

if (disabled && name !== 'nativeeditor') {
item.addClass('ui-state-disabled');
}

item.append(link);
menu.append(item);
});
Expand Down Expand Up @@ -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);
});

Expand Down
1 change: 1 addition & 0 deletions lang/ca/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
1 change: 1 addition & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit f0ee0c5

Please sign in to comment.