Go thru eslint problems

- And pull maximal stuff out of most try-catches (with empty catches)
- Simplify Firebase event cleanup by structuring data
main
Isaiah Odhner 2019-09-20 13:15:21 -04:00
parent 5a4abc4591
commit 874e50fc3e
6 changed files with 29 additions and 16 deletions

View File

@ -137,7 +137,7 @@ function $ColorBox(){
colors.background = col;
}
$G.trigger("option-changed");
};
}
function rgb2hex(col){
if(!col.match){ // i.e. CanvasPattern
return "#000000";

View File

@ -278,6 +278,7 @@ OnCanvasSelection.prototype.scale = function(factor){
};
OnCanvasSelection.prototype.draw = function(){
// eslint-disable-next-line no-empty
try{ctx.drawImage(this.canvas, this.x, this.y);}catch(e){}
};

View File

@ -767,6 +767,7 @@ function get_tool_by_name(name){
return tools[i];
}
}
// eslint-disable-next-line no-redeclare
for(var i=0; i<extra_tools.length; i++){
if(extra_tools[i].name == name){
return extra_tools[i];
@ -880,7 +881,9 @@ function make_monochrome_palette(){
var lightness = i / n_colors;
palette.push(make_monochrome_pattern(lightness));
}
// eslint-disable-next-line no-redeclare
for(var i=0; i<n_colors_per_row; i++){
// eslint-disable-next-line no-redeclare
var lightness = 1 - i / n_colors;
palette.push(make_monochrome_pattern(lightness));
}

View File

@ -240,8 +240,10 @@ var menus = {
checkbox: {
toggle: function(){
$extras_menu_button.toggle();
var checked = this.check();
try{
localStorage["jspaint extras menu visible"] = this.check();
localStorage["jspaint extras menu visible"] = checked;
// eslint-disable-next-line no-empty
}catch(e){}
},
check: function(){
@ -449,7 +451,7 @@ var menus = {
name = name.trim();
if(name == ""){
show_error_message("The session name cannot be empty.");
}else if(name.match(/[.\/\[\]#$]/)){
}else if(name.match(/[./[\]#$]/)){
show_error_message("The session name cannot contain any of ./[]#$");
}else{
location.hash = "session:" + name;
@ -503,6 +505,7 @@ if(frameElement){
$MenuBar = parent.$MenuBar;
go_outside_frame = true;
}
// eslint-disable-next-line no-empty
}catch(e){}
}
var $menu_bar = $MenuBar(menus);
@ -520,9 +523,14 @@ $menu_bar.on("default-info", function(e){
});
var $extras_menu_button = $menu_bar.get(0).ownerDocument.defaultView.$(".extras-menu-button");
// if localStorage is not avaiable, the default setting is visible
var extras_menu_should_start_visible = true;
try{
// if localStorage is avaiable, the default setting is invisible
// TODO: refactor shared key string
if(localStorage["jspaint extras menu visible"] != "true"){
extras_menu_should_start_visible = localStorage["jspaint extras menu visible"] != "true"
// eslint-disable-next-line no-empty
}catch(e){}
if(extras_menu_should_start_visible){
$extras_menu_button.hide();
}
}catch(e){}

View File

@ -160,7 +160,7 @@
// provide a great way to clean up event listeners
session._fb_listeners = [];
var _fb_on = function(fb, event_type, callback, error_callback){
session._fb_listeners.push([fb, event_type, callback, error_callback]);
session._fb_listeners.push({fb, event_type, callback, error_callback});
fb.on(event_type, callback, error_callback);
};
@ -351,11 +351,11 @@
$G.off(".session-hook");
// Remove collected Firebase event listeners
var _;
while(_ = session._fb_listeners.pop()){
log("remove listener for " + _[0].path.toString() + " .on " + _[1]);
_[0].off(_[1], _[2], _[3]);
}
session._fb_listeners.forEach((listener)=> {
log("remove listener for " + listener.fb.path.toString() + " .on " + listener.event_type);
listener.fb.off(listener.event_type, listener.callback, listener.error_callback);
});
session._fb_listeners.length = 0;
// Remove the user from the session
session.fb_user.remove();
@ -394,10 +394,10 @@
if(session_id === ""){
log("invalid session id; session id cannot be empty");
end_current_session();
}else if(!local && session_id.match(/[\.\/\[\]#$]/)){
}else if(!local && session_id.match(/[./[\]#$]/)){
log("session id is not a valid Firebase location; it cannot contain any of ./[]#$");
end_current_session();
}else if(!session_id.match(/[\-0-9A-Za-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02af\u1d00-\u1d25\u1d62-\u1d65\u1d6b-\u1d77\u1d79-\u1d9a\u1e00-\u1eff\u2090-\u2094\u2184-\u2184\u2488-\u2490\u271d-\u271d\u2c60-\u2c7c\u2c7e-\u2c7f\ua722-\ua76f\ua771-\ua787\ua78b-\ua78c\ua7fb-\ua7ff\ufb00-\ufb06]+/)){
}else if(!session_id.match(/[-0-9A-Za-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02af\u1d00-\u1d25\u1d62-\u1d65\u1d6b-\u1d77\u1d79-\u1d9a\u1e00-\u1eff\u2090-\u2094\u2184-\u2184\u2488-\u2490\u271d-\u271d\u2c60-\u2c7c\u2c7e-\u2c7f\ua722-\ua76f\ua771-\ua787\ua78b-\ua78c\ua7fb-\ua7ff\ufb00-\ufb06]+/)){
log("invalid session id; it must consist of 'alphanumeric-esque' character");
end_current_session();
}else if(current_session && current_session.id === session_id){

View File

@ -674,9 +674,10 @@ tools = [{
if(w < 0){ x += w; w = -w; }
if(h < 0){ y += h; h = -h; }
var radius;
if(w < stroke_size || h < stroke_size){
ctx.fillStyle = ctx.strokeStyle;
var radius = Math.min(8, w/2, h/2);
radius = Math.min(8, w/2, h/2);
// var radius_x = Math.min(8, w/2);
// var radius_y = Math.min(8, h/2);
draw_rounded_rectangle(
@ -688,7 +689,7 @@ tools = [{
true
);
}else{
var radius = Math.min(8, (w - stroke_size)/2, (h - stroke_size)/2);
radius = Math.min(8, (w - stroke_size)/2, (h - stroke_size)/2);
// var radius_x = Math.min(8, (w - stroke_size)/2);
// var radius_y = Math.min(8, (h - stroke_size)/2);
draw_rounded_rectangle(