mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 14:10:14 -05:00
Use Events object to install 'load' event in PaperScript.
This commit is contained in:
parent
b85235e1cb
commit
ef1da14c0e
1 changed files with 19 additions and 22 deletions
|
@ -147,32 +147,29 @@ var PaperScript = new function() {
|
|||
return xhr.send(null);
|
||||
}
|
||||
|
||||
function runScripts() {
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
for (var i = 0, l = scripts.length; i < l; i++) {
|
||||
var script = scripts[i];
|
||||
if (script.type === 'text/paperscript') {
|
||||
// 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))) {
|
||||
new Document(canvas);
|
||||
}
|
||||
if (script.src) {
|
||||
load(script.src);
|
||||
} else {
|
||||
run(script.innerHTML);
|
||||
Events.add(window, {
|
||||
load: 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') {
|
||||
// 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))) {
|
||||
new Document(canvas);
|
||||
}
|
||||
if (script.src) {
|
||||
load(script.src);
|
||||
} else {
|
||||
run(script.innerHTML);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
if (window.addEventListener) {
|
||||
addEventListener('load', runScripts, false);
|
||||
} else {
|
||||
attachEvent('onload', runScripts);
|
||||
}
|
||||
//#endif // BROWSER
|
||||
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue