From: john@roojs.com Date: Wed, 2 Jan 2019 07:32:22 +0000 (+0800) Subject: FIX: bezier signature upload image X-Git-Url: http://git.roojs.org/?p=roojs1;a=commitdiff_plain;h=267027b86f0cf2f99b77589a6ca0aab049dbf514 FIX: bezier signature upload image --- diff --git a/Roo/bootstrap/BezierSignature.js b/Roo/bootstrap/BezierSignature.js index 3bbdd17b9d..379c181cc3 100644 --- a/Roo/bootstrap/BezierSignature.js +++ b/Roo/bootstrap/BezierSignature.js @@ -121,6 +121,11 @@ Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component, { width: this.canvas_width } ] + }, + { + tag: 'input', + type: 'file', + style: 'display: none' } ] }; @@ -157,6 +162,9 @@ Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component, { Roo.EventManager.onWindowResize(this.resize, this, true); + // file input event + this.fileEl().on('change', this.uploadImage, this); + this.clear(); this.resize(); @@ -392,6 +400,11 @@ Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component, { this.is_empty = true; }, + fileEl: function() + { + return this.el.select('input',true).first(); + }, + canvasEl: function() { return this.el.select('canvas',true).first(); @@ -425,6 +438,27 @@ Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component, { this.is_empty = false; }, + selectImage: function() + { + this.fileEl().dom.click(); + }, + + uploadImage: function(e) + { + var reader = new FileReader(); + + reader.onload = function(e){ + var img = new Image(); + img.onload = function(){ + this.reset(); + this.canvasElCtx().drawImage(img, 0, 0); + }.bind(this); + img.src = e.target.result; + }.bind(this); + + reader.readAsDataURL(e.target.files[0]); + }, + // Bezier Point Constructor Point: (function () { function Point(x, y, time) { diff --git a/roojs-bootstrap-debug.js b/roojs-bootstrap-debug.js index 4f56030627..3fc684a5d2 100644 --- a/roojs-bootstrap-debug.js +++ b/roojs-bootstrap-debug.js @@ -41623,6 +41623,11 @@ Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component, { width: this.canvas_width } ] + }, + { + tag: 'input', + type: 'file', + style: 'display: none' } ] }; @@ -41659,6 +41664,9 @@ Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component, { Roo.EventManager.onWindowResize(this.resize, this, true); + // file input event + this.fileEl().on('change', this.uploadImage, this); + this.clear(); this.resize(); @@ -41894,6 +41902,11 @@ Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component, { this.is_empty = true; }, + fileEl: function() + { + return this.el.select('input',true).first(); + }, + canvasEl: function() { return this.el.select('canvas',true).first(); @@ -41927,6 +41940,27 @@ Roo.extend(Roo.bootstrap.BezierSignature, Roo.bootstrap.Component, { this.is_empty = false; }, + selectImage: function() + { + this.fileEl().dom.click(); + }, + + uploadImage: function(e) + { + var reader = new FileReader(); + + reader.onload = function(e){ + var img = new Image(); + img.onload = function(){ + this.reset(); + this.canvasElCtx().drawImage(img, 0, 0); + }.bind(this); + img.src = e.target.result; + }.bind(this); + + reader.readAsDataURL(e.target.files[0]); + }, + // Bezier Point Constructor Point: (function () { function Point(x, y, time) { diff --git a/roojs-bootstrap.js b/roojs-bootstrap.js index a021590248..b8a92f657d 100644 --- a/roojs-bootstrap.js +++ b/roojs-bootstrap.js @@ -1733,24 +1733,26 @@ return false;}return true;},validate:function(){if(this.disabled||this.allowBlan // Roo/bootstrap/BezierSignature.js Roo.bootstrap.BezierSignature=function(A){Roo.bootstrap.BezierSignature.superclass.constructor.call(this,A);this.addEvents({"resize":true});};Roo.extend(Roo.bootstrap.BezierSignature,Roo.bootstrap.Component,{curve_data:[],is_empty:true,mouse_btn_down:true,canvas_height:'200px',dot_size:false,min_width:0.5,max_width:2.5,throttle:16,min_distance:5,bg_color:'rgba(0, 0, 0, 0)',dot_color:'black',velocity_filter_weight:0.7,onBegin:false,onEnd:false,getAutoCreate:function(){var A='roo-signature column'; if(this.cls){A+=' '+this.cls;}var B=['lg','md','sm','xs'];for(var i=0;i0&&D[D.length-1];var F=E?B.distanceTo(E)<=this.min_distance:false;var G=C.color;if(!E||!(E&&F)){var H=this.addPoint(B); -if(!E){this.drawDot({color:G,point:B});}else if(H){this.drawCurve({color:G,curve:H});}D.push({time:B.time,x:B.x,y:B.y});}},strokeEnd:function(e){this.strokeUpdate(e);if(typeof this.onEnd==='function'){this.onEnd(e);}},addPoint:function(A){var B=this._lastPoints; -B.push(A);if(B.length>2){if(B.length===3){B.unshift(B[0]);}var C=this.calculateCurveWidths(B[1],B[2]);var D=this.Bezier.fromPoints(B,C,this);B.shift();return D;}return null;},calculateCurveWidths:function(A,B){var C=this.velocity_filter_weight*B.velocityFrom(A)+(1-this.velocity_filter_weight)*this._lastVelocity; -var D=Math.max(this.max_width/(C+1),this.min_width);var E={end:D,start:this._lastWidth};this._lastVelocity=C;this._lastWidth=D;return E;},drawDot:function(_a){var A=_a.color,B=_a.point;var C=this.canvasElCtx();var D=typeof this.dot_size==='function'?this.dot_size():this.dot_size; -C.beginPath();this.drawCurveSegment(B.x,B.y,D);C.closePath();C.fillStyle=A;C.fill();},drawCurve:function(_a){var A=_a.color,B=_a.curve;var C=this.canvasElCtx();var D=B.endWidth-B.startWidth;var E=Math.floor(B.length())*2;C.beginPath();C.fillStyle=A;for(var i=0; -i0&&D[D.length-1];var F=E?B.distanceTo(E)<=this.min_distance:false;var G=C.color;if(!E||!(E&&F)){var H=this.addPoint(B);if(!E){this.drawDot({color:G,point:B});}else if(H){this.drawCurve({color:G,curve:H});}D.push({time:B.time,x:B.x,y:B.y} +);}},strokeEnd:function(e){this.strokeUpdate(e);if(typeof this.onEnd==='function'){this.onEnd(e);}},addPoint:function(A){var B=this._lastPoints;B.push(A);if(B.length>2){if(B.length===3){B.unshift(B[0]);}var C=this.calculateCurveWidths(B[1],B[2]);var D=this.Bezier.fromPoints(B,C,this); +B.shift();return D;}return null;},calculateCurveWidths:function(A,B){var C=this.velocity_filter_weight*B.velocityFrom(A)+(1-this.velocity_filter_weight)*this._lastVelocity;var D=Math.max(this.max_width/(C+1),this.min_width);var E={end:D,start:this._lastWidth} +;this._lastVelocity=C;this._lastWidth=D;return E;},drawDot:function(_a){var A=_a.color,B=_a.point;var C=this.canvasElCtx();var D=typeof this.dot_size==='function'?this.dot_size():this.dot_size;C.beginPath();this.drawCurveSegment(B.x,B.y,D);C.closePath();C.fillStyle=A; +C.fill();},drawCurve:function(_a){var A=_a.color,B=_a.curve;var C=this.canvasElCtx();var D=B.endWidth-B.startWidth;var E=Math.floor(B.length())*2;C.beginPath();C.fillStyle=A;for(var i=0;i