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.

110 lines
2.9 KiB

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