Some experiments with web applications
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.

111 lines
3.0 KiB

  1. // variable to en-/disable debug
  2. // set to 1 to enable debug log
  3. if (DEBUG === undefined) {
  4. var DEBUG;
  5. }
  6. var gcf = {
  7. // decode special characters with their utf-8 representation
  8. decodeHtml : function (token) {
  9. var i,
  10. y,
  11. start = [33, 58, 91, 123, 161],
  12. stop = [47, 64, 96, 126, 255],
  13. startLength = start.length;
  14. for (y = 0; y < startLength; y++) {
  15. for (i = start[y]; i <= stop[y]; i++) {
  16. token = token.replace("&#" + i +";", String.fromCharCode(255));
  17. }
  18. }
  19. return token;
  20. },
  21. // get the path of the cgi-bin dir with correct http(s) protocol
  22. // for using with ajax calls (to with same origin policy)
  23. getCgiBinPath : function () {
  24. // parse actual url and parse for protocol type (http/https)
  25. // set the ajax server url dependent on the protocol
  26. // for strato ssl-proxy, we have to insert the 1st part of the url path
  27. var serverUrl = window.location.protocol + "//" + window.location.hostname;
  28. if (serverUrl.indexOf("https") === -1) {
  29. serverUrl += "/cgi-bin/";
  30. } else {
  31. serverUrl += "/" + window.location.pathname.split("/")[1] + "/cgi-bin/";
  32. }
  33. return serverUrl;
  34. },
  35. // xmlhttp object function
  36. getHTTPObject : function () {
  37. // debug log
  38. if (DEBUG === 1) {console.log("xml http object function");}
  39. // variable definitions
  40. var xhr;
  41. // check for availibility if xmlhttprequest object
  42. if(window.XMLHttpRequest) {
  43. xhr = new XMLHttpRequest();
  44. } else if(window.ActiveXObject) {
  45. xhr = new ActiveXObject("Msxml2.XMLHTTP");
  46. }
  47. return xhr;
  48. },
  49. // ajax call function
  50. ajaxCall : function (dataUrl, outputElement, callback, responseType) {
  51. // debug log
  52. if (DEBUG === 1) {console.log("ajax function");}
  53. // variable definitions
  54. var response,
  55. request = this.getHTTPObject(); // get the xmlhttp object which is supported
  56. outputElement.innerHTML = "Lade Daten ...";
  57. request.onreadystatechange = function() {
  58. if(request.readyState === 4 && request.status === 200) {
  59. //save ajax response
  60. if (responseType === "json") {
  61. response = JSON.parse(request.responseText);
  62. } else if (responseType === "xml") {
  63. response = request.responseXML;
  64. } else {
  65. response = request.responseText;
  66. }
  67. // check if callback is a function
  68. if(typeof callback === "function") {
  69. callback(response);
  70. } else {
  71. if (DEBUG === 1) {console.log(callback + " is no callback function");}
  72. }
  73. }
  74. };
  75. request.open("get", dataUrl, true);
  76. request.send(null);
  77. }
  78. };