Merge pull request #517 from OptimistikSAS/issues/103

master
JFH 2021-05-22 18:34:14 +02:00 committed by GitHub
commit 5989a4cbd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 16 additions and 20 deletions

View File

@ -655,7 +655,7 @@ class EditorStartup {
editorObj.svgCanvas.selectOnly([ newImage ]);
editorObj.svgCanvas.alignSelectedElements('m', 'page');
editorObj.svgCanvas.alignSelectedElements('c', 'page');
editorObj.topPanelHandlers.updateContextPanel();
editorObj.topPanel.updateContextPanel();
document.getElementById('se-prompt-dialog').setAttribute('close', true);
};
// create dummy img so we know the default dimensions

View File

@ -325,7 +325,8 @@ class LayersPanel {
* @returns {void}
*/
layerRename() {
const oldName = document.querySelector("#layerlist tr.layersel td.layername").textContent;
const ele = document.querySelector("#layerlist tr.layersel td.layername");
const oldName = (ele) ? ele.textContent : '';
const newName = prompt(this.editor.i18next.t('notification.enterNewLayerName'), "");
if (!newName) {
return;
@ -425,7 +426,8 @@ class LayersPanel {
const elements = $id('layerlist').querySelectorAll("td.layervis");
Array.from(elements).forEach(function(element) {
element.addEventListener('click', function(evt) {
const name = evt.currentTarget.parentNode.querySelector("td.layername").textContent;
const ele = evt.currentTarget.parentNode.querySelector("td.layername");
const name = (ele)? ele.textContent : '';
const vis = evt.currentTarget.classList.contains("layerinvis");
self.editor.svgCanvas.setLayerVisibility(name, vis);
evt.currentTarget.classList.toggle("layerinvis");

View File

@ -3,12 +3,8 @@
* @license MIT
* @copyright 2011 Jeff Schiller
*/
/* globals jQuery */
import { jGraduate } from '../editor/components/jgraduate/jQuery.jGraduate.js';
import * as hstry from './history.js';
import jQueryPluginSVG from './jQuery.attr.js';
import { NS } from '../common/namespaces.js';
import {
getVisibleElements, getStrokedBBoxDefaultVisible, findDefs,
@ -19,8 +15,6 @@ import {
} from '../common/units.js';
import { getParents } from '../editor/components/jgraduate/Util.js';
const $ = jQueryPluginSVG(jQuery);
const {
InsertElementCommand, RemoveElementCommand,
ChangeElementCommand, BatchCommand
@ -272,7 +266,7 @@ export const setBBoxZoomMethod = function (val, editorW, editorH) {
switch (val) {
case 'selection': {
if (!selectedElements[0]) { return undefined; }
const selectedElems = $.map(selectedElements, function (n) {
const selectedElems = selectedElements.map(function (n, _) {
if (n) {
return n;
}
@ -722,7 +716,7 @@ export const getTextMethod = function () {
const selectedElements = elemContext_.getSelectedElements();
const selected = selectedElements[0];
if (isNullish(selected)) { return ''; }
return selected.textContent;
return (selected) ? selected.textContent : '';
};
/**

View File

@ -294,7 +294,7 @@ export class ChangeElementCommand extends Command {
this.oldValues = attrs;
for (const attr in attrs) {
if (attr === '#text') {
this.newValues[attr] = elem.textContent;
this.newValues[attr] = (elem) ? elem.textContent : '';
} else if (attr === '#href') {
this.newValues[attr] = getHref(elem);
} else {

View File

@ -735,8 +735,11 @@ export const convertToGroup = function (elem) {
} else if (dataStorage.has($elem, 'symbol')) {
elem = dataStorage.get($elem, 'symbol');
ts = $elem.attr('transform');
const pos = $elem.attr([ 'x', 'y' ]);
ts = $elem.getAttribute('transform');
const pos = {
x: $elem.getAttribute('x'),
y: $elem.getAttribute('y')
};
const vb = elem.getAttribute('viewBox');

View File

@ -351,7 +351,7 @@ export const setSvgString = function (xmlString, preventUndo) {
const elements = content.querySelectorAll('image');
Array.prototype.forEach.call(elements, function (image) {
preventClickDefault(image);
const val = svgContext_.getCanvas().getHref(this);
const val = svgContext_.getCanvas().getHref(image);
if (val) {
if (val.startsWith('data:')) {
// Check if an SVG-edit data URI

View File

@ -1324,11 +1324,8 @@ export const snapToGrid = function (value) {
* @returns {void}
*/
export const preventClickDefault = function (img) {
const elements = document.querySelectorAll(img);
Array.from(elements).forEach(function (element) {
element.addEventListener('click', function (e) {
e.preventDefault();
});
img.addEventListener('click', function (e) {
e.preventDefault();
});
};