##// END OF EJS Templates
Added AJAX text preview to the form.
neko259 -
r1217:1037d51e default
parent child Browse files
Show More
@@ -99,3 +99,7 b' textarea, input {'
99 .post-image-full {
99 .post-image-full {
100 width: 100%;
100 width: 100%;
101 }
101 }
102
103 #preview-text {
104 display: none;
105 }
@@ -531,3 +531,14 b' ul {'
531 border-left: solid 1px #777;
531 border-left: solid 1px #777;
532 border-right: solid 1px #777;
532 border-right: solid 1px #777;
533 }
533 }
534
535 #preview-text {
536 border: solid 1px white;
537 margin: 1ex 0 1ex 0;
538 padding: 1ex;
539 }
540
541 button {
542 border: 1px solid white;
543 margin-bottom: 0.5ex;
544 }
@@ -370,3 +370,9 b' input[type="submit"]:hover {'
370 .highlight {
370 .highlight {
371 background-color: #F9E8A5;
371 background-color: #F9E8A5;
372 }
372 }
373
374 #preview-text {
375 border: solid 1px black;
376 margin: 1ex 0 1ex 0;
377 padding: 1ex;
378 }
@@ -401,3 +401,9 b' li {'
401 .dead_post {
401 .dead_post {
402 border-right: 1ex solid #666;
402 border-right: 1ex solid #666;
403 }
403 }
404
405 #preview-text {
406 border: solid 1px white;
407 margin: 1ex 0 1ex 0;
408 padding: 1ex;
409 }
@@ -24,4 +24,20 b" var form = $('#form');"
24 if (event.which == 13 && event.ctrlKey) {
24 if (event.which == 13 && event.ctrlKey) {
25 form.submit();
25 form.submit();
26 }
26 }
27 }); No newline at end of file
27 });
28
29 $('#preview-button').click(function() {
30 var data = {
31 raw_text: $('textarea').val()
32 }
33
34 var diffUrl = '/api/preview/';
35
36 $.post(diffUrl,
37 data,
38 function(data) {
39 var previewTextBlock = $('#preview-text');
40 previewTextBlock.html(data);
41 previewTextBlock.show();
42 })
43 })
@@ -310,6 +310,7 b' function resetForm(form) {'
310 form.find('input:radio, input:checkbox')
310 form.find('input:radio, input:checkbox')
311 .removeAttr('checked').removeAttr('selected');
311 .removeAttr('checked').removeAttr('selected');
312 $('.file_wrap').find('.file-thumb').remove();
312 $('.file_wrap').find('.file-thumb').remove();
313 $('#preview-text').hide();
313 }
314 }
314
315
315 /**
316 /**
@@ -122,12 +122,10 b''
122 <div>
122 <div>
123 {% trans 'Tags must be delimited by spaces. Text or image is required.' %}
123 {% trans 'Tags must be delimited by spaces. Text or image is required.' %}
124 </div>
124 </div>
125 <div>
125 <div><button id="preview-button">{% trans 'Preview' %}</button></div>
126 <a href="{% url "staticpage" name="help" %}">{% trans 'Text syntax' %}</a>
126 <div id="preview-text"></div>
127 </div>
127 <div><a href="{% url "staticpage" name="help" %}">{% trans 'Text syntax' %}</a></div>
128 <div>
128 <div><a href="{% url "tags" "required" %}">{% trans 'Tags' %}</a></div>
129 <a href="{% url "tags" "required" %}">{% trans 'Tags' %}</a>
130 </div>
131 </div>
129 </div>
132 </div>
130 </div>
133
131
@@ -39,6 +39,8 b''
39 </div>
39 </div>
40 </form>
40 </form>
41 </div>
41 </div>
42 <div><button id="preview-button">{% trans 'Preview' %}</button></div>
43 <div id="preview-text"></div>
42 <div><a href="{% url "staticpage" name="help" %}">
44 <div><a href="{% url "staticpage" name="help" %}">
43 {% trans 'Text syntax' %}</a></div>
45 {% trans 'Text syntax' %}</a></div>
44 <div><a id="form-close-button" href="#" onClick="resetFormPosition(); return false;">{% trans 'Close form' %}</a></div>
46 <div><a id="form-close-button" href="#" onClick="resetFormPosition(); return false;">{% trans 'Close form' %}</a></div>
@@ -65,6 +65,7 b" urlpatterns = patterns('',"
65 name='add_post'),
65 name='add_post'),
66 url(r'^api/notifications/(?P<username>\w+)/$', api.api_get_notifications,
66 url(r'^api/notifications/(?P<username>\w+)/$', api.api_get_notifications,
67 name='api_notifications'),
67 name='api_notifications'),
68 url(r'^api/preview/$', api.api_get_preview, name='preview'),
68
69
69 # Search
70 # Search
70 url(r'^search/$', BoardSearchView.as_view(), name='search'),
71 url(r'^search/$', BoardSearchView.as_view(), name='search'),
@@ -11,6 +11,7 b' from boards.models import Post, Thread, '
11 from boards.utils import datetime_to_epoch
11 from boards.utils import datetime_to_epoch
12 from boards.views.thread import ThreadView
12 from boards.views.thread import ThreadView
13 from boards.models.user import Notification
13 from boards.models.user import Notification
14 from boards.mdx_neboard import Parser
14
15
15
16
16 __author__ = 'neko259'
17 __author__ = 'neko259'
@@ -230,3 +231,10 b' def get_post_data(post_id, format_type=D'
230 post = get_object_or_404(Post, id=post_id)
231 post = get_object_or_404(Post, id=post_id)
231 return post.get_post_data(format_type=format_type, request=request,
232 return post.get_post_data(format_type=format_type, request=request,
232 include_last_update=include_last_update)
233 include_last_update=include_last_update)
234
235
236 def api_get_preview(request):
237 raw_text = request.POST['raw_text']
238
239 parser = Parser()
240 return HttpResponse(content=parser.parse(parser.preparse(raw_text)))
General Comments 0
You need to be logged in to leave comments. Login now