Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Ability to pass DOM ID and class to the canvas element #85

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Angular 2 component for [szimek/signature_pad](https://www.npmjs.com/package/sig
API is identical to [szimek/signature_pad](https://www.npmjs.com/package/signature_pad).

Options are as per [szimek/signature_pad](https://www.npmjs.com/package/signature_pad) with the following additions:
* canvasId: ID of the canvas element
* canvasClass: CSS class to be added to the canvas element
* canvasWidth: width of the canvas (px)
* canvasHeight: height of the canvas (px)
The above options are provided to avoid accessing the DOM directly from your component to adjust the canvas size.
Expand Down
28 changes: 20 additions & 8 deletions package-lock.json

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

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
"@angular/platform-browser": "2.0.1",
"@angular/platform-browser-dynamic": "2.0.1",
"@angular/platform-server": "2.0.1",
"rxjs": "5.0.0-beta.12",
"typescript": "2.0.3",
"rxjs": "5.4.2",
"rxjs-compat": "^6.5.3",
"tslib": "^1.10.0",
"typescript": "2.4.1",
"zone.js": "0.6.25"
}
}
8 changes: 8 additions & 0 deletions signature-pad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ export class SignaturePad {
public ngAfterContentInit(): void {
let sp: any = require('signature_pad')['default'];
let canvas: any = this.elementRef.nativeElement.querySelector('canvas');

if ((<any>this.options)['canvasId']) {
canvas.id = (<any>this.options)['canvasId'];
}

if ((<any>this.options)['canvasClass']) {
canvas.classList.add((<any>this.options)['canvasClass']);
}

if ((<any>this.options)['canvasHeight']) {
canvas.height = (<any>this.options)['canvasHeight'];
}
Expand Down