-
Notifications
You must be signed in to change notification settings - Fork 0
/
what_happen_md.html
101 lines (86 loc) · 2.97 KB
/
what_happen_md.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>See we're doing things</title>
<link rel="stylesheet" href="{{ url_for('static', filename='custom.css') }}">
<script type=text/javascript src="{{ url_for('static', filename='jquery.js') }}"></script>
<script type="text/javascript" src="//simonwaldherr.github.io/micromarkdown.js/dist/micromarkdown.min.js"></script>
</head>
<script type=text/javascript>
$SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
</script>
<body>
<div id="everything">
<div id="textarea">
<textarea id="what_happen_text">
{{ text }}
</textarea>
</div>
<div id="preview">
{{ text|markdown }}
</div>
<div class="clear"></div>
</div>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.6/socket.io.min.js"></script>
<script type="text/javascript">
var change_count = 0;
// var isConnected = false;
var isDirty = false;
var sentData = false;
// on page load connect to websocket
// var socket = io.connect('http://' + document.domain + ':' + location.port);
// socket.on('connect', function() {
// isConnected = true;
// });
var area = document.querySelector('textarea#what_happen_text');
if (area.addEventListener) {
area.addEventListener('input', function() {
if (!isDirty) {
isDirty = true;
oldTime = new Date().getTime();
}
change_count = change_count + 1;
console.log(change_count);
var todo = document.getElementById("what_happen_text").value;
if (change_count == 15) {
send_md(todo);
change_count = 0;
oldTime = new Date().getTime();
sentData = true;
}
}, false);
} else if (area.attachEvent) {
area.attachEvent('onpropertychange', function() {
// IE-specific event handling code
});
}
setInterval(function() {
if (!sentData && isDirty) {
// todo: what happens after first call dirty-ing isdirty?
var todo = document.getElementById("what_happen_text").value;
send_md(todo);
}
}, 10000);
function send_md(todo) {
$.ajax({
type : "POST",
url : $SCRIPT_ROOT + '/md_change',
data: todo,
contentType: 'text;charset=UTF-8',
success: function(result) {
// console.log(micromarkdown.parse(result))
var input = document.getElementById('what_happen_text').value;
var preview = document.getElementById('preview');
preview.innerHTML = micromarkdown.parse(input);
// $('#preview').html(micromarkdown.parse(result));
sendData = false;
}
});
// if (isConnected) {
// socket.emit('md change', todo);
// }
}
</script>
</body>
</html>