Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuan Nguyen committed Jan 15, 2019
1 parent cf589c2 commit 904f10d
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Servoy
Copyright (c) 2016 Servoy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
9 changes: 9 additions & 0 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Manifest-Version: 1.0
Bundle-SymbolicName: svysignature
Bundle-Name: svysignature
Bundle-Version: 1.0.0
Package-Type: Web-Component

Name: pad/pad.spec
Web-Component: True

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
# svySignature
Signature component for Servoy

Getting started
-------------

Get the latest version from the [releases](https://github.com/Servoy/svySignature/releases). Download and import the [svySignatureExample.servoy](https://github.com/Servoy/svySignature/releases) example solution or check out source directly from github.

Documentation
-------------
See the [Wiki](https://github.com/Servoy/svySignature/wiki) for the available documentation


Feature Requests & Bugs
-----------------------
Found a bug or would like to see a new feature implemented? Raise an issue in the [Issue Tracker](https://github.com/Servoy/svySignature/issues)


Contributing
-------------
Eager to fix a bug or introduce a new feature? Clone the repository and issue a pull request


License
-------
svySignature is licensed under the [MIT license](https://opensource.org/licenses/MIT)
Binary file added icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions pad/lib/signature_pad.min.js

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

3 changes: 3 additions & 0 deletions pad/pad.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div id="{{::model.svyMarkupId}}-wrapper" ng-class=model.styleClass style="height:100%;width:100%;">
<canvas id="{{::model.svyMarkupId}}" ng-class=model.styleClass style="height:100%;width:100%;"></canvas>
</div>
94 changes: 94 additions & 0 deletions pad/pad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
angular.module('svysignaturePad', ['servoy']).directive('svysignaturePad', function() {
return {
restrict: 'E',
scope: {
model: '=svyModel',
handlers: "=svyHandlers",
api: "=svyApi",
svyServoyapi: "="
},
controller: function($scope, $element, $attrs) {
$scope.signaturePad = null;

/*
* Draw image with a base 64 string
* @param {String} data base64 data string to draw
*
*/
$scope.api.setDataUrl = function(data) {
return $scope.signaturePad.fromDataURL(data);
};

/*
* Get image as base64 string
* @param {String} [type] image mimetype to save as ("image/jpeg","image/png") full list at https://mdn.io/todataurl
*
* @private
*/
$scope.api.getDataUrl = function(type) {

var datatemp = $scope.signaturePad.toData();
setTimeout(function() {
$scope.signaturePad.fromData(datatemp);
}, 500);

var data = $scope.signaturePad.toDataURL(type);

return data;
};

/*
* Clear Signature Pad
*/
$scope.api.clear = function() {
$scope.signaturePad.clear();
};

/*
* Initialize Signature Pad
* @param {Object} options additional options
* Options {}
* dotSize : (float or function) Radius of a single dot.
* minWidth : (float) Minimum width of a line. Defaults to 0.5.
* maxWidth : (float) Maximum width of a line. Defaults to 2.5.
* throttle : (integer) Draw the next point at most once per every x milliseconds. Set it to 0 to turn off throttling. Defaults to 16.
* minDistance : (integer) Add the next point only if the previous one is farther than x pixels. Defaults to 5.
* backgroundColor : (string) Color used to clear the background. Can be any color format accepted by context.fillStyle.
* Defaults to "rgba(0,0,0,0)" (transparent black). Use a non-transparent color e.g. "rgb(255,255,255)" (opaque white)
* if you'd like to save signatures as JPEG images.
* penColor: (string) Color used to draw the lines. Can be any color format accepted by context.fillStyle. Defaults to "black".
* velocityFilterWeight : (float) Weight used to modify new velocity based on the previous velocity. Defaults to 0.7.
* onBegin : (function) Callback when stroke begin.
* onEnd : (function) Callback when stroke end.
*/
$scope.api.init = function(options) {
var element = document.getElementById($scope.model.svyMarkupId + '-wrapper');
var canvas = document.getElementById($scope.model.svyMarkupId);

//add onBegin/onEnd Handlers
if ($scope.handlers.onBegin) {
options.onBegin = $scope.handlers.onBegin
}
if ($scope.handlers.onEnd) {
options.onEnd = $scope.handlers.onEnd
}
$scope.signaturePad = new SignaturePad(canvas, options);

function resizeCanvas() {
var data = $scope.signaturePad.toData()
var ratio = Math.max(window.devicePixelRatio || 1, 1);
canvas.width = canvas.offsetWidth * ratio;
canvas.height = canvas.offsetHeight * ratio;
canvas.getContext("2d").scale(ratio, ratio);
$scope.signaturePad.clear(); // otherwise isEmpty() might return incorrect value
$scope.signaturePad.fromData(data);
}

window.addEventListener("resize", resizeCanvas);
resizeCanvas();

};
},
templateUrl: 'svysignature/pad/pad.html'
};
})
98 changes: 98 additions & 0 deletions pad/pad.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"name": "svysignature-pad",
"displayName": "pad",
"version": 1,
"definition": "svysignature/pad/pad.js",
"libraries":
[
{
"name": "signature_pad.min.js",
"version": "2.3.2",
"url": "svysignature/pad/lib/signature_pad.min.js",
"mimetype": "text/javascript"
}
],

"model":
{
"styleClass":
{
"type": "styleclass",
"tags":
{
"scope": "design"
},

"default": "",
"values":
[
]
}
},

"handlers":
{
"onBegin":
{
"parameters":
[

]
},

"onEnd":
{
"parameters":
[

]
}
},

"api":
{
"init":
{
"parameters":
[
{
"name": "options",
"type": "object"
}
],

"returns": "boolean"
},

"getDataUrl":
{
"parameters":
[
{
"name": "type",
"type": "string"
}
],

"returns": "string"
},

"setDataUrl":
{
"parameters":
[
{
"name": "data",
"type": "string"
}
],

"returns": "boolean"
},

"clear":
{
"returns": "boolean"
}
}
}
12 changes: 12 additions & 0 deletions webpackage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "svySignature",
"displayName": "svySignature",
"packageType": "Web-Component",
"icon": "https://raw.githubusercontent.com/Servoy/svySignature/master/icon.png",
"description": "Signature component for Servoy",
"wikiUrl": "https://github.com/Servoy/svySignature/wiki",
"sourceUrl": "https://github.com/Servoy/svySignature",
"releases": [
{"version": "1.0.0","url": "https://github.com/Servoy/svySignature/releases/download/v1.0.0/svySignature.zip","servoy-version":"8.2.0"},
]
}

0 comments on commit 904f10d

Please sign in to comment.