add varAdjust

This commit is contained in:
Alex Pankratov
2021-04-07 18:51:52 +02:00
parent 092a6175fa
commit 0db7f67577

View File

@@ -948,6 +948,20 @@
opacity: 1; opacity: 1;
} }
/***/
.adjusting * {
cursor: row-resize !important;
}
.adjusting .config .teaser {
display: none;
}
.adjusting .config .bulk {
display: block;
opacity: 1;
}
/***/ /***/
.overlay { .overlay {
position: fixed; position: fixed;
@@ -1395,6 +1409,15 @@
<script src="extras/jquery-3.3.1.min.js"></script> <script src="extras/jquery-3.3.1.min.js"></script>
<script>window.jQuery || document.write('<script src="https://code.jquery.com/jquery-3.3.1.min.js">\x3C/script>')</script> <script>window.jQuery || document.write('<script src="https://code.jquery.com/jquery-3.3.1.min.js">\x3C/script>')</script>
<script type="text/javascript">
Number.prototype.clamp = function(min, max)
{
return Math.min(Math.max(this, min), max);
};
</script>
<script type="text/javascript"> <script type="text/javascript">
function AppConfig() function AppConfig()
@@ -2233,6 +2256,58 @@
</script> </script>
<script type="text/javascript">
function VarAdjust()
{
// state
this.onChange = null;
this.startY = 0;
this.used = false;
// api
this.start = function(ev, onChange)
{
if (! onChange)
return;
this.onChange = onChange;
this.startY = ev.clientY;
this.used = false;
var self = this;
setTimeout(function(){
if (self.onChange)
{
$('body').addClass('adjusting');
self.used = true;
self.onChange(0);
}
}, 350);
}
this.onMouseMove = function(ev)
{
if (! this.onChange)
return;
$('body').addClass('adjusting');
self.used = true;
this.onChange(ev.clientY - this.startY);
}
this.end = function()
{
if (! this.onChange)
return;
$('body').removeClass('adjusting');
this.onChange = null;
}
}
</script>
<script type="text/javascript"> <script type="text/javascript">
/* /*
@@ -3078,9 +3153,9 @@
var max = $board.width(); var max = $board.width();
var want = $lists[0].scrollWidth; var want = $lists[0].scrollWidth;
var have = $inner.width(); var have = $inner.outerWidth();
if (want <= max) if (want <= max+1)
{ {
$scroller.hide(); $scroller.hide();
return; return;
@@ -3228,7 +3303,7 @@
if (conf.lineHeight) if (conf.lineHeight)
setLineHeight(conf.lineHeight); setLineHeight(conf.lineHeight);
updateVars(); updateVarsAndLayout();
} }
function onFontLoaded(f, ok) function onFontLoaded(f, ok)
@@ -3272,8 +3347,7 @@
$list.removeClass('active'); $list.removeClass('active');
$list.filter('[font="' + font + '"]').addClass('active'); $list.filter('[font="' + font + '"]').addClass('active');
updateVars(); updateVarsAndLayout();
adjustLayout();
} }
// //
@@ -3322,50 +3396,47 @@
return val; return val;
} }
function updateVars() function updateVarsAndLayout()
{ {
updateFontSize(); updateFontSize();
updateLineHeight(); updateLineHeight();
updateListWidth(); updateListWidth();
adjustLayout();
} }
// //
function setFontSize(fs) function setFontSize(fs)
{ {
if (9 <= fs && fs <= 24) fs = fs.clamp(9, 24);
{
$('html').css('--fs', fs + '').addClass('fs-set'); $('html').css('--fs', fs + '').addClass('fs-set');
updateVars(); updateVarsAndLayout();
adjustLayout();
if (getLineHeight() < fs) if (getLineHeight() < fs)
setLineHeight(fs); setLineHeight(fs);
}
return getFontSize(); return getFontSize();
} }
function setLineHeight(lh) function setLineHeight(lh)
{ {
lh = parseInt(10*lh) / 10.; // trim to a single decimal digit
var fs = getFontSize(); var fs = getFontSize();
if (fs <= lh && lh <= 3*fs)
{ lh = parseInt(10*lh) / 10.; // trim to a single decimal digit
lh = lh.clamp(fs, 3*fs);
$('html').css('--lh', lh + '').addClass('lh-set'); $('html').css('--lh', lh + '').addClass('lh-set');
updateVars(); updateVarsAndLayout();
adjustLayout();
}
return getLineHeight(); return getLineHeight();
} }
function setListWidth(lw) function setListWidth(lw)
{ {
if (200 <= lw && lw <= 400) lw = lw.clamp(200, 400);
{
$('html').css('--lw', lw + '').addClass('lw-set'); $('html').css('--lw', lw + '').addClass('lw-set');
updateVars(); updateVarsAndLayout();
adjustLayout();
}
return getListWidth(); return getListWidth();
} }
@@ -3373,21 +3444,21 @@
function resetFontSize() function resetFontSize()
{ {
$('html').css('--fs', '').removeClass('fs-set'); $('html').css('--fs', '').removeClass('fs-set');
adjustLayout(); updateVarsAndLayout();
return updateFontSize(); return updateFontSize();
} }
function resetLineHeight() function resetLineHeight()
{ {
$('html').css('--lh', '').removeClass('lh-set'); $('html').css('--lh', '').removeClass('lh-set');
adjustLayout(); updateVarsAndLayout();
return updateLineHeight(); return updateLineHeight();
} }
function resetListWidth() function resetListWidth()
{ {
$('html').css('--lw', '').removeClass('lw-set'); $('html').css('--lw', '').removeClass('lw-set');
adjustLayout(); updateVarsAndLayout();
return updateListWidth(); return updateListWidth();
} }
@@ -3653,15 +3724,34 @@
NB.loadDrag.prime(this, ev); NB.loadDrag.prime(this, ev);
}); });
//
$('.config').on('mousedown', '.ui-fs .val', function(ev){
var org = getFontSize();
NB.varAdjust.start(ev, function(delta){ setFontSize( org + delta/50. ); });
});
$('.config').on('mousedown', '.ui-lh .val', function(ev){
var org = getLineHeight();
NB.varAdjust.start(ev, function(delta){ setLineHeight( org + delta/50. ); });
});
$('.config').on('mousedown', '.ui-lw .val', function(ev){
var org = getListWidth();
NB.varAdjust.start(ev, function(delta){ setListWidth( org + delta/5. ); });
});
//
$(document).on('mouseup', function(ev){ $(document).on('mouseup', function(ev){
NB.noteDrag.end(); NB.noteDrag.end();
NB.loadDrag.end(); NB.loadDrag.end();
NB.varAdjust.end();
}); });
$(document).on('mousemove', function(ev){ $(document).on('mousemove', function(ev){
setRevealState(ev); setRevealState(ev);
NB.noteDrag.onMouseMove(ev); NB.noteDrag.onMouseMove(ev);
NB.loadDrag.onMouseMove(ev); NB.loadDrag.onMouseMove(ev);
NB.varAdjust.onMouseMove(ev);
}); });
// //
@@ -3700,42 +3790,42 @@
// //
$('.config .f-prefs .ui-fs .less').on('click', function(){ $('.config .f-prefs .ui-fs .less').on('click', function(){
var fs = setFontSize( getFontSize() - 0.5 ); var fs = setFontSize( parseInt(10*getFontSize()) / 10. - 0.5 );
NB.storage.setFontSize(fs); NB.storage.setFontSize(fs);
return false; return false;
}); });
$('.config .f-prefs .ui-fs .val').on('click', function(){ $('.config .f-prefs .ui-fs .val').on('click', function(){
if (NB.varAdjust.used) return false;
var fs = resetFontSize(); var fs = resetFontSize();
if (getLineHeight() < fs) if (getLineHeight() < fs) setLineHeight(fs);
setLineHeight(fs);
NB.storage.setFontSize(null); NB.storage.setFontSize(null);
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( getFontSize() + 0.5 ); var fs = setFontSize( parseInt(10*getFontSize()) / 10. + 0.5 );
NB.storage.setFontSize(fs); NB.storage.setFontSize(fs);
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( getLineHeight() - 0.1 ); var lh = setLineHeight( parseInt(10*getLineHeight()) / 10. - 0.1 );
NB.storage.setLineHeight(lh); NB.storage.setLineHeight(lh);
return false; return false;
}); });
$('.config .f-prefs .ui-lh .val').on('click', function(){ $('.config .f-prefs .ui-lh .val').on('click', function(){
if (NB.varAdjust.used) return false;
var lh = resetLineHeight(); var lh = resetLineHeight();
if (lh < getFontSize()) if (lh < getFontSize()) setFontSize(lh);
setFontSize(lh);
NB.storage.setLineHeight(null); NB.storage.setLineHeight(null);
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( getLineHeight() + 0.1 ); var lh = setLineHeight( parseInt(10*getLineHeight()) / 10. + 0.1 );
NB.storage.setLineHeight(lh); NB.storage.setLineHeight(lh);
return false; return false;
}); });
@@ -3748,6 +3838,7 @@
}); });
$('.config .f-prefs .ui-lw .val').on('click', function(){ $('.config .f-prefs .ui-lw .val').on('click', function(){
if (NB.varAdjust.used) return false;
resetListWidth(); resetListWidth();
NB.storage.setListWidth(null); NB.storage.setListWidth(null);
return false; return false;
@@ -3804,8 +3895,8 @@
*/ */
var NB = var NB =
{ {
codeVersion: 20210402, codeVersion: 20210407,
blobVersion: 20190412, // board blobs in storage blobVersion: 20190412, // board blob format in Storage
board: null, board: null,
}; };
@@ -3836,6 +3927,8 @@
initDragAndDrop(); initDragAndDrop();
NB.varAdjust = new VarAdjust()
// //
if (conf.theme) if (conf.theme)
$('html').addClass('theme-' + conf.theme); $('html').addClass('theme-' + conf.theme);