// signature_signature.js
// RJM Programming
// May, 2017
// Help out signature_signature.html and others like it
var esent=false, reduction=0.7;
var wasisgood='', listofbrowseimages='|';
var domymd5=false, mymd5prefix="http://www.rjmprogramming.com.au/nonexistantplace/", mymd5="", mymd5suffix=".jpg";
var sil=10, presobutton="", phpit=true, globalendtrue="", cqarr='', sobutton='', wastarget='', sodelim='', socoords='', imurl="", kurl="", otherthings='', showits=null, wascolcf="", allowed=true, exceptwhen=false, transcontent=false, elemis=null, contextis=null, tlx=-1, tly=-1;
var undoprefix='undoi', undonum=0, thisundonum=0;
var tenimages='';
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='', wasScribble=-1, isScribble=1; //0;
var prevlines=[], lines=[];
var eighteen=18;
var ourx, oury, iqarr, qarr=[];
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','');
// Thanks to https://stackoverflow.com/questions/14733374/how-to-generate-md5-file-hash-on-javascript for below
var MD5 = function(s){function L(k,d){return(k<>>(32-d))}function K(G,k){var I,d,F,H,x;F=(G&2147483648);H=(k&2147483648);I=(G&1073741824);d=(k&1073741824);x=(G&1073741823)+(k&1073741823);if(I&d){return(x^2147483648^F^H)}if(I|d){if(x&1073741824){return(x^3221225472^F^H)}else{return(x^1073741824^F^H)}}else{return(x^F^H)}}function r(d,F,k){return(d&F)|((~d)&k)}function q(d,F,k){return(d&k)|(F&(~k))}function p(d,F,k){return(d^F^k)}function n(d,F,k){return(F^(d|(~k)))}function u(G,F,aa,Z,k,H,I){G=K(G,K(K(r(F,aa,Z),k),I));return K(L(G,H),F)}function f(G,F,aa,Z,k,H,I){G=K(G,K(K(q(F,aa,Z),k),I));return K(L(G,H),F)}function D(G,F,aa,Z,k,H,I){G=K(G,K(K(p(F,aa,Z),k),I));return K(L(G,H),F)}function t(G,F,aa,Z,k,H,I){G=K(G,K(K(n(F,aa,Z),k),I));return K(L(G,H),F)}function e(G){var Z;var F=G.length;var x=F+8;var k=(x-(x%64))/64;var I=(k+1)*16;var aa=Array(I-1);var d=0;var H=0;while(H>>29;return aa}function B(x){var k="",F="",G,d;for(d=0;d<=3;d++){G=(x>>>(d*8))&255;F="0"+G.toString(16);k=k+F.substr(F.length-2,2)}return k}function J(k){k=k.replace(/rn/g,"n");var d="";for(var F=0;F127)&&(x<2048)){d+=String.fromCharCode((x>>6)|192);d+=String.fromCharCode((x&63)|128)}else{d+=String.fromCharCode((x>>12)|224);d+=String.fromCharCode(((x>>6)&63)|128);d+=String.fromCharCode((x&63)|128)}}}return d}var C=Array();var P,h,E,v,g,Y,X,W,V;var S=7,Q=12,N=17,M=22;var A=5,z=9,y=14,w=20;var o=4,m=11,l=16,j=23;var U=6,T=10,R=15,O=21;s=J(s);C=e(s);Y=1732584193;X=4023233417;W=2562383102;V=271733878;for(P=0;P 0) thisundonum=9;
} else {
thisundonum--;
if (parent.document.getElementById(undoprefix + eval(thisundonum)).src.length <= 0) thisundonum++;
}
canvas.style.width=parent.document.getElementById(undoprefix + eval(thisundonum)).style.width;
canvas.style.height=parent.document.getElementById(undoprefix + eval(thisundonum)).style.height;
canvas.width=parent.document.getElementById(undoprefix + eval(thisundonum)).width;
canvas.height=parent.document.getElementById(undoprefix + eval(thisundonum)).height;
con.drawImage(parent.document.getElementById(undoprefix + eval(thisundonum)), 0, 0);
if (document.getElementById('nonblankremove').value == '' && document.getElementById('sscoords').value != '') {
//document.getElementById('myform').action=document.getElementById('myform').action.split('.php')[0] + '.php?nonblankremove=y';
document.getElementById('nonblankremove').value='y';
document.getElementById('myask').name='myask';
document.getElementById('myform').target='myask';
document.getElementById('myform').method='POST';
if (1 == 1) {
document.getElementById('myask').src=document.getElementById('myform').action.split('.php')[0] + '.php?nonblankremove=y&sscoords=' + encodeURIComponent(document.getElementById('sscoords').value);
} else {
document.getElementById('sscoords').value+='@!@';
document.getElementById('mysbut').click;
}
setTimeout(lateryes, 6000);
//alert('sent ' + document.getElementById('myform').innerHTML);
}
}
function redosnapshotcanvas(canvas, con) {
if (typeof canvas === "undefined" && topelem != null) canvas = topelem;
if (typeof canvas === "undefined" && topelem == null) canvas = elem;
if (typeof con === "undefined" && topelem != null) con = topcontext;
if (typeof con === "undefined" && topelem == null) con = context;
if (thisundonum == 9) {
if (parent.document.getElementById(undoprefix + '0').src.length > 0) thisundonum=0;
} else {
thisundonum++;
if (parent.document.getElementById(undoprefix + eval(thisundonum)).src.length <= 0) thisundonum--;
}
canvas.style.width=parent.document.getElementById(undoprefix + eval(thisundonum)).style.width;
canvas.style.height=parent.document.getElementById(undoprefix + eval(thisundonum)).style.height;
canvas.width=parent.document.getElementById(undoprefix + eval(thisundonum)).width;
canvas.height=parent.document.getElementById(undoprefix + eval(thisundonum)).height;
con.drawImage(parent.document.getElementById(undoprefix + eval(thisundonum)), 0, 0);
}
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 andtn() {
allowed=true;
parent.document.getElementById('dcm').value=''; //Text';
isScribble=1;
if (wastarget != '') {
document.getElementById('myform').target=wastarget;
wastarget='';
}
}
function endtruefinish() { // work text sequences
var fone="";
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)];
for (iqarr=0; iqarr 1) {
ourx += eval(eval(jsrectbits[2] - jsrectbits[0]) / eval(-1 + qarr.length));
oury += eval(eval(jsrectbits[3] - jsrectbits[1]) / eval(-1 + qarr.length));
}
}
if (socoords != '') {
wastarget=document.getElementById('myform').target;
document.getElementById('myform').action=document.getElementById('myform').action.split('.php')[0] + '.php'; //?nonblankremove=y';
document.getElementById('myask').name='myask';
document.getElementById('myform').target='myask';
document.getElementById('myform').method='POST';
document.getElementById('sscoords').value=socoords;
//alert(socoords);
if (phpit) {
document.getElementById('mysbut').click();
setTimeout(laterblank, 16000);
}
socoords='';
sodelim='';
}
wasScribble=isScribble;
isScribble=0;
jsclickno=0;
setTimeout(andtn, 2000);
snapshotcanvas();
}
function lateryes() {
document.getElementById('nonblankremove').value = '';
document.getElementById('sscoords').value='';
document.getElementById('myform').method='POST';
}
function laterblank() {
if (document.getElementById('nonblankremove').value == '') document.getElementById('sscoords').value='';
}
function xto(inxto) {
var ainxto=inxto.split(' x '), jijsuffix='';
if (ainxto.length == 1) {
ainxto=inxto.split(' to ');
if (ainxto.length == 1) {
qarr.push(inxto);
} else {
var numbers1 = ainxto[0].match(/\d+/g); // thanks to https://stackoverflow.com/questions/16096467/how-to-extract-array-of-numbers-from-string-in-javascript
var numbers2 = ainxto[1].match(/\d+/g);
var ndiff=0, npos1=-1, npos2=-1, istep=1, jij, prefix1='', prefix2='', suffix1='', suffix2='';
if (numbers1.length == numbers2.length) {
for (var iij=0; iij 31) {
qarr.push(inxto);
return;
} else {
npos1=ainxto[0].indexOf('0' + numbers1[iij]);
if (npos1 == -1) {
npos1=ainxto[0].indexOf('' + numbers1[iij]);
if (npos1 != -1) {
if (npos1 == ainxto[0].indexOf('0')) jijsuffix='0';
}
} else {
jijsuffix='0';
}
npos2=ainxto[1].indexOf('0' + numbers2[iij]);
if (npos2 == -1) npos2=ainxto[1].indexOf('' + numbers2[iij]);
if (npos1 != npos2) {
qarr.push(inxto);
return;
}
if (npos1 > 0) {
if (ainxto[0].substring(0,npos1) != ainxto[1].substring(0,npos2)) {
qarr.push(inxto);
return;
} else {
prefix1=ainxto[0].substring(0,npos1);
prefix2=ainxto[1].substring(0,npos2);
suffix1=ainxto[0].substring(npos1).replace('' + numbers1[iij],'');
suffix2=ainxto[1].substring(npos2).replace('' + numbers2[iij],'');
}
} else {
suffix1=ainxto[0].replace('' + numbers1[iij],'');
suffix2=ainxto[1].replace('' + numbers2[iij],'');
}
if (suffix1 != suffix2) {
qarr.push(inxto);
return;
}
ndiff=eval(1 + iij);
}
} else if (ndiff != 0 && numbers1[iij] != numbers2[iij]) {
qarr.push(inxto);
return;
}
}
if (ndiff > 0) {
//alert(suffix2 + ' ' + numbers1[eval(-1 + ndiff)] + ' vs ' + numbers2[eval(-1 + ndiff)]);
var ijsuffix='';
if (numbers2[eval(-1 + ndiff)] < numbers1[eval(-1 + ndiff)]) {
for (jij=numbers1[eval(-1 + ndiff)]; jij>=numbers2[eval(-1 + ndiff)]; jij--) {
if (jij >= 10) ijsuffix='';
qarr.push(prefix1 + ijsuffix + jij + suffix1);
ijsuffix=jijsuffix;
//alert(jij);
if (qarr.length > 31) return;
}
} else {
for (jij=numbers1[eval(-1 + ndiff)]; jij<=numbers2[eval(-1 + ndiff)]; jij++) {
if (jij >= 10) ijsuffix='';
qarr.push(prefix1 + ijsuffix + jij + suffix1);
ijsuffix=jijsuffix;
//alert('+' + jij);
if (qarr.length > 31) return;
}
}
}
}
}
} else {
for (var ij=0; ij 31) return;
}
}
}
function endtrue(incqarr) { // work text sequences
if (typeof incqarr === "undefined") incqarr="";
if (incqarr == "" && globalendtrue != "") incqarr=globalendtrue;
phpit=true;
if (incqarr != "") phpit=false;
globalendtrue="";
var fone="";
if (parent.document.getElementById('dcm') && parent.document.getElementById('myta')) {
if (parent.document.getElementById('dcm').value == 'textseq') {
allowed=false;
parent.document.getElementById('myta').value='';
ourx=jsrectbits[0], oury=jsrectbits[1], iqarr, qarr=[];
var coml, icoml;
cqarr="xyz";
while (cqarr.indexOf(' to ') == -1 && cqarr.indexOf(' x ') == -1 && cqarr.indexOf(',') == -1 && cqarr != '') {
if (incqarr != "") {
cqarr=incqarr;
incqarr="";
} else {
cqarr=prompt("Please enter first entry for description of a sequence of values. If you ever use a comma we will see that as you fully defining your sequence of values, and we wait 8 seconds before drawing these giving you a chance to change the text rotation of " + parent.document.getElementById('trotation').value + " degrees from horizontal. Also a blank value or you clicking the Cancel button or you using the word ' to ' or use of ' x ' (as in, times) can achieve this as well. We will also accept the use of the word ' to ' as with the incrementing (or decrementing) by 1 scenario example 29/5/17 to 31/5/17,1/6/17,2/6/17","");
}
if (cqarr == null) cqarr='';
if (cqarr != '') {
cqarr=cqarr.replace(/\"/g,"'").replace(/\`/g,"'");
coml=cqarr.split(',');
for (icoml=0; icoml 31) {
wasScribble=isScribble;
isScribble=0;
jsclickno=0;
setTimeout(andtn, 200);
alert('Sorry, too many items to add');
return;
}
}
}
}
if (1 == 1) {
if (!phpit) {
endtruefinish();
} else {
setTimeout(endtruefinish,8000);
}
} else {
for (iqarr=0; iqarr 1) {
ourx += eval(eval(jsrectbits[2] - jsrectbits[0]) / eval(-1 + qarr.length));
oury += eval(eval(jsrectbits[3] - jsrectbits[1]) / eval(-1 + qarr.length));
}
}
if (socoords != '') {
wastarget=document.getElementById('myform').target;
document.getElementById('myform').action=document.getElementById('myform').action.split('.php')[0] + '.php'; //?nonblankremove=y';
document.getElementById('myask').name='myask';
document.getElementById('myform').target='myask';
document.getElementById('myform').method='POST';
document.getElementById('sscoords').value=socoords;
//alert(socoords);
if (phpit) {
document.getElementById('mysbut').click();
setTimeout(laterblank, 16000);
}
socoords='';
sodelim='';
}
wasScribble=isScribble;
isScribble=0;
jsclickno=0;
setTimeout(andtn, 2000);
snapshotcanvas();
//parent.document.getElementById('dcm').value='Text';
}
}
}
//tlx=-1;
//tly=-1;
return true;
}
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.trim();
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.trim();
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('jsemail')) {
if (esent && 1 == 5) {
esent=false;
parent.document.getElementById('jsemail').value=trim(parent.document.getElementById('jsemail').value);
}
}
}
} else if (esent) {
esent=false;
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(topcontext,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(tlx) > 0 && eval(tly) > 0) {
izero=tlx;
} else 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(tlx) > 0 && eval(tly) > 0) {
fstarth=eval(tly + fifteen);
} else 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', reduction); //); //"image/png");
}
document.getElementById('showi').style.display='inline';
}
}
}
setTimeout(regularly,1000);
}
function canvas_events() {
imurl = top.location.search.split('url=')[1] ? decodeURIComponent(top.location.search.split('url=')[1].split('&')[0]) : '';
//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);
var xf=document.getElementById('myform').innerHTML;
document.getElementById('myform').innerHTML='' + xf;
if (parent.document.getElementById('topcanvas') && parent.document.getElementById('topiframe')) {
//alert('yes');
topelem=parent.document.getElementById('topcanvas');
topielem=parent.document.getElementById('topiframe');
topielem.style.opacity=0.5;
if (document.getElementById('showit') && document.getElementById('rest') && document.getElementById('myform')) {
setTimeout(andrest, 2000);
if (imurl != '') document.getElementById('myform').innerHTML+='';
showits=document.getElementById('showit');
showits.innerHTML=showits.innerHTML.replace(' (as above)',' onto canvas below');
showits.style.position='absolute';
showits.style.display='block';
showits.style.zIndex=19;
showits.style.top='20px';
showits.style.left='20px';
sil=10;
setTimeout(showitsmore, 4000);
}
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");
topcontext.fillStyle = 'white';
topcontext.fillRect(0, 0, topelem.width, topelem.height);
topwidth=('' + topelem.width).replace('px','');
topheight=('' + topelem.height).replace('px','');
if (document.getElementById('animage').src != '') {
topcontext.drawImage(document.getElementById('animage'),0,0);
document.getElementById('animage').src='';
}
//alert('yes again');
snapshotcanvas();
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('"','');
var soa=sscoords.split('|');
if (soa.length > 1) {
//alert(85);
for (var isoa=1; isoaStanding Order for " + soa[isoa].split('`')[0] + " ";
} else {
listofbrowseimages+=soa[isoa].split('`')[0] + '|';
}
} else {
if (soa[isoa].split('`')[0].indexOf('/nonexistantplace/') == -1) {
presobutton+=" Standing Order for " + soa[isoa].split('`')[0] + " ";
} else {
listofbrowseimages+=soa[isoa].split('`')[0] + '|';
}
}
}
}
//alert(presobutton);
}
document.getElementById('longsignature').innerHTML='';
}
regularly();
elem = document.getElementById('canvaselement');
context = elem.getContext("2d");
context.fillStyle = 'white';
context.fillRect(0, 0, elem.width, elem.height);
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 != '') {
if (sscoords.indexOf('|') != -1) {
otherthings=sscoords.replace(sscoords.split('|')[0] + '|',''); //sscoords.split('|')[1];
if (imurl != "") {
if (otherthings != '') {
var huhhuhq=otherthings.split(imurl + '`');
if (huhhuhq.length > 1) {
sobutton=presobutton + '';
}
}
}
}
var asscoords=sscoords.split('|')[0].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')) {
if (parent.document.getElementById('dcm').value.indexOf('textseq') == 0) {
jsrectbits[0]=prevtx;
jsrectbits[1]=prevty;
jsrectbits[2]=ppx;
jsrectbits[3]=ppy;
if (Math.abs(prevty - ppy) > Math.abs(prevtx - ppx)) {
trotis=eval(((Math.atan2((prevtx - ppx), (ppy - prevty)) * 180.0 / Math.PI) + 360) % 360);
}
}
parent.document.getElementById('trotation').value=Math.floor(trotis);
ppx=prevtx;
ppy=prevty;
prevtx=-1;
prevty=-1;
exceptwhen=endtrue(); //true;
if (parent.document.getElementById('dcm').value.indexOf('textseq') == -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) && topcontext != null) {
//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);
if (allowed && parent.document.getElementById('dcm').value != 'textseq') 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;
snapshotcanvas();
}
});
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.indexOf('text') == 0) {
//parent.document.title='here4';
if (1 == 2 && tlx < 0 && tly < 0) {
tlx=ppx;
tly=ppy;
}
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')) {
if (parent.document.getElementById('dcm').value.indexOf('textseq') == 0) {
jsrectbits[0]=prevtx;
jsrectbits[1]=prevty;
jsrectbits[2]=ppx;
jsrectbits[3]=ppy;
if (Math.abs(prevty - ppy) > Math.abs(prevtx - ppx)) {
trotis=eval(((Math.atan2((prevtx - ppx), (ppy - prevty)) * 180.0 / Math.PI) + 360) % 360);
}
}
parent.document.getElementById('trotation').value=Math.floor(trotis);
ppx=prevtx;
ppy=prevty;
prevtx=-1;
prevty=-1;
exceptwhen=endtrue(); //true;
if (parent.document.getElementById('dcm').value.indexOf('textseq') == -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)));
if (allowed && parent.document.getElementById('dcm').value != 'textseq') 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', reduction); //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();
}
if (imurl != "") {
if (imurl.indexOf('Http') == 0) {
imageask('Im', imurl);
} else if (imurl.indexOf('httP') == 0) {
imageask('im', imurl);
} else if (imurl.indexOf('HTTP') == 0) {
imageask('IM', imurl);
} else if (imurl.indexOf('http') == 0) {
imageask('IM', imurl);
} else if (imurl.indexOf('hTTP') == 0) {
imageask('iM', imurl);
}
if (otherthings != '') {
var huhhuh=otherthings.split(imurl + '`');
if (huhhuh.length > 1) {
sobutton=presobutton + ' ';
var ibits,bitsof=huhhuh[1].split('`'), timesbits="", tobits="";
for (ibits=0; ibits';
if (bitsof[ibits].indexOf(' to ') != -1) {
if (tobits == "") {
tobits=bitsof[ibits] + '`' + bitsof[eval(1 + ibits)] + '`' + bitsof[eval(2 + ibits)] + '`' + bitsof[eval(3 + ibits)] + '`' + bitsof[eval(4 + ibits)] + '`' + bitsof[eval(5 + ibits)];
} else {
tobits+='`' + bitsof[ibits] + '`' + bitsof[eval(1 + ibits)] + '`' + bitsof[eval(2 + ibits)] + '`' + bitsof[eval(3 + ibits)] + '`' + bitsof[eval(4 + ibits)] + '`' + bitsof[eval(5 + ibits)];
}
}
if (bitsof[ibits].indexOf(' x ') != -1) {
if (timesbits == "") {
timesbits=bitsof[ibits] + '`' + bitsof[eval(1 + ibits)] + '`' + bitsof[eval(2 + ibits)] + '`' + bitsof[eval(3 + ibits)] + '`' + bitsof[eval(4 + ibits)] + '`' + bitsof[eval(5 + ibits)];
} else {
timesbits+='`' + bitsof[ibits] + '`' + bitsof[eval(1 + ibits)] + '`' + bitsof[eval(2 + ibits)] + '`' + bitsof[eval(3 + ibits)] + '`' + bitsof[eval(4 + ibits)] + '`' + bitsof[eval(5 + ibits)];
}
}
}
if (timesbits != "") sobutton+=' ';
if (tobits != "") sobutton+=' ';
}
}
}
}
function showitsmore() {
sil=eval((sil + 5) % 70);
showits.style.left='' + sil + '%';
setTimeout(showitsmore, 4000);
}
function dostandingorder(details, whichones) {
var ans=null, ansa=[];
if (typeof whichones === "undefined") whichones="";
var ibits,bitsof=details.split('`');
for (ibits=0; ibits
";
//}
topprocessb=parent.document.getElementById('processb');
} else {
if (parent.document.getElementById('divbrowse')) parent.document.getElementById('divbrowse').style.display='inline';
//alert(987);
parent.document.getElementById('dmycbox').innerHTML=" ";
topprocessb=parent.document.getElementById('processb');
}
if (isTouch || isiPad) {
parent.document.getElementById('dcm').value=' ';
}
}
}
}
function dojsemail(tva) {
jsemail=tva;
if (tva.toLowerCase().indexOf("rmetcalfe15@gmail.com") != -1) reduction=0.7; //2;
}
function reinstatecolcf() {
if (wascolcf != "") {
parent.document.getElementById('colcf').value=wascolcf;
isScribble=1;
jsclickno=0;
}
wascolcf="";
}
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';
var okaytotry=true;
if (parent.document.getElementById('jsundo')) {
if (parent.document.getElementById('jsundo').style.display.toLowerCase() != 'inline') okaytotry=false;
} else {
okaytotry=false;
}
if (!okaytotry) {
if (parent.document.getElementById('dcm')) {
parent.document.getElementById('dcm').value='';
jsclickno=0;
isScribble=1;
}
alert("Please, instead, use right-click or two finger gesture Copy commands to copy canvas contents to the left. Please do this within 8 seconds if you intend to proceed.");
if (parent.document.getElementById('colcf')) {
wascolcf=parent.document.getElementById('colcf').value;
parent.document.getElementById('colcf').value='transparent';
setTimeout(reinstatecolcf, 8000);
}
jsclickno=0;
isScribble=1;
} else {
/// create an "off-screen" anchor tag
var lnk = parent.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 (parent.document.createEvent) {
e = parent.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);