Permalink
Browse files

some broken shit

  • Loading branch information...
1 parent 92d7bbf commit 305749356cfdd0ce2656f0e14c71e60fd624f8db @shankj3 shankj3 committed Feb 17, 2017
Showing with 55 additions and 23 deletions.
  1. +15 −6 legis.py
  2. +4 −0 static/jquery.js
  3. +4 −2 static/what_happen.md
  4. +32 −15 templates/what_happen_md.html
View
@@ -21,13 +21,22 @@
# cache for requests
requests_cache.install_cache('test_cache', backend='sqlite', expire_after=300)
+
+@app.route('/md_change', methods=['POST'])
+def md_change():
+ print(request.data)
+ return request.data
+ # a = request.args.get('a', 0, type=int)
+ # b = request.args.get('b', 0, type=int)
+ # return jsonify(result=a + b)
+
# todo: write changes to md_file after 10 minutes - avoid concurrency issues
-@socketio.on('md change')
-def md_change(data):
- print('received json: ' + str(data))
- md_change = open(vars.WHAT_WERE_DOING_MD, 'r+')
- md_change.write(str(data))
- md_change.close()
+# @socketio.on('md change')
+# def md_change(data):
+# print('received json: ' + str(data))
+# md_change = open(vars.WHAT_WERE_DOING_MD, 'r+')
+# md_change.write(str(data))
+# md_change.close()
@app.route('/')
def index():
View
Oops, something went wrong.
@@ -1,4 +1,6 @@
hello
======
-*s *s==
- s
+*s
+*s
+
+ dsf
@@ -4,8 +4,14 @@
<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="//cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.6/socket.io.min.js"></script>
+ <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">
@@ -21,19 +27,18 @@
<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 isConnected = false;
var isDirty = false;
- var oldTime = new Date().getTime();
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 socket = io.connect('http://' + document.domain + ':' + location.port);
+// socket.on('connect', function() {
+// isConnected = true;
+// });
var area = document.querySelector('textarea#what_happen_text');
@@ -47,10 +52,8 @@
change_count = change_count + 1;
console.log(change_count);
- var timeDiff = new Date().getTime() - oldTime;
var todo = document.getElementById("what_happen_text").value;
- if (change_count == 20) {
- console.log('SENDING SOMETHING!', isConnected, change_count, timeDiff);
+ if (change_count == 15) {
send_md(todo);
change_count = 0;
oldTime = new Date().getTime();
@@ -59,7 +62,6 @@
}, false);
} else if (area.attachEvent) {
-
area.attachEvent('onpropertychange', function() {
// IE-specific event handling code
});
@@ -74,9 +76,24 @@
}, 10000);
function send_md(todo) {
- if (isConnected) {
- socket.emit('md change', 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>

0 comments on commit 3057493

Please sign in to comment.