- Refactoring: Switch from `$.param.querystring` to `URL`

master
Brett Zamir 2020-01-05 09:52:34 +08:00
parent 37424278d1
commit 56197a493c
3 changed files with 14 additions and 14 deletions

View File

@ -22,7 +22,8 @@
- Fix: Redirect paths for imagelib redirect checks - Fix: Redirect paths for imagelib redirect checks
- Optimization: Remove unused `jquery-ui-1.8.custom.min.js` file - Optimization: Remove unused `jquery-ui-1.8.custom.min.js` file
- Localization: Add 'SVG-Edit Home Page' to locale files - Localization: Add 'SVG-Edit Home Page' to locale files
- Refactoring: Ensure file-global tags are at beginning of file - Refactoring: Switch from `$.param.querystring` to `URL`
- Refactoring: Ensure file-global jsdoc tags are at beginning of file
- Linting (ESLint): Simplify regexes - Linting (ESLint): Simplify regexes
- Linting (ESLint): Replace `innerHTML` with `textContent` from old demo - Linting (ESLint): Replace `innerHTML` with `textContent` from old demo
- Linting (ESLint): Update as per latest ash-nazg - Linting (ESLint): Update as per latest ash-nazg

View File

@ -28,8 +28,8 @@ export default {
svgEditor.setCustomHandlers({ svgEditor.setCustomHandlers({
async save (win, data) { async save (win, data) {
const svg = '<?xml version="1.0"?>\n' + data; const svg = '<?xml version="1.0"?>\n' + data;
const qstr = $.param.querystring(); const {pathname} = new URL(location);
const [, name] = qstr.substr(9).split('/+get/'); const name = pathname.replace(/\/+get\//, '');
const svgData = encode64(svg); const svgData = encode64(svg);
if (!$('#export_canvas').length) { if (!$('#export_canvas').length) {
$('<canvas>', {id: 'export_canvas'}).hide().appendTo('body'); $('<canvas>', {id: 'export_canvas'}).hide().appendTo('body');

View File

@ -726,7 +726,6 @@ editor.init = function () {
} }
(() => { (() => {
// Load config/data from URL if given // Load config/data from URL if given
let src, qstr;
urldata = $.deparam.querystring(true); urldata = $.deparam.querystring(true);
if (!$.isEmptyObject(urldata)) { if (!$.isEmptyObject(urldata)) {
if (urldata.dimensions) { if (urldata.dimensions) {
@ -759,19 +758,19 @@ editor.init = function () {
setupCurConfig(); setupCurConfig();
if (!curConfig.preventURLContentLoading) { if (!curConfig.preventURLContentLoading) {
src = urldata.source; let {source} = urldata;
qstr = $.param.querystring(); if (!source) { // urldata.source may have been null if it ended with '='
if (!src) { // urldata.source may have been null if it ended with '=' const {searchParams} = new URL(location);
if (qstr.includes('source=data:')) { const src = searchParams.get('source');
src = qstr.match(/source=(data:[^&]*)/)[1]; if (src.startsWith('data:')) {
// ({src} = qstr.match(/source=(?<src>data:[^&]*)/).groups); source = src;
} }
} }
if (src) { if (source) {
if (src.startsWith('data:')) { if (source.startsWith('data:')) {
editor.loadFromDataURI(src); editor.loadFromDataURI(source);
} else { } else {
editor.loadFromString(src); editor.loadFromString(source);
} }
return; return;
} }