From 91332d465ac2d3c59a488f8d340093b5694894f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 14 May 2011 13:10:38 +0300 Subject: [PATCH] Switch to using an internal PaperScope class and have the global paper variable simply be a pointer to the currently active one (step one of PaperScope context switching and support of multiple PaperScript instances within one web-site). --- src/paper.js | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/paper.js b/src/paper.js index 3e6b0bdc..c8619ed5 100644 --- a/src/paper.js +++ b/src/paper.js @@ -36,28 +36,31 @@ ***/ var paper = new function() { -// Have a pointer to the paper object already during the 'bootstraping' so code -// can rely on it being there all the time. -var paper = this; - -this.document = null; -this.documents = []; - -/** - * Installs the paper scope into any other given scope. Can be used for examle - * to inject into the window's global scope: - * - * paper.install(window); - */ -this.install = function(scope) { - for (var i in this) { - scope[i] = this[i]; - } -}; // Inline Bootstrap core (the Base class) inside the paper scope first: //#include "../lib/bootstrap.js" +var PaperScope = Base.extend({ + initialize: function() { + this.document = null; + this.documents = []; + this.tools = []; + }, + + /** + * Installs 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: + * + * paper.install(window); + */ + install: function(scope) { + for (var i in this) { + scope[i] = this[i]; + } + } +}); + // Extend Base with utility functions used across the library. Base.inject({ statics: true, @@ -205,4 +208,8 @@ Base.inject({ //#include "util/Numerical.js" //#include "util/PaperScript.js" //#include "util/BlendMode.js" + +// new create the first Paper scope and return it. + +return new PaperScope(); };