Test code for tool handlers and only create tool if they are present.

This commit is contained in:
Jürg Lehni 2011-03-04 01:13:21 +00:00
parent c86eaf5684
commit 453da21bab

View file

@ -119,18 +119,18 @@ var PaperScript = new function() {
// Use paper.extend() to create a paper scope within which the code is // Use paper.extend() to create a paper scope within which the code is
// evaluated. // evaluated.
with (paper.extend()) { with (paper.extend()) {
// TODO: Only create tool if code contains reference to tool scripts! var tool = /onMouse(?:Up|Down|Move|Drag)/.test(code) && new Tool();
var tool = new Tool();
var res = eval(compile(code)); var res = eval(compile(code));
// TODO: Again, only do this if we actually detected a tool script: if (tool) {
Base.each(['onEditOptions', 'onOptions', 'onSelect', 'onDeselect', Base.each(['onEditOptions', 'onOptions', 'onSelect',
'onReselect', 'onMouseDown', 'onMouseUp', 'onMouseDrag', 'onDeselect', 'onReselect', 'onMouseDown', 'onMouseUp',
'onMouseMove'], function(key) { 'onMouseDrag', 'onMouseMove'], function(key) {
try { try {
tool[key] = eval(key); tool[key] = eval(key);
} catch (e) { } catch (e) {
} }
}); });
}
return res; return res;
} }
} }