From 470360301c38d0b45a28d6e0966e08dcd8756b7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 19 Jul 2011 23:51:50 +0100 Subject: [PATCH 1/4] Improve documentation for PaperScope#install() --- src/core/PaperScope.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/PaperScope.js b/src/core/PaperScope.js index c5a8216c..97f132af 100644 --- a/src/core/PaperScope.js +++ b/src/core/PaperScope.js @@ -141,11 +141,14 @@ var PaperScope = this.PaperScope = Base.extend(/** @scope _global_ */{ }, /** - * Installs the paper scope into any other given scope. Can be used for + * Injects the paper scope into any other given scope. Can be used for * examle to inject the currently active PaperScope into the window's global - * scope, to emulate PaperScript-style globally accessible Paper classes: + * scope, to emulate PaperScript-style globally accessible Paper classes and + * objects: * + * @example * paper.install(window); + * * @ignore */ install: function(scope) { From 9f1f4d334e42ed012d0a3ca7e2073bdec67f60bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 19 Jul 2011 23:52:32 +0100 Subject: [PATCH 2/4] Introduce PaperScope#setup(canvas), as a simple way to setup a standard project when not using PaperScript. --- src/core/PaperScope.js | 17 +++++++++++++++++ src/core/PaperScript.js | 7 +------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/core/PaperScope.js b/src/core/PaperScope.js index 97f132af..b6b5d788 100644 --- a/src/core/PaperScope.js +++ b/src/core/PaperScope.js @@ -140,6 +140,23 @@ var PaperScope = this.PaperScope = Base.extend(/** @scope _global_ */{ return res; }, + /** + * Sets up the scope for a standard project, by creating an empty + * {@link Project} object for us, along with a {@link View} for the passed + * canvas, both linked to this scope. + */ + setup: function(canvas) { + // We need to set the global paper reference to this scope, + // since that will be used in the Project constructor to set + // internal references. + paper = this; + new Project(); + if (canvas) { + // Activate the newly created view straight away + new View(canvas).activate(); + } + }, + /** * Injects the paper scope into any other given scope. Can be used for * examle to inject the currently active PaperScope into the window's global diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index 2fa74d5f..3f0deb72 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -138,12 +138,7 @@ var PaperScript = this.PaperScript = new function() { // so the active project is defined. var canvas = PaperScript.getAttribute(code, 'canvas'); if (canvas = canvas && document.getElementById(canvas)) { - // Create an empty Project for this scope, and a view for the - // canvas, both using the right paper scope - paper = scope; - new Project(); - // Activate the newly created view straight away - new View(canvas).activate(); + scope.setup(canvas); } if (code.src) { // If we're loading from a source, request that first and then From 688c1671edfba53da6597d695c3b419687871e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 19 Jul 2011 23:53:13 +0100 Subject: [PATCH 3/4] Remove all parameters from Tool constructor, to simplify use outside PaperScript. --- src/core/PaperScript.js | 6 +++--- src/tool/Tool.js | 8 +++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index 3f0deb72..974baa44 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -150,15 +150,15 @@ var PaperScript = this.PaperScript = new function() { } } //#endif // BROWSER + // Set currently active scope. + paper = scope; var view = scope.view, // TODO: Add support for multiple tools tool = scope.tool = /on(?:Key|Mouse)(?:Up|Down|Move|Drag)/.test(code) - && new Tool(null, scope), + && new Tool(), res; // Define variables for potential handlers, so eval() calls below to // fetch their values do not require try-catch around them. - // Set currently active scope. - paper = scope; // Use with(){} in order to make the scope the current 'global' scope // instead of window. with (scope) { diff --git a/src/tool/Tool.js b/src/tool/Tool.js index 2ca8c8bd..5051134a 100644 --- a/src/tool/Tool.js +++ b/src/tool/Tool.js @@ -48,11 +48,9 @@ */ var Tool = this.Tool = Base.extend(/** @lends Tool# */{ // DOCS: rewrite Tool constructor explanation - /** - * Initializes the tool's settings, so a new tool can be assigned to it - */ - initialize: function(handlers, scope) { - this._scope = scope; + initialize: function() { + // Store reference to the currently active global paper scope: + this._scope = paper; this._firstMove = true; this._count = 0; this._downCount = 0; From 88626e3903e0350fe84df7ddd030539a54fe4446 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 19 Jul 2011 23:55:56 +0100 Subject: [PATCH 4/4] ToolEvent#getItem(): Replace all #parent getters with direct access to internal variable. --- src/tool/ToolEvent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tool/ToolEvent.js b/src/tool/ToolEvent.js index ecb2d252..c8420287 100644 --- a/src/tool/ToolEvent.js +++ b/src/tool/ToolEvent.js @@ -183,7 +183,7 @@ var ToolEvent = this.ToolEvent = Event.extend(/** @lends ToolEvent# */{ if (result) { var item = result.item, // Find group parent - parent = item.getParent(); + parent = item._parent; while ((parent instanceof Group && !(parent instanceof Layer)) || parent instanceof CompoundPath) { item = parent;