Simulate graph states in the browser
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1KB

  1. var api = {};
  2. api.poll = function() {
  3. var xmlhttp = new XMLHttpRequest();
  4. xmlhttp.onreadystatechange = function() {
  5. if (xmlhttp.readyState == XMLHttpRequest.DONE) {
  6. if (xmlhttp.status == 200) {
  7. api.update(xmlhttp.responseText);
  8. }
  9. }
  10. };
  11. // Send the request
  12. xmlhttp.open("GET", window.location.href+"/graph", true);
  13. xmlhttp.send();
  14. };
  15. api.update = function(s) {
  16. json = JSON.parse(s);
  17. materials.qubit.size = big.checked ? 2 : 0.4;
  18. graph.update(json);
  19. }
  20. api.edit = function(edit) {
  21. var xmlhttp = new XMLHttpRequest();
  22. xmlhttp.onreadystatechange = function() {
  23. if (xmlhttp.readyState == XMLHttpRequest.DONE) {
  24. if (xmlhttp.status == 200) {
  25. api.update(xmlhttp.responseText);
  26. }
  27. }
  28. };
  29. // Send the request
  30. xmlhttp.open("POST", window.location.href+"/edit", true);
  31. xmlhttp.setRequestHeader("Content-Type", "application/json");
  32. xmlhttp.send(JSON.stringify(edit));
  33. }
  34. // Launch the polling loop
  35. setInterval(api.poll, 1000);