added serialization + minor fixes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
fb2e88cfa0
commit
0ff97ccb6f
@ -46,7 +46,7 @@
|
|||||||
- Gallery: drop images
|
- Gallery: drop images
|
||||||
- Gallery: drag to sort
|
- Gallery: drag to sort
|
||||||
- Gallery: remove image
|
- Gallery: remove image
|
||||||
- <b>Gallery: serialize / deserialize</b>
|
- <s>Gallery: serialize / deserialize</s>
|
||||||
- <s>Lightbox: navigation (keyboard / mouse)</s>
|
- <s>Lightbox: navigation (keyboard / mouse)</s>
|
||||||
- <s>Lightbox: fullscreen mode</s>
|
- <s>Lightbox: fullscreen mode</s>
|
||||||
- Gallery: element (???)
|
- Gallery: element (???)
|
||||||
|
|||||||
@ -20,6 +20,8 @@
|
|||||||
// XXX need to account for scrollbar -- add hysteresis???
|
// XXX need to account for scrollbar -- add hysteresis???
|
||||||
var patchFlexRows =
|
var patchFlexRows =
|
||||||
function(elems, prevent_row_expansion=false){
|
function(elems, prevent_row_expansion=false){
|
||||||
|
if(elems.length == 0){
|
||||||
|
return }
|
||||||
// NOTE: -1 here is to compensate for rounding errors...
|
// NOTE: -1 here is to compensate for rounding errors...
|
||||||
var W = elems[0].parentElement.clientWidth - 1
|
var W = elems[0].parentElement.clientWidth - 1
|
||||||
var w = 0
|
var w = 0
|
||||||
@ -492,14 +494,73 @@ var Gallery = {
|
|||||||
patchFlexRows(this.images, !this.allow_row_expansion)
|
patchFlexRows(this.images, !this.allow_row_expansion)
|
||||||
return this },
|
return this },
|
||||||
|
|
||||||
load: function(urls){
|
// .load(<image>)
|
||||||
this.clear()
|
// .load(<images>)
|
||||||
var images = this.dom.querySelector('.images')
|
// .load(<image>, <index>)
|
||||||
for(var url of urls){
|
// .load(<images>, <index>)
|
||||||
var img = document.createElement('img')
|
//
|
||||||
img.src = url
|
// <images> ::=
|
||||||
images.appendChild(img) }
|
// <image>
|
||||||
return this },
|
// | [ <image>, .. ]
|
||||||
|
// <image> ::=
|
||||||
|
// <url>
|
||||||
|
// | [ <url>, <caption>, .. ]
|
||||||
|
// | { url: <url>, caption: <caption>, .. }
|
||||||
|
//
|
||||||
|
// XXX do we handle previews here???
|
||||||
|
load: function(images, index=undefined){
|
||||||
|
images = images instanceof Array ?
|
||||||
|
images
|
||||||
|
: [images]
|
||||||
|
// create images...
|
||||||
|
var elems = []
|
||||||
|
for(var data of images){
|
||||||
|
if(typeof(data) == 'string'){
|
||||||
|
var [url] = [data]
|
||||||
|
} else if(data instanceof Array){
|
||||||
|
var [url, ...data] = data
|
||||||
|
} else {
|
||||||
|
var {url, ...data} = data }
|
||||||
|
var elem = document.createElement('img')
|
||||||
|
elem.src = url
|
||||||
|
for(var [key, value] of Object.entries(data)){
|
||||||
|
value
|
||||||
|
&& elem.setAttribute(key, value) }
|
||||||
|
elems.push(elem) }
|
||||||
|
// add to gallery...
|
||||||
|
if(index == null){
|
||||||
|
this.clear() }
|
||||||
|
if(index == null
|
||||||
|
|| this.length > 0){
|
||||||
|
this.dom.querySelector('.images')
|
||||||
|
.append(...elems)
|
||||||
|
} else {
|
||||||
|
var sibling = this.images.at(index)
|
||||||
|
index < 0 ?
|
||||||
|
sibling.after(...elems)
|
||||||
|
: sibling.before(...elems) }
|
||||||
|
return this
|
||||||
|
.update() },
|
||||||
|
__image_attributes__: [
|
||||||
|
'caption',
|
||||||
|
],
|
||||||
|
// XXX do we handle previews here???
|
||||||
|
json: function(){
|
||||||
|
var that = this
|
||||||
|
return this.images
|
||||||
|
.map(function(img){
|
||||||
|
var res = { url: img.src }
|
||||||
|
for(var key of that.__image_attributes__){
|
||||||
|
var value = img.getAttribute(key)
|
||||||
|
value
|
||||||
|
&& (res[key] = value) }
|
||||||
|
return res }) },
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
remove: function(){
|
||||||
|
// XXX
|
||||||
|
return this
|
||||||
|
},
|
||||||
clear: function(){
|
clear: function(){
|
||||||
this.dom.querySelector('.images').innerHTML = ''
|
this.dom.querySelector('.images').innerHTML = ''
|
||||||
return this },
|
return this },
|
||||||
@ -655,6 +716,7 @@ var Lightbox = {
|
|||||||
.addEventListener('click', function(evt){
|
.addEventListener('click', function(evt){
|
||||||
evt.stopPropagation()
|
evt.stopPropagation()
|
||||||
that.gallery.exit_fullscreen_on_lightbox_close
|
that.gallery.exit_fullscreen_on_lightbox_close
|
||||||
|
&& document.fullscreenElement
|
||||||
&& document.exitFullscreen()
|
&& document.exitFullscreen()
|
||||||
that.hide() })
|
that.hide() })
|
||||||
this.dom.querySelector('.fullscreen')
|
this.dom.querySelector('.fullscreen')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user