Browse Source

Merge remote-tracking branch 'origin/master'

Conflicts:
	scripts/haltestellen.js
master
T. Meissner 11 years ago
parent
commit
b064a10f4b
3 changed files with 73 additions and 19 deletions
  1. +1
    -0
      index.html
  2. +69
    -0
      scripts/gcf.js
  3. +3
    -19
      scripts/haltestellen.js

+ 1
- 0
index.html View File

@ -21,6 +21,7 @@
<div id="output"></div>
<script src="scripts/gcf.js"></script>
<script src="scripts/haltestellen.js"></script>
</body>


+ 69
- 0
scripts/gcf.js View File

@ -0,0 +1,69 @@
/**
* Created with JetBrains WebStorm.
* User: torsten
* Date: 28.03.13
* Time: 23:07
* To change this template use File | Settings | File Templates.
*/
gcf = {
// xmlhttp object function
getHTTPObject : function () {
// debug log
if (DEBUG === 1) {console.log("xml http object function");}
// variable definitions
var xhr;
// check for availibility if xmlhttprequest object
if(window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if(window.ActiveXObject) {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
return xhr;
},
// ajax call function
ajaxCall : function (dataUrl, outputElement, callback, responseType) {
// debug log
if (DEBUG === 1) {console.log("ajax function");}
// variable definitions
var response,
request = this.getHTTPObject(); // get the xmlhttp object which is supported
outputElement.innerHTML = "Lade Daten ...";
request.onreadystatechange = function() {
if(request.readyState === 4 && request.status === 200) {
//save ajax response
if (responseType === "json") {
response = JSON.parse(request.responseText);
} else if (responseType === "xml") {
response = request.responseXML;
} else {
response = request.responseText;
}
// check if callback is a function
if(typeof callback === "function") {
callback(response);
}
}
};
request.open("get", dataUrl, true);
request.send(null);
}
}

+ 3
- 19
scripts/haltestellen.js View File

@ -61,24 +61,6 @@ function ajaxCall(dataUrl, outputElement, callback, responseType) {
}
// decode special characters with their utf-8 representation
function decodeHtml(token) {
var i,
y,
start = [33, 58, 91, 123, 161],
stop = [47, 64, 96, 126, 255],
startLength = start.length;
for (y = 0; y < startLength; y++) {
for (i = start[y]; i <= stop[y]; i++) {
token = token.replace("&#" + i +";", String.fromCharCode(255));
}
}
return token;
}
// wrap all in anonymous function to get out of global scope
(function() {
@ -146,8 +128,9 @@ function decodeHtml(token) {
// replace useless chars & split string into array
data = data.replace(/\(.+?\)/gi, ''); // remove all content in round parentheses
data = data.replace('ß', 'ss'); // remove some special characters
data = data.replace(/<(.+?)>/gi, '$1'); // remove tag parentheses to prevent code injection
data = data.slice(3, -3).split("],["); // split at array boundaries to get an array of arrays
data = data.slice(3, -3).split("],["); // split at array boundaries to get an array of arrays
// debug log
if (DEBUG === 1) {console.log("parsed data: " + data);}
@ -231,6 +214,7 @@ function decodeHtml(token) {
// replace useless chars & split string into array
data = data.replace(/\[\[\[.+?\]\],/gi, '['); // remove useless first city entry
data = data.replace(/\(.+?\)/gi, ''); // remove all content in round parentheses
data = data.replace('ß', 'ss'); // remove some special characters
data = data.replace(/<(.+?)>/gi, '$1'); // remove tag parentheses to prevent code injection
data = data.slice(4, -4).split("],["); // split at array boundaries to get an array of arrays


Loading…
Cancel
Save