207 lines
6.6 KiB
HTML
Executable File
207 lines
6.6 KiB
HTML
Executable File
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<link rel="import" href="../bower_components/polymer/polymer.html">
|
|
<link rel="import" href="../bower_components/paper-icon-button/paper-icon-button.html">
|
|
<link rel="import" href="../bower_components/iron-flex-layout/iron-flex-layout-classes.html">
|
|
<link rel="import" href="../bower_components/iron-icon/iron-icon.html">
|
|
<link rel="import" href="../bower_components/iron-icons/iron-icons.html">
|
|
<link rel="import" href="../bower_components/iron-pages/iron-pages.html">
|
|
</head>
|
|
|
|
<dom-module id="ken-burns">
|
|
<template>
|
|
<style is="custom-style" include="iron-flex iron-flex-alignment iron-positioning">
|
|
:host {
|
|
position: fixed;
|
|
top: 0px;
|
|
left: 0px;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: rgba(0, 0, 0, 0.8);
|
|
transition: opacity 0.5s ease-in-out;
|
|
-webkit-transition: opacity 0.5s ease-in-out;
|
|
box-sizing: border-box;
|
|
pointer-events: all;
|
|
}
|
|
|
|
#image {
|
|
display: inline-block;
|
|
position: absolute;
|
|
top: 0px;
|
|
left: 0px;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-size: contain;
|
|
background-position: center center;
|
|
background-repeat: no-repeat;
|
|
transition: opacity 0.5s ease-in-out;
|
|
-webkit-transition: opacity 0.5s ease-in-out;
|
|
}
|
|
|
|
</style>
|
|
|
|
<div id="image">
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
"use strict";
|
|
Polymer({
|
|
is: "ken-burns",
|
|
properties: {
|
|
"src": {
|
|
type: String,
|
|
value: ""
|
|
},
|
|
"unique": {
|
|
type: String,
|
|
value: ""
|
|
}
|
|
},
|
|
|
|
listeners: {
|
|
},
|
|
|
|
observers: [
|
|
"widthChanged(width)",
|
|
"thumbChanged(thumbpath, visible)",
|
|
"srcChanged(src, unique)"
|
|
],
|
|
|
|
srcChanged: function(src) {
|
|
if (!src) {
|
|
return;
|
|
}
|
|
this.loadImage(src);
|
|
},
|
|
|
|
loadImage: function(path) {
|
|
if (this.$.image.style.opacity != 0) {
|
|
this.waitUntil = (Date.now() / 1000) + 500;
|
|
} else {
|
|
this.waitUntil = 0;
|
|
}
|
|
this.$.image.style.opacity = 0;
|
|
|
|
this.image = new Image();
|
|
this.requested = path;
|
|
this.loading = true;
|
|
|
|
this.image.onload = function(path) {
|
|
this.loading = false;
|
|
var remaining = Math.max(this.waitUntil - Date.now() / 1000, 0);
|
|
this.async(function() {
|
|
if (!this.image || this.requested != path) {
|
|
return;
|
|
}
|
|
|
|
this.showImage();
|
|
|
|
this.$.image.style.backgroundImage = 'url(' + this.image.src + ')';
|
|
this.$.image.style.opacity = 1;
|
|
this.image = undefined;
|
|
}, remaining);
|
|
}.bind(this, path);
|
|
|
|
this.image.src = path + (this.unique ? ("?" + this.unique) : "");
|
|
},
|
|
|
|
formatDateTime: function(date) {
|
|
return window.moment(new Date(date)).format("lll");
|
|
},
|
|
|
|
widthChanged: function(width) {
|
|
this.style.width = width + "px";
|
|
this.style.height = width + "px";
|
|
},
|
|
|
|
safeItemThumbFilepath: function(item, base, unique) {
|
|
if (item === undefined|| base === undefined || item.path === undefined) {
|
|
return "";
|
|
}
|
|
return base + item.path + "thumbs/" + item.filename + (this.unique ? ("?" + this.unique) : "");
|
|
},
|
|
|
|
date: function(item) {
|
|
var datetime = item.taken || item.modified || item.added;
|
|
return datetime.replace(/T.*$/, "");
|
|
},
|
|
|
|
reload: function() {
|
|
this.unique = parseInt(this.unique || 0) + 1;
|
|
},
|
|
|
|
randomizer: function(min,max) {
|
|
return Math.random() * (max - min) + min;
|
|
},
|
|
|
|
attached: function() {
|
|
var base = document.querySelector("base");
|
|
if (base) {
|
|
this.base = new URL(base.href).pathname.replace(/\/$/, "") + "/"; /* Make sure there is a trailing slash */
|
|
} else {
|
|
this.base = "/";
|
|
}
|
|
|
|
this.showImage();
|
|
},
|
|
|
|
showImage: function() {
|
|
var maxscale = 1.4;
|
|
var minscale = 1.1;
|
|
var minMov = 5;
|
|
var maxMov = 10;
|
|
var scalar = this.randomizer(minscale,maxscale).toFixed(2);
|
|
var moveX = this.randomizer(minMov,maxMov).toFixed(2);
|
|
|
|
moveX = Math.random() < 0.5 ? -Math.abs(moveX) : Math.abs(moveX);
|
|
|
|
var moveY = this.randomizer(minMov,maxMov).toFixed(2);
|
|
moveY = Math.random() < 0.5 ? -Math.abs(moveY) : Math.abs(moveY);
|
|
|
|
var prefix = "";
|
|
if (CSSRule.WEBKIT_KEYFRAMES_RULE) {
|
|
prefix = "-webkit-";
|
|
} else if (CSSRule.MOZ_KEYFRAMES_RULE) {
|
|
prefix = "-moz-";
|
|
}
|
|
|
|
var style =
|
|
"#image { " +
|
|
"animation: zoom 12s alternate infinite; " +
|
|
"position: absolute; " +
|
|
"top: 0; left:-5%; width: 110%; height: 110%; " +
|
|
"}" +
|
|
"\n" +
|
|
"@" + prefix + "keyframes burnseffect { " +
|
|
"10% { " +
|
|
prefix + "transform: scale(1);" +
|
|
"} " +
|
|
"90% { " +
|
|
prefix + "transform: scale(" + scalar +" ) translate(" + moveX +"%," + moveY + "%);" +
|
|
"} " +
|
|
"100% { " +
|
|
prefix + "transform: scale(" + scalar + ") translate(" + moveX +"%," + moveY +"%);" +
|
|
"}" +
|
|
"}";
|
|
|
|
if (this.animStyle) {
|
|
this.root.removeChild(this.animStyle);
|
|
}
|
|
this.animStyle = document.createElement("style");
|
|
this.animStyle.appendChild(document.createTextNode(style));
|
|
this.root.insertBefore(this.animStyle, this.firstChild);
|
|
|
|
this.$.image.style.animationName = 'burnseffect';
|
|
this.$.image.style.webkitAnimationName = 'burnseffect';
|
|
this.$.image.style.mozAnimationName = 'burnseffect';
|
|
this.$.image.style.animationName = 'burnseffect';
|
|
|
|
this.updateStyles();
|
|
}
|
|
});
|
|
</script>
|
|
</dom-module>
|
|
</html> |