]> git.ipfire.org Git - ipfire.org.git/blame - src/templates/wiki/edit.html
wiki: Add a little JS editor for highlighting text
[ipfire.org.git] / src / templates / wiki / edit.html
CommitLineData
d398ca08
MT
1{% extends "base.html" %}
2
3{% block title %}{% if page %}{{ _("Edit %s") % page.title }}{% else %}{{ _("Create A New Page") }}{% end %}{% end block %}
4
6c13ca2d
MT
5{% block sidebar %}
6 {% set help = backend.wiki.get_page("/wiki/edit") %}
7
8 {% if help %}
9 {% raw help.html %}
10 {% end %}
11{% end block %}
12
d398ca08 13{% block main %}
2901b734 14 <div class="card mb-4">
d398ca08
MT
15 <div class="card-body">
16 <h4 class="card-title">
17 {% if page %}{{ _("Edit %s") % page.title }}{% else %}{{ _("Create A New Page") }}{% end %}
18 </h4>
19
40cb87a4 20 <form action="" method="POST">
d398ca08
MT
21 {% raw xsrf_form_html() %}
22
feeace6e
MT
23 <div class="form-group editor">
24 <div class="btn-toolbar mb-3" role="toolbar">
25 <div class="btn-group btn-group-sm" role="group">
26 <button type="button" class="btn btn-secondary" id="bold">
27 <i class="fas fa-bold"></i>
28 </button>
29 <button type="button" class="btn btn-secondary" id="italic">
30 <i class="fas fa-italic"></i>
31 </button>
32 </div>
33 </div>
34
2901b734 35 <textarea class="form-control" rows="16" name="content" id="content" placeholder="{{ _("Text") }}"
d398ca08
MT
36 >{% if page and page.markdown %}{{ page.markdown }}{% end %}</textarea>
37 </div>
38
39 <div class="form-group row">
db82550d
MT
40 <label class="col-sm-4 col-form-label">{{ _("What has changed?") }}</label>
41 <div class="col-sm-8">
d398ca08
MT
42 <input type="text" class="form-control" name="changes" required>
43 </div>
44 </div>
45
f2e25ded 46 {% if page and not page.is_watched_by(current_user) %}
917d9cfa 47 <div class="form-group form-check">
47a206ca
MT
48 <div class="custom-control custom-checkbox">
49 <input type="checkbox" class="custom-control-input" name="watch" id="watch" checked>
50 <label class="custom-control-label" for="watch">{{ _("Watch this page") }}</label>
51 </div>
bfb776cd 52
47a206ca 53 <small class="form-text text-muted">
bfb776cd 54 {{ _("Get notified when this page is changed") }}
47a206ca 55 </small>
917d9cfa
MT
56 </div>
57 {% end %}
d64a1e35 58
d398ca08
MT
59 <button type="submit" class="btn btn-primary btn-block">
60 {% if page %}{{ _("Save Page") }}{% else %}{{ _("Create Page") }}{% end %}
61 </button>
62 </form>
63 </div>
64 </div>
2901b734
MT
65
66 <div id="preview" class="fade show">
67 <div class="d-flex align-items-center mb-4">
68 <h4 class="mb-0">{{ _("Preview") }}</h4>
69 <div id="spinner" class="spinner-border ml-auto" role="status" aria-hidden="true"></div>
70 </div>
71
72 <div class="card">
73 <div class="card-body mb-0">
74 <div id="preview-content" class="wiki-content mb-0">
75 {{ _("Loading...") }}
76 </div>
77 </div>
78 </div>
79 </div>
80{% end block %}
81
82{% block javascript %}
3c8524b4
MT
83 {% import os.path %}
84
feeace6e 85 <script src="{{ static_url("js/editor.js") }}"></script>
2901b734
MT
86 <script type="text/javascript">
87 var update = null;
88
89 $(document).ready(function() {
90 var preview = $("#preview");
91 preview.hide();
92
93 $("#content").on("keyup", function(e) {
94 if (update)
95 clearTimeout(update);
96
97 var content = $(this).val();
98
99 // If the field is all empty, we will hide it
100 if (content)
101 preview.show();
102 else
103 preview.hide();
104
105 // Go into update mode
106 preview.addClass("updating");
107
108 update = setTimeout(function() {
109 var c = $("#preview-content");
110
ec606db5 111 $.post("{{ os.path.join(path, "_render") }}", { content : content },
2901b734
MT
112 function(data) {
113 c.html(data);
114
115 // Update finished
116 preview.removeClass("updating");
117 }
118 );
119 }, 750);
120 });
121 });
122 </script>
d398ca08 123{% end block %}