// signature_signature.js
// RJM Programming
// May, 2017
// Help out signature_signature.html and others like it
var transcontent=false, elemis=null, contextis=null;
var trotis=0, rotis=0, always_horizontally_flip=false, always_vertically_flop=false;
var lastrotis=0, lastalways_horizontally_flip=false, lastalways_vertically_flop=false;
var jsanimg=null, lastim='';
var topprocessb=null,topin=null,toplastta='',topfirst=true,toplthere=false, topelem=null, topielem=null, topcontext=null, topwidth=0, topheight=0, topvswidth=0, topvsheight=0, topvswidthoff=0, topvsheightoff=0;
var firstcall=true;savenow=0, lastsavenow=0, ppx=-1,ppy=-1,pmore='', isScribble=1; //0;
var prevlines=[], lines=[];
var eighteen=18;
var njk=0;
var tx=-1, ty=-1;
var prevtx=-1, prevty=-1;
var imgmode="y";
var omyh1;
var lastimis="";
var fcont="";
var bigi=0;
var bigj=0;
var mytaone="\n\n
\n\n\n\n\n";
var wl="", pddcm="";
var doneonce="";
var presm="sm";
var bigbuffer="";
var prevmy_res="";
var bigf=new Array();
var urlsuf="";
var zipcnt=0;var jsrectbits=[0,0,0,0,0,0];
var jsclickno = 0;
var jsimgh=0, jsimgw=0;
var jsemail = "";
var jscf = "18px Verdana", lastjscf=jscf;
var precolcf = "black";
var colcf = "blue rgba(0,0,255,1.0)";
var xua = navigator.userAgent;
var isiPad = /iPad/i.test(xua) || /iPhone/i.test(xua) || /iPhone OS 3_1_2/i.test(xua) || /Andrxoid/i.test(xua) || /iPhone OS 3_2_2/i.test(xua);
var isTouch = /touch/i.test(xua) || /Touch/i.test(xua);
var sscoords = (location.search.split('sscoords=')[1] ? decodeURIComponent(location.search.split('sscoords=')[1].split('&')[0]) : '');
var ninehundred = (location.search.split('ninehundred=')[1] ? eval(decodeURIComponent(location.search.split('ninehundred=')[1].split('&')[0])) : 900);
if (ninehundred > 900) sscoords='';
//var cbrowse='
Read bytes:';
var cbrowse=' ';
cbrowse+='';
cbrowse+=' ';
cbrowse+=' ';
cbrowse+=' ';
cbrowse+=' ';
var cbrowse_nocapture=cbrowse.replace(' capture','');
function dImage(con, img, xx, yy, width, height, deg, flip, flop, center) { // thanks to http://stackoverflow.com/questions/3129099/how-to-flip-images-horizontally-with-html5
//document.getElementById('showit').style.display='inline';
//img.style.display='block';
//if (con) alert(width + ' ' + height);
//con.clearRect(0, 0, width, height);
con.save();
if (typeof width === "undefined") width = img.width;
if (typeof height === "undefined") height = img.height;
if (typeof center === "undefined") center = false;
// Set rotation point to center of image, instead of top/left
if (center) {
xx -= width/2;
yy -= height/2;
}
// Set the origin to the center of the image
con.translate(xx + width/2, yy + height/2);
// Rotate the canvas around the origin
var rad = 2 * Math.PI - deg * Math.PI / 180;
con.rotate(rad);
// Flip/flop the canvas
if (flip) {
flipScale = -1;
//document.title='flipping out';
} else {
flipScale = 1;
}
if (flop) {
flopScale = -1;
//document.title='flopping out';
} else {
flopScale = 1;
//document.title='flopping in';
}
//if (con) alert(width + ' : ' + height);
con.scale(flipScale, flopScale);
//if (con) alert(width + ' ; ' + height);
con.clearRect(eval(-2 * topelem.width), eval(-2 * topelem.height), eval(4 * topelem.width), eval(4 * topelem.height));
//con.clearRect(0, 0, width, height);
// Draw the image
con.drawImage(img, -width/2, -height/2, width, height);
//if (con) alert(width + ' = ' + height);
con.restore();
//if (con) alert(flipScale + ',' + flopScale + ':' + width + ' + ' + height);
}
function maybemedia(inidea) {
var outidea = inidea;
var parts = inidea.split("<");
var pdfi = "icon_pdf.gif";
var doci = "icon_doc.gif";
var xlsi = "icon_xls.gif";
var appi = "icon_popup.gif";
var audioi = "icon_external.gif";
var dparts = String.fromCharCode(34) + parts[0] + String.fromCharCode(34);
var videoi = "icon_external.gif";
if (inidea.indexOf("/pdf") != -1) {
outidea = inidea.replace(" Type is ", " Type is ");
} else if (inidea.indexOf("audio/") != -1) {
outidea = inidea.replace(" Type is ", " Type is ");
} else if (inidea.indexOf("video/") != -1) {
outidea = inidea.replace(" Type is ", " Type is ");
} else if (inidea.indexOf("application/") != -1 && inidea.indexOf("spreadsheet") != -1) {
outidea = inidea.replace(" Type is ", " Type is ");
} else if (inidea.indexOf("application/") != -1 && (inidea.indexOf("document") != -1 || inidea.indexOf("msword") != -1)) {
outidea = inidea.replace(" Type is ", " Type is ");
} else if (inidea.indexOf("application/") != -1) {
outidea = inidea.replace(" Type is ", " Type is ");
} else if (inidea.indexOf("image/") != -1) {
outidea = inidea.replace(" Type is ", " Type is ");
}
//alert(outidea);
return outidea;
}
function readBlob(opt_startByte, opt_stopByte) {
omyh1 = parent.document.getElementById("myh1");
var files = parent.document.getElementById("file").files;
if (!files.length) {
alert("Please select a file!");
return;
}
var file = files[0];
var ourfile;
for (var i = 0; i < files.length; i++) {
ourfile = files[i];
// Check the file type.
if ((ourfile.type.indexOf("audio/") != -1 && (njk == 0 || njk == 2)) || (ourfile.type.indexOf("video/") != -1 && (njk == 0 || njk == 1))) {
// Add the file to the request.
njk = njk + 1;
if (ourfile.type.indexOf("video/") != -1) {
njk = njk + 1;
vformData.append("vfile", ourfile, ourfile.name);
} else {
aformData.append("afile", ourfile, ourfile.name);
}
}
}
var start = parseInt(opt_startByte) || 0;
var stop = parseInt(opt_stopByte) || file.size - 1;
var reader = new FileReader();
if ((imgmode == " " && file.type.match('image.*') && "" != "n") || "" == "no") {
imgmode = "y";
} else if (imgmode == " ") {
imgmode = "";
}
if ("" != "n" && "" != "nowayjose" && (imgmode == "y" || file.type.match('image.*') || file.type.indexOf('/pdf') != -1 || file.type.indexOf('audio/') != -1 || file.type.indexOf('video/') != -1 || file.type.indexOf('application/') != -1)) {
// Closure to capture the file information.
reader.onload = (function(theFile) {
return function(e) {
if ("" == "no") { // zipping files scenario ... yay one
var ond=0; //parseInt(parent.document.getElementById("cntzip").value);
var dno=eval(1 + ond);
if (escape(theFile.name) != "" && parent.document.body.innerHTML.indexOf("*" + escape(theFile.name) + "*") == -1) {
parent.document.body.innerHTML = parent.document.body.innerHTML + "
";
parent.document.getElementById('myta').value=taval;
}
}
parent.document.getElementById('divbrowse').style.display='block';
}
//parent.document.getElementById("file").click();
//alert(1111);
//}
}
}
if (parent.document.getElementById('jsemail') && parent.document.getElementById('jsemailb')) {
if (parent.document.getElementById('jsemail').value.indexOf('@') > 0) {
if (parent.document.getElementById('jsemail').value.indexOf(' ') != -1) { // postcard email
parent.document.getElementById('jsemail').value=parent.document.getElementById('jsemail').value.replace(/\ /g,'');
var greeting="";
if ((parent.document.getElementById('myta').value + ' ').indexOf('<') == 0 && parent.document.getElementById('myta').value != mytaone) {
greeting='';
} else {
parent.document.getElementById('myta').value=mytaone;
greeting=prompt('Given the canvas to the left is your Postcard background image, please supply email Greeting HTML in between
and
supplied (and if you just supply wording we will make it an HTML p element) ... we will accept the ~ character as a line feed ... to Cancel means that you will take your time to do the HTML in textarea below and try again later', '');
}
if (greeting != null) {
if (greeting.length > 0) {
if (greeting.indexOf('<') == -1) {
parent.document.getElementById('myta').value=parent.document.getElementById('myta').value.replace("", "
" + greeting.replace(/~/g," ") + "
");
} else {
parent.document.getElementById('myta').value=parent.document.getElementById('myta').value.replace("", greeting.replace(/~/g," "));
}
}
parent.document.getElementById('jsemailb').style.display='none';
if (parent.document.getElementById('jsemailp')) parent.document.getElementById('jsemailp').style.display='none';
sendtheemail(parent.document.getElementById('myta').value);
}
} else if (parent.document.getElementById('jsemail').value.indexOf(' ') != -1) { // normal email
parent.document.getElementById('jsemail').value=parent.document.getElementById('jsemail').value.replace(/\ /g,'');
parent.document.getElementById('jsemailb').style.display='none';
if (parent.document.getElementById('jsemailp')) parent.document.getElementById('jsemailp').style.display='none';
sendtheemail("");
} else {
parent.document.getElementById('jsemailb').style.display='inline';
if (parent.document.getElementById('jsemailp')) parent.document.getElementById('jsemailp').style.display='inline';
}
}
}
if (parent.document.getElementById('myta')) {
if (parent.document.getElementById('myta').value != '' && (parent.document.getElementById('myta').value + ' ').indexOf('<') != 0) {
if (toplastta != parent.document.getElementById('myta').value) {
var starth=20, izero=0, fstarth=20, jzero=0;
//topcontext.clearRect(0, 0, eval(topwidth.replace('px','')), eval(topvsheightoff));
if (parent.document.getElementById('jscf')) {
jscf=parent.document.getElementById('jscf').value;
if (jscf.indexOf('px') != -1) {
eighteen=(" " + jscf).split('px')[0].trim().split(' ')[eval(-1 + (" " + jscf).split('px')[0].trim().split(' ').length)];
}
}
if (parent.document.getElementById('colcf')) {
colcf=parent.document.getElementById('colcf').value;
}
topcontext.font = jscf;
topcontext.strokeStyle = colcf.split(' ')[eval(-1 + colcf.split(' ').length)];
topcontext.fillStyle = colcf.split(' ')[eval(-1 + colcf.split(' ').length)];
lines=parent.document.getElementById('myta').value.split(String.fromCharCode(10));
var istart=0, iend=0;
if (parent.document.getElementById('dcm')) {
if (parent.document.getElementById('dcm').value.toLowerCase().indexOf('text') == 0) {
iend=1;
}
}
var fifteen=eighteen, five=5, oneless=0;
if (trotis != 0) oneless=1;
for (var ii=istart; ii<=iend; ii++) {
for (var ilines=0; ilines ilines) {
if (prevlines[ilines] != lines[ilines]) {
izero=jzero;
if (jzero == 0 && prevlines[ilines] != '' && lines[ilines] != '' && lines[ilines].indexOf(prevlines[ilines]) == 0 && lastjscf != jscf) {
izero=eval(eval('' + eighteen) / 2.5) * eval(prevlines[ilines].length);
//alert(eval(fstarth + 0) + ' at top vs bottom at ' + eval(starth + 20) + ' and left at ' + izero + ' for width ' + eval(eval(topwidth.replace('px','')) - izero));
if (ii == istart && ii == iend && trotis == 0) topcontext.clearRect(izero, Math.max(0,eval(fstarth - fifteen) / 1), eval(eval(topwidth.replace('px','')) - izero), eval(starth * 0 + eval('' + eighteen) + 2) / 1);
if (ii == iend) rotateStrokeText(topcontent,lines[ilines].substring(prevlines[ilines].length),eval(eval('' + izero) + five),starth); //topcontext.strokeText(lines[ilines].substring(prevlines[ilines].length),eval(eval('' + izero) + five),starth);
} else {
if (ii == istart && ii == iend && trotis == 0) topcontext.clearRect(izero, Math.max(0,eval(fstarth - fifteen)), eval(eval(topwidth.replace('px','')) - izero), eval(starth * 0 + eval('' + eighteen) + 2));
if (ii == iend) rotateStrokeText(topcontext,lines[ilines],eval(eval('' + izero) + five),starth); //topcontext.strokeText(lines[ilines],eval(eval('' + izero) + five),starth);
}
}
} else {
if (ii == istart && ii == iend && trotis == 0) topcontext.clearRect(0, Math.max(0,eval(fstarth - fifteen)), eval(topwidth.replace('px','')), eval(starth * 0 + eval('' + eighteen) + 2));
if (ii == iend) rotateStrokeText(topcontext,lines[ilines],eval(eval('' + izero) + five),starth); // topcontext.strokeText(lines[ilines],eval(eval('' + izero) + five),starth);
}
//if (ii == istart && ii == iend) fifteen=1;
starth+=eval(eval('' + eighteen) + 2);
fstarth=starth;
if (ii == iend) prevlines[ilines]=lines[ilines];
}
if (parent.document.getElementById('dcm')) {
if (parent.document.getElementById('dcm').value.toLowerCase().indexOf('text') == 0) {
if (eval(prevtx) > 0 && eval(prevty) > 0) {
izero=prevtx;
} else if (eval(tx) > 0 && eval(ty) > 0) {
izero=tx;
} else if (eval(ppx) > 0 && eval(x) > 0) {
izero=x;
} else {
izero=ppx;
}
jzero=izero;
fifteen=eval('' + eighteen);
five=0;
if (eval(prevtx) > 0 && eval(prevty) > 0) {
fstarth=eval(prevty + fifteen);
} else if (eval(tx) > 0 && eval(ty) > 0) {
fstarth=eval(ty + fifteen);
} if (eval(ppy) > 0 && eval(y) > 0) {
fstarth=eval(y + fifteen);
} else {
fstarth=eval(ppy + fifteen);
}
starth=fstarth;
//alert(izero + "," + fstarth);
if (isTouch || isiPad) {
setTimeout(muchlater,10000);
}
}
}
}
toplastta=parent.document.getElementById('myta').value;
lastjscf=jscf;
}
}
}
if (savenow != 0) {
if (savenow != lastsavenow) {
if (document.getElementById('showi')) {
if (document.getElementById('animage')) {
document.getElementById('animage').src = elem.toDataURL('image/jpeg', 0.7); //"image/png");
}
document.getElementById('showi').style.display='inline';
}
}
}
setTimeout(regularly,1000);
}
function canvas_events() {
//alert(1);
if (parent.document) {
//alert(11);
if (document) {
//alert(111);
if (parent.document != document) { // we are being supervised above another application wanting to access a signature
//alert(1111);
if (parent.document.getElementById('topcanvas') && parent.document.getElementById('topiframe')) {
//alert('yes');
topelem=parent.document.getElementById('topcanvas');
topielem=parent.document.getElementById('topiframe');
if (1 == 1) {
if (parent.document.getElementById('inthemiddleofsomething') == null) {
var honehuhs=parent.document.getElementsByTagName('h1');
if (honehuhs.length > 0) {
honehuhs[0].innerHTML+="";
}
} //else {
//alert(90);
//}
}
if (parent.document.getElementById('inthemiddleofsomething')) {
topin=parent.document.getElementById('inthemiddleofsomething');
} //else {
//alert(98);
//}
topcontext = topelem.getContext("2d");
topwidth=('' + topelem.width).replace('px','');
topheight=('' + topelem.height).replace('px','');
//alert('yes again');
if (topelem && topin && 1 == 1) { // onclick discrete clicks section
// Add event listener for `click` events.
topelem.addEventListener('click', function(event) {
if (x == 0 && y == 0 && lastx == 0 && lasty == 0) {
if (event.pageX || event.pageY) {
x = event.pageX - elemLeft;
y = event.pageY - elemTop;
} else {
x = event.clientX - elemLeft;
y = event.clientY - elemTop;
}
lastx=x;
lasty=y;
} else {
lastx=x;
lasty=y;
if (event.pageX || event.pageY) {
x = event.pageX - elemLeft;
y = event.pageY - elemTop;
} else {
x = event.clientX - elemLeft;
y = event.clientY - elemTop;
}
}
//parent.document.title+=' here';
if (topin) {
if (topin.value == '' || (topin.value + ',').indexOf('- -1,0,0,0,0,') == 0 || (topin.value.indexOf('- -') == 0 && topin.value.indexOf(',0,0,0,0') == -1)) {
if (topin.value == '') {
if (eval(jsclickno % 2) == 0) { // lower left
jsrectbits[eval(jsclickno % 2)] = x;
jsrectbits[eval(jsclickno % 2) + 1] = y;
if (1 == 2) parent.document.title+=' oNclicK at x,y=' + x + ',' + y + ' ' + topin.value;
if (parent.document.getElementById('dcm')) {
if (parent.document.getElementById('dcm').value.toLowerCase().indexOf('text') == 0) {
jsclickno = jsclickno + 1;
jsrectbits[eval(jsclickno % 2) * 2] = x;
jsrectbits[eval(jsclickno % 2) * 2 + 1] = y;
}
}
} else { // upper right
jsrectbits[eval(jsclickno % 2) * 2] = x;
jsrectbits[eval(jsclickno % 2) * 2 + 1] = y;
if (1 == 2) parent.document.title+=' oNClicK at x,y=' + x + ',' + y + ' ' + topin.value;
shapedraw();
}
topin.value = '';
} else {
if (eval(jsclickno % 2) != 0) { // upper right
jsrectbits[eval(jsclickno % 2) * 2] = x;
jsrectbits[eval(jsclickno % 2) * 2 + 1] = y;
if (1 == 2) parent.document.title=' oNClick at x,y=' + x + ',' + y + ' ' + topin.value;
shapedraw();
} else { // lower left
jsrectbits[eval(jsclickno % 2)] = x;
jsrectbits[eval(jsclickno % 2) + 1] = y;
if (1 == 2) parent.document.title=' oNclick at x,y=' + x + ',' + y + ' ' + topin.value;
if (parent.document.getElementById('dcm')) {
if (parent.document.getElementById('dcm').value.toLowerCase().indexOf('text') == 0) {
jsclickno = jsclickno + 1;
jsrectbits[eval(jsclickno % 2) * 2] = x;
jsrectbits[eval(jsclickno % 2) * 2 + 1] = y;
}
}
}
topin.value = '- -';
}
jsclickno = jsclickno + 1;
} else {
if (topin.value.indexOf(',0,0,0,0') != -1) {
//parent.document.title=topin.value;
topin.value = '- -';
} //else {
//parent.document.title=topin.value;
//}
}
}
});
}
// }
}
}
}
}
ssj_cookieVal(firstcall);
firstcall=false;
if (sscoords == '' && document.getElementById('longsignature')) {
sscoords=document.getElementById('longsignature').innerHTML.replace('"','').replace('"','');
document.getElementById('longsignature').innerHTML='';
}
regularly();
elem = document.getElementById('canvaselement');
context = elem.getContext("2d");
if (topfirst) {
topfirst=false;
if (topelem) {
topvswidth=('' + elem.width).replace('px','');
topvsheight=('' + elem.height).replace('px','');
if (eval(topheight) >= eval(topvsheight) && eval(topwidth) >= eval(topvswidth)) {
topvswidthoff=0;
topvsheightoff=eval(eval(topheight) - eval(topvsheight));
if (document.getElementById('rest')) {
document.getElementById('rest').style.display='none';
}
//alert('yes yes');
} else {
//alert(topvswidth + ' no ' + topwidth + ' ' + topvsheight + ' no ' + topheight);
topelem=null;
topielem=null;
topcontext=null;
topwidth=0;
topheight=0;
topvswidth=0;
topvsheight=0;
topvswidthoff=0;
topvsheightoff=0;
}
}
}
if (sscoords != '') {
var asscoords=sscoords.split(',');
wassscoords=sscoords;
sscoords = '';
sscoordsdelim='';
context.beginPath();
context.moveTo(Math.abs(eval(asscoords[0])),Math.abs(eval(asscoords[1])));
if (topelem) {
topcontext.beginPath();
topcontext.moveTo(Math.abs(eval(asscoords[0]) + eval(topvswidthoff)),Math.abs(eval(asscoords[1]) + eval(topvsheightoff)));
}
for (var iss=2; iss= 0 && ty >= 0) {
prevtx=tx;
prevty=ty;
trotis=eval(((Math.atan2((ppy - prevty), (ppx - prevtx)) * 180.0 / Math.PI) + 360) % 360);
if (parent.document.getElementById('trotation')) {
parent.document.getElementById('trotation').value=Math.floor(trotis);
ppx=prevtx;
ppy=prevty;
prevtx=-1;
prevty=-1;
parent.document.getElementById('dcm').value = 'Text';
}
//alert(trotis);
}
tx=ppx;
ty=ppy;
} else {
tx=ppx;
ty=ppy;
prevtx=-1;
prevty=-1;
}
} else {
tx=ppx;
ty=ppy;
prevtx=-1;
prevty=-1;
}
lastx=0; // new to scribble
lasty=0;
x=0;
y=0;
}
});
topelem.addEventListener('mousemove', function(event) {
//if (topin) {
// topin.value='-------';
//}
if (isScribble == 2) {
if (x == 0 && y == 0 && lastx == 0 && lasty == 0) {
if (event.pageX || event.pageY) {
x = event.pageX - elemLeft;
y = event.pageY - elemTop;
} else {
x = event.clientX - elemLeft;
y = event.clientY - elemTop;
}
if (ppx >= 0 && ppy >= 0) {
lastx=ppx;
lasty=ppy;
ppx=-1;
ppy=-1;
} else {
lastx=x;
lasty=y;
}
} else {
lastx=x;
lasty=y;
if (event.pageX || event.pageY) {
x = event.pageX - elemLeft;
y = event.pageY - elemTop;
} else {
x = event.clientX - elemLeft;
y = event.clientY - elemTop;
}
}
if (x != lastx || y != lasty) {
//document.getElementById('divannotation').style.display='block';
//document.getElementById('myisubject').style.display = 'inline';
//document.getElementById('myiemail').style.display = 'inline';
//context.strokeStyle=document.getElementById('mycolour').value;
topcontext.beginPath();
topcontext.moveTo(x,y);
topcontext.lineTo(lastx,lasty);
if (topin) {
if (topin.value != '') topin.value+=' --------';
}
if (parent.document.getElementById('colcf')) {
colcf=parent.document.getElementById('colcf').value;
}
topcontext.strokeStyle = colcf.split(' ')[eval(-1 + colcf.split(' ').length)];
topcontext.stroke();
//document.title+=pmore + ' here';
}
}
});
}
elem.addEventListener('mouseup', function(event) {
if (isScribble == 2) {
pmore=' pxm '; isScribble=1;
}
});
elem.addEventListener('touchend', function(event) {
if (isScribble == 2) {
pmore=' pxzm ';
isScribble=1;
}
});
elem.addEventListener('touchstart', function(event) {
if (isScribble == 1) {
pmore=' pxqm ';
isScribble=2;
}
});
elem.addEventListener('mousedown', function(event) {
if (isScribble == 1) {
pmore=' pxam ';
isScribble=2;
if (event.pageX || event.pageY) {
ppx=event.pageX - elemLeft;
ppy=event.pageY - elemTop;
} else {
ppx=event.clientX - elemLeft;
ppy=event.clientY - elemTop;
}
if (parent.document.getElementById('dcm')) {
if (parent.document.getElementById('dcm').value == 'text') {
//parent.document.title='here4';
if (tx >= 0 && ty >= 0) {
prevtx=tx;
prevty=ty;
trotis=eval(((Math.atan2((ppy - prevty), (ppx - prevtx)) * 180.0 / Math.PI) + 360) % 360);
if (parent.document.getElementById('trotation')) {
parent.document.getElementById('trotation').value=Math.floor(trotis);
ppx=prevtx;
ppy=prevty;
prevtx=-1;
prevty=-1;
parent.document.getElementById('dcm').value = 'Text';
}
//alert(trotis);
}
tx=ppx;
ty=ppy;
} else {
tx=ppx;
ty=ppy;
prevtx=-1;
prevty=-1;
}
} else {
tx=ppx;
ty=ppy;
prevtx=-1;
prevty=-1;
}
lastx=0; // new to scribble
lasty=0;
x=0;
y=0;
}
});
elem.addEventListener('mousemove', function(event) {
if (isScribble == 2) {
if (x == 0 && y == 0 && lastx == 0 && lasty == 0) {
if (event.pageX || event.pageY) {
x = event.pageX - elemLeft;
y = event.pageY - elemTop;
} else {
x = event.clientX - elemLeft;
y = event.clientY - elemTop;
}
if (ppx >= 0 && ppy >= 0) {
lastx=ppx;
lasty=ppy;
ppx=-1;
ppy=-1;
} else {
lastx=x;
lasty=y;
}
} else {
lastx=x;
lasty=y;
if (event.pageX || event.pageY) {
x = event.pageX - elemLeft;
y = event.pageY - elemTop;
} else {
x = event.clientX - elemLeft;
y = event.clientY - elemTop;
}
}
if (x != lastx || y != lasty) {
//document.getElementById('divannotation').style.display='block';
//document.getElementById('myisubject').style.display = 'inline';
//document.getElementById('myiemail').style.display = 'inline';
//context.strokeStyle=document.getElementById('mycolour').value;
context.beginPath();
context.moveTo(x,y);
context.lineTo(lastx,lasty);
context.stroke();
if (topelem) {
topcontext.beginPath();
topcontext.moveTo((eval(x) + eval(topvswidthoff)),(eval(y) + eval(topvsheightoff)));
topcontext.lineTo((eval(lastx) + eval(topvswidthoff)),(eval(lasty) + eval(topvsheightoff)));
if (topin) {
topin.value='---------';
}
if (parent.document.getElementById('colcf')) {
colcf=parent.document.getElementById('colcf').value;
}
topcontext.strokeStyle = colcf.split(' ')[eval(-1 + colcf.split(' ').length)];
topcontext.stroke();
toplthere=true;
}
if (sscoords == '') sscoordsdelim='';
if (('*' + sscoords + '*').indexOf(lastx + ',' + lasty + '*') == -1) {
if (sscoords.indexOf(',') != -1) savenow=sscoords.length;
sscoords+=sscordsdelim + '-' + lastx;
sscordsdelim=',';
sscoords+=sscordsdelim + lasty;
if (savenow != 0) {
lastsavenow=savenow;
savenow=sscoords.length;
}
}
if (('*' + sscoords + '*').indexOf(x + ',' + y + '*') == -1) {
if (sscoords.indexOf(',') != -1) savenow=sscoords.length;
sscoords+=sscordsdelim + x;
sscordsdelim=',';
sscoords+=sscordsdelim + y;
if (savenow != 0) {
lastsavenow=savenow;
savenow=sscoords.length;
}
}
wassscoords='';
if (document.getElementById('showit')) {
document.getElementById('showit').style.display='inline';
if (1 == 2 && document.getElementById('animage')) {
document.getElementById('animage').src = elem.toDataURL('image/jpeg', 0.7); //"image/png");
}
}
//document.title+=pmore + ' here';
}
}
});
}
if (topielem && !toplthere) { // no signature, so allow for one to be created
//alert('a visible')
showornot();
} else if (topielem) { // a signature, so hide iframe
//alert('a invisible');
showornot();
}
}
function showornot() {
if (topielem && !toplthere) { // no signature, so allow for one to be created
//alert('visible');
topielem.style.display='block';
topielem.style.zIndex='9';
topielem.style.position='absolute';
topielem.style.left=eval(topvswidthoff) + 'px';
topielem.style.top=eval(topvsheightoff) + 'px';
topielem.style.width=eval(topvswidth) + 'px';
topielem.style.height=eval(topvsheight) + 'px';
//alert('z visible');
if (parent.document.getElementById('toptd')) {
if (parent.document.getElementById('toptd').innerHTML.indexOf('button') == -1) {
//if (parent.document.getElementById('dcm').value.replace('iM','iB') == 'iB') {
//parent.document.getElementById('toptd').innerHTML+="
";
//}
topprocessb=parent.document.getElementById('processb');
} else {
parent.document.getElementById('dmycbox').innerHTML=" ";
topprocessb=parent.document.getElementById('processb');
}
if (isTouch || isiPad) {
parent.document.getElementById('dcm').value=' ';
}
}
}
}
function download(canvas, filename) { // thanks to https://stackoverflow.com/questions/18480474/how-to-save-an-image-from-canvas
if (typeof canvas === "undefined") canvas=topelem;
if (typeof filename === "undefined") filename = 'topelem.png';
/// create an "off-screen" anchor tag
var lnk = document.createElement('a'),
e;
/// the key here is to set the download attribute of the a tag
lnk.download = filename;
/// convert canvas content to data-uri for link. When download
/// attribute is set the content pointed to by link will be
/// pushed as "download" in HTML5 capable browsers
lnk.href = canvas.toDataURL();
/// create a "fake" click-event to trigger the download
if (document.createEvent) {
e = document.createEvent("MouseEvents");
e.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false,
false, 0, null);
lnk.dispatchEvent(e);
} else if (lnk.fireEvent) {
lnk.fireEvent("onclick");
}
}
setTimeout(canvas_events, 2000);