if(typeof Hafas == "undefined")
var Hafas = { Config:{}, Texts:{} };
var SimpleWidget = {
suggestCount: 0,
init: function()
{
this.createContext();
this.loadJS();
this.addCSS();
},
createContext:function()
{
Hafas.Config.gUrlAjaxGetStop = "https://vmt.hafas.cloud/bin/ajax-getstop.exe/dn?L=vs_vmt&";
Hafas.Config.gUrlScriptPath = "https://vmt.hafas.cloud/hafas-res/prod/js/";
Hafas.Config.gUrlCSSPath = "https://vmt.hafas.cloud/hafas-res/prod/css/";
Hafas.Config.gImagePath = "https://vmt.hafas.cloud/hafas-res/prod/img/";
Hafas.Config.version = "?guiV=017&";
Hafas.Config.cookieName = "vmtHistory";
Hafas.JsError = {};
Hafas.JsError.suggestAjaxError = '';
},
loadJS: function()
{
var simpleSuggestJS = document.createElement("script");
simpleSuggestJS.type = "text/javascript";
simpleSuggestJS.src = Hafas.Config.gUrlScriptPath+"SimpleSuggest.js" + Hafas.Config.version;
simpleSuggestJS.onload = this.createSuggests.bind(this);
document.getElementsByTagName('head')[0].appendChild(simpleSuggestJS);
},
addCSS: function()
{
var head = document.head || document.getElementsByTagName('head')[0],
suggestIcons = document.createElement('style');
var css = 'i[class*="hfs-icon-suggest-"] { background-image: url(' + Hafas.Config.gImagePath + 'icons/sprite_simplesuggest.png); }';
suggestIcons.type = 'text/css';
if (suggestIcons.styleSheet){
suggestIcons.styleSheet.cssText = css;
} else {
suggestIcons.appendChild(document.createTextNode(css));
}
head.appendChild(suggestIcons);
var simpleSuggestCSS = document.createElement("link");
simpleSuggestCSS.type = "text/css";
simpleSuggestCSS.rel = "stylesheet";
simpleSuggestCSS.href = Hafas.Config.gUrlCSSPath+"hafas_default_suggest.css" + Hafas.Config.version;
document.head.appendChild(simpleSuggestCSS);
},
createSuggests: function()
{
if(typeof SimpleLocSuggest == "undefined")
{
return;
}
// &#220;berpr&#252;fe, ob es sich um Elemente aus den Hafas-Seiten handelt
var suggestList = [];
var elList = document.getElementsByTagName('input');
for (var e=0 ; e < elList.length ; e++) {
if (elList[e].className.match(/HafasSuggest/)) {
if (elList[e].getAttribute('data-ishafas') !== 'true') {
// H&#228;nge nur die input-Felder ohne das Attribut "data-ishafas"
// in die Liste ein (alle anderen werden &#252;ber die js.tpl intanziert)
suggestList.push(elList[e]);
}
}
}
for(var i = 0; i < suggestList.length; i++)
{
var suggestInput = suggestList[i];
new SimpleLocSuggest(suggestInput, { useJSONP:true, forceClientSelection: true });
this.suggestCount++;
}
}
}
SimpleWidget.init();
