@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
157 lines (154 loc) • 5.03 kB
JavaScript
/**
* @package @bitrix24/b24jssdk
* @version 1.0.1
* @copyright (c) 2026 Bitrix24
* @license MIT
* @see https://github.com/bitrix24/b24jssdk
* @see https://bitrix24.github.io/b24jssdk/
*/
import { MessageCommands } from './message/commands.mjs';
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
class SliderManager {
static {
__name(this, "SliderManager");
}
#appFrame;
#messageManager;
constructor(appFrame, messageManager) {
this.#appFrame = appFrame;
this.#messageManager = messageManager;
}
/**
* Returns the URL relative to the domain name and path
*/
getUrl(path = "/") {
return new URL(path, this.#appFrame.getTargetOrigin());
}
/**
* Get the account address BX24
*/
getTargetOrigin() {
return this.#appFrame.getTargetOrigin();
}
/**
* When the method is called, a pop-up window with the application frame will be opened.
*
* @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/additional-functions/bx24-open-application.html
*/
async openSliderAppPage(params = {}) {
return this.#messageManager.send(MessageCommands.openApplication, params);
}
/**
* The method closes the open modal window with the application
*
* @return {Promise<void>}
*
* @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/additional-functions/bx24-close-application.html
*/
async closeSliderAppPage() {
return this.#messageManager.send(MessageCommands.closeApplication, {
/**
* @memo There is no point - everything will be closed, and timeout will not be able to do anything
*/
isSafely: false
});
}
/**
* Defines the base path for width sampling.
*
* @param width
* @private
*/
#getBaseUrlByWidth(width = 1640) {
if (width > 0) {
if (width > 1200 && width <= 1640) {
return "/crm/type/0/details/0/../../../../..";
} else if (width > 950 && width <= 1200) {
return "/company/personal/user/0/groups/create/../../../../../..";
} else if (width > 900 && width <= 950) {
return "/crm/company/requisite/0/../../../..";
} else if (width <= 900) {
return "/workgroups/group/0/card/../../../..";
} else {
return "/crm/deal/../..";
}
} else {
return "/crm/deal/../..";
}
}
/**
* Opens the specified path inside the portal in the slider.
* @param {URL} url
* @param {number} width - Number in the range from 1640 to 1200, from 1200 to 950, from 950 to 900, from 900 ...
* @return {Promise<StatusClose>}
*
* @link https://apidocs.bitrix24.com/sdk/bx24-js-sdk/additional-functions/bx24-open-path.html
* @memo /^\/(crm\/(deal|lead|contact|company|type)|marketplace|company\/personal\/user\/[0-9]+|workgroups\/group\/[0-9]+)\//
*/
async openPath(url, width = 1640) {
const openSliderUrl = new URL(url);
openSliderUrl.searchParams.set("IFRAME", "Y");
openSliderUrl.searchParams.set("IFRAME_TYPE", "SIDE_SLIDER");
return this.#messageManager.send(MessageCommands.openPath, {
path: [
this.#getBaseUrlByWidth(width),
openSliderUrl.pathname,
openSliderUrl.search
].join("")
}).then((response) => {
if (response?.result === "error") {
if (response?.errorCode === "METHOD_NOT_SUPPORTED_ON_DEVICE") {
return new Promise((resolve, reject) => {
const windowObjectReference = window.open(url, "_blank");
if (!windowObjectReference) {
reject(new Error("Error open window"));
return;
}
let iterator = 0;
const iteratorMax = 1e3 * 60 * 5;
const waitCloseWindow = window.setInterval(() => {
iterator = iterator + 1;
if (windowObjectReference.closed) {
clearInterval(waitCloseWindow);
resolve({
isOpenAtNewWindow: true,
isClose: true
});
} else if (iterator > iteratorMax) {
clearInterval(waitCloseWindow);
resolve({
isOpenAtNewWindow: true,
isClose: false
});
}
}, 1e3);
});
} else {
return Promise.reject(new Error(response?.errorCode));
}
} else if (response?.result === "close") {
return Promise.resolve({
isOpenAtNewWindow: false,
isClose: true
});
}
return Promise.resolve({
isOpenAtNewWindow: false,
isClose: false
});
});
}
/**
* @todo test this and remove
*/
// async showAppForm(params: any): Promise<void> {
// console.warn(`deprecated showAppForm`)
// return this.#messageManager.send(MessageCommands.showAppForm, {
// params: params,
// isSafely: true
// })
// }
}
export { SliderManager };
//# sourceMappingURL=slider.mjs.map