Solid theme version

This commit is contained in:
Devine Lu Linvega 2018-09-14 15:03:12 +12:00
parent cc38f04dd6
commit 6a35e60d80
3 changed files with 18 additions and 3 deletions

View File

@ -232,7 +232,7 @@ function Dotgrid(width,height,grid_x,grid_y,block_x,block_y)
let file = e.dataTransfer.files[0];
if(!file.path || file.path.indexOf(".dot") < 0 && file.path.indexOf(".grid") < 0){ console.log("Dotgrid","Not a dot file"); return; }
if(!file || !file.path || file.path.indexOf(".dot") < 0 && file.path.indexOf(".grid") < 0){ console.warn("Dotgrid","Not a dot file"); return; }
let reader = new FileReader();
reader.onload = function(e){

View File

@ -18,18 +18,21 @@ function Theme(default_theme = {background: "#222", f_high: "#fff", f_med: "#777
this.install = function(host = document.body,callback)
{
console.log("Theme","Installing..")
host.appendChild(this.el)
this.callback = callback
}
this.start = function()
{
console.log("Theme","Starting..")
let storage = is_json(localStorage.theme) ? JSON.parse(localStorage.theme) : this.collection.default;
this.load(!storage.background ? this.collection.default : storage)
}
this.save = function(theme)
{
console.log("Theme","Saving..")
this.active = theme;
localStorage.setItem("theme", JSON.stringify(theme));
}
@ -133,7 +136,7 @@ function Theme(default_theme = {background: "#222", f_high: "#fff", f_med: "#777
let file = e.dataTransfer.files[0];
if(!file.name){ console.warn("Theme","Unnamed file."); return; }
if(!file || !file.name){ console.warn("Theme","Unnamed file."); return; }
if(file.name.indexOf(".thm") < 0 && file.name.indexOf(".svg") < 0){ console.warn("Theme","Skipped, not a theme"); return; }
let reader = new FileReader();

View File

@ -87,8 +87,13 @@ function Picker()
document.getElementById("option_color").children[0].style.stroke = hex;
}
this.listen = function(e)
this.listen = function(e,is_down = false)
{
if(is_down && !is_color_char(e.key)){
e.preventDefault();
return;
}
if(e.key == "Enter"){
this.validate();
e.preventDefault();
@ -114,5 +119,12 @@ function Picker()
return re.test(val)
}
function is_color_char(val)
{
let re = /[0-9A-Fa-f]/g;
return re.test(val)
}
this.input.onkeydown = function(event){ dotgrid.picker.listen(event,true); }
this.input.onkeyup = function(event){ dotgrid.picker.listen(event); };
}