ohctech_p8/jquery.signature.package-1.2.1/js/jquery.signature.min.js

8 lines
6.1 KiB
JavaScript
Raw Normal View History

2024-10-16 19:18:52 +05:30
/*! http://keith-wood.name/signature.html
Signature plugin for jQuery UI v1.2.1.
Requires excanvas.js in IE.
Written by Keith Wood (wood.keith{at}optusnet.com.au) April 2012.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
!function(a){"use strict";var b={options:{distance:0,background:"#fff",color:"#000",thickness:2,guideline:!1,guidelineColor:"#a0a0a0",guidelineOffset:50,guidelineIndent:10,notAvailable:"Your browser doesn't support signing",scale:1,syncField:null,syncFormat:"JSON",svgStyles:!1,change:null},_create:function(){this.element.addClass(this.widgetFullName||this.widgetBaseClass);try{this.canvas=a('<canvas width="'+this.element.width()+'" height="'+this.element.height()+'">'+this.options.notAvailable+"</canvas>")[0],this.element.append(this.canvas)}catch(b){a(this.canvas).remove(),this.resize=!0,this.canvas=document.createElement("canvas"),this.canvas.setAttribute("width",this.element.width()),this.canvas.setAttribute("height",this.element.height()),this.canvas.innerHTML=this.options.notAvailable,this.element.append(this.canvas),G_vmlCanvasManager&&G_vmlCanvasManager.initElement(this.canvas)}this.ctx=this.canvas.getContext("2d"),this._refresh(!0),this._mouseInit()},_refresh:function(b){if(this.resize){var c=a(this.canvas);a("div",this.canvas).css({width:c.width(),height:c.height()})}this.ctx.fillStyle=this.options.background,this.ctx.strokeStyle=this.options.color,this.ctx.lineWidth=this.options.thickness,this.ctx.lineCap="round",this.ctx.lineJoin="round",this.clear(b)},clear:function(a){this.options.disabled||(this.ctx.clearRect(0,0,this.element.width(),this.element.height()),this.ctx.fillRect(0,0,this.element.width(),this.element.height()),this.options.guideline&&(this.ctx.save(),this.ctx.strokeStyle=this.options.guidelineColor,this.ctx.lineWidth=1,this.ctx.beginPath(),this.ctx.moveTo(this.options.guidelineIndent,this.element.height()-this.options.guidelineOffset),this.ctx.lineTo(this.element.width()-this.options.guidelineIndent,this.element.height()-this.options.guidelineOffset),this.ctx.stroke(),this.ctx.restore()),this.lines=[],a||this._changed())},_changed:function(b){if(this.options.syncField){var c="";switch(this.options.syncFormat){case"PNG":c=this.toDataURL();break;case"JPEG":c=this.toDataURL("image/jpeg");break;case"SVG":c=this.toSVG();break;default:c=this.toJSON()}a(this.options.syncField).val(c)}this._trigger("change",b,{})},_setOptions:function(){this._superApply?this._superApply(arguments):a.Widget.prototype._setOptions.apply(this,arguments);var b=0,c=!0;for(var d in arguments[0])arguments[0].hasOwnProperty(d)&&(b++,c=c&&"disabled"===d);(b>1||!c)&&this._refresh()},_mouseCapture:function(){return!this.options.disabled},_mouseStart:function(a){this.offset=this.element.offset(),this.offset.left-=document.documentElement.scrollLeft||document.body.scrollLeft,this.offset.top-=document.documentElement.scrollTop||document.body.scrollTop,this.lastPoint=[this._round(a.clientX-this.offset.left),this._round(a.clientY-this.offset.top)],this.curLine=[this.lastPoint],this.lines.push(this.curLine)},_mouseDrag:function(a){var b=[this._round(a.clientX-this.offset.left),this._round(a.clientY-this.offset.top)];this.curLine.push(b),this.ctx.beginPath(),this.ctx.moveTo(this.lastPoint[0],this.lastPoint[1]),this.ctx.lineTo(b[0],b[1]),this.ctx.stroke(),this.lastPoint=b},_mouseStop:function(a){1===this.curLine.length&&(a.clientY+=this.options.thickness,this._mouseDrag(a)),this.lastPoint=null,this.curLine=null,this._changed(a)},_round:function(a){return Math.round(100*a)/100},toJSON:function(){return'{"lines":['+a.map(this.lines,function(b){return"["+a.map(b,function(a){return"["+a+"]"})+"]"})+"]}"},toSVG:function(){var b=this.options.svgStyles?'style="fill: '+this.options.background+';"':'fill="'+this.options.background+'"',c=this.options.svgStyles?'style="fill: none; stroke: '+this.options.color+"; stroke-width: "+this.options.thickness+';"':'fill="none" stroke="'+this.options.color+'" stroke-width="'+this.options.thickness+'"';return'<?xml version="1.0"?>\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg xmlns="http://www.w3.org/2000/svg" width="15cm" height="15cm">\n\t<g '+b+'>\n\t\t<rect x="0" y="0" width="'+this.canvas.width+'" height="'+this.canvas.height+'"/>\n\t\t<g '+c+">\n"
//# sourceMappingURL=jquery.signature.min.map