From fa3f91a754012036b73781af4d92170a556ea0f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 24 Jun 2013 04:23:34 -0700 Subject: [PATCH] Move PaperScript.get/setAttribute() to PaperScope. --- src/core/PaperScope.js | 44 +++++++++++++++++++++++++++-------------- src/core/PaperScript.js | 15 ++------------ src/dom/DomEvent.js | 2 +- src/ui/View.js | 4 ++-- 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/core/PaperScope.js b/src/core/PaperScope.js index 41ff2578..85289c32 100644 --- a/src/core/PaperScope.js +++ b/src/core/PaperScope.js @@ -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') + }; } }); diff --git a/src/core/PaperScript.js b/src/core/PaperScript.js index 26bd8687..c7aef9ed 100644 --- a/src/core/PaperScript.js +++ b/src/core/PaperScript.js @@ -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 diff --git a/src/dom/DomEvent.js b/src/dom/DomEvent.js index 8183dab0..55a4a86a 100644 --- a/src/dom/DomEvent.js +++ b/src/dom/DomEvent.js @@ -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); diff --git a/src/ui/View.js b/src/ui/View.js index e0116c31..a65f5316 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -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,