strict comparisons

master
Mark MacKay 2021-03-03 14:32:06 -06:00
parent a87309c080
commit 4c40b637e5
12 changed files with 60 additions and 60 deletions

View File

@ -18,11 +18,11 @@ MD.Canvas = function(){
w.removeAttribute("readonly");
w.focus();
w.select();
if(w.value == 'fit') {
if(w.value === 'fit') {
w.value = 100
h.value = 100
}
} else if(this.value == 'content') {
} else if(this.value === 'content') {
w.value = 'fit'
h.value = 'fit'
changeSize();

View File

@ -3,7 +3,7 @@ MD.Image = function(){
const reader = new FileReader();
function importImage(e){
const file = (e.type == "drop") ? e.dataTransfer.files[0] : this.files[0];
const file = (e.type === "drop") ? e.dataTransfer.files[0] : this.files[0];
if (!file || file.type.indexOf("image") ) return alert("That doesn't seem to be an image");
if(file.type.indexOf("svg") != -1) importSvg(file)

View File

@ -16,7 +16,7 @@ MD.Import = function(){
workarea.removeAttribute("style");
$('#main_menu').hide();
var file = null;
if (e.type == "drop") file = e.dataTransfer.files[0]
if (e.type === "drop") file = e.dataTransfer.files[0]
else file = this.files[0];
if (!file) return $.alert("File not found");
if (file.type.indexOf("image") === -1) return $.alert("File is not image");
@ -91,7 +91,7 @@ MD.Import = function(){
function openImage(e){
const f = this;
if(f.files.length===1) {
if(f.files.length === 1) {
console.log("clear")
svgCanvas.clear();
var reader = new FileReader();

View File

@ -1,12 +1,12 @@
MD.PaintBox = function(container, type){
var _self = this;
var colorPicker = function(elem) {
var picker = elem[0].id == 'stroke_color' ? 'stroke' : 'fill';
var is_background = elem[0].id == "canvas_color"
var picker = elem[0].id === 'stroke_color' ? 'stroke' : 'fill';
var is_background = elem[0].id === "canvas_color"
if (is_background) picker = 'canvas'
var paint = editor.paintBox[picker].paint;
var title = (picker == 'stroke' ? 'Pick a Stroke Paint and Opacity' : 'Pick a Fill Paint and Opacity');
var title = (picker === 'stroke' ? 'Pick a Stroke Paint and Opacity' : 'Pick a Fill Paint and Opacity');
var was_none = false;
var pos = is_background ? {'right': 175, 'top': 50} : {'left': 50, 'bottom': 50}
@ -106,7 +106,7 @@ MD.PaintBox = function(container, type){
var opac = paint.alpha / 100;
switch ( ptype ) {
case 'solidColor':
fillAttr = (paint[ptype] == 'none' || paint[ptype] == 'one') ? 'none' : "#" + paint[ptype];
fillAttr = (paint[ptype] === 'none' || paint[ptype] === 'one') ? 'none' : "#" + paint[ptype];
break;
case 'linearGradient':
case 'radialGradient':

View File

@ -126,7 +126,7 @@ MD.Panel = function(){
$('#path_node_y').val(Math.round(point.y));
if(point.type) {
seg_type.val(point.type).removeAttr('disabled');
$("#seg_type_label").html(point.type == 4 ? "Straight" : "Curve")
$("#seg_type_label").html(point.type === 4 ? "Straight" : "Curve")
} else {
seg_type.val(4).attr('disabled','disabled');
}
@ -185,7 +185,7 @@ MD.Panel = function(){
}
// Elements in this array cannot be converted to a path
var no_path = ['image', 'text', 'path', 'g', 'use'].indexOf(elname) == -1;
var no_path = ['image', 'text', 'path', 'g', 'use'].indexOf(elname) === -1;
if (no_path) $('.action_path_convert_selected').removeClass('disabled');
if (elname === "path") $('.action_path_selected').removeClass('disabled');
@ -231,7 +231,7 @@ MD.Panel = function(){
$('#g_panel').show();
}
if (el_name == "path" || el_name == "polyline") {
if (el_name === "path" || el_name === "polyline") {
$('#path_panel').show();
}
@ -242,7 +242,7 @@ MD.Panel = function(){
// corner radius has to live in a different panel
// because otherwise it changes the position of the
// of the elements
if(el_name == "rect") $("#cornerRadiusLabel").show()
if(el_name === "rect") $("#cornerRadiusLabel").show()
else $("#cornerRadiusLabel").hide()
$.each(cur_panel, function(i, item) {
@ -270,7 +270,7 @@ MD.Panel = function(){
$('#text').val(elem.textContent);
$('#preview_font').text(cleanFontFamily).css('font-family', font_family);
} // text
else if(el_name == 'image') {
else if(el_name === 'image') {
setImageURL(svgCanvas.getHref(elem));
} // image
else if(el_name === 'g' || el_name === 'use') {

View File

@ -91,7 +91,7 @@ var supportsHVLineContainerBBox_ = (function() {
var bbox = g.getBBox();
document.documentElement.removeChild(svgcontent);
// Webkit gives 0, FF gives 10, Opera (correctly) gives 15
return (bbox.width == 15);
return (bbox.width === 15);
})();
var supportsEditableText_ = (function() {
@ -104,7 +104,7 @@ var supportsGoodDecimals_ = (function() {
var rect = document.createElementNS(svgns, 'rect');
rect.setAttribute('x',.1);
var crect = rect.cloneNode(false);
var retValue = (crect.getAttribute('x').indexOf(',') == -1);
var retValue = (crect.getAttribute('x').indexOf(',') === -1);
if(!retValue) {
$.alert("NOTE: This version of Opera is known to contain bugs in SVG-edit.\n\
Please upgrade to the <a href='http://opera.com'>latest version</a> in which the problems have been fixed.");
@ -124,7 +124,7 @@ var supportsNativeSVGTransformLists_ = (function() {
var t1 = svg.createSVGTransform();
rxform.appendItem(t1);
return rxform.getItem(0) == t1;
return rxform.getItem(0) === t1;
})();
var supportsBlobs_ = (function() {

View File

@ -10,7 +10,7 @@
var dbox = function(type, msg, callback, defText) {
$('#dialog_content').html('<p>'+msg.replace(/\n/g,'</p><p>')+'</p>')
.toggleClass('prompt',(type=='prompt'));
.toggleClass('prompt',(type==='prompt'));
btn_holder.empty();
var ok = $('<input type="button" value="OK">').appendTo(btn_holder);
@ -21,13 +21,13 @@
.on("click touchstart", function() { box.hide();callback(false)});
}
if(type == 'prompt') {
if(type === 'prompt') {
var input = $('<input type="text">').prependTo(btn_holder);
input.val(defText || '');
input.bind('keydown', 'return', function() {ok.trigger("click touchstart");});
}
if(type == 'process') {
if(type === 'process') {
ok.hide();
}
@ -35,11 +35,11 @@
ok.on("click touchstart", function() {
box.hide();
var resp = (type == 'prompt')?input.val():true;
var resp = (type === 'prompt')?input.val():true;
if(callback) callback(resp);
}).focus();
if(type == 'prompt') input.focus();
if(type === 'prompt') input.focus();
}
$.alert = function(msg, cb) { dbox('alert', msg, cb);};

View File

@ -58,13 +58,13 @@ svgedit.draw.Layer.prototype.getGroup = function() {
// Params:
// enableRandomization - flag indicating if documents should have randomized ids
svgedit.draw.randomizeIds = function(enableRandomization, current_drawing) {
randomize_ids = enableRandomization == false ?
randomize_ids = enableRandomization === false ?
RandomizeModes.NEVER_RANDOMIZE :
RandomizeModes.ALWAYS_RANDOMIZE;
if (randomize_ids == RandomizeModes.ALWAYS_RANDOMIZE && !current_drawing.getNonce()) {
if (randomize_ids === RandomizeModes.ALWAYS_RANDOMIZE && !current_drawing.getNonce()) {
current_drawing.setNonce(Math.floor(Math.random() * 100001));
} else if (randomize_ids == RandomizeModes.NEVER_RANDOMIZE && current_drawing.getNonce()) {
} else if (randomize_ids === RandomizeModes.NEVER_RANDOMIZE && current_drawing.getNonce()) {
current_drawing.clearNonce();
}
};
@ -133,7 +133,7 @@ svgedit.draw.Drawing = function(svgElem, opt_idPrefix) {
// else, if randomizeIds(true) has been called, create and set the nonce.
if (!!n && randomize_ids != RandomizeModes.NEVER_RANDOMIZE) {
this.nonce_ = n;
} else if (randomize_ids == RandomizeModes.ALWAYS_RANDOMIZE) {
} else if (randomize_ids === RandomizeModes.ALWAYS_RANDOMIZE) {
this.setNonce(Math.floor(Math.random() * 100001));
}
};
@ -258,7 +258,7 @@ svgedit.draw.Drawing.prototype.getNumLayers = function() {
// 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;
if(this.all_layers[i][0] === name) return true;
}
return false;
};
@ -294,7 +294,7 @@ svgedit.draw.Drawing.prototype.getCurrentLayer = function() {
// The name of the currently active layer.
svgedit.draw.Drawing.prototype.getCurrentLayerName = function() {
for (var i = 0; i < this.getNumLayers(); ++i) {
if (this.all_layers[i][1] == this.current_layer) {
if (this.all_layers[i][1] === this.current_layer) {
return this.getLayerName(i);
}
}
@ -312,7 +312,7 @@ svgedit.draw.Drawing.prototype.getCurrentLayerName = function() {
// true if the current layer was switched, otherwise false
svgedit.draw.Drawing.prototype.setCurrentLayer = function(name) {
for (var i = 0; i < this.getNumLayers(); ++i) {
if (name == this.getLayerName(i)) {
if (name === this.getLayerName(i)) {
if (this.current_layer != this.all_layers[i][1]) {
this.current_layer.setAttribute("style", "pointer-events:none");
this.current_layer = this.all_layers[i][1];
@ -355,8 +355,8 @@ svgedit.draw.Drawing.prototype.identifyLayers = function() {
for (var i = 0; i < numchildren; ++i) {
var child = this.svgElem_.childNodes.item(i);
// for each g, find its layer name
if (child && child.nodeType == 1) {
if (child.tagName == "g") {
if (child && child.nodeType === 1) {
if (child.tagName === "g") {
childgroups = true;
var name = $("title",child).text();
@ -448,7 +448,7 @@ svgedit.draw.Drawing.prototype.getLayerVisibility = function(layername) {
// find the layer
var layer = null;
for (var i = 0; i < this.getNumLayers(); ++i) {
if (this.getLayerName(i) == layername) {
if (this.getLayerName(i) === layername) {
layer = this.all_layers[i][1];
break;
}
@ -474,7 +474,7 @@ svgedit.draw.Drawing.prototype.setLayerVisibility = function(layername, bVisible
// find the layer
var layer = null;
for (var i = 0; i < this.getNumLayers(); ++i) {
if (this.getLayerName(i) == layername) {
if (this.getLayerName(i) === layername) {
layer = this.all_layers[i][1];
break;
}
@ -499,7 +499,7 @@ svgedit.draw.Drawing.prototype.setLayerVisibility = function(layername, bVisible
// if layername is not a valid layer
svgedit.draw.Drawing.prototype.getLayerOpacity = function(layername) {
for (var i = 0; i < this.getNumLayers(); ++i) {
if (this.getLayerName(i) == layername) {
if (this.getLayerName(i) === layername) {
var g = this.all_layers[i][1];
var opacity = g.getAttribute('opacity');
if (!opacity) {
@ -523,7 +523,7 @@ svgedit.draw.Drawing.prototype.setLayerOpacity = function(layername, opacity) {
return;
}
for (var i = 0; i < this.getNumLayers(); ++i) {
if (this.getLayerName(i) == layername) {
if (this.getLayerName(i) === layername) {
var g = this.all_layers[i][1];
g.setAttribute("opacity", opacity);
break;

View File

@ -29,7 +29,7 @@ MD.Eyedropper = function() {
function getStyle(opts) {
// if we are in eyedropper mode, we don't want to disable the eye-dropper tool
var mode = svgCanvas.getMode();
if (mode == "eyedropper") return;
if (mode === "eyedropper") return;
var tool = $('#tool_eyedropper');
}
@ -84,7 +84,7 @@ MD.Eyedropper = function() {
var mode = svgCanvas.getMode();
var e = opts.event;
var target = (e.target.id === "svgroot") ? document.getElementById('canvas_background') : e.target;
if (mode == "eyedropper" && target) {
if (mode === "eyedropper" && target) {
currentStyle.fillPaint = target.getAttribute("fill") || "white";
currentStyle.fillOpacity = target.getAttribute("fill-opacity") || 1.0;
currentStyle.strokePaint = target.getAttribute("stroke") || 'none';
@ -102,7 +102,7 @@ MD.Eyedropper = function() {
editor.paintBox.stroke.setPaint(stroke)
return;
}
if ($.inArray(opts.selectedElements.nodeName, ['g', 'use']) == -1) {
if ($.inArray(opts.selectedElements.nodeName, ['g', 'use']) === -1) {
var changes = {};
var change = function(elem, attrname, newvalue) {
changes[attrname] = elem.getAttribute(attrname);

View File

@ -223,7 +223,7 @@ svgedit.history.RemoveElementCommand.prototype.unapply = function(handler) {
}
svgedit.transformlist.removeElementFromListMap(this.elem);
if(this.nextSibling == null) {
if(this.nextSibling === null) {
if(window.console) console.log('Error: reference element was lost');
}
this.parent.insertBefore(this.elem, this.nextSibling);
@ -256,8 +256,8 @@ svgedit.history.ChangeElementCommand = function(elem, attrs, text) {
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);
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);
}
};
@ -279,12 +279,12 @@ svgedit.history.ChangeElementCommand.prototype.apply = function(handler) {
var bChangedTransform = false;
for(var 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])
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") {
if (attr === "#text") {
this.elem.textContent = "";
}
else {
@ -293,7 +293,7 @@ svgedit.history.ChangeElementCommand.prototype.apply = function(handler) {
}
}
if (attr == "transform") { bChangedTransform = true; }
if (attr === "transform") { bChangedTransform = true; }
}
// relocate rotational transform, if necessary
@ -327,17 +327,17 @@ svgedit.history.ChangeElementCommand.prototype.unapply = function(handler) {
var bChangedTransform = false;
for(var 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]);
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") {
if (attr === "#text") {
this.elem.textContent = "";
}
else this.elem.removeAttribute(attr);
}
if (attr == "transform") { bChangedTransform = true; }
if (attr === "transform") { bChangedTransform = true; }
}
// relocate rotational transform, if necessary
if(!bChangedTransform) {
@ -435,7 +435,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;
@ -453,7 +453,7 @@ svgedit.history.BatchCommand.prototype.addSubCommand = function(cmd) {
// Function: svgedit.history.BatchCommand.isEmpty
// Returns a boolean indicating whether or not the batch command is empty
svgedit.history.BatchCommand.prototype.isEmpty = function() {
return this.stack.length == 0;
return this.stack.length === 0;
};
@ -562,7 +562,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 +586,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)) {

View File

@ -91,7 +91,7 @@ svgedit.math.hasMatrixTransform = function(tlist) {
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;
};
@ -162,12 +162,12 @@ svgedit.math.transformBox = function(l, t, w, h, m) {
// Returns:
// A single matrix transform object
svgedit.math.transformListToTransform = function(tlist, min, max) {
if(tlist == null) {
if(tlist === null) {
// Or should tlist = null have been prevented before this?
return svg.createSVGTransformFromMatrix(svg.createSVGMatrix());
}
var min = min == undefined ? 0 : min;
var max = max == undefined ? (tlist.numberOfItems-1) : max;
var min = min === undefined ? 0 : min;
var max = max === undefined ? (tlist.numberOfItems-1) : max;
min = parseInt(min);
max = parseInt(max);
if (min > max) { var temp = max; max = min; min = temp; }

View File

@ -411,7 +411,7 @@ svgedit.path.Segment.prototype.update = function(full) {
if(this.ptgrip) {
var pt = svgedit.path.getGripPt(this);
var reposition = (svgedit.browser.isTouch() ? 15 : 2.5)
var properties = (this.ptgrip.nodeName == "rect") ? {'x': pt.x-reposition, 'y': pt.y-reposition} : {'cx': pt.x, 'cy': pt.y};
var properties = (this.ptgrip.nodeName === "rect") ? {'x': pt.x-reposition, 'y': pt.y-reposition} : {'cx': pt.x, 'cy': pt.y};
svgedit.utilities.assignAttributes(this.ptgrip, properties);
svgedit.path.getSegSelector(this, true);
@ -460,7 +460,7 @@ svgedit.path.Segment.prototype.move = function(dx, dy) {
svgedit.path.Segment.prototype.setLinked = function(num) {
var seg, anum, pt;
if (num == 2) {
if (num === 2) {
anum = 1;
seg = this.next;
if(!seg) return;
@ -568,7 +568,7 @@ svgedit.path.Path.prototype.init = function() {
seg.next.prev = seg;
seg.mate = segs[start_i];
seg.addGrip();
if(this.first_seg == null) {
if(this.first_seg === null) {
this.first_seg = seg;
}
} else if(!next_seg) {