mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -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,21 +188,35 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{
|
|||
delete PaperScope._scopes[this._id];
|
||||
},
|
||||
|
||||
statics: /** @lends PaperScope */{
|
||||
_scopes: {},
|
||||
_id: 0,
|
||||
|
||||
/**
|
||||
* Retrieves a PaperScope object with the given id or associated with
|
||||
* the passed canvas element.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
get: function(id) {
|
||||
// If a script tag is passed, get the id from it.
|
||||
if (typeof id === 'object')
|
||||
id = id.getAttribute('id');
|
||||
return this._scopes[id] || null;
|
||||
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: {},
|
||||
_id: 0,
|
||||
|
||||
/**
|
||||
* Retrieves a PaperScope object with the given id or associated with
|
||||
* the passed canvas element.
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
get: function(id) {
|
||||
// If a script tag is passed, get the id from it.
|
||||
if (typeof id === 'object')
|
||||
id = id.getAttribute('id');
|
||||
return this._scopes[id] || null;
|
||||
},
|
||||
|
||||
getAttribute: handleAttribute('get'),
|
||||
hasAttribute: handleAttribute('has')
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
|
@ -287,7 +287,7 @@ var PaperScript = new function() {
|
|||
// retrieved through PaperScope.get().
|
||||
// If a canvas id is provided, pass it on to the PaperScope
|
||||
// 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
|
||||
// it, to support multiple scripts per canvas. Otherwise
|
||||
// create a new one.
|
||||
|
@ -316,21 +316,10 @@ var PaperScript = new function() {
|
|||
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 {
|
||||
compile: compile,
|
||||
evaluate: evaluate,
|
||||
load: load,
|
||||
getAttribute: handleAttribute('get'),
|
||||
hasAttribute: handleAttribute('has')
|
||||
load: load
|
||||
};
|
||||
|
||||
/*#*/ } else { // !options.browser
|
||||
|
|
|
@ -135,7 +135,7 @@ DomEvent.requestAnimationFrame = new function() {
|
|||
var entry = callbacks[i],
|
||||
func = entry[0],
|
||||
el = entry[1];
|
||||
if (!el || (PaperScript.getAttribute(el, 'keepalive') == 'true'
|
||||
if (!el || (PaperScope.getAttribute(el, 'keepalive') == 'true'
|
||||
|| focused) && DomElement.isInView(el)) {
|
||||
// Handle callback and remove it from callbacks list.
|
||||
callbacks.splice(i, 1);
|
||||
|
|
|
@ -38,7 +38,7 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
DomEvent.add(element, this._viewHandlers);
|
||||
// If the element has the resize attribute, resize the it to fill the
|
||||
// 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
|
||||
// stretch it in
|
||||
var offset = DomElement.getOffset(element, true),
|
||||
|
@ -74,7 +74,7 @@ var View = Base.extend(Callback, /** @lends View# */{
|
|||
element.width = size.width;
|
||||
element.height = size.height;
|
||||
// TODO: Test this on IE:
|
||||
if (PaperScript.hasAttribute(element, 'stats')) {
|
||||
if (PaperScope.hasAttribute(element, 'stats')) {
|
||||
this._stats = new Stats();
|
||||
// Align top-left to the element
|
||||
var stats = this._stats.domElement,
|
||||
|
|
Loading…
Reference in a new issue