Residual linting
{object} -> {Object} Remove extra semicolons. Use jQuery’s .empty(). Make nodelist loops O(n) rather than O(n^2). Specify radix in parseInt to prevent guessing octal.master
parent
4fd4054f03
commit
f9fb7f47ae
|
@ -745,8 +745,7 @@ function build (opts) {
|
||||||
|
|
||||||
if (node != null && node.nodeType === 1) { // ELEMENT_NODE
|
if (node != null && node.nodeType === 1) { // ELEMENT_NODE
|
||||||
// add children
|
// add children
|
||||||
for (var i = 0; i < node.childNodes.length; i++) {
|
for (var i = 0, childNode; (childNode = node.childNodes[i]); i++) {
|
||||||
var childNode = node.childNodes[i];
|
|
||||||
if (childNode.nodeType === 1) this.addChild(childNode, true); // ELEMENT_NODE
|
if (childNode.nodeType === 1) this.addChild(childNode, true); // ELEMENT_NODE
|
||||||
if (this.captureTextNodes && (childNode.nodeType === 3 || childNode.nodeType === 4)) {
|
if (this.captureTextNodes && (childNode.nodeType === 3 || childNode.nodeType === 4)) {
|
||||||
var text = childNode.nodeValue || childNode.text || '';
|
var text = childNode.nodeValue || childNode.text || '';
|
||||||
|
@ -2227,8 +2226,8 @@ function build (opts) {
|
||||||
this.base(node);
|
this.base(node);
|
||||||
|
|
||||||
this.hasText = true;
|
this.hasText = true;
|
||||||
for (var i = 0; i < node.childNodes.length; i++) {
|
for (var i = 0, childNode; (childNode = node.childNodes[i]); i++) {
|
||||||
if (node.childNodes[i].nodeType !== 3) this.hasText = false;
|
if (childNode.nodeType !== 3) this.hasText = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// this might contain text
|
// this might contain text
|
||||||
|
@ -2359,8 +2358,8 @@ function build (opts) {
|
||||||
|
|
||||||
// text, or spaces then CDATA
|
// text, or spaces then CDATA
|
||||||
var css = '';
|
var css = '';
|
||||||
for (var i = 0; i < node.childNodes.length; i++) {
|
for (var i = 0, childNode; (childNode = node.childNodes[i]); i++) {
|
||||||
css += node.childNodes[i].nodeValue;
|
css += childNode.nodeValue;
|
||||||
}
|
}
|
||||||
css = css.replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm, ''); // remove comments
|
css = css.replace(/(\/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+\/)|(^[\s]*\/\/.*)/gm, ''); // remove comments
|
||||||
css = svg.compressSpaces(css); // replace whitespace
|
css = svg.compressSpaces(css); // replace whitespace
|
||||||
|
|
|
@ -47,7 +47,7 @@ svgedit.coords.init = function (editorContext) {
|
||||||
/**
|
/**
|
||||||
* Applies coordinate changes to an element based on the given matrix
|
* Applies coordinate changes to an element based on the given matrix
|
||||||
* @param {Element} selected - DOM element to be changed
|
* @param {Element} selected - DOM element to be changed
|
||||||
* @param {object} changes - Object with changes to be remapped
|
* @param {Object} changes - Object with changes to be remapped
|
||||||
* @param {SVGMatrix} m - Matrix object to use for remapping coordinates
|
* @param {SVGMatrix} m - Matrix object to use for remapping coordinates
|
||||||
*/
|
*/
|
||||||
svgedit.coords.remapElement = function (selected, changes, m) {
|
svgedit.coords.remapElement = function (selected, changes, m) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ svgedit.history.HistoryEventTypes = {
|
||||||
/**
|
/**
|
||||||
* An interface that all command objects must implement.
|
* An interface that all command objects must implement.
|
||||||
* @typedef svgedit.history.HistoryCommand
|
* @typedef svgedit.history.HistoryCommand
|
||||||
* @type {object}
|
* @type {Object}
|
||||||
* void apply(svgedit.history.HistoryEventHandler);
|
* void apply(svgedit.history.HistoryEventHandler);
|
||||||
* void unapply(svgedit.history.HistoryEventHandler);
|
* void unapply(svgedit.history.HistoryEventHandler);
|
||||||
* Element[] elements();
|
* Element[] elements();
|
||||||
|
|
|
@ -142,7 +142,7 @@ HistoryRecordingService.prototype.removeElement = function (elem, oldNextSibling
|
||||||
/**
|
/**
|
||||||
* Add a ChangeElementCommand to the history or current batch command
|
* Add a ChangeElementCommand to the history or current batch command
|
||||||
* @param {Element} elem - The DOM element that was changed
|
* @param {Element} elem - The DOM element that was changed
|
||||||
* @param {object} attrs - An object with the attributes to be changed and the values they had *before* the change
|
* @param {Object} attrs - An object with the attributes to be changed and the values they had *before* the change
|
||||||
* @param {string} [text] - An optional string visible to user related to this change
|
* @param {string} [text] - An optional string visible to user related to this change
|
||||||
* @returns {svgedit.history.HistoryRecordingService}
|
* @returns {svgedit.history.HistoryRecordingService}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -180,7 +180,7 @@ Layer.prototype.setName = function (name, hrService) {
|
||||||
// now change the underlying title element contents
|
// now change the underlying title element contents
|
||||||
var title = this.getTitleElement();
|
var title = this.getTitleElement();
|
||||||
if (title) {
|
if (title) {
|
||||||
while (title.firstChild) { title.removeChild(title.firstChild); }
|
$(title).empty();
|
||||||
title.textContent = name;
|
title.textContent = name;
|
||||||
this.name_ = name;
|
this.name_ = name;
|
||||||
if (hrService) {
|
if (hrService) {
|
||||||
|
|
|
@ -22,7 +22,7 @@ var langParam;
|
||||||
|
|
||||||
function setStrings (type, obj, ids) {
|
function setStrings (type, obj, ids) {
|
||||||
// Root element to look for element from
|
// Root element to look for element from
|
||||||
var i, sel, val, $elem, elem, node, parent = $('#svg_editor').parent();
|
var sel, val, $elem, elem, parent = $('#svg_editor').parent();
|
||||||
for (sel in obj) {
|
for (sel in obj) {
|
||||||
val = obj[sel];
|
val = obj[sel];
|
||||||
if (!val) { console.log(sel); }
|
if (!val) { console.log(sel); }
|
||||||
|
@ -34,9 +34,8 @@ function setStrings (type, obj, ids) {
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'content':
|
case 'content':
|
||||||
for (i = 0; i < elem.childNodes.length; i++) {
|
for (var i = 0, node; (node = elem.childNodes[i]); i++) {
|
||||||
node = elem.childNodes[i];
|
if (node.nodeType === 3 && node.textContent.trim() === '') {
|
||||||
if (node.nodeType === 3 && node.textContent.replace(/\s/g, '')) {
|
|
||||||
node.textContent = val;
|
node.textContent = val;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef AngleCoord45
|
* @typedef AngleCoord45
|
||||||
* @type {object}
|
* @type {Object}
|
||||||
* @property {number} x - The angle-snapped x value
|
* @property {number} x - The angle-snapped x value
|
||||||
* @property {number} y - The angle-snapped y value
|
* @property {number} y - The angle-snapped y value
|
||||||
* @property {number} a - The angle at which to snap
|
* @property {number} a - The angle at which to snap
|
||||||
|
@ -39,7 +39,7 @@ var svg = document.createElementNS(svgedit.NS.SVG, 'svg');
|
||||||
* @param {number} x - Float representing the x coordinate
|
* @param {number} x - Float representing the x coordinate
|
||||||
* @param {number} y - Float representing the y coordinate
|
* @param {number} y - Float representing the y coordinate
|
||||||
* @param {SVGMatrix} m - Matrix object to transform the point with
|
* @param {SVGMatrix} m - Matrix object to transform the point with
|
||||||
* @returns {object} An x, y object representing the transformed point
|
* @returns {Object} An x, y object representing the transformed point
|
||||||
*/
|
*/
|
||||||
svgedit.math.transformPoint = function (x, y, m) {
|
svgedit.math.transformPoint = function (x, y, m) {
|
||||||
return {x: m.a * x + m.c * y + m.e, y: m.b * x + m.d * y + m.f};
|
return {x: m.a * x + m.c * y + m.e, y: m.b * x + m.d * y + m.f};
|
||||||
|
@ -80,7 +80,7 @@ svgedit.math.matrixMultiply = function (matr) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See if the given transformlist includes a non-indentity matrix transform
|
* See if the given transformlist includes a non-indentity matrix transform
|
||||||
* @param {object} [tlist] - The transformlist to check
|
* @param {Object} [tlist] - The transformlist to check
|
||||||
* @returns {boolean} Whether or not a matrix transform was found
|
* @returns {boolean} Whether or not a matrix transform was found
|
||||||
*/
|
*/
|
||||||
svgedit.math.hasMatrixTransform = function (tlist) {
|
svgedit.math.hasMatrixTransform = function (tlist) {
|
||||||
|
@ -100,7 +100,7 @@ svgedit.math.hasMatrixTransform = function (tlist) {
|
||||||
* @param {number} w - Float with the box width
|
* @param {number} w - Float with the box width
|
||||||
* @param {number} h - Float with the box height
|
* @param {number} h - Float with the box height
|
||||||
* @param {SVGMatrix} m - Matrix object to transform the box by
|
* @param {SVGMatrix} m - Matrix object to transform the box by
|
||||||
* @returns {object} An object with the following values:
|
* @returns {Object} An object with the following values:
|
||||||
* tl - The top left coordinate (x,y object)
|
* tl - The top left coordinate (x,y object)
|
||||||
* tr - The top right coordinate (x,y object)
|
* tr - The top right coordinate (x,y object)
|
||||||
* bl - The bottom left coordinate (x,y object)
|
* bl - The bottom left coordinate (x,y object)
|
||||||
|
@ -143,11 +143,11 @@ svgedit.math.transformBox = function (l, t, w, h, m) {
|
||||||
* (this is the equivalent of SVGTransformList.consolidate() but unlike
|
* (this is the equivalent of SVGTransformList.consolidate() but unlike
|
||||||
* that method, this one does not modify the actual SVGTransformList)
|
* that method, this one does not modify the actual SVGTransformList)
|
||||||
* This function is very liberal with its min, max arguments
|
* This function is very liberal with its min, max arguments
|
||||||
* @param {object} tlist - The transformlist object
|
* @param {Object} tlist - The transformlist object
|
||||||
* @param {integer} [min=0] - Optional integer indicating start transform position
|
* @param {integer} [min=0] - Optional integer indicating start transform position
|
||||||
* @param {integer} [max] - Optional integer indicating end transform position;
|
* @param {integer} [max] - Optional integer indicating end transform position;
|
||||||
* defaults to one less than the tlist's numberOfItems
|
* defaults to one less than the tlist's numberOfItems
|
||||||
* @returns {object} A single matrix transform object
|
* @returns {Object} A single matrix transform object
|
||||||
*/
|
*/
|
||||||
svgedit.math.transformListToTransform = function (tlist, min, max) {
|
svgedit.math.transformListToTransform = function (tlist, min, max) {
|
||||||
if (tlist == null) {
|
if (tlist == null) {
|
||||||
|
|
|
@ -291,8 +291,8 @@ window.svgEditor = (function ($) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows setting of preferences or configuration (including extensions).
|
* Allows setting of preferences or configuration (including extensions).
|
||||||
* @param {object} opts The preferences or configuration (including extensions)
|
* @param {Object} opts The preferences or configuration (including extensions)
|
||||||
* @param {object} [cfgCfg] Describes configuration which applies to the particular batch of supplied options
|
* @param {Object} [cfgCfg] Describes configuration which applies to the particular batch of supplied options
|
||||||
* @param {boolean} [cfgCfg.allowInitialUserOverride=false] Set to true if you wish
|
* @param {boolean} [cfgCfg.allowInitialUserOverride=false] Set to true if you wish
|
||||||
* to allow initial overriding of settings by the user via the URL
|
* to allow initial overriding of settings by the user via the URL
|
||||||
* (if permitted) or previously stored preferences (if permitted);
|
* (if permitted) or previously stored preferences (if permitted);
|
||||||
|
@ -375,7 +375,7 @@ window.svgEditor = (function ($) {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {object} opts Extension mechanisms may call setCustomHandlers with three functions: opts.open, opts.save, and opts.exportImage
|
* @param {Object} opts Extension mechanisms may call setCustomHandlers with three functions: opts.open, opts.save, and opts.exportImage
|
||||||
* opts.open's responsibilities are:
|
* opts.open's responsibilities are:
|
||||||
* - invoke a file chooser dialog in 'open' mode
|
* - invoke a file chooser dialog in 'open' mode
|
||||||
* - let user pick a SVG file
|
* - let user pick a SVG file
|
||||||
|
|
|
@ -99,7 +99,7 @@ var svgcontent = svgdoc.createElementNS(NS.SVG, 'svg');
|
||||||
|
|
||||||
// This function resets the svgcontent element while keeping it in the DOM.
|
// This function resets the svgcontent element while keeping it in the DOM.
|
||||||
var clearSvgContentElement = canvas.clearSvgContentElement = function () {
|
var clearSvgContentElement = canvas.clearSvgContentElement = function () {
|
||||||
while (svgcontent.firstChild) { svgcontent.removeChild(svgcontent.firstChild); }
|
$(svgcontent).empty();
|
||||||
|
|
||||||
// TODO: Clear out all other attributes first?
|
// TODO: Clear out all other attributes first?
|
||||||
$(svgcontent).attr({
|
$(svgcontent).attr({
|
||||||
|
@ -193,13 +193,13 @@ var getJsonFromSvgElement = this.getJsonFromSvgElement = function (data) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Iterate attributes
|
// Iterate attributes
|
||||||
for (var i = 0; i < data.attributes.length; i++) {
|
for (var i = 0, attr; (attr = data.attributes[i]); i++) {
|
||||||
retval.attr[data.attributes[i].name] = data.attributes[i].value;
|
retval.attr[attr.name] = attr.value;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Iterate children
|
// Iterate children
|
||||||
for (var i = 0; i < data.childNodes.length; i++) {
|
for (var i = 0, node; (node = data.childNodes[i]); i++) {
|
||||||
retval.children.push(getJsonFromSvgElement(data.childNodes[i]));
|
retval.children[i] = getJsonFromSvgElement(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -3056,7 +3056,7 @@ return {
|
||||||
var curPt;
|
var curPt;
|
||||||
if (id.substr(0, 14) === 'pathpointgrip_') {
|
if (id.substr(0, 14) === 'pathpointgrip_') {
|
||||||
// Select this point
|
// Select this point
|
||||||
curPt = svgedit.path.path.cur_pt = parseInt(id.substr(14));
|
curPt = svgedit.path.path.cur_pt = parseInt(id.substr(14), 10);
|
||||||
svgedit.path.path.dragging = [startX, startY];
|
svgedit.path.path.dragging = [startX, startY];
|
||||||
var seg = svgedit.path.path.segs[curPt];
|
var seg = svgedit.path.path.segs[curPt];
|
||||||
|
|
||||||
|
|
|
@ -926,7 +926,7 @@ svgedit.utilities.getBBoxWithTransform = function (elem, addSvgElementFromJson,
|
||||||
function getStrokeOffsetForBBox (elem) {
|
function getStrokeOffsetForBBox (elem) {
|
||||||
var sw = elem.getAttribute('stroke-width');
|
var sw = elem.getAttribute('stroke-width');
|
||||||
return (!isNaN(sw) && elem.getAttribute('stroke') !== 'none') ? sw / 2 : 0;
|
return (!isNaN(sw) && elem.getAttribute('stroke') !== 'none') ? sw / 2 : 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
// Function: getStrokedBBox
|
// Function: getStrokedBBox
|
||||||
// Get the bounding box for one or more stroked and/or transformed elements
|
// Get the bounding box for one or more stroked and/or transformed elements
|
||||||
|
|
Loading…
Reference in New Issue