mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-16 17:51:07 +00:00
Fix function body matching regex. Add fabric.util.getFunctionBody
This commit is contained in:
parent
46183d8a85
commit
1c1b7e4b95
7 changed files with 36 additions and 17 deletions
13
dist/all.js
vendored
13
dist/all.js
vendored
|
|
@ -2448,6 +2448,10 @@ fabric.Collection = {
|
|||
];
|
||||
}
|
||||
|
||||
function getFunctionBody(fn) {
|
||||
return String(fn).match(/function[^{]*\{([\s\S]*)\}/)[1];
|
||||
}
|
||||
|
||||
fabric.util.removeFromArray = removeFromArray;
|
||||
fabric.util.degreesToRadians = degreesToRadians;
|
||||
fabric.util.radiansToDegrees = radiansToDegrees;
|
||||
|
|
@ -2468,6 +2472,7 @@ fabric.Collection = {
|
|||
fabric.util.createAccessors = createAccessors;
|
||||
fabric.util.clipContext = clipContext;
|
||||
fabric.util.multiplyTransformMatrices = multiplyTransformMatrices;
|
||||
fabric.util.getFunctionBody = getFunctionBody;
|
||||
|
||||
})();
|
||||
|
||||
|
|
@ -5543,8 +5548,7 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
|
|||
|
||||
// callback
|
||||
if (typeof this.source === 'function') {
|
||||
source = String(this.source)
|
||||
.match(/function\s+\w*\s*\(.*\)\s+\{([\s\S]*)\}/)[1];
|
||||
source = fabric.util.getFunctionBody(this.source);
|
||||
}
|
||||
// <img> element
|
||||
else if (typeof this.source.src === 'string') {
|
||||
|
|
@ -8134,9 +8138,8 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
},
|
||||
|
||||
getPatternSrcBody: function() {
|
||||
return String(this.getPatternSrc)
|
||||
.match(/function\s*\w*\s*(.*)\s*\{([\s\S]*)\}/)[1]
|
||||
.replace('this.color', '"' + this.color + '"');
|
||||
return fabric.util.getFunctionBody(this.getPatternSrc)
|
||||
.replace('this.color', '"' + this.color + '"');
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
12
dist/all.min.js
vendored
12
dist/all.min.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/all.min.js.gz
vendored
BIN
dist/all.min.js.gz
vendored
Binary file not shown.
|
|
@ -24,9 +24,8 @@ fabric.PatternBrush = fabric.util.createClass(fabric.PencilBrush, /** @lends fab
|
|||
},
|
||||
|
||||
getPatternSrcBody: function() {
|
||||
return String(this.getPatternSrc)
|
||||
.match(/function\s*\w*\s*(.*)\s*\{([\s\S]*)\}/)[1]
|
||||
.replace('this.color', '"' + this.color + '"');
|
||||
return fabric.util.getFunctionBody(this.getPatternSrc)
|
||||
.replace('this.color', '"' + this.color + '"');
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -56,8 +56,7 @@ fabric.Pattern = fabric.util.createClass(/** @lends fabric.Pattern.prototype */
|
|||
|
||||
// callback
|
||||
if (typeof this.source === 'function') {
|
||||
source = String(this.source)
|
||||
.match(/function\s+\w*\s*\(.*\)\s+\{([\s\S]*)\}/)[1];
|
||||
source = fabric.util.getFunctionBody(this.source);
|
||||
}
|
||||
// <img> element
|
||||
else if (typeof this.source.src === 'string') {
|
||||
|
|
|
|||
|
|
@ -446,6 +446,10 @@
|
|||
];
|
||||
}
|
||||
|
||||
function getFunctionBody(fn) {
|
||||
return String(fn).match(/function[^{]*\{([\s\S]*)\}/)[1];
|
||||
}
|
||||
|
||||
fabric.util.removeFromArray = removeFromArray;
|
||||
fabric.util.degreesToRadians = degreesToRadians;
|
||||
fabric.util.radiansToDegrees = radiansToDegrees;
|
||||
|
|
@ -466,5 +470,6 @@
|
|||
fabric.util.createAccessors = createAccessors;
|
||||
fabric.util.clipContext = clipContext;
|
||||
fabric.util.multiplyTransformMatrices = multiplyTransformMatrices;
|
||||
fabric.util.getFunctionBody = getFunctionBody;
|
||||
|
||||
})();
|
||||
|
|
|
|||
|
|
@ -732,4 +732,17 @@
|
|||
ok(typeof destination.ffffffffff === 'undefined');
|
||||
});
|
||||
|
||||
})();
|
||||
test('fabric.util.getFunctionBody', function() {
|
||||
equal(fabric.util.getFunctionBody('function(){}'), '');
|
||||
|
||||
equal(fabric.util.getFunctionBody('function(){return 1 + 2}'),
|
||||
'return 1 + 2');
|
||||
|
||||
equal(fabric.util.getFunctionBody('function () {\n return "blah" }'),
|
||||
'\n return "blah" ');
|
||||
|
||||
equal(fabric.util.getFunctionBody('function foo (a , boo_bar, baz123 )\n{\n if (1) { alert(12345) } }'),
|
||||
'\n if (1) { alert(12345) } ');
|
||||
});
|
||||
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue