-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace some textarea with a proper text editor
- Loading branch information
Showing
15 changed files
with
419 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import {basicSetup, EditorView} from "codemirror"; | ||
import {EditorState} from "@codemirror/state"; | ||
import {ayuLight, amy} from 'thememirror'; | ||
|
||
console.log('Colander text editor ready'); | ||
|
||
function editorFromTextArea(textarea, extensions) { | ||
let view = new EditorView({ | ||
doc: textarea.value, | ||
extensions | ||
}) | ||
$(view.dom).height('52em'); | ||
$(view.dom).css({'overflow': 'auto', 'max-width': '100%', 'border': '1px solid #c4c3c8', 'border-radius': '8px'}); | ||
textarea.parentNode.insertBefore(view.dom, textarea) | ||
$($(textarea.form), $('button[type=submit]')).click(() => { | ||
textarea.value = view.state.doc.toString() | ||
}) | ||
if (textarea.form) textarea.form.addEventListener("submit", () => { | ||
textarea.value = view.state.doc.toString() | ||
}) | ||
return view | ||
} | ||
|
||
|
||
window.addEventListener('DOMContentLoaded', () => { | ||
// Replace textarea with a text editor | ||
$('textarea.colander-text-editor').each(function (index, elt) { | ||
const extensions = [ | ||
EditorView.contentAttributes.of({contenteditable: true}), | ||
basicSetup, | ||
ayuLight, | ||
] | ||
editorFromTextArea(elt, extensions); | ||
$(this).css('visibility', 'hidden'); | ||
$(this).css('position', 'absolute'); | ||
}) | ||
// Replace pre > code with a text editor in read-only mode | ||
$('pre.colander-text-editor > code').each(function (index, elt) { | ||
let view = new EditorView({ | ||
doc: elt.innerHTML, | ||
state: EditorState.create({ | ||
doc: elt.innerHTML, | ||
extensions: [ | ||
EditorView.contentAttributes.of({contenteditable: false}), | ||
amy, | ||
basicSetup, | ||
EditorView.lineWrapping, | ||
] | ||
}), | ||
}) | ||
$(view.dom).css({ | ||
'max-height': '64em', | ||
'overflow': 'auto', | ||
'border': '1px solid #c4c3c8', | ||
'border-radius': '8px' | ||
}); | ||
|
||
elt.parentNode.parentNode.insertBefore(view.dom, elt.parentNode); | ||
$(this).removeClass(); | ||
$(this).parent().remove(); | ||
}) | ||
}) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% load i18n %} | ||
{% load colander_tags %} | ||
|
||
<table class="table table-sm"> | ||
<tbody> | ||
{% for k,v in attributes.items %} | ||
{% if v %} | ||
<tr> | ||
<td data-bs-toggle="tooltip" data-bs-placement="left" title="{{ k }}">{{ k|to_title }}</td> | ||
<td class="font-monospace text-wrap4">{{ v }}</td> | ||
</tr> | ||
{% endif %} | ||
{% endfor %} | ||
</tbody> | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.