UNPKG

castelog

Version:

Programación JavaScript en castellano.

1,072 lines (981 loc) 1.38 MB
<!DOCTYPE html><html><head> <title>Diagrama de Gantt</title> <meta charset="utf8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <style> html { font-family: Arial; } * { box-sizing: border-box; } .visibility_hidden { visibility: hidden; } .DiagramaDeGantt { padding: 0px; border: 1px solid #333; } .tarea_box_container { } .tarea_box { margin: 2px; border: 0px solid #333; background-color: rgba(0,0,40,0.5); color: white; text-shadow: 0 0 1px white; font-size: 9px; min-height: 13px; } .tarea_title { display: table; width: 100%; padding: 5px; border-bottom: 0px solid #333; background-color: #333; color: white; min-height: 13px; text-align: left; padding-top: 0px; padding-bottom: 0px; } .tarea_title_text { display: table-cell; width: 100%; } .tarea_buttons { display: table-cell; width: 100%; white-space: nowrap; } .tarea_tiempos { display: table; width: 100%; } .tarea_inicio { display: table-cell; width: 50%; padding: 5px; border-bottom: 0px solid #333; background-color: rgba(60,110,200,0.5); min-height: 13px; } .tarea_final { display: table-cell; width: 50%; padding: 5px; border-bottom: 0px solid #333; background-color: rgba(20,30,90,0.5); color: yellow; text-shadow: 0 0 1px yellow; text-decoration: underline; min-height: 13px; } .tarea_agentes { display: block; padding: 5px; border-top: 1px solid #333; border-bottom: 1px solid #333; background-color: rgba(200,60,110,0.5); color: white; text-shadow: 0 0 1px white; min-height: 13px; } .tarea_tareas { display: block; padding: 0px; margin-top. 0px; margin-left: 0px; border-top: 1px solid #333; border-bottom: 1px solid #333; background-color: #FFF; color: black; text-shadow: 0 0 1px black; min-height: 13px; } .AgentesDeDiagramaDeGantt { font-size: 9px; } .AgentesDeDiagramaDeGantt .agentes_informacion { display: block; width: 100%; border-top: 0px solid #333; padding: 2px; padding-bottom: 0px; } .AgentesDeDiagramaDeGantt .agente_detalles { display: table; width: 100%; margin-bottom: 2px; background-color: #333; color: white; font-weight: bold; } .AgentesDeDiagramaDeGantt .agente_orden { display: table-cell; width: 1%; padding: 2px; padding-left: 5px; font-weight: bold; border-bottom: 0px solid #333; min-height: 13px; } .AgentesDeDiagramaDeGantt .agente_nombre { display: table-cell; width: 100%; padding: 2px; font-weight: bold; border: 1px solid #333; border-top: 0px solid #333; min-height: 13px; } .float_right { float: right; } .hide { display: none; } input[type=radio] { vertical-align: middle; } select, option, button { cursor: pointer; border-radius: 3pt; overflow: hidden; border: 1px solid #333; background-color: #CCC; padding: 2px; font-size: 9px; font-family: Arial; } select.control_input { font-size: 9px; } .panel_de_pestanyas { font-size: 9px; margin-top: 0px; overflow: hidden; } .panel_de_pestanyas > .grupo_de_pestanyas { display: table; width: 100%; margin-bottom: 0px; } .panel_de_pestanyas > .grupo_de_pestanyas > .pestanya { display: table-cell; width: 25%; padding: 2px; margin-right: 2px; margin-bottom: 2px; border: 1px solid #333; border-radius: 0pt; text-align: center; cursor: pointer; white-space: nowrap; } .panel_de_pestanyas > .grupo_de_pestanyas > .pestanya.seleccionada { background-color: black; color: white; } .panel_de_pestanyas > .grupo_de_paneles {} .panel_de_pestanyas > .grupo_de_paneles > .panel { display: none; padding: 0px; border: 1px solid #333; } .panel_de_pestanyas > .grupo_de_paneles > .panel.seleccionado { display: block; } .dialogos_estaticos_box { position: fixed; top: 0px; bottom: 0px; left: 0px; right: 0px; z-index: 9999; background-color: rgba(255,255,255,0.5); padding: 5px; } .dialogo_box_container { position: relative; width: 100%; height: 100%; } .dialogo_box { position: relative; width: 100%; height: 100%; border-radius: 2pt; } .dialogo_box_content { display: flex; flex-direction: column; height: 100%; } .dialogo_header { background-color: #333; color: white; text-align: left; font-size: 15px; padding: 5px; } .dialogo_body { flex-grow: 1; background-color: #DDD; color: black; font-size: 9px; padding: 10px; padding-top: 0px; min-height: 120px; overflow: scroll; } .dialogo_footer { background-color: #333; color: white; text-align: right; font-size: 9px; padding: 5px; } .control_item { padding-top: 1px; } .control_item > .control_label { margin-top: 2px; padding-top: 5px; border-top: 1px solid #BBB; font-weight: bold; text-decoration: underline; white-space: nowrap; padding-bottom: 2px; } .control_input { width: 100%; font-size: 12px; } .control_inline_select { display: table; width: 100%; } .control_inline_checkbox { display: inline-block; } .control_checkbox { display: inline-block; width: auto; } .control_checkbox > .control_label { cursor: pointer; } .control_checkbox > .control_label > .control_input { display: inline-block; width: auto; vertical-align: middle; } .control_inline_select > .control_label { display: table-cell; width: 1%; padding-right: 5px; vertical-align: middle; white-space: nowrap; } .control_inline_select > .control_input { display: table-cell; width: 100%; vertical-align: middle; } </style> </head><body><div id="app"></div><script> // [castelog:html5izable] ACTIVADO con: {"autor":"allnulled","nombre":"gantt-01","version":"0.0.1","contenido":{"head":"<head>\n <title>Diagrama de Gantt</title>\n <meta charset=\"utf8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <style>\n html {\n font-family: Arial;\n }\n * {\n box-sizing: border-box;\n }\n .visibility_hidden { visibility: hidden; }\n .DiagramaDeGantt {\n padding: 0px;\n border: 1px solid #333;\n }\n .tarea_box_container {\n }\n .tarea_box {\n margin: 2px;\n border: 0px solid #333;\n background-color: rgba(0,0,40,0.5);\n color: white;\n text-shadow: 0 0 1px white;\n font-size: 9px;\n min-height: 13px;\n }\n .tarea_title {\n display: table;\n width: 100%;\n padding: 5px;\n border-bottom: 0px solid #333;\n background-color: #333;\n color: white;\n min-height: 13px;\n text-align: left;\n padding-top: 0px;\n padding-bottom: 0px;\n }\n .tarea_title_text {\n display: table-cell;\n width: 100%;\n }\n .tarea_buttons {\n display: table-cell;\n width: 100%;\n white-space: nowrap;\n }\n .tarea_tiempos {\n display: table;\n width: 100%;\n }\n .tarea_inicio {\n display: table-cell;\n width: 50%;\n padding: 5px;\n border-bottom: 0px solid #333;\n background-color: rgba(60,110,200,0.5);\n min-height: 13px;\n }\n .tarea_final {\n display: table-cell;\n width: 50%;\n padding: 5px;\n border-bottom: 0px solid #333;\n background-color: rgba(20,30,90,0.5);\n color: yellow;\n text-shadow: 0 0 1px yellow;\n text-decoration: underline;\n min-height: 13px;\n }\n .tarea_agentes {\n display: block;\n padding: 5px;\n border-top: 1px solid #333;\n border-bottom: 1px solid #333;\n background-color: rgba(200,60,110,0.5);\n color: white;\n text-shadow: 0 0 1px white;\n min-height: 13px;\n }\n .tarea_tareas {\n display: block;\n padding: 0px;\n margin-top. 0px;\n margin-left: 0px;\n border-top: 1px solid #333;\n border-bottom: 1px solid #333;\n background-color: #FFF;\n color: black;\n text-shadow: 0 0 1px black;\n min-height: 13px;\n }\n .AgentesDeDiagramaDeGantt {\n font-size: 9px;\n }\n .AgentesDeDiagramaDeGantt .agentes_informacion {\n display: block;\n width: 100%;\n border-top: 0px solid #333;\n padding: 2px;\n padding-bottom: 0px;\n }\n .AgentesDeDiagramaDeGantt .agente_detalles {\n display: table;\n width: 100%;\n margin-bottom: 2px;\n background-color: #333;\n color: white;\n font-weight: bold;\n }\n .AgentesDeDiagramaDeGantt .agente_orden {\n display: table-cell;\n width: 1%;\n padding: 2px;\n padding-left: 5px;\n font-weight: bold;\n border-bottom: 0px solid #333;\n min-height: 13px;\n }\n .AgentesDeDiagramaDeGantt .agente_nombre {\n display: table-cell;\n width: 100%;\n padding: 2px;\n font-weight: bold;\n border: 1px solid #333;\n border-top: 0px solid #333;\n min-height: 13px;\n }\n .float_right { float: right; }\n .hide { display: none; }\n input[type=radio] {\n vertical-align: middle;\n }\n select,\n option,\n button {\n cursor: pointer;\n border-radius: 3pt;\n overflow: hidden;\n border: 1px solid #333;\n background-color: #CCC;\n padding: 2px;\n font-size: 9px;\n font-family: Arial;\n }\n select.control_input {\n font-size: 9px;\n }\n .panel_de_pestanyas {\n font-size: 9px;\n margin-top: 0px;\n overflow: hidden;\n }\n .panel_de_pestanyas > .grupo_de_pestanyas {\n display: table;\n width: 100%;\n margin-bottom: 0px;\n }\n .panel_de_pestanyas > .grupo_de_pestanyas > .pestanya {\n display: table-cell;\n width: 25%;\n padding: 2px;\n margin-right: 2px;\n margin-bottom: 2px;\n border: 1px solid #333;\n border-radius: 0pt;\n text-align: center;\n cursor: pointer;\n white-space: nowrap;\n }\n .panel_de_pestanyas > .grupo_de_pestanyas > .pestanya.seleccionada {\n background-color: black;\n color: white;\n }\n .panel_de_pestanyas > .grupo_de_paneles {}\n .panel_de_pestanyas > .grupo_de_paneles > .panel {\n display: none;\n padding: 0px;\n border: 1px solid #333;\n }\n .panel_de_pestanyas > .grupo_de_paneles > .panel.seleccionado {\n display: block;\n }\n .dialogos_estaticos_box {\n position: fixed;\n top: 0px;\n bottom: 0px;\n left: 0px;\n right: 0px;\n z-index: 9999;\n background-color: rgba(255,255,255,0.5);\n padding: 5px;\n }\n .dialogo_box_container {\n position: relative;\n width: 100%;\n height: 100%;\n }\n .dialogo_box {\n position: relative;\n width: 100%;\n height: 100%;\n border-radius: 2pt;\n }\n .dialogo_box_content {\n display: flex;\n flex-direction: column;\n height: 100%;\n }\n .dialogo_header {\n background-color: #333;\n color: white;\n text-align: left;\n font-size: 15px;\n padding: 5px;\n }\n .dialogo_body {\n flex-grow: 1;\n background-color: #DDD;\n color: black;\n font-size: 9px;\n padding: 10px;\n padding-top: 0px;\n min-height: 120px;\n overflow: scroll;\n }\n .dialogo_footer {\n background-color: #333;\n color: white;\n text-align: right;\n font-size: 9px;\n padding: 5px;\n }\n .control_item {\n padding-top: 1px;\n }\n .control_item > .control_label {\n margin-top: 2px;\n padding-top: 5px;\n border-top: 1px solid #BBB;\n font-weight: bold;\n text-decoration: underline;\n white-space: nowrap;\n padding-bottom: 2px;\n }\n .control_input {\n width: 100%;\n font-size: 12px;\n }\n .control_inline_select {\n display: table;\n width: 100%;\n }\n .control_inline_checkbox {\n display: inline-block;\n }\n .control_checkbox {\n display: inline-block;\n width: auto;\n }\n .control_checkbox > .control_label {\n cursor: pointer;\n }\n .control_checkbox > .control_label > .control_input {\n display: inline-block;\n width: auto;\n vertical-align: middle;\n }\n .control_inline_select > .control_label {\n display: table-cell;\n width: 1%;\n padding-right: 5px;\n vertical-align: middle;\n white-space: nowrap;\n }\n .control_inline_select > .control_input {\n display: table-cell;\n width: 100%;\n vertical-align: middle;\n }\n </style>\n</head>","body":"<body><div id=\"app\"></div></body>"}} //Included:lib/000.inicializacion.part.js // CASTELOG@0.0.1 /*************************************************************************************** ***[ Manifiesto de Castelog v.0.0.1 ]**********************************[ 2022/08 ]***** *************************************************************************************** *** *** *** Castelog es un software construido por «allnulled» o «Carlos Jimeno Hernández». *** *** *** *** No tiene licencia, haz lo que quieras con él. *** *** *** *************************************************[ Carlos J. / +34 619 98 26 22 ]****** ******************************************************************************[ ]****** ***************************************************[ Licencia gratis siempre ya ]****** ******************************************************************************[ ]****** ******************************************************************************[ ]******/ //////////////////////////////////////////////////////////////////////////////// // Aquí empieza el script de Castelog ////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> //Included:lib/001.01.xhr2-v.part.js /*lib:xhr2 v0.2.1 + modifications*/ // Generated by CoffeeScript 2.5.1 (function () { const is_nodejs_environment = (typeof global !== "undefined") && (typeof require !== "undefined"); if(!is_nodejs_environment) return; // This file's name is set up in such a way that it will always show up first in // the list of files given to coffee --join, so that the other files can assume // that XMLHttpRequestEventTarget was already defined. // The DOM EventTarget subclass used by XMLHttpRequest. // @see http://xhr.spec.whatwg.org/#interface-xmlhttprequest var InvalidStateError, NetworkError, ProgressEvent, SecurityError, SyntaxError, XMLHttpRequest, XMLHttpRequestEventTarget, XMLHttpRequestUpload, http, https, os, url; XMLHttpRequestEventTarget = (function () { class XMLHttpRequestEventTarget { // @private // This is an abstract class and should not be instantiated directly. constructor() { this.onloadstart = null; this.onprogress = null; this.onabort = null; this.onerror = null; this.onload = null; this.ontimeout = null; this.onloadend = null; this._listeners = {}; } // Adds a new-style listener for one of the XHR events. // @see http://www.w3.org/TR/XMLHttpRequest/#events // @param {String} eventType an XHR event type, such as 'readystatechange' // @param {function(ProgressEvent)} listener function that will be called when // the event fires // @return {undefined} undefined addEventListener(eventType, listener) { var base; eventType = eventType.toLowerCase(); (base = this._listeners)[eventType] || (base[eventType] = []); this._listeners[eventType].push(listener); return void 0; } // Removes an event listener added by calling addEventListener. // @param {String} eventType an XHR event type, such as 'readystatechange' // @param {function(ProgressEvent)} listener the value passed in a previous // call to addEventListener. // @return {undefined} undefined removeEventListener(eventType, listener) { var index; eventType = eventType.toLowerCase(); if (this._listeners[eventType]) { index = this._listeners[eventType].indexOf(listener); if (index !== -1) { this._listeners[eventType].splice(index, 1); } } return void 0; } // Calls all the listeners for an event. // @param {ProgressEvent} event the event to be dispatched // @return {undefined} undefined dispatchEvent(event) { var eventType, j, len, listener, listeners; event.currentTarget = event.target = this; eventType = event.type; if (listeners = this._listeners[eventType]) { for (j = 0, len = listeners.length; j < len; j++) { listener = listeners[j]; listener.call(this, event); } } if (listener = this[`on${eventType}`]) { listener.call(this, event); } return void 0; } }; // @property {function(ProgressEvent)} DOM level 0-style handler // for the 'loadstart' event XMLHttpRequestEventTarget.prototype.onloadstart = null; // @property {function(ProgressEvent)} DOM level 0-style handler // for the 'progress' event XMLHttpRequestEventTarget.prototype.onprogress = null; // @property {function(ProgressEvent)} DOM level 0-style handler // for the 'abort' event XMLHttpRequestEventTarget.prototype.onabort = null; // @property {function(ProgressEvent)} DOM level 0-style handler // for the 'error' event XMLHttpRequestEventTarget.prototype.onerror = null; // @property {function(ProgressEvent)} DOM level 0-style handler // for the 'load' event XMLHttpRequestEventTarget.prototype.onload = null; // @property {function(ProgressEvent)} DOM level 0-style handler // for the 'timeout' event XMLHttpRequestEventTarget.prototype.ontimeout = null; // @property {function(ProgressEvent)} DOM level 0-style handler // for the 'loadend' event XMLHttpRequestEventTarget.prototype.onloadend = null; return XMLHttpRequestEventTarget; }).call(this); // This file's name is set up in such a way that it will always show up second // in the list of files given to coffee --join, so it can use the // XMLHttpRequestEventTarget definition and so that the other files can assume // that XMLHttpRequest was already defined. http = require('http'); https = require('https'); os = require('os'); url = require('url'); XMLHttpRequest = (function () { // The ECMAScript HTTP API. // @see http://www.w3.org/TR/XMLHttpRequest/#introduction class XMLHttpRequest extends XMLHttpRequestEventTarget { // Creates a new request. // @param {Object} options one or more of the options below // @option options {Boolean} anon if true, the request's anonymous flag // will be set // @see http://www.w3.org/TR/XMLHttpRequest/#constructors // @see http://www.w3.org/TR/XMLHttpRequest/#anonymous-flag constructor(options) { super(); this.onreadystatechange = null; this._anonymous = options && options.anon; this.readyState = XMLHttpRequest.UNSENT; this.response = null; this.responseText = ''; this.responseType = ''; this.responseURL = ''; this.status = 0; this.statusText = ''; this.timeout = 0; this.upload = new XMLHttpRequestUpload(this); this._method = null; // String this._url = null; // Return value of url.parse() this._sync = false; this._headers = null; // Object<String, String> this._loweredHeaders = null; // Object<lowercase String, String> this._mimeOverride = null; this._request = null; // http.ClientRequest this._response = null; // http.ClientResponse this._responseParts = null; // Array<Buffer, String> this._responseHeaders = null; // Object<lowercase String, String> this._aborting = null; this._error = null; this._loadedBytes = 0; this._totalBytes = 0; this._lengthComputable = false; } // Sets the XHR's method, URL, synchronous flag, and authentication params. // @param {String} method the HTTP method to be used // @param {String} url the URL that the request will be made to // @param {?Boolean} async if false, the XHR should be processed // synchronously; true by default // @param {?String} user the user credential to be used in HTTP basic // authentication // @param {?String} password the password credential to be used in HTTP basic // authentication // @return {undefined} undefined // @throw {SecurityError} method is not one of the allowed methods // @throw {SyntaxError} urlString is not a valid URL // @throw {Error} the URL contains an unsupported protocol; the supported // protocols are file, http and https // @see http://www.w3.org/TR/XMLHttpRequest/#the-open()-method open(method, url, async, user, password) { var xhrUrl; method = method.toUpperCase(); if (method in this._restrictedMethods) { throw new SecurityError(`HTTP method ${method} is not allowed in XHR`); } xhrUrl = this._parseUrl(url); if (async === void 0) { async = true; } switch (this.readyState) { case XMLHttpRequest.UNSENT: case XMLHttpRequest.OPENED: case XMLHttpRequest.DONE: // Nothing to do here. null; break; case XMLHttpRequest.HEADERS_RECEIVED: case XMLHttpRequest.LOADING: // TODO(pwnall): terminate abort(), terminate send() null; } this._method = method; this._url = xhrUrl; this._sync = !async; this._headers = {}; this._loweredHeaders = {}; this._mimeOverride = null; this._setReadyState(XMLHttpRequest.OPENED); this._request = null; this._response = null; this.status = 0; this.statusText = ''; this._responseParts = []; this._responseHeaders = null; this._loadedBytes = 0; this._totalBytes = 0; this._lengthComputable = false; return void 0; } // Appends a header to the list of author request headers. // @param {String} name the HTTP header name // @param {String} value the HTTP header value // @return {undefined} undefined // @throw {InvalidStateError} readyState is not OPENED // @throw {SyntaxError} name is not a valid HTTP header name or value is not // a valid HTTP header value // @see http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader()-method setRequestHeader(name, value) { var loweredName; if (this.readyState !== XMLHttpRequest.OPENED) { throw new InvalidStateError("XHR readyState must be OPENED"); } loweredName = name.toLowerCase(); if (this._restrictedHeaders[loweredName] || /^sec\-/.test(loweredName) || /^proxy-/.test(loweredName)) { console.warn(`Refused to set unsafe header \"${name}\"`); return void 0; } value = value.toString(); if (loweredName in this._loweredHeaders) { // Combine value with the existing header value. name = this._loweredHeaders[loweredName]; this._headers[name] = this._headers[name] + ', ' + value; } else { // New header. this._loweredHeaders[loweredName] = name; this._headers[name] = value; } return void 0; } // Initiates the request. // @param {?String, ?ArrayBufferView} data the data to be sent; ignored for // GET and HEAD requests // @return {undefined} undefined // @throw {InvalidStateError} readyState is not OPENED // @see http://www.w3.org/TR/XMLHttpRequest/#the-send()-method send(data) { if (this.readyState !== XMLHttpRequest.OPENED) { throw new InvalidStateError("XHR readyState must be OPENED"); } if (this._request) { throw new InvalidStateError("send() already called"); } switch (this._url.protocol) { case 'file:': this._sendFile(data); break; case 'http:': case 'https:': this._sendHttp(data); break; default: throw new NetworkError(`Unsupported protocol ${this._url.protocol}`); } return void 0; } // Cancels the network activity performed by this request. // @return {undefined} undefined // @see http://www.w3.org/TR/XMLHttpRequest/#the-abort()-method abort() { if (!this._request) { return; } this._request.abort(); this._setError(); this._dispatchProgress('abort'); this._dispatchProgress('loadend'); return void 0; } // Returns a header value in the HTTP response for this XHR. // @param {String} name case-insensitive HTTP header name // @return {?String} value the value of the header whose name matches the // given name, or null if there is no such header // @see http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method getResponseHeader(name) { var loweredName; if (!this._responseHeaders) { return null; } loweredName = name.toLowerCase(); if (loweredName in this._responseHeaders) { return this._responseHeaders[loweredName]; } else { return null; } } // Returns all the HTTP headers in this XHR's response. // @return {String} header lines separated by CR LF, where each header line // has the name and value separated by a ": " (colon, space); the empty // string is returned if the headers are not available // @see http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders()-method getAllResponseHeaders() { var lines, name, value; if (!this._responseHeaders) { return ''; } lines = (function () { var ref, results; ref = this._responseHeaders; results = []; for (name in ref) { value = ref[name]; results.push(`${name}: ${value}`); } return results; }).call(this); return lines.join("\r\n"); } // Overrides the Content-Type // @return {undefined} undefined // @see http://www.w3.org/TR/XMLHttpRequest/#the-overridemimetype()-method overrideMimeType(newMimeType) { if (this.readyState === XMLHttpRequest.LOADING || this.readyState === XMLHttpRequest.DONE) { throw new InvalidStateError("overrideMimeType() not allowed in LOADING or DONE"); } this._mimeOverride = newMimeType.toLowerCase(); return void 0; } // Network configuration not exposed in the XHR API. // Although the XMLHttpRequest specification calls itself "ECMAScript HTTP", // it assumes that requests are always performed in the context of a browser // application, where some network parameters are set by the browser user and // should not be modified by Web applications. This API provides access to // these network parameters. // NOTE: this is not in the XMLHttpRequest API, and will not work in // browsers. It is a stable node-xhr2 API. // @param {Object} options one or more of the options below // @option options {?http.Agent} httpAgent the value for the nodejsHttpAgent // property (the agent used for HTTP requests) // @option options {?https.Agent} httpsAgent the value for the // nodejsHttpsAgent property (the agent used for HTTPS requests) // @return {undefined} undefined nodejsSet(options) { var baseUrl, parsedUrl; if ('httpAgent' in options) { this.nodejsHttpAgent = options.httpAgent; } if ('httpsAgent' in options) { this.nodejsHttpsAgent = options.httpsAgent; } if ('baseUrl' in options) { baseUrl = options.baseUrl; if (baseUrl !== null) { parsedUrl = url.parse(baseUrl, false, true); if (!parsedUrl.protocol) { throw new SyntaxError("baseUrl must be an absolute URL"); } } this.nodejsBaseUrl = baseUrl; } return void 0; } // Default settings for the network configuration not exposed in the XHR API. // NOTE: this is not in the XMLHttpRequest API, and will not work in // browsers. It is a stable node-xhr2 API. // @param {Object} options one or more of the options below // @option options {?http.Agent} httpAgent the default value for the // nodejsHttpAgent property (the agent used for HTTP requests) // @option options {https.Agent} httpsAgent the default value for the // nodejsHttpsAgent property (the agent used for HTTPS requests) // @return {undefined} undefined // @see XMLHttpRequest.nodejsSet static nodejsSet(options) { // "this" will be set to XMLHttpRequest.prototype, so the instance nodejsSet // operates on default property values. XMLHttpRequest.prototype.nodejsSet(options); return void 0; } // Sets the readyState property and fires the readystatechange event. // @private // @param {Number} newReadyState the new value of readyState // @return {undefined} undefined _setReadyState(newReadyState) { var event; this.readyState = newReadyState; event = new ProgressEvent('readystatechange'); this.dispatchEvent(event); return void 0; } // XMLHttpRequest#send() implementation for the file: protocol. // @private _sendFile() { if (this._url.method !== 'GET') { throw new NetworkError('The file protocol only supports GET'); } throw new Error("Protocol file: not implemented"); } // XMLHttpRequest#send() implementation for the http: and https: protocols. // @private // This method sets the instance variables and calls _sendHxxpRequest(), which // is responsible for building a node.js request and firing it off. The code // in _sendHxxpRequest() is separated off so it can be reused when handling // redirects. // @see http://www.w3.org/TR/XMLHttpRequest/#infrastructure-for-the-send()-method _sendHttp(data) { if (this._sync) { throw new Error("Synchronous XHR processing not implemented"); } if ((data != null) && (this._method === 'GET' || this._method === 'HEAD')) { console.warn(`Discarding entity body for ${this._method} requests`); data = null; } else { // Send Content-Length: 0 data || (data = ''); } // NOTE: this is called before finalizeHeaders so that the uploader can // figure out Content-Length and Content-Type. this.upload._setData(data); this._finalizeHeaders(); this._sendHxxpRequest(); return void 0; } // Sets up and fires off a HTTP/HTTPS request using the node.js API. // @private // This method contains the bulk of the XMLHttpRequest#send() implementation, // and is also used to issue new HTTP requests when handling HTTP redirects. // @see http://www.w3.org/TR/XMLHttpRequest/#infrastructure-for-the-send()-method _sendHxxpRequest() { var agent, hxxp, request; if (this._url.protocol === 'http:') { hxxp = http; agent = this.nodejsHttpAgent; } else { hxxp = https; agent = this.nodejsHttpsAgent; } request = hxxp.request({ hostname: this._url.hostname, port: this._url.port, path: this._url.path, auth: this._url.auth, method: this._method, headers: this._headers, agent: agent }); this._request = request; if (this.timeout) { request.setTimeout(this.timeout, () => { return this._onHttpTimeout(request); }); } request.on('response', (response) => { return this._onHttpResponse(request, response); }); request.on('error', (error) => { return this._onHttpRequestError(request, error); }); this.upload._startUpload(request); if (this._request === request) { // An http error might have already fired. this._dispatchProgress('loadstart'); } return void 0; } // Fills in the restricted HTTP headers with default values. // This is called right before the HTTP request is sent off. // @private // @return {undefined} undefined _finalizeHeaders() { var base; this._headers['Connection'] = 'keep-alive'; this._headers['Host'] = this._url.host; if (this._anonymous) { this._headers['Referer'] = 'about:blank'; } (base = this._headers)['User-Agent'] || (base['User-Agent'] = this._userAgent); this.upload._finalizeHeaders(this._headers, this._loweredHeaders); return void 0; } // Called when the headers of an HTTP response have been received. // @private // @param {http.ClientRequest} request the node.js ClientRequest instance that // produced this response // @param {http.ClientResponse} response the node.js ClientResponse instance // passed to _onHttpResponse(request, response) { var lengthString; if (this._request !== request) { return; } // Transparent redirection handling. switch (response.statusCode) { case 301: case 302: case 303: case 307: case 308: this._url = this._parseUrl(response.headers['location']); this._method = 'GET'; if ('content-type' in this._loweredHeaders) { delete this._headers[this._loweredHeaders['content-type']]; delete this._loweredHeaders['content-type']; } // XMLHttpRequestUpload#_finalizeHeaders() sets Content-Type directly. if ('Content-Type' in this._headers) { delete this._headers['Content-Type']; } // Restricted headers can't be set by the user, no need to check // loweredHeaders. delete this._headers['Content-Length']; this.upload._reset(); this._finalizeHeaders(); this._sendHxxpRequest(); return; } this._response = response; this._response.on('data', (data) => { return this._onHttpResponseData(response, data); }); this._response.on('end', () => { return this._onHttpResponseEnd(response); }); this._response.on('close', () => { return this._onHttpResponseClose(response); }); this.responseURL = this._url.href.split('#')[0]; this.status = this._response.statusCode; this.statusText = http.STATUS_CODES[this.status]; this._parseResponseHeaders(response); if (lengthString = this._responseHeaders['content-length']) { this._totalBytes = parseInt(lengthString); this._lengthComputable = true; } else { this._lengthComputable = false; } return this._setReadyState(XMLHttpRequest.HEADERS_RECEIVED); } // Called when some data has been received on a HTTP connection. // @private // @param {http.ClientResponse} response the node.js ClientResponse instance // that fired this event // @param {String, Buffer} data the data that has been received _onHttpResponseData(response, data) { if (this._response !== response) { return; } this._responseParts.push(data); this._loadedBytes += data.length; if (this.readyState !== XMLHttpRequest.LOADING) { this._setReadyState(XMLHttpRequest.LOADING); } return this._dispatchProgress('progress'); } // Called when the HTTP request finished processing. // @private // @param {http.ClientResponse} response the node.js ClientResponse instance // that fired this event _onHttpResponseEnd(response) { if (this._response !== response) { return; } this._parseResponse(); this._request = null; this._response = null; this._setReadyState(XMLHttpRequest.DONE); this._dispatchProgress('load'); return this._dispatchProgress('loadend'); } // Called when the underlying HTTP connection was closed prematurely. // If this method is called, it will be called after or instead of // onHttpResponseEnd. // @private // @param {http.ClientResponse} response the node.js ClientResponse instance // that fired this event _onHttpResponseClose(response) { var request; if (this._response !== response) { return; } request = this._request; this._setError(); request.abort(); this._setReadyState(XMLHttpRequest.DONE); this._dispatchProgress('error'); return this._dispatchProgress('loadend'); } // Called when the timeout set on the HTTP socket expires. // @private // @param {http.ClientRequest} request the node.js ClientRequest instance that // fired this event _onHttpTimeout(request) { if (this._request !== request) { return; } this._setError(); request.abort(); this._setReadyState(XMLHttpRequest.DONE); this._dispatchProgress('timeout'); return this._dispatchProgress('loadend'); } // Called when something wrong happens on the HTTP socket // @private // @param {http.ClientRequest} request the node.js ClientRequest instance that // fired this event // @param {Error} error emitted exception _onHttpRequestError(request, error) { if (this._request !== request) { return; } this._setError(); request.abort(); this._setReadyState(XMLHttpRequest.DONE); this._dispatchProgress('error'); return this._dispatchProgress('loadend'); } // Fires an XHR progress event. // @private // @param {String} eventType one of the XHR progress event types, such as // 'load' and 'progress' _dispatchProgress(eventType) { var event; event = new ProgressEvent(eventType); event.lengthComputable = this._lengthComputable; event.loaded = this._loadedBytes; event.total = this._totalBytes; this.dispatchEvent(event); return void 0; } // Sets up the XHR to reflect the fact that an error has occurred. // The possible errors are a network error, a timeout, or an abort. // @private _setError() { this._request = null; this._response = null; this._responseHeaders = null; this._responseParts = null; return void 0; } // Parses a request URL string. // @private // This method is a thin wrapper around url.parse() that normalizes HTTP // user/password credentials. It is used to parse the URL string passed to // XMLHttpRequest#open() and the URLs in the Location headers of HTTP redirect // responses. // @param {String} urlString the URL to be parsed // @return {Object} parsed URL _parseUrl(urlString) { var absoluteUrlString, index, password, user, xhrUrl; if (this.nodejsBaseUrl === null) { absoluteUrlString = urlString; } else { absoluteUrlString = url.resolve(this.nodejsBaseUrl, urlString); } xhrUrl = url.parse(absoluteUrlString, false, true); xhrUrl.hash = null; if (xhrUrl.auth && ((typeof user !== "undefined" && user !== null) || (typeof password !== "undefined" && password !== null))) { index = xhrUrl.auth.indexOf(':'); if (index === -1) { if (!user) { user = xhrUrl.auth; } } else { if (!user) { user = xhrUrl.substring(0, index); } if (!password) { password = xhrUrl.substring(index + 1); } } } if (user || password) { xhrUrl.auth = `${user}:${password}`; } return xhrUrl; } // Reads the headers from a node.js ClientResponse instance. // @private // @param {http.ClientResponse} response the response whose headers will be // imported into this XMLHttpRequest's state // @return {undefined} undefined // @see http://www.w3.org/TR/XMLHttpRequest/#the-getresponseheader()-method // @see http://www.w3.org/TR/XMLHttpRequest/#the-getallresponseheaders()-method _parseResponseHeaders(response) { var loweredName, name, ref, value; this._responseHeaders = {}; ref = response.headers; for (name in ref) { value = ref[name]; loweredName = name.toLowerCase(); if (this._privateHeaders[loweredName]) {