mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Move PaperScript.get/setAttribute() to PaperScope.
This commit is contained in:
parent
75c1225d4f
commit
fa3f91a754
4 changed files with 34 additions and 31 deletions
|
@ -188,7 +188,17 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
|
||||||
delete PaperScope._scopes[this._id];
|
delete PaperScope._scopes[this._id];
|
||||||
},
|
},
|
||||||
|
|
||||||
statics: /** @lends PaperScope */{
|
statics: new function() {
|
||||||
|
// Produces helpers to e.g. check for both 'canvas' and
|
||||||
|
// 'data-paper-canvas' attributes:
|
||||||
|
function handleAttribute(name) {
|
||||||
|
name += 'Attribute';
|
||||||
|
return function(el, attr) {
|
||||||
|
return el[name](attr) || el[name]('data-paper-' + attr);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return /** @lends PaperScope */{
|
||||||
_scopes: {},
|
_scopes: {},
|
||||||
_id: 0,
|
_id: 0,
|
||||||
|
|
||||||
|
@ -203,6 +213,10 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
|
||||||
if (typeof id === 'object')
|
if (typeof id === 'object')
|
||||||
id = id.getAttribute('id');
|
id = id.getAttribute('id');
|
||||||
return this._scopes[id] || null;
|
return this._scopes[id] || null;
|
||||||
}
|
},
|
||||||
|
|
||||||
|
getAttribute: handleAttribute('get'),
|
||||||
|
hasAttribute: handleAttribute('has')
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -287,7 +287,7 @@ var PaperScript = new function() {
|
||||||
// retrieved through PaperScope.get().
|
// retrieved through PaperScope.get().
|
||||||
// If a canvas id is provided, pass it on to the PaperScope
|
// If a canvas id is provided, pass it on to the PaperScope
|
||||||
// so a project is created for it now.
|
// so a project is created for it now.
|
||||||
var canvas = PaperScript.getAttribute(script, 'canvas'),
|
var canvas = PaperScope.getAttribute(script, 'canvas'),
|
||||||
// See if there already is a scope for this canvas and reuse
|
// See if there already is a scope for this canvas and reuse
|
||||||
// it, to support multiple scripts per canvas. Otherwise
|
// it, to support multiple scripts per canvas. Otherwise
|
||||||
// create a new one.
|
// create a new one.
|
||||||
|
@ -316,21 +316,10 @@ var PaperScript = new function() {
|
||||||
DomEvent.add(window, { load: load });
|
DomEvent.add(window, { load: load });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Produces helpers to e.g. check for both 'canvas' and 'data-paper-canvas'
|
|
||||||
// attributes:
|
|
||||||
function handleAttribute(name) {
|
|
||||||
name += 'Attribute';
|
|
||||||
return function(el, attr) {
|
|
||||||
return el[name](attr) || el[name]('data-paper-' + attr);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
compile: compile,
|
compile: compile,
|
||||||
evaluate: evaluate,
|
evaluate: evaluate,
|
||||||
load: load,
|
load: load
|
||||||
getAttribute: handleAttribute('get'),
|
|
||||||
hasAttribute: handleAttribute('has')
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*#*/ } else { // !options.browser
|
/*#*/ } else { // !options.browser
|
||||||
|
|
|
@ -135,7 +135,7 @@ DomEvent.requestAnimationFrame = new function() {
|
||||||
var entry = callbacks[i],
|
var entry = callbacks[i],
|
||||||
func = entry[0],
|
func = entry[0],
|
||||||
el = entry[1];
|
el = entry[1];
|
||||||
if (!el || (PaperScript.getAttribute(el, 'keepalive') == 'true'
|
if (!el || (PaperScope.getAttribute(el, 'keepalive') == 'true'
|
||||||
|| focused) && DomElement.isInView(el)) {
|
|| focused) && DomElement.isInView(el)) {
|
||||||
// Handle callback and remove it from callbacks list.
|
// Handle callback and remove it from callbacks list.
|
||||||
callbacks.splice(i, 1);
|
callbacks.splice(i, 1);
|
||||||
|
|
|
@ -38,7 +38,7 @@ var View = Base.extend(Callback, /** @lends View# */{
|
||||||
DomEvent.add(element, this._viewHandlers);
|
DomEvent.add(element, this._viewHandlers);
|
||||||
// If the element has the resize attribute, resize the it to fill the
|
// If the element has the resize attribute, resize the it to fill the
|
||||||
// window and resize it again whenever the user resizes the window.
|
// window and resize it again whenever the user resizes the window.
|
||||||
if (PaperScript.hasAttribute(element, 'resize')) {
|
if (PaperScope.hasAttribute(element, 'resize')) {
|
||||||
// Subtract element' viewport offset from the total size, to
|
// Subtract element' viewport offset from the total size, to
|
||||||
// stretch it in
|
// stretch it in
|
||||||
var offset = DomElement.getOffset(element, true),
|
var offset = DomElement.getOffset(element, true),
|
||||||
|
@ -74,7 +74,7 @@ var View = Base.extend(Callback, /** @lends View# */{
|
||||||
element.width = size.width;
|
element.width = size.width;
|
||||||
element.height = size.height;
|
element.height = size.height;
|
||||||
// TODO: Test this on IE:
|
// TODO: Test this on IE:
|
||||||
if (PaperScript.hasAttribute(element, 'stats')) {
|
if (PaperScope.hasAttribute(element, 'stats')) {
|
||||||
this._stats = new Stats();
|
this._stats = new Stats();
|
||||||
// Align top-left to the element
|
// Align top-left to the element
|
||||||
var stats = this._stats.domElement,
|
var stats = this._stats.domElement,
|
||||||
|
|
Loading…
Reference in a new issue