]> git.ipfire.org Git - ipfire.org.git/blob - src/templates/wiki/edit.html
wiki: Add a little JS editor for highlighting text
[ipfire.org.git] / src / templates / wiki / edit.html
1 {% extends "base.html" %}
2
3 {% block title %}{% if page %}{{ _("Edit %s") % page.title }}{% else %}{{ _("Create A New Page") }}{% end %}{% end block %}
4
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
13 {% block main %}
14 <div class="card mb-4">
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
20 <form action="" method="POST">
21 {% raw xsrf_form_html() %}
22
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
35 <textarea class="form-control" rows="16" name="content" id="content" placeholder="{{ _("Text") }}"
36 >{% if page and page.markdown %}{{ page.markdown }}{% end %}</textarea>
37 </div>
38
39 <div class="form-group row">
40 <label class="col-sm-4 col-form-label">{{ _("What has changed?") }}</label>
41 <div class="col-sm-8">
42 <input type="text" class="form-control" name="changes" required>
43 </div>
44 </div>
45
46 {% if page and not page.is_watched_by(current_user) %}
47 <div class="form-group form-check">
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>
52
53 <small class="form-text text-muted">
54 {{ _("Get notified when this page is changed") }}
55 </small>
56 </div>
57 {% end %}
58
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>
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 %}
83 {% import os.path %}
84
85 <script src="{{ static_url("js/editor.js") }}"></script>
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
111 $.post("{{ os.path.join(path, "_render") }}", { content : content },
112 function(data) {
113 c.html(data);
114
115 // Update finished
116 preview.removeClass("updating");
117 }
118 );
119 }, 750);
120 });
121 });
122 </script>
123 {% end block %}