Sketchy/build/web/js/events.js

1 line
6.0 KiB
JavaScript

"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) li").each(function(){"Current Color"!==$(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)").removeClass("hidden")})}),$("#pro").on("click tap",function(){$("#save ol:nth-of-type(2) li").each(function(){"Current Color"!==$(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("click tap",function(){$(".picker").removeClass("hidden"),$(".picker").attr("data-caller",a),setTimeout(function(){$("body").on("click tap","canvas, #menu, header",function(){$(".picker").addClass("hidden"),$("body").off("click tap")})},500)}):void $(this).on("click tap",function(b){b.preventDefault(),$('form[id="'+a+'"]').removeClass("hidden")})});var e;$('div[role="slider"] button').on("mousedown touchstart",function(){$(this).attr("data-moving","true"),e||(e=$('div[role="slider"] button').offset().left)}).on("mousemove touchmove",function(a){if($(this).attr("data-moving")){a.changedTouches&&(a=a.changedTouches[0]);var b=parseInt(a.pageX-e-15),c=$("."+$(this).parents('div[role="slider"]').attr("class")),d=c.find("progress"),f=+d.attr("max"),g=+d.attr("min");if(f>=b&&b>=g){c.find("button").css("left",b+"%"),d.attr("value",b);var h=c.attr("class");settings[h]=b,$("#"+h+" span").html(b)}}}).on("mouseup mouseleave touchend",function(){$(this).removeAttr("data-moving")}),$(".fill, .stroke").on("click tap",function(){var a=$("."+$(this).attr("class")).find("span");"Yes"==a.html()?(a.html("No"),settings[$(this).attr("class")]=!1):(a.html("Yes"),settings[$(this).attr("class")]=!0)}),$(".close, .tour button").on("click tap",function(){$(this).parent().addClass("hidden"),$("body").off("click tap")}),$("#clear").on("click tap",function(){c.clear();var a=window.points.history;window.points=[],window.points.history=a,window.points.history.last<window.points.history.length-1&&window.points.history.splice(window.points.history.last+1),window.points.history.push({data:c.getImageData(0,0,width(),height()),points:[]}),window.points.history.last=window.points.history.length-1}),$("#undo").on("click tap",undo),$("#redo").on("click tap",redo),$("#about").on("click tap",function(){$(".about").removeClass("hidden")}),window.mobile&&$("*").on("click mousemove mousedown mouseup mouseleave",function(){return!1})});