diff --git a/build.sh b/build.sh index 1fa133b..910e765 100644 --- a/build.sh +++ b/build.sh @@ -11,9 +11,16 @@ PUBLIC_CSS="$PUBLIC_DIR/css" PUBLIC_JS="$PUBLIC_DIR/js" NODE_PATH='./node_modules' -NODE_DEST="$PUBLIC_JS/libs.js" -NODE_IMPORT=( - 'turbolinks/dist/turbolinks.js' + +NODE_DEST_JS="$PUBLIC_JS/libs.js" +NODE_IMPORT_JS=( + #'turbolinks/dist/turbolinks.js' doesn't work with yuuno + 'highlightjs/highlight.pack.min.js' +) + +NODE_DEST_CSS="$PUBLIC_CSS/libs.css" +NODE_IMPORT_CSS=( + 'highlightjs/styles/default.css' ) # delete old files, using find to avoid errors @@ -55,10 +62,22 @@ done # node imports echo echo "=> NPM imports" -echo "Creating $NODE_DEST" -touch $NODE_DEST -for FILE in $NODE_IMPORT; do -echo "==> $FILE" -cat "$NODE_PATH/$FILE" >> $NODE_DEST + +echo "==> JavaScript" +echo "Creating $NODE_DEST_JS" +touch $NODE_DEST_JS +for FILE in "${NODE_IMPORT_JS[@]}"; do +echo "===> $FILE" +cat "$NODE_PATH/$FILE" >> $NODE_DEST_JS +done +echo + +echo "==> CSS" +echo "Creating $NODE_DEST_CSS" +touch $NODE_DEST_CSS +for FILE in "${NODE_IMPORT_CSS[@]}"; do +echo "===> $FILE" +cat "$NODE_PATH/$FILE" >> $NODE_DEST_CSS done + diff --git a/package.json b/package.json index 5296b1e..e489f4e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "private": true, "dependencies": { + "highlightjs": "^9.8.0", "turbolinks": "^5.0.0" } } diff --git a/resources/assets/typescript/Sakura/Editor.ts b/resources/assets/typescript/Sakura/Editor.ts index ba1a2c2..0d5471d 100644 --- a/resources/assets/typescript/Sakura/Editor.ts +++ b/resources/assets/typescript/Sakura/Editor.ts @@ -1,3 +1,5 @@ +declare var hljs: any; + namespace Sakura { export class Editor @@ -19,6 +21,14 @@ namespace Sakura this.PreviewClient.SetSend({"text": text.value}); this.PreviewClient.AddCallback(200, (client: AJAX) => { target.innerHTML = client.Response(); + + var codeBlocks = target.querySelectorAll("pre code"); + + for (var i in codeBlocks) { + if ((typeof codeBlocks[i]).toLowerCase() === 'object') { + hljs.highlightBlock(codeBlocks[i]); + } + } }); this.PreviewClient.Start(HTTPMethod.POST); } diff --git a/resources/views/yuuno/forum/elements/replyForm.twig b/resources/views/yuuno/forum/elements/replyForm.twig index 3c043de..1aa278e 100644 --- a/resources/views/yuuno/forum/elements/replyForm.twig +++ b/resources/views/yuuno/forum/elements/replyForm.twig @@ -70,48 +70,12 @@ } }); - /*setInterval(function () { - if (lastParsed < Date.now() - 1000 - && lastKeystroke > Date.now() - 1000 - && parserActive !== true) { - lastParsed = Date.now(); - - var text = pText.value; - - if (text.length == 0) { - rText.innerHTML = ""; - } else if (text.length < textMin) { - rText.innerHTML = "Too short!"; - } else if (text.length > textMax) { - rText.innerHTML = "Too long!"; - } else { - parserActive = true; - - parser.SetSend({"text":text}); - - parser.AddCallback(200, function () { - rText.innerHTML = parser.Response(); - - var codeBlocks = rText.querySelectorAll("pre code"); - - for (var _i in codeBlocks) { - if ((typeof codeBlocks[_i]).toLowerCase() === 'object') { - hljs.highlightBlock(codeBlocks[_i]); - } - } - - parserActive = false; - }); - - parser.Start(Sakura.HTTPMethod.POST); - } - } - }, 1000);*/ - - pText.addEventListener("keydown", function (e) { + function postUpdateEvent(e) { if (e.keyCode == 9) { e.preventDefault(); - insertText('postingText', ' '); + var tab = ' '; + Sakura.DOM.EnterAtCursor(e.target, tab); + Sakura.DOM.SetPosition(e.target, Sakura.DOM.GetPosition(e.target) + tab.length); } if (e.keyCode == 13 && e.ctrlKey) { @@ -119,7 +83,10 @@ } Sakura.Editor.PreviewTimeout(rText, pText); - }); + } + + pText.addEventListener("change", postUpdateEvent); + pText.addEventListener("keydown", postUpdateEvent); pTitle.addEventListener("keyup", function (e) { var title = pTitle.value; diff --git a/resources/views/yuuno/forum/topic.twig b/resources/views/yuuno/forum/topic.twig index ddf94f4..44c8029 100644 --- a/resources/views/yuuno/forum/topic.twig +++ b/resources/views/yuuno/forum/topic.twig @@ -50,12 +50,7 @@ {% set paginationUrl = route('forums.topic', topic.id) %} {% endif %} -{% block css %} - -{% endblock %} - {% block js %} - {{ block('js') }} diff --git a/yarn.lock b/yarn.lock index 70da762..4d4276f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,10 @@ # yarn lockfile v1 +highlightjs@^9.8.0: + version "9.8.0" + resolved "https://registry.yarnpkg.com/highlightjs/-/highlightjs-9.8.0.tgz#981418614f45b04fa01623850990e016f950eb54" + turbolinks@^5.0.0: version "5.0.0" resolved "https://registry.yarnpkg.com/turbolinks/-/turbolinks-5.0.0.tgz#94c73fa299716824b0d96639b993b2efd7ef0e44"