Save font-size/line-height/list-width changes made by up/down drags

This commit is contained in:
Alex Pankratov
2021-04-14 17:15:13 +02:00
parent d5f59ee1bc
commit f5f3ba4e75

View File

@@ -1516,30 +1516,35 @@
setTheme(theme) setTheme(theme)
{ {
if (this.conf.theme == theme) return;
this.conf.theme = theme; this.conf.theme = theme;
return this.setJson('config', this.conf); return this.setJson('config', this.conf);
} }
setFontName(fname) setFontName(fname)
{ {
if (this.conf.fontName == fname) return;
this.conf.fontName = fname; this.conf.fontName = fname;
return this.setJson('config', this.conf); return this.setJson('config', this.conf);
} }
setFontSize(fs) setFontSize(fs)
{ {
if (this.conf.fontSize == fs) return;
this.conf.fontSize = fs; this.conf.fontSize = fs;
return this.setJson('config', this.conf); return this.setJson('config', this.conf);
} }
setLineHeight(lh) setLineHeight(lh)
{ {
if (this.conf.lineHeight == lh) return;
this.conf.lineHeight = lh; this.conf.lineHeight = lh;
return this.setJson('config', this.conf); return this.setJson('config', this.conf);
} }
setListWidth(lw) setListWidth(lw)
{ {
if (this.conf.listWidth == lw) return;
this.conf.listWidth = lw; this.conf.listWidth = lw;
return this.setJson('config', this.conf); return this.setJson('config', this.conf);
} }
@@ -2327,16 +2332,18 @@
{ {
// state // state
this.onChange = null; this.onChange = null;
this.onFinish = null;
this.startY = 0; this.startY = 0;
this.used = false; this.used = false;
// api // api
this.start = function(ev, onChange) this.start = function(ev, onChange, onFinish)
{ {
if (! onChange) if (! onChange)
return; return;
this.onChange = onChange; this.onChange = onChange;
this.onFinish = onFinish;
this.startY = ev.clientY; this.startY = ev.clientY;
this.used = false; this.used = false;
@@ -2366,6 +2373,8 @@
$('body').removeClass('adjusting'); $('body').removeClass('adjusting');
this.onChange = null; this.onChange = null;
if (this.onFinish) this.onFinish();
} }
} }
@@ -3542,6 +3551,15 @@
return updateListWidth(); return updateListWidth();
} }
//
function saveUiPrefs()
{
var $html = $('html');
NB.storage.setFontSize ( $html.hasClass('fs-set') ? getFontSize() : null );
NB.storage.setLineHeight ( $html.hasClass('lh-set') ? getLineHeight() : null );
NB.storage.setListWidth ( $html.hasClass('lw-set') ? getListWidth() : null );
}
/* /*
* event handlers * event handlers
*/ */
@@ -3807,17 +3825,17 @@
// //
$('.config').on('mousedown', '.ui-fs .val', function(ev){ $('.config').on('mousedown', '.ui-fs .val', function(ev){
var org = getFontSize(); var org = getFontSize();
NB.varAdjust.start(ev, function(delta){ setFontSize( org + delta/50. ); }); NB.varAdjust.start(ev, function(delta){ setFontSize( org + delta/50. ); }, saveUiPrefs);
}); });
$('.config').on('mousedown', '.ui-lh .val', function(ev){ $('.config').on('mousedown', '.ui-lh .val', function(ev){
var org = getLineHeight(); var org = getLineHeight();
NB.varAdjust.start(ev, function(delta){ setLineHeight( org + delta/50. ); }); NB.varAdjust.start(ev, function(delta){ setLineHeight( org + delta/50. ); }, saveUiPrefs);
}); });
$('.config').on('mousedown', '.ui-lw .val', function(ev){ $('.config').on('mousedown', '.ui-lw .val', function(ev){
var org = getListWidth(); var org = getListWidth();
NB.varAdjust.start(ev, function(delta){ setListWidth( org + delta/5. ); }); NB.varAdjust.start(ev, function(delta){ setListWidth( org + delta/5. ); }, saveUiPrefs);
}); });
// //
@@ -3870,8 +3888,8 @@
// //
$('.config .f-prefs .ui-fs .less').on('click', function(){ $('.config .f-prefs .ui-fs .less').on('click', function(){
var fs = setFontSize( parseInt(10*getFontSize()) / 10. - 0.5 ); setFontSize( parseInt(10*getFontSize()) / 10. - 0.5 );
NB.storage.setFontSize(fs); saveUiPrefs();
return false; return false;
}); });
@@ -3879,20 +3897,20 @@
if (NB.varAdjust.used) return false; if (NB.varAdjust.used) return false;
var fs = resetFontSize(); var fs = resetFontSize();
if (getLineHeight() < fs) setLineHeight(fs); if (getLineHeight() < fs) setLineHeight(fs);
NB.storage.setFontSize(null); saveUiPrefs();
return false; return false;
}); });
$('.config .f-prefs .ui-fs .more').on('click', function(){ $('.config .f-prefs .ui-fs .more').on('click', function(){
var fs = setFontSize( parseInt(10*getFontSize()) / 10. + 0.5 ); setFontSize( parseInt(10*getFontSize()) / 10. + 0.5 );
NB.storage.setFontSize(fs); saveUiPrefs();
return false; return false;
}); });
// //
$('.config .f-prefs .ui-lh .less').on('click', function(){ $('.config .f-prefs .ui-lh .less').on('click', function(){
var lh = setLineHeight( parseInt(10*getLineHeight()) / 10. - 0.1 ); setLineHeight( parseInt(10*getLineHeight()) / 10. - 0.1 );
NB.storage.setLineHeight(lh); saveUiPrefs();
return false; return false;
}); });
@@ -3900,33 +3918,33 @@
if (NB.varAdjust.used) return false; if (NB.varAdjust.used) return false;
var lh = resetLineHeight(); var lh = resetLineHeight();
if (lh < getFontSize()) setFontSize(lh); if (lh < getFontSize()) setFontSize(lh);
NB.storage.setLineHeight(null); saveUiPrefs();
return false; return false;
}); });
$('.config .f-prefs .ui-lh .more').on('click', function(){ $('.config .f-prefs .ui-lh .more').on('click', function(){
var lh = setLineHeight( parseInt(10*getLineHeight()) / 10. + 0.1 ); setLineHeight( parseInt(10*getLineHeight()) / 10. + 0.1 );
NB.storage.setLineHeight(lh); saveUiPrefs();
return false; return false;
}); });
// //
$('.config .f-prefs .ui-lw .less').on('click', function(){ $('.config .f-prefs .ui-lw .less').on('click', function(){
var lw = setListWidth( getListWidth() - 5 ); setListWidth( getListWidth() - 5 );
NB.storage.setListWidth(lw); saveUiPrefs();
return false; return false;
}); });
$('.config .f-prefs .ui-lw .val').on('click', function(){ $('.config .f-prefs .ui-lw .val').on('click', function(){
if (NB.varAdjust.used) return false; if (NB.varAdjust.used) return false;
resetListWidth(); resetListWidth();
NB.storage.setListWidth(null); saveUiPrefs();
return false; return false;
}); });
$('.config .f-prefs .ui-lw .more').on('click', function(){ $('.config .f-prefs .ui-lw .more').on('click', function(){
var lw = setListWidth( getListWidth() + 5 ); setListWidth( getListWidth() + 5 );
NB.storage.setListWidth(lw); saveUiPrefs();
return false; return false;
}); });
@@ -3982,7 +4000,7 @@
*/ */
var NB = var NB =
{ {
codeVersion: 20210414, codeVersion: 20210415,
blobVersion: 20190412, // board blob format in Storage blobVersion: 20190412, // board blob format in Storage
board: null, board: null,
}; };