Skip to content

Commit

Permalink
Improves first constructor argument
Browse files Browse the repository at this point in the history
This closes #21.
  • Loading branch information
xavierfoucrier committed Oct 10, 2018
1 parent 365f345 commit 5cf42f2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
6 changes: 6 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ let camera = new Instacam(
);
```

You can also **pass a selector** to the constructor, and Instacam will get the DOM element for you:

```js
let camera = new Instacam('#canvas1');
```

**Custom options** are passed through the second parameter:

```js
Expand Down
4 changes: 2 additions & 2 deletions dist/instacam.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/instacam.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "instacam",
"version": "1.0.2",
"version": "1.1.2",
"description": "Instant canvas video",
"main": "src/instacam.js",
"scripts": {
Expand Down
9 changes: 7 additions & 2 deletions src/instacam.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class Instacam {

/**
Class constructor
@param {Object} viewport - canvas element from the DOM
@param {Object} viewport - selector or canvas element from the DOM
@param {Object} options - custom options of the class
*/
constructor(viewport, options) {
Expand All @@ -24,9 +24,14 @@ export class Instacam {
return;
}

// rewrites the viewport element if the user passed a selector to the constructor
if (typeof viewport === 'string') {
viewport = document.querySelector(viewport);
}

// checks the viewport element
if (typeof viewport === 'undefined' || viewport === null || viewport.nodeName.toLowerCase() !== 'canvas') {
throw new Error('Invalid viewport, you need to pass a valid HTML5 canvas element');
throw new Error('Invalid viewport, you need to pass a valid selector or HTML5 canvas element');
}

// initializes the viewport
Expand Down

0 comments on commit 5cf42f2

Please sign in to comment.