annotate gcalendar/static/js/gcalendar.js @ 1095:74d7e56a9cfb

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