Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update fancybox to latest #38

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions REST/PhotoFrame/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ app.use(
'/fancybox',
express.static(
fileURLToPath(
new URL('./node_modules/@fancyapps/fancybox/dist/', import.meta.url)
new URL('./node_modules/@fancyapps/ui/dist/', import.meta.url)
),
)
);
Expand Down Expand Up @@ -201,9 +201,11 @@ app.get('/', (req, res) => {
// GET request to log out the user.
// Destroy the current session and redirect back to the log in screen.
app.get('/logout', (req, res) => {
req.logout();
req.session.destroy();
res.redirect('/');
req.logout(function(err) {
if (err) { return next(err); }
req.session.destroy();
res.redirect('/');
});
});

// Star the OAuth login process for Google.
Expand Down Expand Up @@ -238,6 +240,9 @@ app.get('/album', (req, res) => {
renderIfAuthenticated(req, res, 'pages/album');
});

app.get('/fancyboxcfg', (req, res) => {
res.json( config.fancybox );
});

// Handles form submissions from the search page.
// The user has made a selection and wants to load photos into the photo frame
Expand Down
7 changes: 7 additions & 0 deletions REST/PhotoFrame/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,10 @@ config.albumPageSize = 50;

// The API end point to use. Do not change.
config.apiEndpoint = 'https://photoslibrary.googleapis.com';

config.fancybox = {
Slideshow: { playOnStart: true, timeout:20e3 },
Thumbs: { showOnStart: false },
Fullscreen: { autoStart: true },
hideScrollbar: true,
};
22 changes: 9 additions & 13 deletions REST/PhotoFrame/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion REST/PhotoFrame/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"main": "app.js",
"type": "module",
"dependencies": {
"@fancyapps/fancybox": "^3.5.7",
"@fancyapps/ui": "^5.0.36",
"body-parser": "^1.19.1",
"ejs": "^3.1.7",
"express": "^4.18.1",
Expand Down
4 changes: 4 additions & 0 deletions REST/PhotoFrame/static/css/frame.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ pre {
opacity: 1 !important;
}

.fancybox__container {
background-color: rgba(24, 24, 27, 1.0)
}

.loading-dialog {
position: fixed;
margin: 0;
Expand Down
33 changes: 14 additions & 19 deletions REST/PhotoFrame/static/js/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ function showPreview(source, mediaItems) {
$('startSlideshow').removeClass('disabled');
}

function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
shuffleArray(mediaItems);
// Loop over each media item and render it.
$.each(mediaItems, (i, item) => {
// Construct a thumbnail URL from the item's base URL at a small pixel size.
Expand Down Expand Up @@ -78,8 +85,8 @@ function showPreview(source, mediaItems) {
.attr('data-height', item.mediaMetadata.height);
// Add the thumbnail image to the link to the full image for fancybox.
const thumbnailImage = $('<img />')
.attr('src', thumbnailUrl)
.attr('alt', captionText)
// .attr('src', thumbnailUrl)
// .attr('alt', captionText)
.addClass('img-fluid rounded thumbnail');
linkToFullImage.append(thumbnailImage);

Expand Down Expand Up @@ -126,28 +133,16 @@ function loadQueue() {
$(document).ready(() => {
// Load the queue of photos selected by the user for the photo
loadQueue();

// Set up the fancybox image gallery.
$().fancybox({
selector: '[data-fancybox="gallery"]',
loop: true,
buttons: ['slideShow', 'fullScreen', 'close'],
image: {preload: true},
transitionEffect: 'fade',
transitionDuration: 1000,
fullScreen: {autoStart: false},
// Automatically advance after 3s to next photo.
slideShow: {autoStart: true, speed: 3000},
// Display the contents figcaption element as the caption of an image
caption: function(instance, item) {
return $(this).find('figcaption').html();
}

$.get( "/fancyboxcfg", function( data ) {
// Set up the fancybox image gallery.
Fancybox.bind('[data-fancybox="gallery"]', data);
});

// Clicking the 'view fullscreen' button opens the gallery from the first
// image.
$('#startSlideshow')
.on('click', (e) => $('#images-container a').first().click());
.on('click', (e) => Fancybox.fromSelector('[data-fancybox="gallery"]') )

// Clicking log out opens the log out screen.
$('#logout').on('click', (e) => {
Expand Down
3 changes: 2 additions & 1 deletion REST/PhotoFrame/views/pages/frame.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<%- include('../partials/dialogs') %>

<%- include('../partials/js') %>
<script src="/fancybox/jquery.fancybox.min.js"></script>
<script src="/fancybox/fancybox/fancybox.umd.js"></script>
<script src="/fancybox/carousel/carousel.autoplay.umd.js"></script>
<script src="/js/frame.js"></script>

<%- include('../partials/footer') %>
3 changes: 2 additions & 1 deletion REST/PhotoFrame/views/partials/head.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:300,400,500,700" type="text/css">

<!-- Fancybox Gallery CSS -->
<link rel="stylesheet" type="text/css" href="/fancybox/jquery.fancybox.min.css">
<link rel="stylesheet" href="/fancybox/fancybox/fancybox.css"/>
<link rel="stylesheet" href="/fancybox/carousel/carousel.autoplay.css"/>

<!-- Material design icon-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
Expand Down