Skip to content

Commit

Permalink
refactor: extract variables and minor lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: David Jimenez <[email protected]>
  • Loading branch information
dvejmz committed Oct 24, 2021
1 parent 531311f commit 39da7c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion templates/repo/wiki/new.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
{{end}}
</div>
<form id="edit_form" class="ui form" action="{{.Link}}" method="post">
<form class="ui form" action="{{.Link}}" method="post">
{{.CsrfTokenHtml}}
<div class="field {{if .Err_Title}}error{{end}}">
<input name="title" value="{{.title}}" autofocus required>
Expand Down
20 changes: 11 additions & 9 deletions web_src/js/features/repo-wiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export function initRepoWikiForm() {
let sideBySideChanges = 0;
let sideBySideTimeout = null;
let hasSimpleMDE = true;

if ($editArea.length > 0) {
const $form = $('.repository.wiki.new .ui.form');
const simplemde = new SimpleMDE({
autoDownloadFontAwesome: false,
element: $editArea[0],
Expand Down Expand Up @@ -105,7 +107,6 @@ export function initRepoWikiForm() {
action(e) {
e.toTextArea();
hasSimpleMDE = false;
const $form = $('.repository.wiki.new .ui.form');
const $root = $form.find('.field.content');
const loading = $root.data('loading');
$root.append(`<div class="ui bottom tab markup" data-tab="preview">${loading}</div>`);
Expand All @@ -117,23 +118,24 @@ export function initRepoWikiForm() {
]
});

$('#edit_form').on('submit', (e) => {
const $markdownEditorTextArea = $(simplemde.codemirror.getInputField());
$markdownEditorTextArea.addClass('js-quick-submit');

$form.on('submit', function (e) {
// The original edit area HTML element is hidden and replaced by the
// SimpleMDE editor, breaking HTML5 input validation if the text area is empty.
// This is a workaround for this upstream bug.
// See https://github.com/sparksuite/simplemde-markdown-editor/issues/324
const input = $editArea.val()
const input = $editArea.val();
if (!input.length) {
$(simplemde.codemirror.getInputField()).attr('required', true);
document.querySelector('#edit_form').reportValidity();
e.preventDefault()
e.preventDefault();
$markdownEditorTextArea.prop('required', true);
this.reportValidity();
} else {
$(simplemde.codemirror.getInputField()).attr('required', false);
$markdownEditorTextArea.prop('required', false);
}
});

$(simplemde.codemirror.getInputField()).addClass('js-quick-submit');

setTimeout(() => {
const $bEdit = $('.repository.wiki.new .previewtabs a[data-tab="write"]');
const $bPrev = $('.repository.wiki.new .previewtabs a[data-tab="preview"]');
Expand Down

0 comments on commit 39da7c2

Please sign in to comment.