- Linting (ESLint): Fix other indents besides main (though continue to disable check)

master
Brett Zamir 2018-05-17 13:15:20 +08:00
parent fff77db4f1
commit 25b1e9be01
1 changed files with 2653 additions and 2651 deletions

View File

@ -46,6 +46,7 @@ if (window.opera) {
// Parameters:
// container - The container HTML element that should hold the SVG root element
// config - An object that contains configuration data
$.SvgCanvas = function (container, config) {
// Alias Namespace constants
var NS = svgedit.NS;
@ -72,7 +73,8 @@ var canvas = this;
var svgdoc = container.ownerDocument;
// This is a container for the document being edited, not the document itself.
var svgroot = svgdoc.importNode(svgedit.utilities.text2xml(
var svgroot = svgdoc.importNode(
svgedit.utilities.text2xml(
'<svg id="svgroot" xmlns="' + NS.SVG + '" xlinkns="' + NS.XLINK + '" ' +
'width="' + dimensions[0] + '" height="' + dimensions[1] + '" x="' + dimensions[0] + '" y="' + dimensions[1] + '" overflow="visible">' +
'<defs>' +
@ -85,7 +87,8 @@ var svgroot = svgdoc.importNode(svgedit.utilities.text2xml(
'</feMerge>' +
'</filter>' +
'</defs>' +
'</svg>').documentElement,
'</svg>'
).documentElement,
true
);
container.appendChild(svgroot);
@ -466,15 +469,14 @@ var restoreRefElems = function (elem) {
}
};
(function () {
// TODO For Issue 208: this is a start on a thumbnail
// var svgthumb = svgdoc.createElementNS(NS.SVG, 'use');
// svgthumb.setAttribute('width', '100');
// svgthumb.setAttribute('height', '100');
// svgedit.utilities.setHref(svgthumb, '#svgcontent');
// svgroot.appendChild(svgthumb);
}());
// (function () {
// TODO For Issue 208: this is a start on a thumbnail
// var svgthumb = svgdoc.createElementNS(NS.SVG, 'use');
// svgthumb.setAttribute('width', '100');
// svgthumb.setAttribute('height', '100');
// svgedit.utilities.setHref(svgthumb, '#svgcontent');
// svgroot.appendChild(svgthumb);
// }());
// Object to contain image data for raster images that were found encodable
var encodableImages = {},
@ -510,7 +512,7 @@ var encodableImages = {},
curProperties = curShape,
// Array with selected elements' Bounding box object
// selectedBBoxes = new Array(1),
// selectedBBoxes = new Array(1),
// The DOM element that was just selected
justSelected = null,
@ -718,38 +720,38 @@ var getId, getNextId;
var textActions, pathActions;
(function (c) {
// Object to contain editor event names and callback functions
var events = {};
// Object to contain editor event names and callback functions
var events = {};
getId = c.getId = function () { return getCurrentDrawing().getId(); };
getNextId = c.getNextId = function () { return getCurrentDrawing().getNextId(); };
getId = c.getId = function () { return getCurrentDrawing().getId(); };
getNextId = c.getNextId = function () { return getCurrentDrawing().getNextId(); };
// Function: call
// Run the callback function associated with the given event
//
// Parameters:
// event - String with the event name
// arg - Argument to pass through to the callback function
call = c.call = function (event, arg) {
// Function: call
// Run the callback function associated with the given event
//
// Parameters:
// event - String with the event name
// arg - Argument to pass through to the callback function
call = c.call = function (event, arg) {
if (events[event]) {
return events[event](this, arg);
}
};
};
// Function: bind
// Attaches a callback function to an event
//
// Parameters:
// event - String indicating the name of the event
// f - The callback function to bind to the event
//
// Return:
// The previous event
c.bind = function (event, f) {
// Function: bind
// Attaches a callback function to an event
//
// Parameters:
// event - String indicating the name of the event
// f - The callback function to bind to the event
//
// Return:
// The previous event
c.bind = function (event, f) {
var old = events[event];
events[event] = f;
return old;
};
};
}(canvas));
// Function: canvas.prepareSvg
@ -861,7 +863,7 @@ var recalculateAllSelectedDimensions = this.recalculateAllSelectedDimensions = f
var i = selectedElements.length;
while (i--) {
var elem = selectedElements[i];
// if (svgedit.utilities.getRotationAngle(elem) && !svgedit.math.hasMatrixTransform(getTransformList(elem))) { continue; }
// if (svgedit.utilities.getRotationAngle(elem) && !svgedit.math.hasMatrixTransform(getTransformList(elem))) { continue; }
var cmd = svgedit.recalculate.recalculateDimensions(elem);
if (cmd) {
batchCmd.addSubCommand(cmd);
@ -937,7 +939,7 @@ var addToSelection = this.addToSelection = function (elemsToAdd, showGrips) {
selectedElements[j] = elem;
// only the first selectedBBoxes element is ever used in the codebase these days
// if (j === 0) selectedBBoxes[0] = svgedit.utilities.getBBox(elem);
// if (j === 0) selectedBBoxes[0] = svgedit.utilities.getBBox(elem);
j++;
var sel = selectorManager.requestSelector(elem, bbox);
@ -1092,7 +1094,7 @@ var drawnPath = null;
// Mouse events
(function () {
var dAttr = null,
var dAttr = null,
startX = null,
startY = null,
rStartX = null,
@ -1116,7 +1118,7 @@ var drawnPath = null;
THRESHOLD_DIST = 0.8,
STEP_COUNT = 10;
var getBsplinePoint = function (t) {
var getBsplinePoint = function (t) {
var spline = {x: 0, y: 0},
p0 = controllPoint2,
p1 = controllPoint1,
@ -1150,12 +1152,12 @@ var drawnPath = null;
x: spline.x,
y: spline.y
};
};
// - when we are in a create mode, the element is added to the canvas
// but the action is not recorded until mousing up
// - when we are in select mode, select the element, remember the position
// and do nothing else
var mouseDown = function (evt) {
};
// - when we are in a create mode, the element is added to the canvas
// but the action is not recorded until mousing up
// - when we are in select mode, select the element, remember the position
// and do nothing else
var mouseDown = function (evt) {
if (canvas.spaceKey || evt.button === 1) { return; }
var rightClick = evt.button === 2;
@ -1518,11 +1520,11 @@ var drawnPath = null;
started = true;
}
});
};
};
// in this function we do not record any state changes yet (but we do update
// any elements that are still being created, moved or resized on the canvas)
var mouseMove = function (evt) {
// in this function we do not record any state changes yet (but we do update
// any elements that are still being created, moved or resized on the canvas)
var mouseMove = function (evt) {
if (!started) { return; }
if (evt.button === 1 || canvas.spaceKey) { return; }
@ -1940,14 +1942,14 @@ var drawnPath = null;
mouse_y: mouseY,
selected: selected
});
}; // mouseMove()
}; // mouseMove()
// - in create mode, the element's opacity is set properly, we create an InsertElementCommand
// and store it on the Undo stack
// - in move/resize mode, the element's attributes which were affected by the move/resize are
// identified, a ChangeElementCommand is created and stored on the stack for those attrs
// this is done in when we recalculate the selected dimensions()
var mouseUp = function (evt) {
// - in create mode, the element's opacity is set properly, we create an InsertElementCommand
// and store it on the Undo stack
// - in move/resize mode, the element's attributes which were affected by the move/resize are
// identified, a ChangeElementCommand is created and stored on the stack for those attrs
// this is done in when we recalculate the selected dimensions()
var mouseUp = function (evt) {
if (evt.button === 2) { return; }
var tempJustSelected = justSelected;
justSelected = null;
@ -2007,7 +2009,7 @@ var drawnPath = null;
selectorManager.requestSelector(selected).showGrips(true);
// This shouldn't be necessary as it was done on mouseDown...
// call('selected', [selected]);
// call('selected', [selected]);
}
// always recalculate dimensions to strip off stray identity transforms
recalculateAllSelectedDimensions();
@ -2256,9 +2258,9 @@ var drawnPath = null;
}
startTransform = null;
};
};
var dblClick = function (evt) {
var dblClick = function (evt) {
var evtTarget = evt.target;
var parent = evtTarget.parentNode;
@ -2297,21 +2299,21 @@ var drawnPath = null;
return;
}
setContext(mouseTarget);
};
};
// prevent links from being followed in the canvas
var handleLinkInCanvas = function (e) {
// prevent links from being followed in the canvas
var handleLinkInCanvas = function (e) {
e.preventDefault();
return false;
};
};
// Added mouseup to the container here.
// TODO(codedread): Figure out why after the Closure compiler, the window mouseup is ignored.
$(container).mousedown(mouseDown).mousemove(mouseMove).click(handleLinkInCanvas).dblclick(dblClick).mouseup(mouseUp);
// $(window).mouseup(mouseUp);
// Added mouseup to the container here.
// TODO(codedread): Figure out why after the Closure compiler, the window mouseup is ignored.
$(container).mousedown(mouseDown).mousemove(mouseMove).click(handleLinkInCanvas).dblclick(dblClick).mouseup(mouseUp);
// $(window).mouseup(mouseUp);
// TODO(rafaelcastrocouto): User preference for shift key and zoom factor
$(container).bind('mousewheel DOMMouseScroll', function (e) {
// TODO(rafaelcastrocouto): User preference for shift key and zoom factor
$(container).bind('mousewheel DOMMouseScroll', function (e) {
// if (!e.shiftKey) { return; }
e.preventDefault();
var evt = e.originalEvent;
@ -2332,24 +2334,24 @@ var drawnPath = null;
bbox.factor = Math.max(3 / 4, Math.min(4 / 3, (delta)));
call('zoomed', bbox);
});
});
}());
// Group: Text edit functions
// Functions relating to editing text elements
textActions = canvas.textActions = (function () {
var curtext;
var textinput;
var cursor;
var selblock;
var blinker;
var chardata = [];
var textbb; // , transbb;
var matrix;
var lastX, lastY;
var allowDbl;
var curtext;
var textinput;
var cursor;
var selblock;
var blinker;
var chardata = [];
var textbb; // , transbb;
var matrix;
var lastX, lastY;
var allowDbl;
function setCursor (index) {
function setCursor (index) {
var empty = (textinput.value === '');
$(textinput).focus();
@ -2398,9 +2400,9 @@ textActions = canvas.textActions = (function () {
});
if (selblock) { selblock.setAttribute('d', ''); }
}
}
function setSelection (start, end, skipInput) {
function setSelection (start, end, skipInput) {
if (start === end) {
setCursor(end);
return;
@ -2441,9 +2443,9 @@ textActions = canvas.textActions = (function () {
d: dstr,
'display': 'inline'
});
}
}
function getIndexFromPoint (mouseX, mouseY) {
function getIndexFromPoint (mouseX, mouseY) {
// Position cursor here
var pt = svgroot.createSVGPoint();
pt.x = mouseX;
@ -2468,22 +2470,22 @@ textActions = canvas.textActions = (function () {
charpos++;
}
return charpos;
}
}
function setCursorFromPoint (mouseX, mouseY) {
function setCursorFromPoint (mouseX, mouseY) {
setCursor(getIndexFromPoint(mouseX, mouseY));
}
}
function setEndSelectionFromPoint (x, y, apply) {
function setEndSelectionFromPoint (x, y, apply) {
var i1 = textinput.selectionStart;
var i2 = getIndexFromPoint(x, y);
var start = Math.min(i1, i2);
var end = Math.max(i1, i2);
setSelection(start, end, !apply);
}
}
function screenToPt (xIn, yIn) {
function screenToPt (xIn, yIn) {
var out = {
x: xIn,
y: yIn
@ -2499,9 +2501,9 @@ textActions = canvas.textActions = (function () {
}
return out;
}
}
function ptToScreen (xIn, yIn) {
function ptToScreen (xIn, yIn) {
var out = {
x: xIn,
y: yIn
@ -2517,23 +2519,23 @@ textActions = canvas.textActions = (function () {
out.y *= currentZoom;
return out;
}
}
/*
// Not currently in use
function hideCursor () {
/*
// Not currently in use
function hideCursor () {
if (cursor) {
cursor.setAttribute('visibility', 'hidden');
}
}
*/
}
*/
function selectAll (evt) {
function selectAll (evt) {
setSelection(0, curtext.textContent.length);
$(this).unbind(evt);
}
}
function selectWord (evt) {
function selectWord (evt) {
if (!allowDbl || !curtext) { return; }
var ept = svgedit.math.transformPoint(evt.pageX, evt.pageY, rootSctm),
@ -2553,9 +2555,9 @@ textActions = canvas.textActions = (function () {
setTimeout(function () {
$(evt.target).unbind('click', selectAll);
}, 300);
}
}
return {
return {
select: function (target, x, y) {
curtext = target;
textActions.toEditMode(x, y);
@ -2730,30 +2732,30 @@ textActions = canvas.textActions = (function () {
});
setSelection(textinput.selectionStart, textinput.selectionEnd, true);
}
};
};
}());
// TODO: Migrate all of this code into path.js
// Group: Path edit functions
// Functions relating to editing path elements
pathActions = canvas.pathActions = (function () {
var subpath = false;
var currentPath;
var newPoint, firstCtrl;
var subpath = false;
var currentPath;
var newPoint, firstCtrl;
function resetD (p) {
function resetD (p) {
p.setAttribute('d', pathActions.convertPath(p));
}
}
// TODO: Move into path.js
svgedit.path.Path.prototype.endChanges = function (text) {
// TODO: Move into path.js
svgedit.path.Path.prototype.endChanges = function (text) {
if (svgedit.browser.isWebkit()) { resetD(this.elem); }
var cmd = new svgedit.history.ChangeElementCommand(this.elem, {d: this.last_d}, text);
addCommandToHistory(cmd);
call('changed', [this.elem]);
};
};
svgedit.path.Path.prototype.addPtsToSelection = function (indexes) {
svgedit.path.Path.prototype.addPtsToSelection = function (indexes) {
var i, seg;
if (!$.isArray(indexes)) { indexes = [indexes]; }
for (i = 0; i < indexes.length; i++) {
@ -2782,16 +2784,16 @@ pathActions = canvas.pathActions = (function () {
pathActions.closed_subpath = this.subpathIsClosed(this.selected_pts[0]);
call('selected', grips);
};
};
currentPath = null;
drawnPath = null;
var hasMoved = false;
currentPath = null;
drawnPath = null;
var hasMoved = false;
// This function converts a polyline (created by the fh_path tool) into
// a path element and coverts every three line segments into a single bezier
// curve in an attempt to smooth out the free-hand
var smoothPolylineIntoPath = function (element) {
// This function converts a polyline (created by the fh_path tool) into
// a path element and coverts every three line segments into a single bezier
// curve in an attempt to smooth out the free-hand
var smoothPolylineIntoPath = function (element) {
var i, points = element.points;
var N = points.numberOfItems;
if (N >= 4) {
@ -2856,9 +2858,9 @@ pathActions = canvas.pathActions = (function () {
// No need to call "changed", as this is already done under mouseUp
}
return element;
};
};
return {
return {
mouseDown: function (evt, mouseTarget, startX, startY) {
var id;
if (currentMode === 'path') {
@ -3038,7 +3040,7 @@ pathActions = canvas.pathActions = (function () {
if (subpath) { index += svgedit.path.path.segs.length; }
svgedit.path.addPointGrip(index, x, y);
}
// keep = true;
// keep = true;
}
return;
@ -3503,7 +3505,7 @@ pathActions = canvas.pathActions = (function () {
} else if (i === index) {
// Remove it
list.removeItem(lastM);
// index--;
// index--;
} else if (item.pathSegType === 1 && index < i) {
// Remove the closing seg of this subpath
zSeg = i - 1;
@ -3653,7 +3655,7 @@ pathActions = canvas.pathActions = (function () {
},
// Convert a path to one with only absolute or relative values
convertPath: svgedit.utilities.convertPath
};
};
})();
// end pathActions
@ -3798,15 +3800,15 @@ this.svgToString = function (elem, indent) {
var vb = '';
// TODO: Allow this by dividing all values by current baseVal
// Note that this also means we should properly deal with this on import
// if (curConfig.baseUnit !== 'px') {
// var unit = curConfig.baseUnit;
// var unit_m = svgedit.units.getTypeMap()[unit];
// res.w = svgedit.units.shortFloat(res.w / unit_m)
// res.h = svgedit.units.shortFloat(res.h / unit_m)
// vb = ' viewBox="' + [0, 0, res.w, res.h].join(' ') + '"';
// res.w += unit;
// res.h += unit;
// }
// if (curConfig.baseUnit !== 'px') {
// var unit = curConfig.baseUnit;
// var unitM = svgedit.units.getTypeMap()[unit];
// res.w = svgedit.units.shortFloat(res.w / unitM);
// res.h = svgedit.units.shortFloat(res.h / unitM);
// vb = ' viewBox="' + [0, 0, res.w, res.h].join(' ') + '"';
// res.w += unit;
// res.h += unit;
// }
if (unit !== 'px') {
res.w = svgedit.units.convertUnit(res.w, unit) + unit;
@ -5700,7 +5702,7 @@ this.getPaintOpacity = function (type) {
// elem - The element to check the blur value for
this.getBlur = function (elem) {
var val = 0;
// var elem = selectedElements[0];
// var elem = selectedElements[0];
if (elem) {
var filterUrl = elem.getAttribute('filter');
@ -5715,16 +5717,16 @@ this.getBlur = function (elem) {
};
(function () {
var curCommand = null;
var filter = null;
var filterHidden = false;
var curCommand = null;
var filter = null;
var filterHidden = false;
// Function: setBlurNoUndo
// Sets the stdDeviation blur value on the selected element without being undoable
//
// Parameters:
// val - The new stdDeviation value
canvas.setBlurNoUndo = function (val) {
// Function: setBlurNoUndo
// Sets the stdDeviation blur value on the selected element without being undoable
//
// Parameters:
// val - The new stdDeviation value
canvas.setBlurNoUndo = function (val) {
if (!filter) {
canvas.setBlur(val);
return;
@ -5747,24 +5749,24 @@ this.getBlur = function (elem) {
changeSelectedAttributeNoUndo('stdDeviation', val, [filter.firstChild]);
canvas.setBlurOffsets(filter, val);
}
};
};
function finishChange () {
function finishChange () {
var bCmd = canvas.undoMgr.finishUndoableChange();
curCommand.addSubCommand(bCmd);
addCommandToHistory(curCommand);
curCommand = null;
filter = null;
}
}
// Function: setBlurOffsets
// Sets the x, y, with, height values of the filter element in order to
// make the blur not be clipped. Removes them if not neeeded
//
// Parameters:
// filter - The filter DOM element to update
// stdDev - The standard deviation value on which to base the offset size
canvas.setBlurOffsets = function (filter, stdDev) {
// Function: setBlurOffsets
// Sets the x, y, with, height values of the filter element in order to
// make the blur not be clipped. Removes them if not neeeded
//
// Parameters:
// filter - The filter DOM element to update
// stdDev - The standard deviation value on which to base the offset size
canvas.setBlurOffsets = function (filter, stdDev) {
if (stdDev > 3) {
// TODO: Create algorithm here where size is based on expected blur
svgedit.utilities.assignAttributes(filter, {
@ -5782,15 +5784,15 @@ this.getBlur = function (elem) {
filter.removeAttribute('height');
}
}
};
};
// Function: setBlur
// Adds/updates the blur filter to the selected element
//
// Parameters:
// val - Float with the new stdDeviation blur value
// complete - Boolean indicating whether or not the action should be completed (to add to the undo manager)
canvas.setBlur = function (val, complete) {
// Function: setBlur
// Adds/updates the blur filter to the selected element
//
// Parameters:
// val - Float with the new stdDeviation blur value
// complete - Boolean indicating whether or not the action should be completed (to add to the undo manager)
canvas.setBlur = function (val, complete) {
if (curCommand) {
finishChange();
return;
@ -5849,7 +5851,7 @@ this.getBlur = function (elem) {
canvas.setBlurNoUndo(val);
finishChange();
}
};
};
}());
// Function: getBold