Simulate graph states in the browser
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

api.js 1.1KB

il y a 6 ans
il y a 6 ans
il y a 6 ans
123456789101112131415161718192021222324252627282930313233343536373839404142
  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);