-
Notifications
You must be signed in to change notification settings - Fork 10
/
site.min.js
26 lines (26 loc) · 4.46 KB
/
site.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$(document).ready(function(){var h=new Audio("alert.mp3");var m=0;var d;var e;var a;var b;var c;if(localStorage.cycle){g=localStorage.cycle;d=g;}else{d=30;
g=d;e=g;}var g;var i=0;var k=function(){h.play();$("body").removeClass("working").addClass("log");$("#new").prop("checked",true);$("#what").focus();};var f=function(){$("body").removeClass("working").addClass("log");
$("#new").prop("checked",true);$("#what").focus();};var j=function(n){$("body").removeClass("working").addClass(n);};$("#timer span").countdown({until:0,format:"MS",compact:true,onExpiry:k});
if(typeof(Storage)!==undefined){for(var l in localStorage){if(l=="count"||l.indexOf("task")===-1){continue;}$("#done").prepend(localStorage.getItem(l));
}if(localStorage.count){$(".count").text(localStorage.count);i=localStorage.count;$("body").addClass("list");}else{$("body").addClass("new");}}$(".set-cycle").on("click",function(){$("body").addClass("settings-open");
$("#cycle").val(localStorage.cycle);return false;});$(".set-next").on("click",function(){$("body").addClass("settings-open");$("#nextCycle").val(localStorage.nextCycle);
return false;});$("#cycle").on("input",function(n){this.value=this.value.replace(/[^0-9]/g,"");g=$(this).val();});$("#nextCycle").on("input",function(n){this.value=this.value.replace(/[^0-9]/g,"");
e=$(this).val();});$("#cycle-form").submit(function(){if($("#cycle").val()===""){$("#cycle").val("30");localStorage.setItem("cycle",30);localStorage.setItem("nextCycle",30);
}else{localStorage.setItem("cycle",g);localStorage.setItem("nextCycle",g);}d=localStorage.cycle;$("body").removeClass("settings-open");return false;});
$("#next-form").submit(function(){localStorage.setItem("nextCycle",e);e=localStorage.nextCycle;$("body").removeClass("settings-open");return false;});$("#settings .overlay").on("click",function(){$("body").removeClass("settings-open");
$("#cycle").val(localStorage.cycle);$("#nextCycle").val(localStorage.nextCycle);});$(".btn-start").on("click",function(){a=new Date();b=("0"+a.getHours()).slice(-2);
c=("0"+a.getMinutes()).slice(-2);$("body").removeClass().addClass("working");$("#timer span").countdown("option",{until:+g*60,onExpiry:k});$("#actions span").hide();
$("#reset").show();return false;});$("#end").on("click",function(){m=$("#timer span").countdown("getTimes");$("#timer span").countdown("option",{until:0,onExpiry:f});
return false;});$("#cancel").on("click",function(){if(localStorage.count){$("#timer span").countdown("option",{until:0,onExpiry:null});j("list");}else{$("#timer span").countdown("option",{until:0,onExpiry:null});
j("new");}return false;});$("#logActivity").submit(function(){var o=$("#what").val();var s=new Date();var n=("0"+s.getHours()).slice(-2);var q=("0"+s.getMinutes()).slice(-2);
var p;i++;localStorage.count=i;h.currentTime=0;h.pause();if(typeof m[5]!=="number"){p=0;}else{p=m[5];}var r="<li data-task='task"+("0"+i).slice(-2)+"'><h6>"+b+":"+c+" - "+n+":"+q+"</h6><br /><p>"+o+"<small>"+(g-p)+" minutes</p></li>";
if(e!==g){g=localStorage.nextCycle;localStorage.setItem("cycle",localStorage.nextCycle);}localStorage.setItem("task"+("0"+i).slice(-2),r);$("#done").prepend(r);
if($("#new").is(":checked")){$("#timer span").countdown("option",{until:+g*60});$("body").removeClass("log").addClass("working");}else{$("body").removeClass("log").addClass("list");
}a=new Date();b=("0"+a.getHours()).slice(-2);c=("0"+a.getMinutes()).slice(-2);return false;});$("#done").on("mouseenter","li[data-task]",function(){$(this).find("p").prepend("<span class='delete'>x</span>");
$(this).find(".delete").on("click",function(){var n=$(this).parent().parent().attr("data-task");$(this).parent().parent().remove();localStorage.removeItem(n);
});});$("#done").on("mouseleave","li",function(){$(this).find("span.delete").remove();});$("#reset").on("click",function(){$(this).hide();$(this).siblings("span").show();
return false;});$("#actions .confirm").on("click",function(){for(var n in localStorage){if(n==="nextCycle"||n==="cycle"){continue;}localStorage.removeItem(n);
}i=0;$("#done").html("");$("body").removeClass().addClass("new");$(".count").text(i);$(this).parent().hide();$(this).parent().siblings("#reset").show();
return false;});$("#actions .cancel").on("click",function(){$(this).parent().hide();$(this).parent().siblings("#reset").show();return false;});$(window).blur(function(){h.addEventListener("ended",function(){this.currentTime=0;
this.play();},false);});$(window).focus(function(){h.addEventListener("ended",function(){this.currentTime=0;this.pause();},false);h.pause();h.currentTime=0;
});});