mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
ESLINT: Addressed remaining detected issues
This commit is contained in:
@ -3,50 +3,8 @@ let lastApprovedOrigin;
|
||||
let onInit; let
|
||||
onSave;
|
||||
|
||||
/**
|
||||
* Show the draw.io editor.
|
||||
* @param {String} drawioUrl
|
||||
* @param {Function} onInitCallback - Must return a promise with the xml to load for the editor.
|
||||
* @param {Function} onSaveCallback - Is called with the drawing data on save.
|
||||
*/
|
||||
function show(drawioUrl, onInitCallback, onSaveCallback) {
|
||||
onInit = onInitCallback;
|
||||
onSave = onSaveCallback;
|
||||
|
||||
iFrame = document.createElement('iframe');
|
||||
iFrame.setAttribute('frameborder', '0');
|
||||
window.addEventListener('message', drawReceive);
|
||||
iFrame.setAttribute('src', drawioUrl);
|
||||
iFrame.setAttribute('class', 'fullscreen');
|
||||
iFrame.style.backgroundColor = '#FFFFFF';
|
||||
document.body.appendChild(iFrame);
|
||||
lastApprovedOrigin = (new URL(drawioUrl)).origin;
|
||||
}
|
||||
|
||||
function close() {
|
||||
drawEventClose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Receive and handle a message event from the draw.io window.
|
||||
* @param {MessageEvent} event
|
||||
*/
|
||||
function drawReceive(event) {
|
||||
if (!event.data || event.data.length < 1) return;
|
||||
if (event.origin !== lastApprovedOrigin) return;
|
||||
|
||||
const message = JSON.parse(event.data);
|
||||
if (message.event === 'init') {
|
||||
drawEventInit();
|
||||
} else if (message.event === 'exit') {
|
||||
drawEventClose();
|
||||
} else if (message.event === 'save') {
|
||||
drawEventSave(message);
|
||||
} else if (message.event === 'export') {
|
||||
drawEventExport(message);
|
||||
} else if (message.event === 'configure') {
|
||||
drawEventConfigure();
|
||||
}
|
||||
function drawPostMessage(data) {
|
||||
iFrame.contentWindow.postMessage(JSON.stringify(data), lastApprovedOrigin);
|
||||
}
|
||||
|
||||
function drawEventExport(message) {
|
||||
@ -75,15 +33,54 @@ function drawEventConfigure() {
|
||||
}
|
||||
|
||||
function drawEventClose() {
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
window.removeEventListener('message', drawReceive);
|
||||
if (iFrame) document.body.removeChild(iFrame);
|
||||
}
|
||||
|
||||
function drawPostMessage(data) {
|
||||
iFrame.contentWindow.postMessage(JSON.stringify(data), lastApprovedOrigin);
|
||||
/**
|
||||
* Receive and handle a message event from the draw.io window.
|
||||
* @param {MessageEvent} event
|
||||
*/
|
||||
function drawReceive(event) {
|
||||
if (!event.data || event.data.length < 1) return;
|
||||
if (event.origin !== lastApprovedOrigin) return;
|
||||
|
||||
const message = JSON.parse(event.data);
|
||||
if (message.event === 'init') {
|
||||
drawEventInit();
|
||||
} else if (message.event === 'exit') {
|
||||
drawEventClose();
|
||||
} else if (message.event === 'save') {
|
||||
drawEventSave(message);
|
||||
} else if (message.event === 'export') {
|
||||
drawEventExport(message);
|
||||
} else if (message.event === 'configure') {
|
||||
drawEventConfigure();
|
||||
}
|
||||
}
|
||||
|
||||
async function upload(imageData, pageUploadedToId) {
|
||||
/**
|
||||
* Show the draw.io editor.
|
||||
* @param {String} drawioUrl
|
||||
* @param {Function} onInitCallback - Must return a promise with the xml to load for the editor.
|
||||
* @param {Function} onSaveCallback - Is called with the drawing data on save.
|
||||
*/
|
||||
export function show(drawioUrl, onInitCallback, onSaveCallback) {
|
||||
onInit = onInitCallback;
|
||||
onSave = onSaveCallback;
|
||||
|
||||
iFrame = document.createElement('iframe');
|
||||
iFrame.setAttribute('frameborder', '0');
|
||||
window.addEventListener('message', drawReceive);
|
||||
iFrame.setAttribute('src', drawioUrl);
|
||||
iFrame.setAttribute('class', 'fullscreen');
|
||||
iFrame.style.backgroundColor = '#FFFFFF';
|
||||
document.body.appendChild(iFrame);
|
||||
lastApprovedOrigin = (new URL(drawioUrl)).origin;
|
||||
}
|
||||
|
||||
export async function upload(imageData, pageUploadedToId) {
|
||||
const data = {
|
||||
image: imageData,
|
||||
uploaded_to: pageUploadedToId,
|
||||
@ -92,12 +89,16 @@ async function upload(imageData, pageUploadedToId) {
|
||||
return resp.data;
|
||||
}
|
||||
|
||||
export function close() {
|
||||
drawEventClose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load an existing image, by fetching it as Base64 from the system.
|
||||
* @param drawingId
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async function load(drawingId) {
|
||||
export async function load(drawingId) {
|
||||
try {
|
||||
const resp = await window.$http.get(window.baseUrl(`/images/drawio/base64/${drawingId}`));
|
||||
return `data:image/png;base64,${resp.data.content}`;
|
||||
@ -109,7 +110,3 @@ async function load(drawingId) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
show, close, upload, load,
|
||||
};
|
||||
|
Reference in New Issue
Block a user