PageSourceSearch

https://web.girona.cat/o/frontend-js-web/liferay/liferay.js

js girona.cat collected 2026-10-01 10:38:19 UTC 5,424 bytes, 227 lines download raw bytes

1/**
2 * SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
3 * SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
4 */
5
6Liferay = window.Liferay || {};
7
8(function () {
9	const isFunction = function (val) {
10		return typeof val === 'function';
11	};
12
13	const isNode = function (node) {
14		return node && (node._node || node.jquery || node.nodeType);
15	};
16
17	const REGEX_METHOD_GET = /^get$/i;
18
19	const STR_MULTIPART = 'multipart/form-data';
20
21	Liferay.namespace = function namespace(object, path) {
22		if (path === undefined) {
23			path = object;
24
25			object = this;
26		}
27
28		const parts = path.split('.');
29
30		for (let part; parts.length && (part = parts.shift()); ) {
31			if (object[part] && object[part] !== Object.prototype[part]) {
32				object = object[part];
33			}
34			else {
35				object = object[part] = {};
36			}
37		}
38
39		return object;
40	};
41
42	/**
43	 * OPTIONS
44	 *
45	 * Required
46	 * service {string|object}: Either the service name, or an object with the keys as the service to call, and the value as the service configuration object.
47	 *
48	 * Optional
49	 * data {object|node|string}: The data to send to the service. If the object passed is the ID of a form or a form element, the form fields will be serialized and used as the data.
50	 * successCallback {function}: A function to execute when the server returns a response. It receives a JSON object as it's first parameter.
51	 * exceptionCallback {function}: A function to execute when the response from the server contains a service exception. It receives a the exception message as it's first parameter.
52	 */
53
54	const Service = function () {
55		const args = Service.parseInvokeArgs(
56			Array.prototype.slice.call(arguments, 0)
57		);
58
59		return Service.invoke.apply(Service, args);
60	};
61
62	Service.URL_INVOKE = themeDisplay.getPathContext() + '/api/jsonws/invoke';
63
64	Service.bind = function () {
65		const args = Array.prototype.slice.call(arguments, 0);
66
67		return function () {
68			const newArgs = Array.prototype.slice.call(arguments, 0);
69
70			return Service.apply(Service, args.concat(newArgs));
71		};
72	};
73
74	Service.parseInvokeArgs = function (args) {
75		const instance = this;
76
77		let payload = args[0];
78
79		const ioConfig = instance.parseIOConfig(args);
80
81		if (typeof payload === 'string') {
82			payload = instance.parseStringPayload(args);
83
84			instance.parseIOFormConfig(ioConfig, args);
85
86			const lastArg = args[args.length - 1];
87
88			if (typeof lastArg === 'object' && lastArg.method) {
89				ioConfig.method = lastArg.method;
90			}
91		}
92
93		return [payload, ioConfig];
94	};
95
96	Service.parseIOConfig = function (args) {
97		const payload = args[0];
98
99		const ioConfig = payload.io || {};
100
101		delete payload.io;
102
103		if (!ioConfig.success) {
104			const callbacks = args.filter(isFunction);
105
106			let callbackException = callbacks[1];
107			const callbackSuccess = callbacks[0];
108
109			if (!callbackException) {
110				callbackException = callbackSuccess;
111			}
112
113			ioConfig.error = callbackException;
114
115			ioConfig.complete = function (response) {
116				if (
117					!Object.prototype.hasOwnProperty.call(response, 'exception')
118				) {
119					if (callbackSuccess) {
120						callbackSuccess.call(this, response);
121					}
122				}
123				else if (callbackException) {
124					const exception = response
125						? response.exception
126						: 'The server returned an empty response';
127
128					callbackException.call(this, exception, response);
129				}
130			};
131		}
132
133		if (
134			!Object.prototype.hasOwnProperty.call(ioConfig, 'cache') &&
135			REGEX_METHOD_GET.test(ioConfig.type)
136		) {
137			ioConfig.cache = false;
138		}
139
140		return ioConfig;
141	};
142
143	Service.parseIOFormConfig = function (ioConfig, args) {
144		const form = args[1];
145
146		if (isNode(form)) {
147			if (form.enctype === STR_MULTIPART) {
148				ioConfig.contentType = 'multipart/form-data';
149			}
150
151			ioConfig.formData = new FormData(form);
152		}
153	};
154
155	Service.parseStringPayload = function (args) {
156		let params = {};
157		const payload = {};
158
159		const config = args[1];
160
161		if (!isFunction(config) && !isNode(config)) {
162			params = config;
163		}
164
165		payload[args[0]] = params;
166
167		return payload;
168	};
169
170	Service.invoke = function (payload, ioConfig) {
171		const instance = this;
172
173		const cmd = JSON.stringify(payload);
174
175		let data = cmd;
176
177		if (ioConfig.formData) {
178			ioConfig.formData.append('cmd', cmd);
179			data = ioConfig.formData;
180		}
181
182		return Liferay.Util.fetch(instance.URL_INVOKE, {
183			body: data,
184			headers: {
185				contentType: ioConfig.contentType,
186			},
187			method: 'POST',
188		})
189			.then((response) =>
190				Promise.all([Promise.resolve(response), response.json()])
191			)
192			.then(([response, content]) => {
193				if (response.ok) {
194					ioConfig.complete(content);
195				}
196				else {
197					ioConfig.error();
198				}
199			})
200			.catch(ioConfig.error);
201	};
202
203	function getHttpMethodFunction(httpMethodName) {
204		return function () {
205			const args = Array.prototype.slice.call(arguments, 0);
206
207			const method = {method: httpMethodName};
208
209			args.push(method);
210
211			return Service.apply(Service, args);
212		};
213	}
214
215	Service.get = getHttpMethodFunction('get');
216	Service.del = getHttpMethodFunction('delete');
217	Service.post = getHttpMethodFunction('post');
218	Service.put = getHttpMethodFunction('put');
219	Service.update = getHttpMethodFunction('update');
220
221	Liferay.Service = Service;
222
223	Liferay.Template = {
224		PORTLET:
225			'<div class="portlet"><div class="portlet-topper"><div class="portlet-title"></div></div><div class="portlet-content"></div><div class="forbidden-action"></div></div>',
226	};
227})();

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.