项目作者: jerme404

项目描述 :
AngularJS signature pad component
高级语言: JavaScript
项目地址: git://github.com/jerme404/ng-sign-here.git
创建时间: 2018-06-25T12:34:35Z
项目社区:https://github.com/jerme404/ng-sign-here

开源协议:MIT License

下载


ng-sign-here

AngularJS wrapper component for signature_pad.

Demo

The demo uses on-signature-update to set the background image of a div after each signature stroke.

Install

  1. npm install ng-sign-here

Dependencies

The only dependency, other than AngularJS, is signature_pad. You can either link it, or install the latest release package with

  1. npm install signature_pad

Getting Started

Include ngSignHere.min.js and signature_pad.

  1. <script src="https://cdn.jsdelivr.net/npm/signature_pad@2.3.2/dist/signature_pad.min.js"></script>
  2. <script src="../dist/ngSignHere.min.js"></script>

Add ngSignaturePad as a module dependency.

  1. angular.module('demoApp', ['ngSignHere']);

Add the sign-here component to your html.

  1. <sign-here></sign-here>

Examples

Adding the component in html isn’t very useful by itself. You can draw on the canvas, but that’s about it. All bindings are optional, and one-way.

Size

To set the signature pad size, simply add a css class or inline style. The signature pad will size itself to fit.

  1. <sign-here style="width: 600px; height: 300px;">
  2. </sign-here>

Background Color

Set the background color using background-color.
Supports hex, rgb/rgba, and color names. Defaults to transparent.

  1. <!-- Sets background color to black -->
  2. <sign-here background-color="#000000">
  3. </sign-here>

Pen Color

Set the pen color using pen-color.
Supports hex, rgb/rgba, and color names. Defaults to a dark blue.

  1. <!-- Sets pen color to green -->
  2. <sign-here pen-color="#6BD425">
  3. </sign-here>

Image Format

Set the returned image format using image-format.
Valid formats are png, jpg/jpeg, and svg. Defaults to png.

  1. <!-- Sets image format to svg -->
  2. <sign-here image-format="svg">
  3. </sign-here>

Getting the Signature

Pass a function to on-signature-update. Internally, this is called on the signature_pad onEnd event, meaning at the end of each signature stroke.

  1. // Controller signature update function.
  2. ctrl.onSignatureUpdate = function (signatureData) {
  3. // Set a signatureData property on your controller.
  4. ctrl.signature = signatureData;
  5. };
  1. <sign-here on-signature-update="demo.onSignatureUpdate">
  2. </sign-here>

Clearing the Signature

This component does NOT use two-way binding, so you need to register a handler with register-clear-handler, and then call that handler from your controller. On clear, the onSignatureUpdate event will fire with undefined.

  1. // Your controller's clear handler.
  2. let clearSignatureHandler = null;
  3. // Register clear handler function.
  4. ctrl.registerClearHandler = function (handler) {
  5. // Set the handler returned from the component.
  6. clearSignatureHandler = handler;
  7. };
  8. // Handle the clear button click.
  9. ctrl.clearSignature = function () {
  10. // Check if a the clearSignatureHandler is registered.
  11. if (clearSignatureHandler) {
  12. clearSignatureHandler();
  13. }
  14. };
  1. <!-- Register your controller's clear handler -->
  2. <sign-here demo.registerClearHandler(handler)>
  3. </sign-here>
  4. <!-- A clear button somewhere on your page -->
  5. <button ng-click="demo.clearSignature()">
  6. CLEAR
  7. </button>

Non Implemented

The following signature_pad options/features have been omitted because I didn’t need them. I may or may not add these in the future, but you’re certainly welcome to submit a pull request if you want to add them.

  • dotSize
  • minWidth
  • maxWidth
  • throttle
  • minDistance
  • velocityFilterWeight
  • onBegin

    Build from Source

    Clone the repository.
    1. git clone https://github.com/jerme404/ng-sign-here.git
    Install npm packages.
    1. npm install
    Run gulp.
    1. gulp