Added actions to photo-lightbox and toggle on tap
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
caab741e2c
commit
b348d1578f
@ -61,10 +61,51 @@
|
|||||||
#overlay > div {
|
#overlay > div {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#info {
|
||||||
|
color: white;
|
||||||
|
position: absolute;
|
||||||
|
padding: 0.5em;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
opacity: 0;
|
||||||
|
bottom: 0px;
|
||||||
|
left: 0px;
|
||||||
|
right: 0px;
|
||||||
|
font-size: 0.6em;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#actions {
|
||||||
|
display: flex;
|
||||||
|
padding: 0.5em;
|
||||||
|
background-color: rgba(0, 0, 0, 0.5);
|
||||||
|
opacity: 0;
|
||||||
|
font-size: 0.6em;
|
||||||
|
color: #ddd;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host([active]) #info,
|
||||||
|
:host([active]) #actions {
|
||||||
|
opacity: 1;
|
||||||
|
pointer-events: all;
|
||||||
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div id="image" class="layout vertical" on-tap="onTap">
|
<div id="image" class="layout vertical" on-tap="onTap">
|
||||||
|
<div id="actions" on-tap="_hideActions" class="flex horziontal layout center end-justified">
|
||||||
<paper-icon-button on-tap="download" class="start-end" icon="file-download"></paper-icon-button>
|
<paper-icon-button on-tap="download" class="start-end" icon="file-download"></paper-icon-button>
|
||||||
|
<template is="dom-repeat" items="[[actions]]">
|
||||||
|
<paper-icon-button on-tap="_fireAction" icon="[[item]]"></paper-icon-button>
|
||||||
|
</template>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="info" on-tap="_hideActions" class="layout vertical start">
|
||||||
|
<div>[[item.name]] ([[item.id]])</div>
|
||||||
|
<div>[[item.taken]]</div>
|
||||||
|
<div on-tap="_pathTap">[[item.path]]</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="overlay" class="layout vertical center">
|
<div id="overlay" class="layout vertical center">
|
||||||
@ -79,20 +120,30 @@
|
|||||||
Polymer({
|
Polymer({
|
||||||
is: "photo-lightbox",
|
is: "photo-lightbox",
|
||||||
properties: {
|
properties: {
|
||||||
|
"active": {
|
||||||
|
type: Boolean,
|
||||||
|
reflectToAttribute: true,
|
||||||
|
value: false
|
||||||
|
},
|
||||||
"src": {
|
"src": {
|
||||||
type: String
|
type: String,
|
||||||
|
value: ""
|
||||||
},
|
},
|
||||||
"thumb": {
|
"thumb": {
|
||||||
type: String
|
type: String
|
||||||
},
|
},
|
||||||
loading: {
|
"loading": {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
value: false
|
value: false
|
||||||
|
},
|
||||||
|
"unique": {
|
||||||
|
type: String,
|
||||||
|
value: ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
observers: [
|
observers: [
|
||||||
"srcChanged(src)"
|
"srcChanged(src, unique)"
|
||||||
],
|
],
|
||||||
|
|
||||||
listeners: {
|
listeners: {
|
||||||
@ -155,8 +206,25 @@ Polymer({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
reload: function() {
|
||||||
|
this.unique = parseInt(this.unique || 0) + 1;
|
||||||
|
},
|
||||||
|
|
||||||
|
_fireAction: function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
this.fire("action", event.model.item);
|
||||||
|
},
|
||||||
|
|
||||||
download: function(event) {
|
download: function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
|
||||||
console.log("Download tapped");
|
console.log("Download tapped");
|
||||||
|
|
||||||
var anchor = document.createElement('a');
|
var anchor = document.createElement('a');
|
||||||
anchor.href = this.base + this.item.path + "/" + this.item.filename;
|
anchor.href = this.base + this.item.path + "/" + this.item.filename;
|
||||||
anchor.setAttribute("download", this.src.replace(/.*\/([^/]+)$/, "$1"));
|
anchor.setAttribute("download", this.src.replace(/.*\/([^/]+)$/, "$1"));
|
||||||
@ -164,15 +232,12 @@ Polymer({
|
|||||||
document.body.appendChild(anchor);
|
document.body.appendChild(anchor);
|
||||||
anchor.click();
|
anchor.click();
|
||||||
document.body.removeChild(anchor);
|
document.body.removeChild(anchor);
|
||||||
event.preventDefault();
|
|
||||||
event.stopPropagation();
|
|
||||||
event.stopImmediatePropagation();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
close: function() {
|
close: function() {
|
||||||
this.style.opacity = 0;
|
this.style.opacity = 0;
|
||||||
|
|
||||||
this.async(function() {
|
this.async(function() {
|
||||||
|
this.setActive(false);
|
||||||
this.style.display = 'none';
|
this.style.display = 'none';
|
||||||
this.image = undefined;
|
this.image = undefined;
|
||||||
this.$.image.style.opacity = 0;
|
this.$.image.style.opacity = 0;
|
||||||
@ -184,6 +249,9 @@ Polymer({
|
|||||||
},
|
},
|
||||||
|
|
||||||
srcChanged: function(src) {
|
srcChanged: function(src) {
|
||||||
|
if (!src) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.loadImage(src);
|
this.loadImage(src);
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -192,16 +260,27 @@ Polymer({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((event.detail.y < this.$.actions.offsetHeight) ||
|
||||||
|
(event.detail.y > this.offsetHeight - this.$.info.offsetHeight)) {
|
||||||
|
this.setActive(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event.detail.x <= 0.1 * this.offsetWidth) {
|
if (event.detail.x <= 0.1 * this.offsetWidth) {
|
||||||
this.previous();
|
this.previous();
|
||||||
} else if (event.detail.x >= 0.9 * this.offsetWidth) {
|
return;
|
||||||
this.next();
|
|
||||||
} else {
|
|
||||||
this.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.detail.x >= 0.9 * this.offsetWidth) {
|
||||||
|
this.next();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.close();
|
||||||
},
|
},
|
||||||
|
|
||||||
open: function() {
|
open: function() {
|
||||||
|
this.setActive(true);
|
||||||
this.closed = false;
|
this.closed = false;
|
||||||
this.opened = true;
|
this.opened = true;
|
||||||
this.loadImage(this.src);
|
this.loadImage(this.src);
|
||||||
@ -210,7 +289,19 @@ Polymer({
|
|||||||
this.focus();
|
this.focus();
|
||||||
},
|
},
|
||||||
|
|
||||||
loadImage: function(image) {
|
_hideActions: function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
event.stopPropagation();
|
||||||
|
|
||||||
|
this.setActive(false);
|
||||||
|
},
|
||||||
|
|
||||||
|
setActive: function(active) {
|
||||||
|
this.active = active;
|
||||||
|
},
|
||||||
|
|
||||||
|
loadImage: function(path) {
|
||||||
if (this.$.image.style.opacity != 0) {
|
if (this.$.image.style.opacity != 0) {
|
||||||
this.waitUntil = (Date.now() / 1000) + 500;
|
this.waitUntil = (Date.now() / 1000) + 500;
|
||||||
} else {
|
} else {
|
||||||
@ -219,24 +310,25 @@ Polymer({
|
|||||||
this.$.image.style.opacity = 0;
|
this.$.image.style.opacity = 0;
|
||||||
|
|
||||||
this.image = new Image();
|
this.image = new Image();
|
||||||
this.requested = image;
|
this.requested = path;
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
|
|
||||||
this.image.onload = function(src) {
|
this.image.onload = function(path) {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
var remaining = Math.max(this.waitUntil - Date.now() / 1000, 0);
|
var remaining = Math.max(this.waitUntil - Date.now() / 1000, 0);
|
||||||
this.async(function() {
|
this.async(function() {
|
||||||
if (!this.image || this.requested != src) {
|
if (!this.image || this.requested != path) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$.image.style.backgroundImage = 'url("' + this.image.src + '")';
|
this.$.image.style.backgroundImage = 'url("' + this.image.src + '")';
|
||||||
this.$.image.style.opacity = 1;
|
this.$.image.style.opacity = 1;
|
||||||
this.image = undefined;
|
this.image = undefined;
|
||||||
|
this.setActive(true);
|
||||||
}, remaining);
|
}, remaining);
|
||||||
}.bind(this, image);
|
}.bind(this, path);
|
||||||
|
|
||||||
this.image.src = image;
|
this.image.src = path + (this.unique ? ("?" + this.unique) : "");
|
||||||
},
|
},
|
||||||
|
|
||||||
attached: function() {
|
attached: function() {
|
||||||
|
@ -455,7 +455,12 @@
|
|||||||
</paper-dialog>
|
</paper-dialog>
|
||||||
<paper-toast id="toast"></paper-toast>
|
<paper-toast id="toast"></paper-toast>
|
||||||
<photo-lightbox tabindex="0"
|
<photo-lightbox tabindex="0"
|
||||||
id="lightbox" on-close="lightBoxClose" on-next="lightBoxNext" on-previous="lightBoxPrevious"></photo-lightbox>
|
id="lightbox"
|
||||||
|
on-close="lightBoxClose"
|
||||||
|
on-next="lightBoxNext"
|
||||||
|
on-previous="lightBoxPrevious"
|
||||||
|
actions="[[actions]]"
|
||||||
|
on-action="_imageAction"></photo-lightbox>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -464,6 +469,10 @@
|
|||||||
Polymer({
|
Polymer({
|
||||||
is: "ketr-photos",
|
is: "ketr-photos",
|
||||||
properties: {
|
properties: {
|
||||||
|
actions: {
|
||||||
|
type: Array,
|
||||||
|
value: []
|
||||||
|
},
|
||||||
password: {
|
password: {
|
||||||
type: String,
|
type: String,
|
||||||
value: ""
|
value: ""
|
||||||
@ -1224,16 +1233,7 @@
|
|||||||
var thumbnail = document.createElement("photo-thumbnail");
|
var thumbnail = document.createElement("photo-thumbnail");
|
||||||
thumbnail.item = photo;
|
thumbnail.item = photo;
|
||||||
if (this.user.maintainer) {
|
if (this.user.maintainer) {
|
||||||
let actions = [ "delete" ];
|
thumbnail.actions = this.actions;
|
||||||
if (this.mode == "duplicates") {
|
|
||||||
actions.unshift("text-format");
|
|
||||||
} else if (this.mode == "trash") {
|
|
||||||
actions.unshift("undo");
|
|
||||||
} else {
|
|
||||||
actions.unshift("image:rotate-right");
|
|
||||||
actions.unshift("image:rotate-left");
|
|
||||||
}
|
|
||||||
thumbnail.actions = actions;
|
|
||||||
thumbnail.addEventListener("action", this._imageAction.bind(this));
|
thumbnail.addEventListener("action", this._imageAction.bind(this));
|
||||||
}
|
}
|
||||||
thumbnail.addEventListener("load-image", this._imageTap.bind(this));
|
thumbnail.addEventListener("load-image", this._imageTap.bind(this));
|
||||||
@ -1378,10 +1378,13 @@
|
|||||||
|
|
||||||
rotateAction: function(thumbnail, direction) {
|
rotateAction: function(thumbnail, direction) {
|
||||||
thumbnail.disabled = true;
|
thumbnail.disabled = true;
|
||||||
|
thumbnail.loading = true;
|
||||||
|
|
||||||
window.fetch("api/v1/photos/" + thumbnail.item.id + "?a=rotate&direction=" + direction,
|
window.fetch("api/v1/photos/" + thumbnail.item.id + "?a=rotate&direction=" + direction,
|
||||||
function(thumbnail, error, xhr) {
|
function(thumbnail, error, xhr) {
|
||||||
|
|
||||||
thumbnail.disabled = false;
|
thumbnail.disabled = false;
|
||||||
|
thumbnail.loading = false;
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log("Unable to take action on photo: " + error);
|
console.log("Unable to take action on photo: " + error);
|
||||||
@ -1389,6 +1392,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
thumbnail.reload();
|
thumbnail.reload();
|
||||||
|
/* If we are in the lightbox mode, then reload the corresponing
|
||||||
|
* thumb in the main view as well */
|
||||||
|
if (thumbnail.tagName == "PHOTO-LIGHTBOX") {
|
||||||
|
for (var i = 0; i < this.thumbnails.length; i++) {
|
||||||
|
if (this.thumbnails[i].item.id == thumbnail.item.id) {
|
||||||
|
this.thumbnails[i].reload();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}.bind(this, thumbnail), {}, "PUT");
|
}.bind(this, thumbnail), {}, "PUT");
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -1585,15 +1598,31 @@
|
|||||||
if (!user) {
|
if (!user) {
|
||||||
this.mode = "login";
|
this.mode = "login";
|
||||||
this.loginStatus = null;
|
this.loginStatus = null;
|
||||||
|
this.actions = [];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.authenticated && user.mailVerified) {
|
if (user.authenticated && user.mailVerified) {
|
||||||
this.loginStatus = null;
|
this.loginStatus = null;
|
||||||
this.mode = "memories";
|
this.mode = "memories";
|
||||||
|
if (user.maintainer) {
|
||||||
|
let actions = [ "delete" ];
|
||||||
|
if (this.mode == "duplicates") {
|
||||||
|
actions.unshift("text-format");
|
||||||
|
} else if (this.mode == "trash") {
|
||||||
|
actions.unshift("undo");
|
||||||
|
} else {
|
||||||
|
actions.unshift("image:rotate-right");
|
||||||
|
actions.unshift("image:rotate-left");
|
||||||
|
}
|
||||||
|
this.actions = actions;
|
||||||
|
} else {
|
||||||
|
this.actions = [];
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.actions = [];
|
||||||
this.mode = "login";
|
this.mode = "login";
|
||||||
|
|
||||||
if (!user.mailVerified) {
|
if (!user.mailVerified) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user