fixed missing JS functions in Article Editor
This commit is contained in:
parent
0d3111647b
commit
bc4a78382c
|
@ -109,52 +109,6 @@
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<SectionContent SectionName="scripts">
|
<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>
|
</SectionContent>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
|
|
@ -44,8 +44,54 @@
|
||||||
<CascadingValue Value="UserTheme" Name="UserTheme">
|
<CascadingValue Value="UserTheme" Name="UserTheme">
|
||||||
<Routes />
|
<Routes />
|
||||||
</CascadingValue>
|
</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>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -280,7 +280,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// published articles may only be edited my admins or moderators
|
// 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?
|
article.Reviewer = me; // TODO replace with editor or something?
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue