Skip to content

Commit cf204c6

Browse files
authored
Merge pull request #186 from cosmocode/toggle-button
Toggle button
2 parents 14bd46c + 0ba02a1 commit cf204c6

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

action/editor.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ public function addDataAndToggleButton(Doku_Event $event, $param)
6363
return;
6464
}
6565

66+
/** @var Doku_Form|\dokuwiki\Form\Form $form */
67+
$form = $event->data;
68+
69+
// return early if content is not editable
70+
if ($this->isReadOnly($form)) return;
71+
72+
6673
$useWYSIWYG = get_doku_pref('plugin_prosemirror_useWYSIWYG', false);
6774

6875
$prosemirrorJSON = '';
@@ -85,16 +92,13 @@ public function addDataAndToggleButton(Doku_Event $event, $param)
8592
}
8693
}
8794

88-
/** @var Doku_Form|\dokuwiki\Form\Form $form */
89-
$form = $event->data;
90-
91-
if(is_a($form, \dokuwiki\Form\Form::class)) {
92-
$form->addElement($this->buildToggleButton());
95+
if (is_a($form, \dokuwiki\Form\Form::class)) {
96+
$form->addElement($this->buildToggleButton(), 0);
9397
$form->setHiddenField('prosemirror_json',$prosemirrorJSON);
9498
$form->addHTML('<div class="prosemirror_wrapper" id="prosemirror__editor"></div>', 1);
9599
} else {
96100
// todo remove when old stable is no longer supported
97-
$form->addElement($this->buildOldToggleButton());
101+
$form->insertElement(0, $this->buildOldToggleButton());
98102
$form->addHidden('prosemirror_json',$prosemirrorJSON);
99103
$form->insertElement(1, '<div class="prosemirror_wrapper" id="prosemirror__editor"></div>');
100104
}
@@ -106,7 +110,7 @@ public function addDataAndToggleButton(Doku_Event $event, $param)
106110
* Creates it as hidden if forcing WYSIWYG
107111
*
108112
* @deprecated use buildToggleButton instead
109-
* @return array the pseudo-tag expected by \Doku_Form::addElement
113+
* @return array the pseudo-tag expected by \Doku_Form::insertElement
110114
*/
111115
protected function buildOldToggleButton()
112116
{
@@ -322,6 +326,27 @@ public function addJSINFO()
322326
global $JSINFO;
323327
$JSINFO['SMILEY_CONF'] = getSmileys();
324328
}
329+
330+
/**
331+
* Returns true if the current content is read only
332+
*
333+
* @todo remove Doku_Form case when the class is removed
334+
*
335+
* @param $form
336+
* @return bool
337+
*/
338+
protected function isReadOnly($form)
339+
{
340+
if (is_a($form, \dokuwiki\Form\Form::class)) {
341+
$textareaPos = $form->findPositionByType('textarea');
342+
$readonly = $textareaPos !== false && !empty($form->getElementAt($textareaPos)->attr('readonly'));
343+
} else {
344+
/** @var Doku_Form $form */
345+
$textareaPos = $form->findElementByType('wikitext');
346+
$readonly = $textareaPos !== false && !empty($form->getElementAt($textareaPos)['readonly']);
347+
}
348+
return $readonly;
349+
}
325350
}
326351

327352
// vim:ts=4:sw=4:et:

lang/de/lang.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
// custom language strings for the plugin
9-
$lang['switch_editors'] = 'Schalte WYSIWYG-Editor um';
9+
$lang['switch_editors'] = 'Syntax &#11020; Visueller Editor umschalten';
1010

1111
$lang['link target'] = 'Linkziel';
1212
$lang['type:wiki page'] = 'Eine Seite in diesem Wiki';

lang/en/lang.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
// custom language strings for the plugin
9-
$lang['switch_editors'] = 'Toggle WYSIWYG editor';
9+
$lang['switch_editors'] = 'Toggle syntax &#11020; visual editor';
1010

1111
$lang['link target'] = 'Link target';
1212
$lang['type:wiki page'] = 'A page in this wiki';

style.less

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,8 @@
9595

9696
.dokuwiki {
9797
.plugin_prosemirror_useWYSIWYG {
98-
position: absolute;
99-
top: 2.9em;
100-
right: 2em;
101-
padding: 3px 8px;
102-
color: #444;
103-
background-color: white;
98+
display: flex;
99+
margin-bottom: 0.75rem;
104100
}
105101

106102
.footnote-tooltip {

0 commit comments

Comments
 (0)