]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/static/js/editor.js
wiki: Support links in editor
[ipfire.org.git] / src / static / js / editor.js
index 2e3c57a4acaa83e1ad8239210c34d33d9baf0be0..148eb69a0e064efe087bad88be8c6ef57d629dd4 100644 (file)
@@ -61,6 +61,11 @@ class Editor {
                 case 72:
                     editor.headline();
                     break;
+
+                // L - Link
+                case 76:
+                    editor.link();
+                    break;
             }
         });
     }
@@ -75,6 +80,9 @@ class Editor {
         this.parent.find("#headline").click(this.headline.bind(this));
         this.parent.find("#headline-down").click(this.headline_down.bind(this));
         this.parent.find("#headline-up").click(this.headline_up.bind(this));
+
+        // Links
+        this.parent.find("#link").click(this.link.bind(this));
     }
 
     // Functions to modify the text
@@ -112,6 +120,16 @@ class Editor {
         }
     }
 
+    link() {
+        // Handle URLs
+        if (this.selection.text.startsWith("https://") || this.selection.text.startsWith("http://")) {
+            this.replaceSelection("[" + this.selection.text + "](" + this.selection.text + ")");
+        // Handle selected text
+        } else {
+            this.replaceSelection("[" + this.selection.text + "]()")
+        }
+    }
+
     // Headlines
 
     findLevel() {