var WebDelivery; (function (WebDelivery) { /* (C) 2021 NWB Verlag, Herne Germany */ var Loader = /** @class */ (function () { // Constructor function Loader(id, nwburlVorgabe, getNwbDomain) { this.id = id; this.targetDivKey = "#nwbdeliverytargetcontent"; this.urlParameterKey = "nwburl"; this.urlParameterKeyClassic = "geturl"; this.nwbDomain = getNwbDomain; // nwburl prüfen this.targetUrl = null; if (this.targetUrl == undefined || this.targetUrl == null || this.targetUrl.length == 0) { this.targetUrl = this.getUrlParameter(this.urlParameterKey); } if (this.targetUrl == undefined || this.targetUrl == null || this.targetUrl.length == 0) { // Wenn auch dort kein nwburl vorgegeben ist, schauen, ob der alte GetUrl einen classic Wert mitliefert var oldGetUrl = this.getUrlParameter(this.urlParameterKeyClassic); if (oldGetUrl != undefined && oldGetUrl != null && oldGetUrl.length > 0) { this.targetUrl = "/Delivery/Default/ClassicGetUrl/?id=" + id + "&geturl=" + oldGetUrl; } } if (this.targetUrl == undefined || this.targetUrl == null || this.targetUrl.length == 0) { // Wenn keine nwburl im gesamt-URL angebenen ist, schauen, den Parameter aus dem Javascript-Include-URL übernehmen this.targetUrl = nwburlVorgabe; } if (this.targetUrl == undefined || this.targetUrl == null || this.targetUrl.length == 0) { // Wenn gar nichts vorgegeben ist, auf den Standard-URL zurückfallen this.targetUrl = "/Delivery/Default/?id=" + id; } // Die Domain ermitteln, in welcher das Javascript eingebunden ist. // Den Inhalt vom nwburl holen und in das nwbdeliverytarget einsetzen this.ladeContent(this.targetUrl); } // Läd den Inhalt in das nwbdeliverytarget DIV Loader.prototype.ladeContent = function (nwbContentUrl) { jQuery(this.targetDivKey).html("

...Inhalt wird geladen...

"); var that = this; nwbContentUrl = this.nwbDomain + nwbContentUrl + "&domain=" + encodeURI(document.location.origin); jQuery.support.cors = true; jQuery.ajax({ url: nwbContentUrl, async: true, cache: false, type: "GET", //timeout: 1999, crossDomain: true, //xhrFields: { // withCredentials: true // führt zu weniger funktionieren //}, success: function (responseTxt, statusTxt, xhr) { var content; if (statusTxt == "success") { // Inhalt korrekt geladen content = responseTxt; } // Den Content in das Ziel-Div schreiben jQuery(that.targetDivKey).html(content); // Die Links aktivieren jQuery(".nwburllink").click(function (e) { var url = jQuery(this).data("nwburl"); window.location.href = that.updateQueryString(that.urlParameterKey, encodeURIComponent(url), window.location.href); e.preventDefault(); e.stopImmediatePropagation(); return false; }); }, error: function (request, type, errorThrown) { var message = "There was an error with the AJAX request.\n"; switch (type) { case 'timeout': message += "The request timed out."; break; //case 'notmodified': // message += "The request was not modified but was not retrieved from the cache."; // break; case 'parsererror': message += "XML/Json format is bad."; break; default: message += "HTTP Error (" + request.status + " " + request.statusText + ")."; } message += "\n"; // Fehler beim Laden des Inhalts var content = "

2 Fehler beim Laden des Inhalts '" + nwbContentUrl + "': " + errorThrown + ": " + message + "/" + errorThrown + "

"; // Den Content in das Ziel-Div schreiben jQuery(that.targetDivKey).html(content); } }); }; // Liefert den Inhalt eines URL Parameters Loader.prototype.getUrlParameter = function (name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)", "gi"), results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/gi, " ")); }; // setzt den Inhalt eines URL Parameters Loader.prototype.updateQueryString = function (key, value, url) { if (!url) url = window.location.href; var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"), hash; if (re.test(url)) { if (typeof value !== 'undefined' && value !== null) return url.replace(re, '$1' + key + "=" + value + '$2$3'); else { hash = url.split('#'); url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, ''); if (typeof hash[1] !== 'undefined' && hash[1] !== null) url += '#' + hash[1]; return url; } } else { if (typeof value !== 'undefined' && value !== null) { var separator = url.indexOf('?') !== -1 ? '&' : '?'; hash = url.split('#'); url = hash[0] + separator + key + '=' + value; if (typeof hash[1] !== 'undefined' && hash[1] !== null) url += '#' + hash[1]; return url; } else return url; } }; return Loader; }()); WebDelivery.Loader = Loader; })(WebDelivery || (WebDelivery = {})); //# sourceMappingURL=Loader.js.map var webDeliveryLoader; jQuery(document).ready(function () { webDeliveryLoader = new WebDelivery.Loader("2QZP4QVLDQ", "/Delivery/Content/NavigationNachThemen/2QZP4QVLDQ/?anzahl=20", "https://datenbank.nwb.de"); });