- Fix: Detection of whether to keep ellipse (rx and ry when just created are now returning 0 instead of null); fixes #262

- Refactoring: Simplify `isValidUnit`
master
Brett Zamir 2018-06-25 12:39:10 +08:00
parent 9f65b1adb9
commit ccb793e78c
2 changed files with 11 additions and 15 deletions

View File

@ -2151,7 +2151,7 @@ const mouseUp = function (evt) {
break;
case 'ellipse':
attrs = $(element).attr(['rx', 'ry']);
keep = (attrs.rx != null || attrs.ry != null);
keep = (attrs.rx || attrs.ry);
break;
case 'fhellipse':
if ((freehand.maxx - freehand.minx) > 0 &&

View File

@ -235,21 +235,19 @@ export const convertToNum = function (attr, val) {
* @param val - String with the attribute value to check
*/
export const isValidUnit = function (attr, val, selectedElement) {
let valid = false;
if (unitAttrs.includes(attr)) {
// True if it's just a number
if (!isNaN(val)) {
valid = true;
} else {
// Not a number, check if it has a valid unit
val = val.toLowerCase();
Object.keys(typeMap_).forEach((unit) => {
if (valid) { return; }
const re = new RegExp('^-?[\\d\\.]+' + unit + '$');
if (re.test(val)) { valid = true; }
});
return true;
}
} else if (attr === 'id') {
// Not a number, check if it has a valid unit
val = val.toLowerCase();
return Object.keys(typeMap_).some((unit) => {
const re = new RegExp('^-?[\\d\\.]+' + unit + '$');
return re.test(val);
});
}
if (attr === 'id') {
// if we're trying to change the id, make sure it's not already present in the doc
// and the id value is valid.
@ -264,7 +262,5 @@ export const isValidUnit = function (attr, val, selectedElement) {
} catch (e) {}
return result;
}
valid = true;
return valid;
return true;
};