/** * ext-server_opensave.js * * @license MIT * * @copyright 2010 Alexis Deveria * */ import {canvg} from '../canvg/canvg.js'; export default { name: 'server_opensave', async init ({$, decode64, encode64, importLocale}) { const strings = await importLocale(); const svgEditor = this; const { curConfig: { extPath, avoidClientSide, // Deprecated avoidClientSideDownload, avoidClientSideOpen }, canvas: svgCanvas } = svgEditor; /** * * @returns {string} */ function getFileNameFromTitle () { const title = svgCanvas.getDocumentTitle(); // We convert (to underscore) only those disallowed Win7 file name characters return title.trim().replace(/[/\\:*?"<>|]/g, '_'); } /** * Escapes XML predefined entities for quoted attributes. * @param {string} str * @returns {string} */ function xhtmlEscape (str) { return str.replace(/&(?!amp;)/g, '&').replace(/"/g, '"').replace(/')[0].download === ''; let a; if (support) { a = $('hidden').attr({ download: (filename || 'image') + suffix, href: uri }).css('display', 'none').appendTo('body'); a[0].click(); return true; } return false; } const saveSvgAction = extPath + 'filesave.php', saveImgAction = extPath + 'filesave.php'; // Create upload target (hidden iframe) let cancelled = false; // Hiding by size instead of display to avoid FF console errors // with `getBBox` in browser.js `supportsPathBBox_`) $( `` ).appendTo('body'); svgEditor.setCustomHandlers({ save (win, data) { const svg = '\n' + data, // Firefox doesn't seem to know it is UTF-8 (no matter whether we use or skip the clientDownload code) despite the Content-Disposition header containing UTF-8, but adding the encoding works filename = getFileNameFromTitle(); if (clientDownloadSupport(filename, '.svg', 'data:image/svg+xml;charset=UTF-8;base64,' + encode64(svg))) { return; } $('