PageSourceSearch

https://www.waldenser.de/_assets/482fb0005a0a42f4ac859ee5c017f74b/JavaScript/ajax.js?1781537971

js waldenser.de collected 2026-10-02 20:40:59 UTC 5,316 bytes, 70 lines download raw bytes

1// ajax with promise
2
3var ajax = ajax || function(opts) {
4  opts.method = opts.method || 'GET';
5  opts.payload = opts.payload || null;
6  if (!opts.url) return false;
7
8  document.dispatchEvent(new CustomEvent('ajax-inprogress-start', {detail:opts,bubbles: true}));
9
10  return new Promise(function(resolve,reject){
11    var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
12    xhr.open(opts.method,opts.url,true);
13
14    xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
15    xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
16    xhr.onload = function () {
17      document.dispatchEvent(new CustomEvent('ajax-inprogress-end', {detail:'success',bubbles: true}));
18
19      if (this.status >= 200 && this.status < 300) {
20        resolve(xhr.response);
21      } else {
22        reject({
23          status: this.status,
24          statusText: xhr.statusText
25        });
26      }
27    };
28    xhr.onerror = function () {
29
30      document.dispatchEvent(new CustomEvent('ajax-inprogress-end', {detail:'error',bubbles: true}));
31
32      reject({
33        status: this.status,
34        statusText: xhr.statusText
35      });
36    };
37    if (opts.headers) {
38      Object.keys(opts.headers).forEach(function (key) {
39        xhr.setRequestHeader(key, opts.headers[key]);
40      });
41    }
42    var params = opts.payload;
43    // We'll need to stringify if we've been given an object
44    // If we have a string, this is skipped.
45    if (params && typeof params === 'object') {
46      params = Object.keys(params).map(function (key) {
47        return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
48      }).join('&');
49    }
50
51    xhr.send(params);
52  });
53};
54(function () {
55  if ( typeof window.CustomEvent === "function" ) return false;
56  function CustomEvent ( event, params ) {
57    params = params || { bubbles: false, cancelable: false, detail: undefined };
58    var evt = document.createEvent( 'CustomEvent' );
59    evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
60    return evt;
61  }
62  CustomEvent.prototype = window.Event.prototype;
63  window.CustomEvent = CustomEvent;
64})();
65// Promise shim
66
67
68!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n():"function"==typeof define&&define.amd?define(n):n()}(0,function(){"use strict";function e(e){var n=this.constructor;return this.then(function(t){return n.resolve(e()).then(function(){return t})},function(t){return n.resolve(e()).then(function(){return n.reject(t)})})}function n(){}function t(e){if(!(this instanceof t))throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=undefined,this._deferreds=[],u(e,this)}function o(e,n){for(;3===e._state;)e=e._value;0!==e._state?(e._handled=!0,t._immediateFn(function(){var t=1===e._state?n.onFulfilled:n.onRejected;if(null!==t){var o;try{o=t(e._value)}catch(f){return void i(n.promise,f)}r(n.promise,o)}else(1===e._state?r:i)(n.promise,e._value)})):e._deferreds.push(n)}function r(e,n){try{if(n===e)throw new TypeError("A promise cannot be resolved with itself.");if(n&&("object"==typeof n||"function"==typeof n)){var o=n.then;if(n instanceof t)return e._state=3,e._value=n,void f(e);if("function"==typeof o)return void u(function(e,n){return function(){e.apply(n,arguments)}}(o,n),e)}e._state=1,e._value=n,f(e)}catch(r){i(e,r)}}function i(e,n){e._state=2,e._value=n,f(e)}function f(e){2===e._state&&0===e._deferreds.length&&t._immediateFn(function(){e._handled||t._unhandledRejectionFn(e._value)});for(var n=0,r=e._deferreds.length;r>n;n++)o(e,e._deferreds[n]);e._deferreds=null}function u(e,n){var t=!1;try{e(function(e){t||(t=!0,r(n,e))},function(e){t||(t=!0,i(n,e))})}catch(o){if(t)return;t=!0,i(n,o)}}var c=setTimeout;t.prototype["catch"]=function(e){return this.then(null,e)},t.prototype.then=function(e,t){var r=new this.constructor(n);return o(this,new function(e,n,t){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof n?n:null,this.promise=t}(e,t,r)),r},t.prototype["finally"]=e,t.all=function(e){return new t(function(n,t){function o(e,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(n){o(e,n)},t)}r[e]=f,0==--i&&n(r)}catch(c){t(c)}}if(!e||"undefined"==typeof e.length)throw new TypeError("Promise.all accepts an array");var r=Array.prototype.slice.call(e);
68if(0===r.length)return n([]);for(var i=r.length,f=0;r.length>f;f++)o(f,r[f])})},t.resolve=function(e){return e&&"object"==typeof e&&e.constructor===t?e:new t(function(n){n(e)})},t.reject=function(e){return new t(function(n,t){t(e)})},t.race=function(e){return new t(function(n,t){for(var o=0,r=e.length;r>o;o++)e[o].then(n,t)})},t._immediateFn="function"==typeof setImmediate&&function(e){setImmediate(e)}||function(e){c(e,0)},t._unhandledRejectionFn=function(e){void 0!==console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};var l=function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw Error("unable to locate global object")}();"Promise"in l?l.Promise.prototype["finally"]||(l.Promise.prototype["finally"]=e):l.Promise=t});
69
70

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.