]> git.0d.be Git - chloro.git/blob - chloro/phyll/static/js/chloro.js
9988be42a16aa8a95cf926979f2b5260465aa904
[chloro.git] / chloro / phyll / static / js / chloro.js
1 $(function() {
2   $('div[contenteditable]').on('input', function(event) {
3     if (event.originalEvent.inputType == "insertParagraph") {
4       var sel = document.getSelection();
5       var anchorNode = sel.anchorNode;
6       var prev_p = sel.anchorNode.previousSibling;
7       if (prev_p.tagName != 'P') {
8         prev_p = $(prev_p).parents('p')[0];
9       }
10       var title_match = prev_p.innerText.match(/^(h[1-6]). /);
11       if (title_match) {
12         var title = document.createElement(title_match[1]);
13         title.innerHTML = prev_p.innerHTML;
14         title.textContent = title.textContent.slice(4);
15         prev_p.replaceWith(title);
16       }
17     }
18     return true;
19   });
20   $('#save').on('click', function() {
21     var text = $('div[contenteditable]')[0].innerHTML;
22     $.post('api-save/', {text: text}).fail(function() {
23       $('#save').css('background', 'red');
24     });
25     return false;
26   });
27 });