From 6b4f728a72045c102b3d279a3187078e2b7009c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 20 Aug 2014 16:53:31 +0200 Subject: [PATCH] Bring back support for paper.setup('id') again, and document it properly. Closes #510. --- src/core/PaperScope.js | 5 +++-- src/item/Raster.js | 7 ++++--- src/project/Project.js | 5 +++-- src/ui/View.js | 4 ++++ 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/core/PaperScope.js b/src/core/PaperScope.js index 1a13e2a9..c0cbc424 100644 --- a/src/core/PaperScope.js +++ b/src/core/PaperScope.js @@ -182,8 +182,9 @@ var PaperScope = Base.extend(/** @lends PaperScope# */{ * Sets up an empty project for us. If a canvas is provided, it also creates * a {@link View} for it, both linked to this scope. * - * @param {HTMLCanvasElement} element the HTML canvas this scope should be - * associated with. + * @param {HTMLCanvasElement|String} element the HTML canvas element this + * scope should be associated with, or an ID string by which to find the + * element. */ setup: function(element) { // Make sure this is the active scope, so the created project and view diff --git a/src/item/Raster.js b/src/item/Raster.js index ab695819..4e229010 100644 --- a/src/item/Raster.js +++ b/src/item/Raster.js @@ -37,9 +37,10 @@ var Raster = Item.extend(/** @lends Raster# */{ * string describing the URL to load the image from, or the ID of a DOM * element to get the image from (either a DOM Image or a Canvas). * - * @param {HTMLImageElement|Canvas|String} [source] the source of the raster + * @param {HTMLImageElement|HTMLCanvasElement|String} [source] the source of + * the raster * @param {Point} [position] the center position at which the raster item is - * placed. + * placed * * @example {@paperscript height=300} // Creating a raster using a url * var url = 'http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png'; @@ -285,7 +286,7 @@ var Raster = Item.extend(/** @lends Raster# */{ * a data-url. * * @bean - * @type HTMLImageElement|Canvas|String + * @type HTMLImageElement|HTMLCanvasElement|String * * @example {@paperscript} * var raster = new Raster(); diff --git a/src/project/Project.js b/src/project/Project.js index 86228a94..71399733 100644 --- a/src/project/Project.js +++ b/src/project/Project.js @@ -43,8 +43,9 @@ var Project = PaperScopeItem.extend(/** @lends Project# */{ * Note that when working with PaperScript, a project is automatically * created for us and the {@link PaperScope#project} variable points to it. * - * @param {HTMLCanvasElement} element the HTML canvas element that should be - * used as the element for the view. + * @param {HTMLCanvasElement|String} element the HTML canvas element that + * should be used as the element for the view, or an ID string by which to + * find the element. */ initialize: function Project(element) { // Activate straight away by passing true to PaperScopeItem constructor, diff --git a/src/ui/View.js b/src/ui/View.js index 12b29687..89a3d914 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -669,6 +669,10 @@ var View = Base.extend(Callback, /** @lends View# */{ _id: 0, create: function(project, element) { +/*#*/ if (__options.environment == 'browser') { + if (typeof element === 'string') + element = document.getElementById(element); +/*#*/ } // __options.environment == 'browser' // Factory to provide the right View subclass for a given element. // Produces only CanvasViews for now: return new CanvasView(project, element);