Mercurial > public > sg101
comparison gcalendar/static/js/gcalendar.js @ 1094:110bbc78a482
GCalendar V3 conversion in progress.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 29 May 2016 23:09:23 -0500 |
parents | ee87ea74d46b |
children | d9cd3180c12c |
comparison
equal
deleted
inserted
replaced
1093:1ac847818aea | 1094:110bbc78a482 |
---|---|
1 function editorReplaceText(textArea, i, j, newText) { | |
2 textArea.value = textArea.value.substring(0, i) + newText + | |
3 textArea.value.substring(j); | |
4 } | |
5 | |
6 function editorWrapSelection(textArea, wrapText) { | |
7 if (wrapText.length == 0) return; | |
8 var i = textArea.selectionStart; | |
9 var j = textArea.selectionEnd; | |
10 if (i == j) return; | |
11 var selection = textArea.value.substring(i, j); | |
12 var newText = wrapText + selection + wrapText; | |
13 editorReplaceText(textArea, i, j, newText); | |
14 textArea.focus(); | |
15 textArea.setSelectionRange(i, j + 2 * wrapText.length); | |
16 } | |
17 | |
18 function editorPrependLines(textArea, s) { | |
19 if (s.length == 0) return; | |
20 var i = textArea.selectionStart; | |
21 var j = textArea.selectionEnd; | |
22 var newText = s; | |
23 var selection = textArea.value.substring(i, j); | |
24 newText += selection.replace(/\n/gm, '\n' + s); | |
25 editorReplaceText(textArea, i, j, newText); | |
26 } | |
27 | |
28 function editorLink(textArea) { | |
29 var i = textArea.selectionStart; | |
30 var j = textArea.selectionEnd; | |
31 var url = window.prompt("Please enter a URL:", "http://"); | |
32 if (!url) return; | |
33 var link; | |
34 if (i == j) { | |
35 link = '[Link](' + url + ')'; | |
36 } else { | |
37 var selection = textArea.value.substring(i, j); | |
38 link = '[' + selection + '](' + url + ')'; | |
39 } | |
40 editorReplaceText(textArea, i, j, link); | |
41 textArea.focus(); | |
42 } | |
43 | |
1 $(document).ready(function() { | 44 $(document).ready(function() { |
2 $('#id_start_date').datepicker({constrainInput: true, | 45 $('#id_start_date').datepicker({constrainInput: true, |
3 dateFormat: 'mm/dd/yy', | 46 dateFormat: 'mm/dd/yy', |
4 onClose: function () { | 47 onClose: function () { |
5 var end = $('#id_end_date'); | 48 var end = $('#id_end_date'); |
17 { | 60 { |
18 start.val(this.value); | 61 start.val(this.value); |
19 } | 62 } |
20 } | 63 } |
21 }); | 64 }); |
22 if ($('#id_all_day:checked').length) | 65 if ($('#id_all_day:checked').length) { |
23 { | 66 $('.all-day-hide').hide(); |
24 $('#id_start_time').hide(); | |
25 $('#id_end_time').hide(); | |
26 $('#id_tz_stuff').hide(); | |
27 } | 67 } |
28 $('#id_all_day').click(function () { | 68 $('#id_all_day').click(function () { |
29 $('#id_start_time').toggle(); | 69 $('.all-day-hide').toggle(); |
30 $('#id_end_time').toggle(); | 70 }); |
31 $('#id_tz_stuff').toggle(); | 71 |
32 }); | 72 var editorPanel = $('#editor-panel textarea'); |
73 var previewPanel = $('#preview-panel'); | |
74 previewPanel.css('height', editorPanel.css('height')); | |
75 var observer = new MutationObserver(function(mutations) { | |
76 if (previewPanel.is(':visible')) { | |
77 alert(editorPanel[0].value); | |
78 $.ajax({ | |
79 url: '/comments/markdown/v3/', | |
80 method: 'POST', | |
81 data: {'data': editorPanel[0].value}, | |
82 dataType: 'html', | |
83 success: function(data, textStatus) { | |
84 alert(data); | |
85 previewPanel.html(data); | |
86 }, | |
87 error: function (xhr, textStatus, ex) { | |
88 alert('Oops, an error occurred: ' + xhr.statusText + ' - ' + | |
89 xhr.responseText); | |
90 } | |
91 }); | |
92 } | |
93 }); | |
94 var target = document.getElementById('preview-panel'); | |
95 observer.observe(target, {attributes: true}); | |
96 | |
97 // Editor stuff | |
98 $('.v3-editor').each(function (index) { | |
99 var $this = $(this); | |
100 var textArea = $this.find('textarea')[0]; | |
101 $this.find('.editor-bold').click(function () { | |
102 editorWrapSelection(textArea, '**'); | |
103 return false; | |
104 }); | |
105 $this.find('.editor-italic').click(function () { | |
106 editorWrapSelection(textArea, '_'); | |
107 return false; | |
108 }); | |
109 $this.find('.editor-strike').click(function () { | |
110 editorWrapSelection(textArea, '---'); | |
111 return false; | |
112 }); | |
113 $this.find('.editor-link').click(function () { | |
114 editorLink(textArea); | |
115 return false; | |
116 }); | |
117 $this.find('.editor-quote').click(function () { | |
118 editorPrependLines(textArea, '> '); | |
119 return false; | |
120 }); | |
121 $this.find('.editor-code').click(function () { | |
122 editorPrependLines(textArea, ' '); | |
123 return false; | |
124 }); | |
125 $this.find('.editor-bullet').click(function () { | |
126 editorPrependLines(textArea, '* '); | |
127 return false; | |
128 }); | |
129 $this.find('.editor-number').click(function () { | |
130 editorPrependLines(textArea, '1. '); | |
131 return false; | |
132 }); | |
133 }); | |
33 }); | 134 }); |