diff --git a/resources/assets/typescript/Sakura/Config.ts b/resources/assets/typescript/Sakura/Config.ts index f095bae..ba12e71 100644 --- a/resources/assets/typescript/Sakura/Config.ts +++ b/resources/assets/typescript/Sakura/Config.ts @@ -7,6 +7,10 @@ namespace Sakura public static LoggedIn: boolean = false; public static ChangelogUrl: string = "https://sakura.flash.moe/"; public static ChangelogApi: string = "api.php/"; + public static ForumTitleMin: number = 0; + public static ForumTitleMax: number = 0; + public static ForumTextMin: number = 0; + public static ForumTextMax: number = 0; public static Set(config: Object): void { diff --git a/resources/assets/typescript/Sakura/Editor.ts b/resources/assets/typescript/Sakura/Editor.ts new file mode 100644 index 0000000..ba1a2c2 --- /dev/null +++ b/resources/assets/typescript/Sakura/Editor.ts @@ -0,0 +1,62 @@ +namespace Sakura +{ + export class Editor + { + private static UpdateTimeout: number = 0; + private static PreviewClient: AJAX; + private static PostClient: AJAX; + + public static Prepare(): void + { + this.PostClient = new AJAX; + this.PreviewClient = new AJAX; + this.PreviewClient.SetUrl("/helper/bbcode/parse"); + this.PreviewClient.Form(); + } + + public static Preview(target: HTMLElement, text: HTMLTextAreaElement): void + { + this.PreviewClient.SetSend({"text": text.value}); + this.PreviewClient.AddCallback(200, (client: AJAX) => { + target.innerHTML = client.Response(); + }); + this.PreviewClient.Start(HTTPMethod.POST); + } + + public static QuotePost(id: number, username: string, target: HTMLTextAreaElement): void + { + this.PostClient.SetUrl("/forum/post/1/raw".replace('1', id.toString())); + this.PostClient.AddCallback(200, (client: AJAX) => { + DOM.EnterAtCursor(target, "[quote=" + username + "]" + client.Response() + "[/quote]"); + target.focus(); + }); + this.PostClient.Start(HTTPMethod.GET); + } + + public static InsertBBCode(target: HTMLTextAreaElement, code: string, param: boolean): void + { + var start: string = "[" + code + (param ? "=" : "") + "]", + end: string = "[/" + code + "]", + selectionLength = DOM.GetSelectionLength(target); + + DOM.EnterAtCursor(target, start); + DOM.SetPosition(target, DOM.GetPosition(target) + selectionLength + start.length); + DOM.EnterAtCursor(target, end); + DOM.SetPosition(target, DOM.GetPosition(target) - selectionLength); + DOM.SetPosition(target, DOM.GetPosition(target) + selectionLength, true); + } + + public static PreviewTimeout(target: HTMLElement, text: HTMLTextAreaElement): void + { + if (this.UpdateTimeout !== 0) { + return; + } + + this.UpdateTimeout = setTimeout(() => { + Editor.Preview(target, text); + clearTimeout(Editor.UpdateTimeout); + Editor.UpdateTimeout = 0; + }, 500); + } + } +} diff --git a/resources/assets/typescript/Yuuno/Editor.ts b/resources/assets/typescript/Yuuno/Editor.ts deleted file mode 100644 index 4e71c2e..0000000 --- a/resources/assets/typescript/Yuuno/Editor.ts +++ /dev/null @@ -1,20 +0,0 @@ -/// - -namespace Yuuno -{ - export class Editor - { - public static InsertBBCode(target: HTMLTextAreaElement, code: string, param: boolean): void - { - var start: string = "[" + code + (param ? "=" : "") + "]", - end: string = "[/" + code + "]", - selectionLength = Sakura.DOM.GetSelectionLength(target); - - Sakura.DOM.EnterAtCursor(target, start); - Sakura.DOM.SetPosition(target, Sakura.DOM.GetPosition(target) + selectionLength + start.length); - Sakura.DOM.EnterAtCursor(target, end); - Sakura.DOM.SetPosition(target, Sakura.DOM.GetPosition(target) - selectionLength); - Sakura.DOM.SetPosition(target, Sakura.DOM.GetPosition(target) + selectionLength, true); - } - } -} diff --git a/resources/views/yuuno/forum/elements/replyForm.twig b/resources/views/yuuno/forum/elements/replyForm.twig index e104110..2f8d8e2 100644 --- a/resources/views/yuuno/forum/elements/replyForm.twig +++ b/resources/views/yuuno/forum/elements/replyForm.twig @@ -24,7 +24,7 @@
{% for code,meta in bbcode %} - + {% endfor %}
@@ -37,11 +37,15 @@