diff options
| author | 2019-04-13 16:39:47 +0100 | |
|---|---|---|
| committer | 2019-04-13 16:39:47 +0100 | |
| commit | 34b72419c312d21b77185b72a47cb49508ed47e9 (patch) | |
| tree | 81391e5d1c2300ad8aebf46f617a989c9f3263bb /pydis_site/static/js | |
| parent | Small cosmetic changes (diff) | |
Some more work towards the editor pages
Diffstat (limited to 'pydis_site/static/js')
| -rw-r--r-- | pydis_site/static/js/wiki/load_editor.js | 51 | 
1 files changed, 39 insertions, 12 deletions
diff --git a/pydis_site/static/js/wiki/load_editor.js b/pydis_site/static/js/wiki/load_editor.js index a9f78e65..1837c7fd 100644 --- a/pydis_site/static/js/wiki/load_editor.js +++ b/pydis_site/static/js/wiki/load_editor.js @@ -1,8 +1,44 @@  (function() {      window.editors = {};  // So that other scripts can get at 'em +    const TOCText = "[TOC]"; + +    const headingAction = { +        name: "heading", +        action: SimpleMDE.toggleHeadingSmaller, +        className: "fa fa-heading", +        title: "Heading", +    }; + +    const imageAction = { +        name: "image", +        action: SimpleMDE.drawImage, +        className: "fa fa-image", +        title: "Insert image", +    }; + +    const TOCAction = { +        name: "toc", +        action: inserTOC, +        className: "fa fa-stream", +        title: "Insert Table of Contents" +    }; +      let elements = document.getElementsByClassName("simple-mde"); +    function inserTOC(editor) { +        let doc = editor.codemirror.getDoc(), +            cursor = doc.getCursor(), +            line = doc.getLine(cursor.line), +            position = {"line": cursor.line}; + +        if (line.length === 0) { +            doc.replaceRange(TOCText, position); +        } else { +            doc.replaceRange("\n" + TOCText, position) +        } +    } +      for (let element of elements) {          window.editors[element.id] = new SimpleMDE({              "element": element, @@ -28,19 +64,10 @@              tabSize: 4,              toolbar: [ -                "bold", "italic", "strikethrough", { -                    name: "heading", -                    action: SimpleMDE.toggleHeadingSmaller, -                    className: "fa fa-heading", -                    title: "Heading", -                }, "|", +                "bold", "italic", "strikethrough", headingAction, "|",                  "code", "quote", "unordered-list", "ordered-list", "|", -                "link", { -                    name: "image", -                    action: SimpleMDE.drawImage, -                    className: "fa fa-image", -                    title: "Insert image", -                }, "table", "horizontal-rule", "|", +                "link", imageAction, "table", "horizontal-rule", "|", +                TOCAction, "|",                  "preview", "side-by-side", "fullscreen", "|",                  "guide"              ],  |