Sketchy/build/web/js/events.js

1 line
5.9 KiB
JavaScript
Raw Normal View History

"use strict";$(document).ready(function(){$(".menu").on("click tap",function(){$("#menu").toggleClass("pulled")}),$(".save").on("click tap",function(){$("#save").removeClass("hidden")}),$(".load").on("click tap",function(){$("#load").removeClass("hidden"),$("#load li, #load p").remove();var a=JSON.parse(localStorage.getItem("projects"));if(!a||a.length<1)return void $("#load ol").append($("<p>No sketch found.</p>"));for(var c=0,d=a.length;d>c;c++)$("#load ol").append($("<li><label><span>"+a[c].name+"</span></label></li>"));b.find("li").off("click").on("click tap",function(){$(this).parent().find("li[aria-selected]").removeAttr("aria-selected"),$(this).attr("aria-selected","true")}),$("#pro").on("click tap",function(){$("#save ol:nth-of-type(2)").addClass("hidden")}),$("#exp").on("click tap",function(){$("#save ol:nth-of-type(2)").removeClass("hidden")})}),$("#pro").on("click tap",function(){$("#save ol:nth-of-type(2) li").each(function(){"Transparent"!==$(this).find("span").html()?($(this).addClass("hidden"),$(this).removeAttr("aria-selected")):$(this).attr("aria-selected","true")})}),$("#exp").on("click tap",function(){$("#save ol:nth-of-type(2) li").removeClass("hidden")}),$c.last().on("mousedown touchstart",function(a){a.preventDefault(),a.changedTouches&&(a=a.changedTouches[0]);var b=relative(a.pageX,a.pageY);startPoint(b.x,b.y),window.active=!0}).on("mousemove touchmove",function(a){if(a.preventDefault(),a.changedTouches&&(a=a.changedTouches[0]),window.active&&"line"!=settings.type){var b=relative(a.pageX,a.pageY);drawPoint(b.x,b.y)}}).on("mouseup touchend",function(a){if(a.preventDefault(),window.active=!1,"eraser"!=settings.type){if(window.points.history.last<window.points.history.length-1&&window.points.history.splice(window.points.history.last+1),"shape"==settings.type){var b=settings.comShape;switch(o.clear(),c.beginPath(),c.fillStyle=settings.color,c.strokeStyle=settings.color,c.lineWidth=settings.lineWidth/20,b.type){case"circle":c.arc(b.x,b.y,b.radius,0,2*Math.PI);break;case"rectangle":c.rect(b.x,b.y,b.w,b.h);break;case"triangle":c.moveTo(b.start.x+b.dix,b.start.y),c.lineTo(b.x,b.y),c.lineTo(b.start.x,b.y),c.lineTo(b.start.x+b.dix,b.start.y)}settings.fill&&c.fill(),settings.stroke&&c.stroke()}"line"!=settings.type&&(window.points.history.push({data:c.getImageData(0,0,width(),height()),points:window.points.slice(0)}),window.points.history.last=window.points.history.length-1)}}).on("longTap",function(a){"line"==settings.type&&(a.preventDefault(),window.active=!1,points[points.length-1].type="",points[points.length-1].start=void 0,finishLine())});var a=$("form.single");a.find("li").on("click tap",function(){$(this).parent().find("li[aria-selected]").removeAttr("aria-selected"),$(this).attr("aria-selected","true");var a=$(this).parents("form").attr("id"),b=$(this).find("label span").html().toLowerCase(),c=$(this).attr("data-target");window.settings[a]=b,$('button[id="set'+a+'"] span').html(b[0].toUpperCase()+b.substr(1)),c&&($("#menu div.options > div").addClass("hidden"),$("#menu div.options > .general, #menu div.options > ."+c).removeClass("hidden")),$(this).parents("form").addClass("hidden")}),a.submit(function(a){a.preventDefault(),$(this).addClass("hidden")});var b=$("form.confirm");b.each(function(){$(this).find("li").on("click tap",function(){$(this).parent().find("li[aria-selected]").removeAttr("aria-selected"),$(this).attr("aria-selected","true")}),$(this).find("button").last().on("click tap",function(a){a.preventDefault();var b=$(this).parents("form").attr("id");$(this).parents("form").find("h1").each(function(a){if(a>0){var c=$(this).html().toLowerCase(),d=$(this).parent().find("ol:nth-of-type("+a+") li[aria-selected] span").html();"file name"!==c&&"file"!==c&&(d=d.toLowerCase()),window[b][c]=d}}),$(this).parents("form").addClass("hidden"),window[b]()}),$(this).find("button").first().on("click tap",function(a){a.preventDefault(),$(this).parents("form").addClass("hidden")})});var d=$('button[id^="set"]');d.each(function(){var a=/set(.*)/.exec($(this).attr("id"))[1];return"color"==a||"bg"==a?$(this).on