diff --git a/editor/coords.js b/editor/coords.js index cc3d36fb..e2ee668e 100644 --- a/editor/coords.js +++ b/editor/coords.js @@ -1,3 +1,5 @@ +/*globals $, svgroot */ +/*jslint vars: true, eqeq: true, forin: true*/ /** * Coords. * @@ -15,7 +17,7 @@ var svgedit = svgedit || {}; -(function() { +(function() {'use strict'; if (!svgedit.coords) { svgedit.coords = {}; @@ -39,18 +41,24 @@ svgedit.coords.init = function(editorContext) { // changes - Object with changes to be remapped // m - Matrix object to use for remapping coordinates svgedit.coords.remapElement = function(selected, changes, m) { - var remap = function(x, y) { return svgedit.math.transformPoint(x, y, m); }, + var i, type, + remap = function(x, y) { return svgedit.math.transformPoint(x, y, m); }, scalew = function(w) { return m.a * w; }, scaleh = function(h) { return m.d * h; }, doSnapping = editorContext_.getGridSnapping() && selected.parentNode.parentNode.localName === 'svg', finishUp = function() { - if (doSnapping) for (var o in changes) changes[o] = svgedit.utilities.snapToGrid(changes[o]); + var o; + if (doSnapping) { + for (o in changes) { + changes[o] = svgedit.utilities.snapToGrid(changes[o]); + } + } svgedit.utilities.assignAttributes(selected, changes, 1000, true); }, box = svgedit.utilities.getBBox(selected); - - for (var i = 0; i < 2; i++) { - var type = i === 0 ? 'fill' : 'stroke'; + + for (i = 0; i < 2; i++) { + type = i === 0 ? 'fill' : 'stroke'; var attrVal = selected.getAttribute(type); if (attrVal && attrVal.indexOf('url(') === 0) { if (m.a < 0 || m.d < 0) { @@ -84,6 +92,7 @@ svgedit.coords.remapElement = function(selected, changes, m) { } var elName = selected.tagName; + var chlist, mt; if (elName === 'g' || elName === 'text' || elName == 'tspan' || elName === 'use') { // if it was a translate, then just update x,y if (m.a == 1 && m.b == 0 && m.c == 0 && m.d == 1 && (m.e != 0 || m.f != 0) ) { @@ -95,14 +104,14 @@ svgedit.coords.remapElement = function(selected, changes, m) { changes.y = parseFloat(changes.y) + t_new.f; } else { // we just absorb all matrices into the element and don't do any remapping - var chlist = svgedit.transformlist.getTransformList(selected); - var mt = svgroot.createSVGTransform(); + chlist = svgedit.transformlist.getTransformList(selected); + mt = svgroot.createSVGTransform(); mt.setMatrix(svgedit.math.matrixMultiply(svgedit.math.transformListToTransform(chlist).matrix, m)); chlist.clear(); chlist.appendItem(mt); } } - + var c, pt, pt1, pt2, len; // now we have a set of changes and an applied reduced transform list // we apply the changes directly to the DOM switch (elName) { @@ -112,13 +121,13 @@ svgedit.coords.remapElement = function(selected, changes, m) { // Allow images to be inverted (give them matrix when flipped) if (elName === 'image' && (m.a < 0 || m.d < 0)) { // Convert to matrix - var chlist = svgedit.transformlist.getTransformList(selected); - var mt = svgroot.createSVGTransform(); + chlist = svgedit.transformlist.getTransformList(selected); + mt = svgroot.createSVGTransform(); mt.setMatrix(svgedit.math.matrixMultiply(svgedit.math.transformListToTransform(chlist).matrix, m)); chlist.clear(); chlist.appendItem(mt); } else { - var pt1 = remap(changes.x, changes.y); + pt1 = remap(changes.x, changes.y); changes.width = scalew(changes.width); changes.height = scaleh(changes.height); changes.x = pt1.x + Math.min(0, changes.width); @@ -129,7 +138,7 @@ svgedit.coords.remapElement = function(selected, changes, m) { finishUp(); break; case 'ellipse': - var c = remap(changes.cx, changes.cy); + c = remap(changes.cx, changes.cy); changes.cx = c.x; changes.cy = c.y; changes.rx = scalew(changes.rx); @@ -139,7 +148,7 @@ svgedit.coords.remapElement = function(selected, changes, m) { finishUp(); break; case 'circle': - var c = remap(changes.cx,changes.cy); + c = remap(changes.cx,changes.cy); changes.cx = c.x; changes.cy = c.y; // take the minimum of the new selected box's dimensions for the new circle radius @@ -147,11 +156,12 @@ svgedit.coords.remapElement = function(selected, changes, m) { var w = tbox.tr.x - tbox.tl.x, h = tbox.bl.y - tbox.tl.y; changes.r = Math.min(w/2, h/2); - if (changes.r) changes.r = Math.abs(changes.r); + if (changes.r) {changes.r = Math.abs(changes.r);} finishUp(); break; case 'line': - var pt1 = remap(changes.x1, changes.y1), pt2 = remap(changes.x2, changes.y2); + pt1 = remap(changes.x1, changes.y1); + pt2 = remap(changes.x2, changes.y2); changes.x1 = pt1.x; changes.y1 = pt1.y; changes.x2 = pt2.x; @@ -170,87 +180,87 @@ svgedit.coords.remapElement = function(selected, changes, m) { break; case 'polyline': case 'polygon': - var len = changes.points.length; - for (var i = 0; i < len; ++i) { - var pt = changes.points[i]; - pt = remap(pt.x, pt.y); - changes.points[i].x = pt.x; - changes.points[i].y = pt.y; + len = changes.points.length; + for (i = 0; i < len; ++i) { + pt = changes.points[i]; + pt = remap(pt.x, pt.y); + changes.points[i].x = pt.x; + changes.points[i].y = pt.y; } - var len = changes.points.length; + len = changes.points.length; var pstr = ''; - for (var i = 0; i < len; ++i) { - var pt = changes.points[i]; - pstr += pt.x + ',' + pt.y + ' '; + for (i = 0; i < len; ++i) { + pt = changes.points[i]; + pstr += pt.x + ',' + pt.y + ' '; } selected.setAttribute('points', pstr); break; -case 'path': + case 'path': + var seg; + var segList = selected.pathSegList; + len = segList.numberOfItems; + changes.d = new Array(len); + for (i = 0; i < len; ++i) { + seg = segList.getItem(i); + changes.d[i] = { + type: seg.pathSegType, + x: seg.x, + y: seg.y, + x1: seg.x1, + y1: seg.y1, + x2: seg.x2, + y2: seg.y2, + r1: seg.r1, + r2: seg.r2, + angle: seg.angle, + largeArcFlag: seg.largeArcFlag, + sweepFlag: seg.sweepFlag + }; + } - var segList = selected.pathSegList; - var len = segList.numberOfItems; - changes.d = new Array(len); - for (var i = 0; i < len; ++i) { - var seg = segList.getItem(i); - changes.d[i] = { - type: seg.pathSegType, - x: seg.x, - y: seg.y, - x1: seg.x1, - y1: seg.y1, - x2: seg.x2, - y2: seg.y2, - r1: seg.r1, - r2: seg.r2, - angle: seg.angle, - largeArcFlag: seg.largeArcFlag, - sweepFlag: seg.sweepFlag - }; - } - - var len = changes.d.length, - firstseg = changes.d[0], - currentpt = remap(firstseg.x, firstseg.y); - changes.d[0].x = currentpt.x; - changes.d[0].y = currentpt.y; - for (var i = 1; i < len; ++i) { - var seg = changes.d[i]; - var type = seg.type; + len = changes.d.length; + var firstseg = changes.d[0], + currentpt = remap(firstseg.x, firstseg.y); + changes.d[0].x = currentpt.x; + changes.d[0].y = currentpt.y; + for (i = 1; i < len; ++i) { + seg = changes.d[i]; + type = seg.type; // if absolute or first segment, we want to remap x, y, x1, y1, x2, y2 // if relative, we want to scalew, scaleh if (type % 2 == 0) { // absolute - var thisx = (seg.x != undefined) ? seg.x : currentpt.x, // for V commands - thisy = (seg.y != undefined) ? seg.y : currentpt.y, // for H commands - pt = remap(thisx,thisy), - pt1 = remap(seg.x1, seg.y1), - pt2 = remap(seg.x2, seg.y2); - seg.x = pt.x; - seg.y = pt.y; - seg.x1 = pt1.x; - seg.y1 = pt1.y; - seg.x2 = pt2.x; - seg.y2 = pt2.y; - seg.r1 = scalew(seg.r1), - seg.r2 = scaleh(seg.r2); + var thisx = (seg.x != undefined) ? seg.x : currentpt.x, // for V commands + thisy = (seg.y != undefined) ? seg.y : currentpt.y; // for H commands + pt = remap(thisx,thisy); + pt1 = remap(seg.x1, seg.y1); + pt2 = remap(seg.x2, seg.y2); + seg.x = pt.x; + seg.y = pt.y; + seg.x1 = pt1.x; + seg.y1 = pt1.y; + seg.x2 = pt2.x; + seg.y2 = pt2.y; + seg.r1 = scalew(seg.r1); + seg.r2 = scaleh(seg.r2); } else { // relative - seg.x = scalew(seg.x); - seg.y = scaleh(seg.y); - seg.x1 = scalew(seg.x1); - seg.y1 = scaleh(seg.y1); - seg.x2 = scalew(seg.x2); - seg.y2 = scaleh(seg.y2); - seg.r1 = scalew(seg.r1), - seg.r2 = scaleh(seg.r2); + seg.x = scalew(seg.x); + seg.y = scaleh(seg.y); + seg.x1 = scalew(seg.x1); + seg.y1 = scaleh(seg.y1); + seg.x2 = scalew(seg.x2); + seg.y2 = scaleh(seg.y2); + seg.r1 = scalew(seg.r1); + seg.r2 = scaleh(seg.r2); } - } // for each segment + } // for each segment - var dstr = ''; - var len = changes.d.length; - for (var i = 0; i < len; ++i) { - var seg = changes.d[i]; - var type = seg.type; + var dstr = ''; + len = changes.d.length; + for (i = 0; i < len; ++i) { + seg = changes.d[i]; + type = seg.type; dstr += pathMap[type]; switch (type) { case 13: // relative horizontal line (h) @@ -287,12 +297,12 @@ case 'path': case 16: // absolute smooth cubic (S) dstr += seg.x2 + ',' + seg.y2 + ' ' + seg.x + ',' + seg.y + ' '; break; - } - } + } + } - selected.setAttribute('d', dstr); - break; + selected.setAttribute('d', dstr); + break; } }; -})(); \ No newline at end of file +}()); \ No newline at end of file diff --git a/editor/draw.js b/editor/draw.js index 9f43f77b..f95d0567 100644 --- a/editor/draw.js +++ b/editor/draw.js @@ -1,3 +1,5 @@ +/*globals $, svgedit*/ +/*jslint vars: true, eqeq: true*/ /** * Package: svgedit.draw * @@ -11,7 +13,7 @@ // 2) browser.js // 3) svgutils.js -(function() { +(function() {'use strict'; if (!svgedit.draw) { svgedit.draw = {}; @@ -169,7 +171,7 @@ svgedit.draw.Drawing.prototype.clearNonce = function() { svgedit.draw.Drawing.prototype.getId = function() { return this.nonce_ ? this.idPrefix + this.nonce_ + '_' + this.obj_num : - this.idPrefix + this.obj_num; + this.idPrefix + this.obj_num; }; /** @@ -225,7 +227,7 @@ svgedit.draw.Drawing.prototype.releaseId = function(id) { return false; } // extract the obj_num of this id - var num = parseInt(id.substr(front.length)); + var num = parseInt(id.substr(front.length), 10); // if we didn't get a positive number or we already released this number // then return false. @@ -251,8 +253,9 @@ svgedit.draw.Drawing.prototype.getNumLayers = function() { // Function: svgedit.draw.Drawing.hasLayer // Check if layer with given name already exists svgedit.draw.Drawing.prototype.hasLayer = function(name) { - for(var i = 0; i < this.getNumLayers(); i++) { - if(this.all_layers[i][0] == name) return true; + var i; + for (i = 0; i < this.getNumLayers(); i++) { + if(this.all_layers[i][0] == name) {return true;} } return false; }; @@ -287,7 +290,8 @@ svgedit.draw.Drawing.prototype.getCurrentLayer = function() { // Returns: // The name of the currently active layer. svgedit.draw.Drawing.prototype.getCurrentLayerName = function() { - for (var i = 0; i < this.getNumLayers(); ++i) { + var i; + for (i = 0; i < this.getNumLayers(); ++i) { if (this.all_layers[i][1] == this.current_layer) { return this.getLayerName(i); } @@ -305,7 +309,8 @@ svgedit.draw.Drawing.prototype.getCurrentLayerName = function() { // Returns: // true if the current layer was switched, otherwise false svgedit.draw.Drawing.prototype.setCurrentLayer = function(name) { - for (var i = 0; i < this.getNumLayers(); ++i) { + var i; + for (i = 0; i < this.getNumLayers(); ++i) { if (name == this.getLayerName(i)) { if (this.current_layer != this.all_layers[i][1]) { this.current_layer.setAttribute("style", "pointer-events:none"); @@ -346,7 +351,8 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() { var orphans = [], layernames = []; var a_layer = null; var childgroups = false; - for (var i = 0; i < numchildren; ++i) { + var i; + for (i = 0; i < numchildren; ++i) { var child = this.svgElem_.childNodes.item(i); // for each g, find its layer name if (child && child.nodeType == 1) { @@ -383,7 +389,7 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() { // create a new layer and add all the orphans to it var svgdoc = this.svgElem_.ownerDocument; if (orphans.length > 0 || !childgroups) { - var i = 1; + i = 1; // TODO(codedread): What about internationalization of "Layer"? while (layernames.indexOf(("Layer " + i)) >= 0) { i++; } var newname = "Layer " + i; @@ -391,7 +397,8 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() { var layer_title = svgdoc.createElementNS(NS.SVG, "title"); layer_title.textContent = newname; a_layer.appendChild(layer_title); - for (var j = 0; j < orphans.length; ++j) { + var j; + for (j = 0; j < orphans.length; ++j) { a_layer.appendChild(orphans[j]); } this.svgElem_.appendChild(a_layer); @@ -435,13 +442,14 @@ svgedit.draw.Drawing.prototype.createLayer = function(name) { svgedit.draw.Drawing.prototype.getLayerVisibility = function(layername) { // find the layer var layer = null; - for (var i = 0; i < this.getNumLayers(); ++i) { + var i; + for (i = 0; i < this.getNumLayers(); ++i) { if (this.getLayerName(i) == layername) { layer = this.all_layers[i][1]; break; } } - if (!layer) return false; + if (!layer) {return false;} return (layer.getAttribute('display') != 'none'); }; @@ -461,16 +469,17 @@ svgedit.draw.Drawing.prototype.setLayerVisibility = function(layername, bVisible } // find the layer var layer = null; - for (var i = 0; i < this.getNumLayers(); ++i) { + var i; + for (i = 0; i < this.getNumLayers(); ++i) { if (this.getLayerName(i) == layername) { layer = this.all_layers[i][1]; break; } } - if (!layer) return null; + if (!layer) {return null;} var oldDisplay = layer.getAttribute("display"); - if (!oldDisplay) oldDisplay = "inline"; + if (!oldDisplay) {oldDisplay = "inline";} layer.setAttribute("display", bVisible ? "inline" : "none"); return layer; }; @@ -486,7 +495,8 @@ svgedit.draw.Drawing.prototype.setLayerVisibility = function(layername, bVisible // The opacity value of the given layer. This will be a value between 0.0 and 1.0, or null // if layername is not a valid layer svgedit.draw.Drawing.prototype.getLayerOpacity = function(layername) { - for (var i = 0; i < this.getNumLayers(); ++i) { + var i; + for (i = 0; i < this.getNumLayers(); ++i) { if (this.getLayerName(i) == layername) { var g = this.all_layers[i][1]; var opacity = g.getAttribute('opacity'); @@ -510,7 +520,8 @@ svgedit.draw.Drawing.prototype.setLayerOpacity = function(layername, opacity) { if (typeof opacity != typeof 1.0 || opacity < 0.0 || opacity > 1.0) { return; } - for (var i = 0; i < this.getNumLayers(); ++i) { + var i; + for (i = 0; i < this.getNumLayers(); ++i) { if (this.getLayerName(i) == layername) { var g = this.all_layers[i][1]; g.setAttribute("opacity", opacity); @@ -519,4 +530,4 @@ svgedit.draw.Drawing.prototype.setLayerOpacity = function(layername, opacity) { } }; -})(); +}()); diff --git a/editor/embedapi.js b/editor/embedapi.js index f45ced7f..e3bd5a3d 100644 --- a/editor/embedapi.js +++ b/editor/embedapi.js @@ -98,12 +98,13 @@ function EmbeddedSVGEdit(frame){ if (typeof e.data !== 'string') { return; } - var data = e.data && JSON.parse(e.data); + var result, cbid, + data = e.data && JSON.parse(e.data); if (!data || typeof data !== 'object' || data.namespace !== 'svg-edit') { return; } - var result = data.result || data.error, - cbid = data.id; + result = data.result || data.error; + cbid = data.id; if(t.callbacks[cbid]){ if(data.result){ t.callbacks[cbid](result); diff --git a/editor/history.js b/editor/history.js index 16a9f4bd..a5cc4051 100644 --- a/editor/history.js +++ b/editor/history.js @@ -1,3 +1,5 @@ +/*globals svgedit*/ +/*jslint vars: true, eqeq: true, continue: true, forin: true*/ /** * Package: svedit.history * @@ -11,7 +13,7 @@ // 2) svgtransformlist.js // 3) svgutils.js -(function() { +(function() {'use strict'; if (!svgedit.history) { svgedit.history = {}; @@ -253,10 +255,11 @@ svgedit.history.ChangeElementCommand = function(elem, attrs, text) { this.text = text ? ("Change " + elem.tagName + " " + text) : ("Change " + elem.tagName); this.newValues = {}; this.oldValues = attrs; - for (var attr in attrs) { - if (attr == "#text") this.newValues[attr] = elem.textContent; - else if (attr == "#href") this.newValues[attr] = svgedit.utilities.getHref(elem); - else this.newValues[attr] = elem.getAttribute(attr); + var attr; + for (attr in attrs) { + if (attr == "#text") {this.newValues[attr] = elem.textContent;} + else if (attr == "#href") {this.newValues[attr] = svgedit.utilities.getHref(elem);} + else {this.newValues[attr] = elem.getAttribute(attr);} } }; svgedit.history.ChangeElementCommand.type = function() { return 'svgedit.history.ChangeElementCommand'; }; @@ -275,11 +278,12 @@ svgedit.history.ChangeElementCommand.prototype.apply = function(handler) { } var bChangedTransform = false; - for (var attr in this.newValues ) { + var attr; + for (attr in this.newValues ) { if (this.newValues[attr]) { - if (attr == "#text") this.elem.textContent = this.newValues[attr]; - else if (attr == "#href") svgedit.utilities.setHref(this.elem, this.newValues[attr]); - else this.elem.setAttribute(attr, this.newValues[attr]); + if (attr == "#text") {this.elem.textContent = this.newValues[attr];} + else if (attr == "#href") {svgedit.utilities.setHref(this.elem, this.newValues[attr]);} + else {this.elem.setAttribute(attr, this.newValues[attr]);} } else { if (attr == "#text") { @@ -298,6 +302,8 @@ svgedit.history.ChangeElementCommand.prototype.apply = function(handler) { if (!bChangedTransform) { var angle = svgedit.utilities.getRotationAngle(this.elem); if (angle) { + // TODO: These instances of elem either need to be declared as global + // (which would not be good for conflicts) or declare/use this.elem var bbox = elem.getBBox(); var cx = bbox.x + bbox.width/2, cy = bbox.y + bbox.height/2; @@ -323,17 +329,20 @@ svgedit.history.ChangeElementCommand.prototype.unapply = function(handler) { } var bChangedTransform = false; - for (var attr in this.oldValues ) { + var attr; + for (attr in this.oldValues ) { if (this.oldValues[attr]) { - if (attr == "#text") this.elem.textContent = this.oldValues[attr]; - else if (attr == "#href") svgedit.utilities.setHref(this.elem, this.oldValues[attr]); - else this.elem.setAttribute(attr, this.oldValues[attr]); + if (attr == "#text") {this.elem.textContent = this.oldValues[attr];} + else if (attr == "#href") {svgedit.utilities.setHref(this.elem, this.oldValues[attr]);} + else { + this.elem.setAttribute(attr, this.oldValues[attr]); + } } else { if (attr == "#text") { this.elem.textContent = ""; } - else this.elem.removeAttribute(attr); + else {this.elem.removeAttribute(attr);} } if (attr == "transform") { bChangedTransform = true; } } @@ -398,8 +407,9 @@ svgedit.history.BatchCommand.prototype.apply = function(handler) { handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_APPLY, this); } - var len = this.stack.length; - for (var i = 0; i < len; ++i) { + var i, + len = this.stack.length; + for (i = 0; i < len; ++i) { this.stack[i].apply(handler); } @@ -415,7 +425,8 @@ svgedit.history.BatchCommand.prototype.unapply = function(handler) { handler.handleHistoryEvent(svgedit.history.HistoryEventTypes.BEFORE_UNAPPLY, this); } - for (var i = this.stack.length-1; i >= 0; i--) { + var i; + for (i = this.stack.length-1; i >= 0; i--) { this.stack[i].unapply(handler); } @@ -433,7 +444,7 @@ svgedit.history.BatchCommand.prototype.elements = function() { var thisElems = this.stack[cmd].elements(); var elem = thisElems.length; while (elem--) { - if (elems.indexOf(thisElems[elem]) == -1) elems.push(thisElems[elem]); + if (elems.indexOf(thisElems[elem]) == -1) {elems.push(thisElems[elem]);} } } return elems; @@ -560,7 +571,7 @@ svgedit.history.UndoManager.prototype.beginUndoableChange = function(attrName, e var oldValues = new Array(i), elements = new Array(i); while (i--) { var elem = elems[i]; - if (elem == null) continue; + if (elem == null) {continue;} elements[i] = elem; oldValues[i] = elem.getAttribute(attrName); } @@ -586,7 +597,7 @@ svgedit.history.UndoManager.prototype.finishUndoableChange = function() { var batchCmd = new svgedit.history.BatchCommand("Change " + attrName); while (i--) { var elem = changeset.elements[i]; - if (elem == null) continue; + if (elem == null) {continue;} var changes = {}; changes[attrName] = changeset.oldValues[i]; if (changes[attrName] != elem.getAttribute(attrName)) { @@ -597,4 +608,4 @@ svgedit.history.UndoManager.prototype.finishUndoableChange = function() { return batchCmd; }; -})(); \ No newline at end of file +}()); \ No newline at end of file diff --git a/editor/jquery-svg.js b/editor/jquery-svg.js index 200ad76e..e2cadefe 100644 --- a/editor/jquery-svg.js +++ b/editor/jquery-svg.js @@ -1,3 +1,5 @@ +/*globals $, jQuery */ +/*jslint vars: true */ /** * jQuery module to work with SVG. * @@ -8,7 +10,7 @@ // Dependencies: // 1) jquery -(function() { +(function() {'use strict'; // This fixes $(...).attr() to work as expected with SVG elements. // Does not currently use *AttributeNS() since we rarely need that. @@ -24,9 +26,10 @@ // TODO use NS.SVG instead svgns = "http://www.w3.org/2000/svg"; jQuery.fn.attr = function(key, value) { - var len = this.length; - if (!len) return proxied.apply(this, arguments); - for (var i = 0; i < len; ++i) { + var i, attr; + var len = this.length; + if (!len) {return proxied.apply(this, arguments);} + for (i = 0; i < len; ++i) { var elem = this[i]; // set/get SVG attribute if (elem.namespaceURI === svgns) { @@ -39,7 +42,7 @@ while (j--) { var aname = key[j]; - var attr = elem.getAttribute(aname); + attr = elem.getAttribute(aname); // This returns a number when appropriate if (attr || attr === "0") { attr = isNaN(attr) ? attr : (attr - 0); @@ -47,14 +50,16 @@ obj[aname] = attr; } return obj; - } else if (typeof key === "object") { + } + if (typeof key === "object") { // Setting attributes form object - for (var v in key) { + var v; + for (v in key) { elem.setAttribute(v, key[v]); } // Getting attribute } else { - var attr = elem.getAttribute(key); + attr = elem.getAttribute(key); if (attr || attr === "0") { attr = isNaN(attr) ? attr : (attr - 0); } diff --git a/editor/math.js b/editor/math.js index acdab5e2..b2d766c2 100644 --- a/editor/math.js +++ b/editor/math.js @@ -1,3 +1,5 @@ +/*globals svgedit*/ +/*jslint vars: true, eqeq: true */ /** * Package: svedit.math * @@ -10,7 +12,7 @@ // Dependencies: // None. -(function() { +(function() {'use strict'; if (!svgedit.math) { svgedit.math = {}; @@ -66,12 +68,12 @@ svgedit.math.matrixMultiply = function() { var m1 = args[i-1]; m = m1.multiply(m); } - if (Math.abs(m.a) < NEAR_ZERO) m.a = 0; - if (Math.abs(m.b) < NEAR_ZERO) m.b = 0; - if (Math.abs(m.c) < NEAR_ZERO) m.c = 0; - if (Math.abs(m.d) < NEAR_ZERO) m.d = 0; - if (Math.abs(m.e) < NEAR_ZERO) m.e = 0; - if (Math.abs(m.f) < NEAR_ZERO) m.f = 0; + if (Math.abs(m.a) < NEAR_ZERO) {m.a = 0;} + if (Math.abs(m.b) < NEAR_ZERO) {m.b = 0;} + if (Math.abs(m.c) < NEAR_ZERO) {m.c = 0;} + if (Math.abs(m.d) < NEAR_ZERO) {m.d = 0;} + if (Math.abs(m.e) < NEAR_ZERO) {m.e = 0;} + if (Math.abs(m.f) < NEAR_ZERO) {m.f = 0;} return m; }; @@ -85,11 +87,11 @@ svgedit.math.matrixMultiply = function() { // Returns: // Boolean on whether or not a matrix transform was found svgedit.math.hasMatrixTransform = function(tlist) { - if (!tlist) return false; + if (!tlist) {return false;} var num = tlist.numberOfItems; while (num--) { var xform = tlist.getItem(num); - if (xform.type == 1 && !svgedit.math.isIdentity(xform.matrix)) return true; + if (xform.type == 1 && !svgedit.math.isIdentity(xform.matrix)) {return true;} } return false; }; @@ -166,7 +168,8 @@ svgedit.math.transformListToTransform = function(tlist, min, max) { max = parseInt(max, 10); if (min > max) { var temp = max; max = min; min = temp; } var m = svg.createSVGMatrix(); - for (var i = min; i <= max; ++i) { + var i; + for (i = min; i <= max; ++i) { // if our indices are out of range, just use a harmless identity matrix var mtom = (i >= 0 && i < tlist.numberOfItems ? tlist.getItem(i).matrix : @@ -238,4 +241,4 @@ svgedit.math.rectsIntersect = function(r1, r2) { (r2.y+r2.height) > r1.y; }; -})(); \ No newline at end of file +}()); \ No newline at end of file diff --git a/editor/svg-editor.js b/editor/svg-editor.js index d3337daf..dc81d6e0 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -942,10 +942,11 @@ if (toolButtonClick(show_sel)) { options.fn(); } + var icon; if (options.icon) { - var icon = $.getSvgIcon(options.icon, true); + icon = $.getSvgIcon(options.icon, true); } else { - var icon = $(options.sel).children().eq(0).clone(); + icon = $(options.sel).children().eq(0).clone(); } icon[0].setAttribute('width', shower.width()); @@ -1169,7 +1170,7 @@ // Add buttons given by extension $.each(ext.buttons, function(i, btn) { - var icon; + var icon, svgicon; var id = btn.id; var num = i; @@ -1182,7 +1183,7 @@ icon = $(''); } else { fallback_obj[id] = btn.icon; - var svgicon = btn.svgicon || btn.id; + svgicon = btn.svgicon || btn.id; if (btn.type == 'app_menu') { placement_obj['#' + id + ' > div'] = svgicon; } else { @@ -1212,7 +1213,7 @@ parent = '#main_menu ul'; break; } - + var flyout_holder, cur_h, show_btn; var button = $((btn.list || btn.type == 'app_menu') ? '
' : '') .attr('id', id) .attr('title', btn.title) @@ -1230,12 +1231,12 @@ // // opts.button, default, position var ref_btn = $(button); - var flyout_holder = ref_btn.parent(); + flyout_holder = ref_btn.parent(); // Create a flyout menu if there isn't one already if (!ref_btn.parent().hasClass('tools_flyout')) { // Create flyout placeholder var tls_id = ref_btn[0].id.replace('tool_', 'tools_'); - var show_btn = ref_btn.clone() + show_btn = ref_btn.clone() .attr('id',tls_id + '_show') .append($('