Make sure PaperScripts are not loaded more than once by setting the loaded attribute to true on them.

This commit is contained in:
Jürg Lehni 2011-05-07 20:50:12 +01:00
parent 791d9335ce
commit 081a303de0

View file

@ -189,13 +189,13 @@ var PaperScript = new function() {
var scripts = document.getElementsByTagName('script');
for (var i = 0, l = scripts.length; i < l; i++) {
var script = scripts[i];
if (script.type === 'text/paperscript') {
// Only load this cript if it not loaded already.
if (script.type === 'text/paperscript'
&& !script.getAttribute('loaded')) {
// If a canvas id is provided, create a document for it now,
// so the active document is defined.
var canvas = script.getAttribute('canvas');
if (canvas && (canvas = document.getElementById(canvas))) {
// var canvas = script.attributes.canvas;
// if (canvas = canvas && document.getElementById(canvas)) {
if (canvas = canvas && document.getElementById(canvas)) {
new Document(canvas);
}
if (script.src) {
@ -203,9 +203,10 @@ var PaperScript = new function() {
} else {
run(script.innerHTML);
}
// Mark script as loaded now.
script.setAttribute('loaded', true);
}
}
return null;
}
Event.add(window, { load: load });