- Refactoring: Avoid redundant use of *AttributeNS methods with

`null` value; just use *Attribute methods without namespace
This commit is contained in:
Brett Zamir
2018-10-23 18:13:36 +08:00
parent f4bbd34d34
commit 2835ec11b6
20 changed files with 98 additions and 96 deletions

4
dist/canvg.js vendored
View File

@@ -4393,8 +4393,8 @@ var canvg = (function (exports) {
_createClass(_class46, [{
key: "apply",
value: function apply(ctx, x, y, width, height) {
if (typeof canvasRGBA_ === 'undefined') {
svg.log('ERROR: `setStackBlurCanvasRGBA` must be run for blur to work');
if (typeof canvasRGBA_ !== 'function') {
svg.log('ERROR: The function `setStackBlurCanvasRGBA` must be present for blur to work');
return;
} // Todo: This might not be a problem anymore with out `instanceof` fix
// StackBlur requires canvas be on document

View File

@@ -235,7 +235,7 @@ var svgEditorExtension_polygon = (function () {
strokeWidth = c.strokeWidth,
sides = c.sides,
edg = Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy)) / 1.5;
newFO.setAttributeNS(null, 'edge', edg);
newFO.setAttribute('edge', edg);
var inradius = edg / 2 * cot(Math.PI / sides);
var circumradius = inradius * sec(Math.PI / sides);
var points = '';
@@ -248,11 +248,11 @@ var svgEditorExtension_polygon = (function () {
} // const poly = newFO.createElementNS(NS.SVG, 'polygon');
newFO.setAttributeNS(null, 'points', points);
newFO.setAttributeNS(null, 'fill', fill);
newFO.setAttributeNS(null, 'stroke', strokecolor);
newFO.setAttributeNS(null, 'stroke-width', strokeWidth); // newFO.setAttributeNS(null, 'transform', 'rotate(-90)');
// const shape = newFO.getAttributeNS(null, 'shape');
newFO.setAttribute('points', points);
newFO.setAttribute('fill', fill);
newFO.setAttribute('stroke', strokecolor);
newFO.setAttribute('stroke-width', strokeWidth); // newFO.setAttribute('transform', 'rotate(-90)');
// const shape = newFO.getAttribute('shape');
// newFO.append(poly);
// DrawPoly(cx, cy, sides, edg, orient);
@@ -280,7 +280,7 @@ var svgEditorExtension_polygon = (function () {
while (i--) {
var elem = selElems[i];
if (elem && elem.getAttributeNS(null, 'shape') === 'regularPoly') {
if (elem && elem.getAttribute('shape') === 'regularPoly') {
if (opts.selectedElement && !opts.multiselected) {
$('#polySides').val(elem.getAttribute('sides'));
showPanel(true);

View File

@@ -4370,8 +4370,8 @@ var svgEditorExtension_server_moinsave = (function () {
_createClass(_class46, [{
key: "apply",
value: function apply(ctx, x, y, width, height) {
if (typeof canvasRGBA_ === 'undefined') {
svg.log('ERROR: `setStackBlurCanvasRGBA` must be run for blur to work');
if (typeof canvasRGBA_ !== 'function') {
svg.log('ERROR: The function `setStackBlurCanvasRGBA` must be present for blur to work');
return;
} // Todo: This might not be a problem anymore with out `instanceof` fix
// StackBlur requires canvas be on document

View File

@@ -4370,8 +4370,8 @@ var svgEditorExtension_server_opensave = (function () {
_createClass(_class46, [{
key: "apply",
value: function apply(ctx, x, y, width, height) {
if (typeof canvasRGBA_ === 'undefined') {
svg.log('ERROR: `setStackBlurCanvasRGBA` must be run for blur to work');
if (typeof canvasRGBA_ !== 'function') {
svg.log('ERROR: The function `setStackBlurCanvasRGBA` must be present for blur to work');
return;
} // Todo: This might not be a problem anymore with out `instanceof` fix
// StackBlur requires canvas be on document

View File

@@ -195,8 +195,8 @@ var svgEditorExtension_star = (function () {
orient = c.orient,
circumradius = Math.sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy)) / 1.5,
inradius = circumradius / document.getElementById('starRadiusMulitplier').value;
newFO.setAttributeNS(null, 'r', circumradius);
newFO.setAttributeNS(null, 'r2', inradius);
newFO.setAttribute('r', circumradius);
newFO.setAttribute('r2', inradius);
var polyPoints = '';
for (var s = 0; point >= s; s++) {
@@ -228,13 +228,13 @@ var svgEditorExtension_star = (function () {
}
}
newFO.setAttributeNS(null, 'points', polyPoints);
newFO.setAttributeNS(null, 'fill', fill);
newFO.setAttributeNS(null, 'stroke', strokecolor);
newFO.setAttributeNS(null, 'stroke-width', strokeWidth);
newFO.setAttribute('points', polyPoints);
newFO.setAttribute('fill', fill);
newFO.setAttribute('stroke', strokecolor);
newFO.setAttribute('stroke-width', strokeWidth);
/* const shape = */
newFO.getAttributeNS(null, 'shape');
newFO.getAttribute('shape');
return {
started: true
};
@@ -258,7 +258,7 @@ var svgEditorExtension_star = (function () {
while (i--) {
var elem = selElems[i];
if (elem && elem.getAttributeNS(null, 'shape') === 'star') {
if (elem && elem.getAttribute('shape') === 'star') {
if (opts.selectedElement && !opts.multiselected) {
// $('#starRadiusMulitplier').val(elem.getAttribute('r2'));
$('#starNumPoints').val(elem.getAttribute('point'));

20
dist/index-es.js vendored
View File

@@ -15152,12 +15152,12 @@ function SvgCanvas(container, config) {
if (iswebkit) {
delayedStroke = function delayedStroke(ele) {
var _stroke = ele.getAttributeNS(null, 'stroke');
var _stroke = ele.getAttribute('stroke');
ele.removeAttributeNS(null, 'stroke'); // Re-apply stroke after delay. Anything higher than 1 seems to cause flicker
ele.removeAttribute('stroke'); // Re-apply stroke after delay. Anything higher than 1 seems to cause flicker
if (_stroke !== null) setTimeout(function () {
ele.setAttributeNS(null, 'stroke', _stroke);
ele.setAttribute('stroke', _stroke);
}, 0);
};
}
@@ -15683,8 +15683,8 @@ function SvgCanvas(container, config) {
y2 = xya.y;
}
shape.setAttributeNS(null, 'x2', x2);
shape.setAttributeNS(null, 'y2', y2);
shape.setAttribute('x2', x2);
shape.setAttribute('y2', y2);
break;
}
@@ -15738,7 +15738,7 @@ function SvgCanvas(container, config) {
rad = snapToGrid(rad);
}
shape.setAttributeNS(null, 'r', rad);
shape.setAttribute('r', rad);
break;
}
@@ -15756,9 +15756,9 @@ function SvgCanvas(container, config) {
cy = snapToGrid(cy);
}
shape.setAttributeNS(null, 'rx', Math.abs(x - cx));
shape.setAttribute('rx', Math.abs(x - cx));
var ry = Math.abs(evt.shiftKey ? x - cx : y - cy);
shape.setAttributeNS(null, 'ry', ry);
shape.setAttribute('ry', ry);
break;
}
@@ -15775,7 +15775,7 @@ function SvgCanvas(container, config) {
case 'fhpath':
{
// dAttr += + realX + ',' + realY + ' ';
// shape.setAttributeNS(null, 'points', dAttr);
// shape.setAttribute('points', dAttr);
end.x = realX;
end.y = realY;
@@ -22001,7 +22001,7 @@ function jqPluginSVGIcons ($) {
var svgroot = document.createElementNS(svgns, 'svg'); // Per https://www.w3.org/TR/xml-names11/#defaulting, the namespace for
// attributes should have no value.
svgroot.setAttributeNS(null, 'viewBox', [0, 0, iconW, iconH].join(' '));
svgroot.setAttribute('viewBox', [0, 0, iconW, iconH].join(' '));
var svg = elem.getElementsByTagNameNS(svgns, 'svg')[0]; // Make flexible by converting width/height to viewBox
var w = svg.getAttribute('width');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

20
dist/index-umd.js vendored
View File

@@ -15158,12 +15158,12 @@
if (iswebkit) {
delayedStroke = function delayedStroke(ele) {
var _stroke = ele.getAttributeNS(null, 'stroke');
var _stroke = ele.getAttribute('stroke');
ele.removeAttributeNS(null, 'stroke'); // Re-apply stroke after delay. Anything higher than 1 seems to cause flicker
ele.removeAttribute('stroke'); // Re-apply stroke after delay. Anything higher than 1 seems to cause flicker
if (_stroke !== null) setTimeout(function () {
ele.setAttributeNS(null, 'stroke', _stroke);
ele.setAttribute('stroke', _stroke);
}, 0);
};
}
@@ -15689,8 +15689,8 @@
y2 = xya.y;
}
shape.setAttributeNS(null, 'x2', x2);
shape.setAttributeNS(null, 'y2', y2);
shape.setAttribute('x2', x2);
shape.setAttribute('y2', y2);
break;
}
@@ -15744,7 +15744,7 @@
rad = snapToGrid(rad);
}
shape.setAttributeNS(null, 'r', rad);
shape.setAttribute('r', rad);
break;
}
@@ -15762,9 +15762,9 @@
cy = snapToGrid(cy);
}
shape.setAttributeNS(null, 'rx', Math.abs(x - cx));
shape.setAttribute('rx', Math.abs(x - cx));
var ry = Math.abs(evt.shiftKey ? x - cx : y - cy);
shape.setAttributeNS(null, 'ry', ry);
shape.setAttribute('ry', ry);
break;
}
@@ -15781,7 +15781,7 @@
case 'fhpath':
{
// dAttr += + realX + ',' + realY + ' ';
// shape.setAttributeNS(null, 'points', dAttr);
// shape.setAttribute('points', dAttr);
end.x = realX;
end.y = realY;
@@ -22007,7 +22007,7 @@
var svgroot = document.createElementNS(svgns, 'svg'); // Per https://www.w3.org/TR/xml-names11/#defaulting, the namespace for
// attributes should have no value.
svgroot.setAttributeNS(null, 'viewBox', [0, 0, iconW, iconH].join(' '));
svgroot.setAttribute('viewBox', [0, 0, iconW, iconH].join(' '));
var svg = elem.getElementsByTagNameNS(svgns, 'svg')[0]; // Make flexible by converting width/height to viewBox
var w = svg.getAttribute('width');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long