Bring back support for paper.setup('id') again, and document it properly.

Closes #510.
This commit is contained in:
Jürg Lehni 2014-08-20 16:53:31 +02:00
parent db1ccd1d1e
commit 6b4f728a72
4 changed files with 14 additions and 7 deletions

View file

@ -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

View file

@ -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();

View file

@ -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,

View file

@ -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);