mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Handle data-paper-ignore like any other Paper attribute, allowing the ignore="true" short-form as well.
This commit is contained in:
parent
93dfd2a15a
commit
72f16eb1c3
1 changed files with 7 additions and 6 deletions
|
@ -450,7 +450,7 @@ Base.exports.PaperScript = (function() {
|
||||||
// Only load this script if it not loaded already.
|
// Only load this script if it not loaded already.
|
||||||
// Support both text/paperscript and text/x-paperscript:
|
// Support both text/paperscript and text/x-paperscript:
|
||||||
if (/^text\/(?:x-|)paperscript$/.test(script.type)
|
if (/^text\/(?:x-|)paperscript$/.test(script.type)
|
||||||
&& !script.getAttribute('data-paper-ignore')) {
|
&& PaperScope.getAttribute(script, 'ignore') !== 'true') {
|
||||||
// Produce a new PaperScope for this script now. Scopes are cheap so
|
// Produce a new PaperScope for this script now. Scopes are cheap so
|
||||||
// let's not worry about the initial one that was already created.
|
// let's not worry about the initial one that was already created.
|
||||||
// Define an id for each PaperScript, so its scope can be retrieved
|
// Define an id for each PaperScript, so its scope can be retrieved
|
||||||
|
@ -460,17 +460,17 @@ Base.exports.PaperScript = (function() {
|
||||||
var canvasId = PaperScope.getAttribute(script, 'canvas'),
|
var canvasId = PaperScope.getAttribute(script, 'canvas'),
|
||||||
canvas = document.getElementById(canvasId),
|
canvas = document.getElementById(canvasId),
|
||||||
src = script.src,
|
src = script.src,
|
||||||
scopeKey = 'data-paper-scope';
|
scopeAttribute = 'data-paper-scope';
|
||||||
if (!canvas)
|
if (!canvas)
|
||||||
throw new Error('Unable to find canvas with id "'
|
throw new Error('Unable to find canvas with id "'
|
||||||
+ canvasId + '"');
|
+ canvasId + '"');
|
||||||
// See if there already is a scope for this canvas and reuse it, to
|
// See if there already is a scope for this canvas and reuse it, to
|
||||||
// support multiple scripts per canvas. Otherwise create a new one.
|
// support multiple scripts per canvas. Otherwise create a new one.
|
||||||
var scope = PaperScope.get(canvas.getAttribute(scopeKey))
|
var scope = PaperScope.get(canvas.getAttribute(scopeAttribute))
|
||||||
|| new PaperScope().setup(canvas);
|
|| new PaperScope().setup(canvas);
|
||||||
// Link the element to this scope, so we can reuse the scope when
|
// Link the element to this scope, so we can reuse the scope when
|
||||||
// compiling multiple scripts for the same element.
|
// compiling multiple scripts for the same element.
|
||||||
canvas.setAttribute(scopeKey, scope._id);
|
canvas.setAttribute(scopeAttribute, scope._id);
|
||||||
if (src) {
|
if (src) {
|
||||||
// If we're loading from a source, request that first and then
|
// If we're loading from a source, request that first and then
|
||||||
// run later.
|
// run later.
|
||||||
|
@ -482,7 +482,7 @@ Base.exports.PaperScript = (function() {
|
||||||
execute(script.innerHTML, scope, script.baseURI);
|
execute(script.innerHTML, scope, script.baseURI);
|
||||||
}
|
}
|
||||||
// Mark script as loaded now.
|
// Mark script as loaded now.
|
||||||
script.setAttribute('data-paper-ignore', true);
|
script.setAttribute('data-paper-ignore', 'true');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,7 +495,8 @@ Base.exports.PaperScript = (function() {
|
||||||
* Note that this method is executed automatically for all scripts in the
|
* Note that this method is executed automatically for all scripts in the
|
||||||
* document through a window load event. You can optionally call it earlier
|
* document through a window load event. You can optionally call it earlier
|
||||||
* (e.g. from a DOM ready event), or you can mark scripts to be ignored by
|
* (e.g. from a DOM ready event), or you can mark scripts to be ignored by
|
||||||
* setting their attribute {@code data-paper-ignore="true"}, and call the
|
* setting the attribute {@code ignore="true"} or
|
||||||
|
* {@code data-paper-ignore="true"}, and call the
|
||||||
* {@code PaperScript.load(script)} method for each script separately when
|
* {@code PaperScript.load(script)} method for each script separately when
|
||||||
* needed.
|
* needed.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue