PageSourceSearch

https://raja.fi/o/frontend-js-web/liferay/liferay.js

js raja.fi collected 2026-10-02 03:35:49 UTC 6,011 bytes, 191 lines download raw bytes

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

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.