minor tweaks and refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-08-22 20:48:36 +03:00
parent f7ea76ec6e
commit 1489ba0c0a

View File

@ -10,13 +10,13 @@
// //
//===================================================================== //=====================================================================
// This compansates for any resize rounding errors in patchFlexRows(..).
var PATCH_MARGIN = 2
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Generic stuff... // Generic stuff...
// This compansates for any resize rounding errors in patchFlexRows(..).
var PATCH_MARGIN = 2
var patchFlexRows = var patchFlexRows =
function(elems, function(elems,
prevent_row_expansion=false, prevent_row_expansion=false,
@ -127,20 +127,20 @@ function(elem) {
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var ruler var _ruler
var px2rem = function(px){ var px2rem = function(px){
if(!ruler){ if(!_ruler){
ruler = document.createElement('div') _ruler = document.createElement('div')
document.body.append(ruler) } document.body.append(_ruler) }
ruler.style.width = '1rem' _ruler.style.width = '1rem'
var c = ruler.offsetWidth var c = _ruler.offsetWidth
return px / c } return px / c }
var rem2px = function(rem){ var rem2px = function(rem){
if(!ruler){ if(!_ruler){
ruler = document.createElement('div') _ruler = document.createElement('div')
document.body.append(ruler) } document.body.append(_ruler) }
ruler.style.width = rem + 'em' _ruler.style.width = rem + 'em'
var px = ruler.offsetWidth var px = _ruler.offsetWidth
return px } return px }
@ -905,6 +905,7 @@ var Gallery = {
img.classList.toggle('marked') } img.classList.toggle('marked') }
return this.updateMarkers() }, return this.updateMarkers() },
// XXX should this be an interface to something like .splash???
get loading(){ get loading(){
return !this.dom.classList.contains('ready') }, return !this.dom.classList.contains('ready') },
showLoading: function(){ showLoading: function(){
@ -917,14 +918,10 @@ var Gallery = {
this.dom.classList.toggle('ready') this.dom.classList.toggle('ready')
return this }, return this },
// show current image in lightbox...
show: function(){ show: function(){
return this.showLightbox() },
showLightbox: function(){
this.lightbox.show() this.lightbox.show()
return this }, return this },
showDetails: function(){
this.details.show()
return this },
__update_grid_size_timeout: undefined, __update_grid_size_timeout: undefined,
__update_grid_size_running: false, __update_grid_size_running: false,
@ -1333,6 +1330,7 @@ var Toolbar = {
toolbar_autohide: 2000, toolbar_autohide: 2000,
// XXX make these generic... // XXX make these generic...
// XXX rename .toggle(..) to something like .toggleExpanded(..)
toggle: function(action='toggle'){ toggle: function(action='toggle'){
var toolbar = this.dom?.classList var toolbar = this.dom?.classList
toolbar toolbar
@ -1352,6 +1350,16 @@ var Toolbar = {
: toolbar.remove('fixed')) : toolbar.remove('fixed'))
return this }, return this },
get shown(){
return this.dom.style.display != 'none' },
show: function(){
// XXX
this.dom.style.display = ''
return this },
hide: function(){
this.dom.style.display = 'none'
return this },
setup: function(dom, gallery){ setup: function(dom, gallery){
var that = this var that = this
this.dom = dom this.dom = dom
@ -1542,7 +1550,7 @@ var Overlay = {
evt.stopPropagation() evt.stopPropagation()
if(that.__clicks_canceled){ if(that.__clicks_canceled){
return } return }
that.gallery.showDetails() }) that.gallery.details.show() })
this.dom.querySelector('.prev') this.dom.querySelector('.prev')
?.addEventListener('click', function(evt){ ?.addEventListener('click', function(evt){
evt.stopPropagation() evt.stopPropagation()