Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Of multiple script/paperscript scripts, only the first seems to run in PaperScope. #153

Closed
GolezTrol opened this issue Dec 27, 2012 · 5 comments
Assignees

Comments

@GolezTrol
Copy link

If I have multiple paperscripts in my page, only the first seems to be run in paperscript scope.

Eg:
< script type="text/paperscript" src="scripts/main.js" canvas="myCanvas"></script>
< script type="text/paperscript" src="scripts/extra.js"></script>

'extra.js' is actually loaded by Paper.js, but I cannot, for instance, alter 'view.zoom'. I have to write 'paper.view.zoom', indicating that this script runs in the global scope instead of the paper scope.

Example project: http://barbata.nl/SO/Maps/ (Cannot promise it will be there forever, sorry)
See also: http://stackoverflow.com/questions/14039554/multiple-script-paperscripts-in-the-same-paperscope

@ghost ghost assigned lehni Dec 27, 2012
@andypayne
Copy link

I needed the ability to load multiple scripts for the same canvas/scope, so I added this in a fork:

andypayne@48ddd4e

Specifying the same canvas name for two scripts will cause them to be loaded in the same scope:

<script type="text/paperscript" src="paperscript1.js" canvas="pcanvas1"></script>
<script type="text/paperscript" src="paperscript2.js" canvas="pcanvas1"></script>
<script type="text/paperscript" src="paperscript3.js" canvas="pcanvas2"></script>

In this example, paperscript1.js and paperscript2.js are both loaded into pcanvas1, while paperscript3.js is loaded into pcanvas2. If compatibility is a concern, one option is to add a data attribute to explicitly control the multiple script behavior (add/overwrite/etc):

<script type="text/paperscript" src="paperscript2.js" canvas="pcanvas1" data-script-scope="add"></script>

I didn't add this extra level of control because I didn't need it, but it wouldn't be a lot of work.

If this is useful for the project, let me know and I'll sign the agreement and send a pull request.

@lehni
Copy link
Member

lehni commented Jan 20, 2013

That's great, and makes a whole lot of sense! I totally agree that the extra level is not needed. I am confident that this will make it into the next release. I just need to look at implementation details first to see if I merge the request, or restructure the code a bit.

@lehni
Copy link
Member

lehni commented Feb 15, 2013

This looks good. @andypayne would you like to create a pull request?

@andypayne
Copy link

Done - #171

@lehni
Copy link
Member

lehni commented Mar 1, 2013

This is merged in, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants