jq-signature.min.js 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*! jq-signature.min.js, v1.0.0, minified 2015-05-25 */
  2. !function (a, b, c) {
  3. var w;
  4. // w=$('windows').width();
  5. w=$(window).width();
  6. var h;
  7. h=$(window).height();
  8. h=h-(h*0.07);
  9. // h=$('windows').height();
  10. "use strict";
  11. function d(a, b) {
  12. this.element = a, this.$element = c(this.element), this.canvas = !1, this.$canvas = !1, this.ctx = !1, this.drawing = !1, this.currentPos = {
  13. x: 0,
  14. y: 0
  15. }, this.lastPos = this.currentPos, this._data = this.$element.data(), this.settings = c.extend({}, f, b, this._data), this.init()
  16. }
  17. a.requestAnimFrame = function (b) {
  18. return a.requestAnimationFrame || a.webkitRequestAnimationFrame || a.mozRequestAnimationFrame || a.oRequestAnimationFrame || a.msRequestAnimaitonFrame || function (b) {
  19. a.setTimeout(b, 1e3 / 60)
  20. }
  21. }();
  22. var e = "jqSignature", f = {
  23. lineColor: "#222222",
  24. lineWidth: 1,
  25. border: "1 dashed #AAAAAA",
  26. background: "#FFFFFF",
  27. width: w,
  28. height: h,
  29. autoFit: !1
  30. }, g = "<canvas></canvas>";
  31. d.prototype = {
  32. init: function () {
  33. this.$canvas = c(g).appendTo(this.$element), this.$canvas.attr({
  34. width: this.settings.width,
  35. height: this.settings.height
  36. }), this.$canvas.css({
  37. boxSizing: "border-box",
  38. width: this.settings.width + "",
  39. height: this.settings.height + "",
  40. border: this.settings.border,
  41. background: this.settings.background,
  42. cursor: "crosshair"
  43. }), this.settings.autoFit === !0 && this._resizeCanvas(), this.canvas = this.$canvas[0], this._resetCanvas(), this.$canvas.on("mousedown touchstart", c.proxy(function (a) {
  44. this.drawing = !0, this.lastPos = this.currentPos = this._getPosition(a)
  45. }, this)), this.$canvas.on("mousemove touchmove", c.proxy(function (a) {
  46. this.currentPos = this._getPosition(a)
  47. }, this)), this.$canvas.on("mouseup touchend", c.proxy(function (a) {
  48. this.drawing = !1;
  49. var b = c.Event("jq.signature.changed");
  50. this.$element.trigger(b)
  51. }, this)), c(b).on("touchstart touchmove touchend", c.proxy(function (a) {
  52. a.target === this.canvas && a.preventDefault()
  53. }, this));
  54. var d = this;
  55. !function e() {
  56. a.requestAnimFrame(e), d._renderCanvas()
  57. }()
  58. }, clearCanvas: function () {
  59. this.canvas.width = this.canvas.width, this._resetCanvas()
  60. }, getDataURL: function () {
  61. return this.canvas.toDataURL()
  62. }, _getPosition: function (a) {
  63. var b, c, d;
  64. return d = this.canvas.getBoundingClientRect(), a = a.originalEvent, -1 !== a.type.indexOf("touch") ? (b = a.touches[0].clientX - d.left, c = a.touches[0].clientY - d.top) : (b = a.clientX - d.left, c = a.clientY - d.top), {
  65. x: b,
  66. y: c
  67. }
  68. }, _renderCanvas: function () {
  69. this.drawing && (this.ctx.moveTo(this.lastPos.x, this.lastPos.y), this.ctx.lineTo(this.currentPos.x, this.currentPos.y), this.ctx.stroke(), this.lastPos = this.currentPos)
  70. }, _resetCanvas: function () {
  71. this.ctx = this.canvas.getContext("2d"), this.ctx.strokeStyle = this.settings.lineColor, this.ctx.lineWidth = this.settings.lineWidth
  72. }, _resizeCanvas: function () {
  73. var a = this.$element.outerWidth();
  74. this.$canvas.attr("width", a), this.$canvas.css("width", a + "")
  75. }
  76. }, c.fn[e] = function (a) {
  77. var b = arguments;
  78. if (void 0 === a || "object" == typeof a)return this.each(function () {
  79. c.data(this, "plugin_" + e) || c.data(this, "plugin_" + e, new d(this, a))
  80. });
  81. if ("string" == typeof a && "_" !== a[0] && "init" !== a) {
  82. var f;
  83. return this.each(function () {
  84. var g = c.data(this, "plugin_" + e);
  85. g instanceof d && "function" == typeof g[a] && (f = g[a].apply(g, Array.prototype.slice.call(b, 1))), "destroy" === a && c.data(this, "plugin_" + e, null)
  86. }), void 0 !== f ? f : this
  87. }
  88. }
  89. }(window, document, jQuery);