Skip to content

Commit

Permalink
fixed missing JS functions in Article Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
miawinter98 committed Apr 29, 2024
1 parent 0d31116 commit bc4a783
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
46 changes: 0 additions & 46 deletions Wave/Components/AdvancedMarkdownEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -109,52 +109,6 @@
</section>

<SectionContent SectionName="scripts">
<script>
window.insertBeforeSelection = function(markdown, startOfLine = false) {
const target = document.getElementById("tool-target");
const start = target.selectionStart;
const end = target.selectionEnd;
const value = target.value;
let doStart = start;
if (startOfLine) {
doStart = value.lastIndexOf("\n", start) +1;
}
target.focus();
target.value = value.substring(0, doStart) + markdown + value.substring(doStart);
target.selectionStart = start + markdown.length;
target.selectionEnd = end + markdown.length;
target.focus();
target.dispatchEvent(new Event("input", { bubbles: true }));
}
window.insertBeforeAndAfterSelection = function (markdown) {
const target = document.getElementById("tool-target");
while (/\s/.test(target.value[target.selectionStart]) && target.selectionStart < target.value.length) {
target.selectionStart++;
}
while (/\s/.test(target.value[target.selectionEnd-1]) && target.selectionEnd > 0) {
target.selectionEnd--;
}
const start = target.selectionStart;
const end = target.selectionEnd;
const value = target.value;
target.focus();
target.value = value.substring(0, start) +
markdown + value.substring(start, end) + markdown +
value.substring(end);
target.selectionStart = start + markdown.length;
target.selectionEnd = end + markdown.length;
target.focus();
target.dispatchEvent(new Event("input", { bubbles: true }));
}
</script>
</SectionContent>

@code {
Expand Down
50 changes: 48 additions & 2 deletions Wave/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,54 @@
<CascadingValue Value="UserTheme" Name="UserTheme">
<Routes />
</CascadingValue>
<SectionOutlet SectionName="scripts" />
<script src="_framework/blazor.web.js" defer></script>
<script src="_framework/blazor.web.js" defer></script>
<SectionOutlet SectionName="scripts" />
<script>
window.insertBeforeSelection = function (markdown, startOfLine = false) {
const target = document.getElementById("tool-target");
const start = target.selectionStart;
const end = target.selectionEnd;
const value = target.value;
let doStart = start;
if (startOfLine) {
doStart = value.lastIndexOf("\n", start) + 1;
}
target.focus();
target.value = value.substring(0, doStart) + markdown + value.substring(doStart);
target.selectionStart = start + markdown.length;
target.selectionEnd = end + markdown.length;
target.focus();
target.dispatchEvent(new Event("input", { bubbles: true }));
}
window.insertBeforeAndAfterSelection = function (markdown) {
const target = document.getElementById("tool-target");
while (/\s/.test(target.value[target.selectionStart]) && target.selectionStart < target.value.length) {
target.selectionStart++;
}
while (/\s/.test(target.value[target.selectionEnd - 1]) && target.selectionEnd > 0) {
target.selectionEnd--;
}
const start = target.selectionStart;
const end = target.selectionEnd;
const value = target.value;
target.focus();
target.value = value.substring(0, start) +
markdown + value.substring(start, end) + markdown +
value.substring(end);
target.selectionStart = start + markdown.length;
target.selectionEnd = end + markdown.length;
target.focus();
target.dispatchEvent(new Event("input", { bubbles: true }));
}
</script>
</body>

</html>
Expand Down
2 changes: 1 addition & 1 deletion Wave/Components/Pages/Partials/ArticleEditorPartial.razor
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
}

// published articles may only be edited my admins or moderators
if (article.Status is ArticleStatus.Published && roles.Any(r => r is "Admin" or "Reviewer")) {
if (article.Status is ArticleStatus.Published && roles.Any(r => r is "Admin" or "Moderator")) {
article.Reviewer = me; // TODO replace with editor or something?
return;
}
Expand Down

0 comments on commit bc4a783

Please sign in to comment.