1 line
2.3 KiB
JavaScript
1 line
2.3 KiB
JavaScript
|
$(document).ready(function(){$("*").off("click mousemove mousedown mouseup mouseleave").on("click mousemove mousedown mouseup mouseleave",function(a){a.preventDefault}),window.save=function(){var a=c.getImageData(0,0,width(),height());switch(save.background){case"white":c.fillStyle="white",c.globalCompositeOperation="destination-over",c.fillRect(0,0,width(),height()),c.fillStyle=settings.color,c.globalCompositeOperation=settings.composite;break;case"current color":c.fillStyle=settings.bg,c.globalCompositeOperation="destination-over",c.fillRect(0,0,width(),height()),c.globalCompositeOperation=settings.composite}var b=$c[0].toDataURL();if("sketchy project"==save.type){var d,e=JSON.parse(localStorage.getItem("projects"));e&&e.some(function(a,b){return a.name==save["file name"]?(d=b,!0):!1})?confirm("A sketch with this name already exists. Do you want to overwrite "+save["file name"]+"?")&&(console.log(d),e[d]={name:save["file name"],data:b,points:window.points,settings:settings},localStorage.setItem("projects",JSON.stringify(e))):(e?e.push({name:save["file name"],data:b,points:window.points,settings:settings}):e=[{name:save["file name"],data:b,points:window.points,settings:settings}],localStorage.setItem("projects",JSON.stringify(e)))}else{window.requestFileSystem(LocalFileSystem.PERSISTENT,0,function(a){{var c=dataToBlob(b);a.root.getFile(save["file name"]+".png",{create:!0},function(a){a.createWriter(function(a){a.write(c),alert("Your Sketch was saved successfuly: "+this.result)},function(){alert("Something bad happened trying to save your sketch "+save["file name"]+"\n Possible reasons:\n Duplicate Name \n Not enough permission")})})}},function(a){alert("Couldn't access filesystem\n"+a.message)})}c.putImageData(a,0,0)},window.load=function(){var a=JSON.parse(localStorage.getItem("projects")).filter(function(a){return a.name==load.file})[0],b=document.createElement("img");b.src=a.data,b.onload=function(){c.clearRect(0,0,width(),height()),c.drawImage(b,0,0),window.points=a.points,window.points.history=[{data:c.createImageData($c.width(),$c.height()),points:[]},{data:c.getImageData(0,0,width(),height()),points:a.points}],$c.first().css("background",a.settings.bg),window.settings.bg=a.settings.bg}},localStorage.getItem("sawVote")||($(".vote").removeClass("hidden"),localStorage.setItem("sawVote",!0))});
|