From 6023bd6f5a6ffad3864022d28fa6322fb33e7817 Mon Sep 17 00:00:00 2001 From: Flint O'Brien Date: Wed, 4 May 2016 09:54:20 -0400 Subject: [PATCH] Formatting changes. --- editor/layer.js | 150 ++++++++++++++++++++++---------------------- editor/svgcanvas.js | 4 +- editor/svgutils.js | 4 +- test/draw_test.html | 30 ++++----- 4 files changed, 94 insertions(+), 94 deletions(-) diff --git a/editor/layer.js b/editor/layer.js index 2124abd2..8b5a09d2 100644 --- a/editor/layer.js +++ b/editor/layer.js @@ -17,7 +17,7 @@ 'use strict'; if (!svgedit.draw) { - svgedit.draw = {}; + svgedit.draw = {}; } var NS = svgedit.NS; @@ -27,9 +27,9 @@ var NS = svgedit.NS; * an existing group element or, with three parameters, will create a new layer group element. * * Usage: - * new Layer( 'name', group) // Use the existing group for this layer. - * new Layer( 'name', group, svgElem) // Create a new group and add it to the DOM after group. - * new Layer( 'name', null, svgElem) // Create a new group and add it to the DOM as the last layer. + * new Layer'name', group) // Use the existing group for this layer. + * new Layer('name', group, svgElem) // Create a new group and add it to the DOM after group. + * new Layer('name', null, svgElem) // Create a new group and add it to the DOM as the last layer. * * @param {string} name - Layer name * @param {SVGGElement|null} group - An existing SVG group element or null. @@ -40,27 +40,27 @@ var NS = svgedit.NS; * a new layer to the document. */ var Layer = svgedit.draw.Layer = function(name, group, svgElem) { - this.name_ = name; - this.group_ = svgElem ? null : group; + this.name_ = name; + this.group_ = svgElem ? null : group; - if (svgElem) { - // Create a group element with title and add it to the DOM. - var svgdoc = svgElem.ownerDocument; - this.group_ = svgdoc.createElementNS(NS.SVG, "g"); - var layer_title = svgdoc.createElementNS(NS.SVG, "title"); - layer_title.textContent = name; - this.group_.appendChild(layer_title); - if( group) { - $(group).after(this.group_); - } else { - svgElem.appendChild(this.group_); - } - } + if (svgElem) { + // Create a group element with title and add it to the DOM. + var svgdoc = svgElem.ownerDocument; + this.group_ = svgdoc.createElementNS(NS.SVG, "g"); + var layer_title = svgdoc.createElementNS(NS.SVG, "title"); + layer_title.textContent = name; + this.group_.appendChild(layer_title); + if (group) { + $(group).after(this.group_); + } else { + svgElem.appendChild(this.group_); + } + } - addLayerClass(this.group_); - svgedit.utilities.walkTree(this.group_, function(e){e.setAttribute("style", "pointer-events:inherit");}); + addLayerClass(this.group_); + svgedit.utilities.walkTree(this.group_, function(e){e.setAttribute("style", "pointer-events:inherit");}); - this.group_.setAttribute("style", svgElem ? "pointer-events:all" : "pointer-events:none"); + this.group_.setAttribute("style", svgElem ? "pointer-events:all" : "pointer-events:none"); }; /** @@ -79,7 +79,7 @@ Layer.CLASS_REGEX = new RegExp('(\\s|^)' + Layer.CLASS_NAME + '(\\s|$)'); * @returns {string} The layer name */ Layer.prototype.getName = function() { - return this.name_; + return this.name_; }; /** @@ -87,21 +87,21 @@ Layer.prototype.getName = function() { * @returns {SVGGElement} The layer SVG group */ Layer.prototype.getGroup = function() { - return this.group_; + return this.group_; }; /** * Active this layer so it takes pointer events. */ Layer.prototype.activate = function() { - this.group_.setAttribute("style", "pointer-events:all"); + this.group_.setAttribute("style", "pointer-events:all"); }; /** * Deactive this layer so it does NOT take pointer events. */ Layer.prototype.deactivate = function() { - this.group_.setAttribute("style", "pointer-events:none"); + this.group_.setAttribute("style", "pointer-events:none"); }; /** @@ -109,11 +109,11 @@ Layer.prototype.deactivate = function() { * @param {boolean} visible - If true, make visible; otherwise, hide it. */ Layer.prototype.setVisible = function(visible) { - var expected = visible === undefined || visible ? "inline" : "none"; - var oldDisplay = this.group_.getAttribute("display"); - if (oldDisplay !== expected) { - this.group_.setAttribute("display", expected); - } + var expected = visible === undefined || visible ? "inline" : "none"; + var oldDisplay = this.group_.getAttribute("display"); + if (oldDisplay !== expected) { + this.group_.setAttribute("display", expected); + } }; /** @@ -121,7 +121,7 @@ Layer.prototype.setVisible = function(visible) { * @returns {boolean} True if visible. */ Layer.prototype.isVisible = function() { - return this.group_.getAttribute('display') !== 'none'; + return this.group_.getAttribute('display') !== 'none'; }; /** @@ -129,11 +129,11 @@ Layer.prototype.isVisible = function() { * @returns {number} Opacity value. */ Layer.prototype.getOpacity = function() { - var opacity = this.group_.getAttribute('opacity'); - if (opacity === null || opacity === undefined) { - return 1; - } - return parseFloat(opacity); + var opacity = this.group_.getAttribute('opacity'); + if (opacity === null || opacity === undefined) { + return 1; + } + return parseFloat(opacity); }; /** @@ -142,9 +142,9 @@ Layer.prototype.getOpacity = function() { * @param {number} opacity - A float value in the range 0.0-1.0 */ Layer.prototype.setOpacity = function(opacity) { - if (typeof opacity === 'number' && opacity >= 0.0 && opacity <= 1.0) { - this.group_.setAttribute('opacity', opacity); - } + if (typeof opacity === 'number' && opacity >= 0.0 && opacity <= 1.0) { + this.group_.setAttribute('opacity', opacity); + } }; /** @@ -152,20 +152,20 @@ Layer.prototype.setOpacity = function(opacity) { * @param {SVGGElement} children - The children to append to this layer. */ Layer.prototype.appendChildren = function(children) { - for (var i = 0; i < children.length; ++i) { - this.group_.appendChild(children[i]); - } + for (var i = 0; i < children.length; ++i) { + this.group_.appendChild(children[i]); + } }; Layer.prototype.getTitleElement = function() { - var len = this.group_.childNodes.length; - for (var i = 0; i < len; ++i) { - var child = this.group_.childNodes.item(i); - if (child && child.tagName === 'title') { - return child; - } - } - return null; + var len = this.group_.childNodes.length; + for (var i = 0; i < len; ++i) { + var child = this.group_.childNodes.item(i); + if (child && child.tagName === 'title') { + return child; + } + } + return null; }; /** @@ -175,20 +175,20 @@ Layer.prototype.getTitleElement = function() { * @returns {string|null} The new name if changed; otherwise, null. */ Layer.prototype.setName = function(name, hrService) { - var previousName = this.name_; - name = svgedit.utilities.toXml(name); - // now change the underlying title element contents - var title = this.getTitleElement(); - if (title) { - while (title.firstChild) { title.removeChild(title.firstChild); } - title.textContent = name; - this.name_ = name; - if( hrService) { - hrService.changeElement(title, {'#text':previousName}); - } - return this.name_; - } - return null; + var previousName = this.name_; + name = svgedit.utilities.toXml(name); + // now change the underlying title element contents + var title = this.getTitleElement(); + if (title) { + while (title.firstChild) { title.removeChild(title.firstChild); } + title.textContent = name; + this.name_ = name; + if (hrService) { + hrService.changeElement(title, {'#text':previousName}); + } + return this.name_; + } + return null; }; /** @@ -197,10 +197,10 @@ Layer.prototype.setName = function(name, hrService) { * @returns {SVGGElement} The layer SVG group that was just removed. */ Layer.prototype.removeGroup = function() { - var parent = this.group_.parentNode; - var group = parent.removeChild(this.group_); - this.group_ = undefined; - return group; + var parent = this.group_.parentNode; + var group = parent.removeChild(this.group_); + this.group_ = undefined; + return group; }; @@ -211,12 +211,12 @@ Layer.prototype.removeGroup = function() { * @param {SVGGElement} elem - The SVG element to update */ function addLayerClass(elem) { - var classes = elem.getAttribute('class'); - if (classes === null || classes === undefined || classes.length === 0) { - elem.setAttribute('class', Layer.CLASS_NAME); - } else if (! Layer.CLASS_REGEX.test(classes)) { - elem.setAttribute('class', classes + ' ' + Layer.CLASS_NAME); - } + var classes = elem.getAttribute('class'); + if (classes === null || classes === undefined || classes.length === 0) { + elem.setAttribute('class', Layer.CLASS_NAME); + } else if (! Layer.CLASS_REGEX.test(classes)) { + elem.setAttribute('class', classes + ' ' + Layer.CLASS_NAME); + } } }()); diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 8f93d699..754745fc 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -360,7 +360,7 @@ var addCommandToHistory = function(cmd) { * @param {svgedit.history.HistoryRecordingService=} hrService - if exists, return it instead of creating a new service. * @returns {svgedit.history.HistoryRecordingService} */ -function historyRecordingService( hrService) { +function historyRecordingService(hrService) { return hrService ? hrService : new svgedit.history.HistoryRecordingService(canvas.undoMgr); } @@ -7174,7 +7174,7 @@ this.getPrivateMethods = function() { BatchCommand: BatchCommand, call: call, ChangeElementCommand: ChangeElementCommand, - copyElem: function( elem) {return getCurrentDrawing().copyElem(elem)}, + copyElem: function(elem) {return getCurrentDrawing().copyElem(elem)}, ffClone: ffClone, findDefs: findDefs, findDuplicateGradient: findDuplicateGradient, diff --git a/editor/svgutils.js b/editor/svgutils.js index 50da7e36..e01916e6 100644 --- a/editor/svgutils.js +++ b/editor/svgutils.js @@ -1211,10 +1211,10 @@ function pathDSegment(letter, points, morePoints, lastPoint) { points[i] = svgedit.units.shortFloat(pnt); }); var segment = letter + points.join(' '); - if( morePoints) { + if (morePoints) { segment += ' ' + morePoints.join(' '); } - if( lastPoint) { + if (lastPoint) { segment += ' ' + svgedit.units.shortFloat(lastPoint); } return segment; diff --git a/test/draw_test.html b/test/draw_test.html index 401942e8..87a5f3be 100644 --- a/test/draw_test.html +++ b/test/draw_test.html @@ -465,18 +465,18 @@ var oldName = drawing.getCurrentLayerName(); var newName = 'New Name' - ok( drawing.layer_map[oldName]); - equals( drawing.layer_map[newName], undefined); // newName shouldn't exist. + ok(drawing.layer_map[oldName]); + equals(drawing.layer_map[newName], undefined); // newName shouldn't exist. var result = drawing.setCurrentLayerName(newName, mockHrService); equals(result, newName); equals(drawing.getCurrentLayerName(), newName); // Was the map updated? - equals( drawing.layer_map[oldName], undefined); - equals( drawing.layer_map[newName], drawing.current_layer); + equals(drawing.layer_map[oldName], undefined); + equals(drawing.layer_map[newName], drawing.current_layer); // Was mockHrService called? - ok( mockHrService.changeElement.calledOnce); - equals( oldName, mockHrService.changeElement.getCall(0).args[1]['#text']); - equals( newName, mockHrService.changeElement.getCall(0).args[0].textContent); + ok(mockHrService.changeElement.calledOnce); + equals(oldName, mockHrService.changeElement.getCall(0).args[1]['#text']); + equals(newName, mockHrService.changeElement.getCall(0).args[0].textContent); cleanupSvg(svg); }); @@ -506,8 +506,8 @@ equals(NEW_LAYER_NAME, drawing.getLayerName(3)); equals(layer_g, mockHrService.insertElement.getCall(0).args[0]); - ok( mockHrService.startBatchCommand.calledOnce); - ok( mockHrService.endBatchCommand.calledOnce); + ok(mockHrService.startBatchCommand.calledOnce); + ok(mockHrService.endBatchCommand.calledOnce); cleanupSvg(svg); }); @@ -540,8 +540,8 @@ // check history record - ok( mockHrService.startBatchCommand.calledOnce); - ok( mockHrService.endBatchCommand.calledOnce); + ok(mockHrService.startBatchCommand.calledOnce); + ok(mockHrService.endBatchCommand.calledOnce); equals(mockHrService.startBatchCommand.getCall(0).args[0], 'Merge Layer'); equals(mockHrService.moveElement.callCount, elementCount - 1); // -1 because the title was not moved. equals(mockHrService.removeElement.callCount, 2); // remove group and title. @@ -611,8 +611,8 @@ equals(layers[0].childElementCount, elementCount * 3 - 2); // -2 because two titles were deleted. // check history record - equals( mockHrService.startBatchCommand.callCount, 3); // mergeAllLayers + 2 * mergeLayer - equals( mockHrService.endBatchCommand.callCount, 3); + equals(mockHrService.startBatchCommand.callCount, 3); // mergeAllLayers + 2 * mergeLayer + equals(mockHrService.endBatchCommand.callCount, 3); equals(mockHrService.startBatchCommand.getCall(0).args[0], 'Merge all Layers'); equals(mockHrService.startBatchCommand.getCall(1).args[0], 'Merge Layer'); equals(mockHrService.startBatchCommand.getCall(2).args[0], 'Merge Layer'); @@ -649,8 +649,8 @@ equals(clone.childElementCount, elementCount); // check history record - ok( mockHrService.startBatchCommand.calledOnce); // mergeAllLayers + 2 * mergeLayer - ok( mockHrService.endBatchCommand.calledOnce); + ok(mockHrService.startBatchCommand.calledOnce); // mergeAllLayers + 2 * mergeLayer + ok(mockHrService.endBatchCommand.calledOnce); equals(mockHrService.startBatchCommand.getCall(0).args[0], 'Duplicate Layer'); equals(mockHrService.insertElement.callCount, 1); equals(mockHrService.insertElement.getCall(0).args[0], clone);