|
|
@@ -2,10 +2,12 @@ function setAlbums(albums) {
|
|
|
var dAlbums = document.getElementById('albums');
|
|
|
dAlbums.innerHTML = '';
|
|
|
Array.prototype.forEach.call(albums, function(alb, i){
|
|
|
- var a = addAlbumDom(dAlbums, alb);
|
|
|
+ var a = addAlbumDom(dAlbums, alb, true);
|
|
|
+ a.setAttribute('data-id', alb.id);
|
|
|
+ a.setAttribute('title', alb.cover.src);
|
|
|
a.addEventListener('click', function() {
|
|
|
jsonGET('/api/albums/' + alb.id + '/', function (alb) {
|
|
|
- startGallery(alb.photos);
|
|
|
+ startGallery(alb.photos, 0, alb.id);
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
@@ -15,10 +17,10 @@ function setIncoming(albums, parent) {
|
|
|
parent.innerHTML = '';
|
|
|
Array.prototype.forEach.call(albums, function(alb, i){
|
|
|
var div = appendElement(parent, 'div', null, 'incoming-album');
|
|
|
- var a = addAlbumDom(div, alb);
|
|
|
+ var a = addAlbumDom(div, alb, true);
|
|
|
a.addEventListener('click', function(e) {
|
|
|
e.preventDefault();
|
|
|
- startGallery(alb.photos);
|
|
|
+ startGallery(alb.photos, 0, i);
|
|
|
});
|
|
|
var form = appendElement(div, 'form', null, null, '<div><p><label>Title</label><input type="text"/></p><p><label>Path</label><input type="text"/></p><p><input type="submit" value="Import"/></p>');
|
|
|
form[0].value = alb.title;
|
|
|
@@ -42,11 +44,27 @@ function setIncoming(albums, parent) {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-function startGallery(items, index) {
|
|
|
+function addAlbumDom(parent, alb, add_count) {
|
|
|
+ var a = appendElement(parent, 'a');
|
|
|
+ var img = appendElement(a, 'img');
|
|
|
+ img.src = alb.cover.src;
|
|
|
+ if (alb.title) {
|
|
|
+ var fig = appendElement(a, 'figure');
|
|
|
+ fig.textContent = alb.title;
|
|
|
+ if (add_count)
|
|
|
+ fig.textContent += ' [' + (alb.count || alb.photos.length) + ']';
|
|
|
+ };
|
|
|
+ return a;
|
|
|
+}
|
|
|
+
|
|
|
+function startGallery(items, index, uid) {
|
|
|
var pswpElement = document.querySelectorAll('.pswp')[0];
|
|
|
|
|
|
var options = {
|
|
|
- index: index || 0
|
|
|
+ preload: [1, 3],
|
|
|
+ loadingIndicatorDelay: 300,
|
|
|
+ index: index || 0,
|
|
|
+ galleryUID: uid || 1
|
|
|
};
|
|
|
|
|
|
// Initializes and opens PhotoSwipe
|
|
|
@@ -56,17 +74,6 @@ function startGallery(items, index) {
|
|
|
return gallery;
|
|
|
}
|
|
|
|
|
|
-function addAlbumDom(parent, alb) {
|
|
|
- var a = appendElement(parent, 'a');
|
|
|
- var img = appendElement(a, 'img');
|
|
|
- img.src = alb.cover.src;
|
|
|
- if (alb.title) {
|
|
|
- var fig = appendElement(a, 'figure');
|
|
|
- fig.textContent = alb.title;
|
|
|
- };
|
|
|
- return a;
|
|
|
-}
|
|
|
-
|
|
|
function appendElement(parent, tag, id, className, innerHTML) {
|
|
|
var el = document.createElement(tag);
|
|
|
if (id) el.id = id;
|