Allow upload of videos

This commit is contained in:
2019-06-28 22:17:46 +02:00
parent 9f7ada89f4
commit e1aac63ae0
10 changed files with 140 additions and 51 deletions

2
.gitignore vendored
View File

@@ -12,4 +12,6 @@
/files/**/*.JPEG /files/**/*.JPEG
/files/**/*.png /files/**/*.png
/files/**/*.PNG /files/**/*.PNG
/files/**/*.mov
/files/**/*.MOV
/geo/*.geojson /geo/*.geojson

View File

@@ -15,7 +15,7 @@ class Uploader extends UploadHandler
$this->error_messages['wrong_project_mode'] = 'Le projet n\'est pas en mode "blog".'; $this->error_messages['wrong_project_mode'] = 'Le projet n\'est pas en mode "blog".';
$this->oPicture = &$oPicture; $this->oPicture = &$oPicture;
$this->sBody = ''; $this->sBody = '';
parent::__construct(array('image_versions'=>array(), 'accept_file_types'=>'/\.(gif|jpe?g|png)$/i')); parent::__construct(array('image_versions'=>array(), 'accept_file_types'=>'/\.(gif|jpe?g|png|mov)$/i'));
} }
protected function validate($uploaded_file, $file, $error, $index) { protected function validate($uploaded_file, $file, $error, $index) {

View File

@@ -88,7 +88,8 @@ function initPage(asHash) {
albumLabel: "Photo %1 sur %2", albumLabel: "Photo %1 sur %2",
fadeDuration: 300, fadeDuration: 300,
imageFadeDuration: 400, imageFadeDuration: 400,
resizeDuration: 600 resizeDuration: 600,
hasVideo: true
}); });
//Assign Track Type Colors //Assign Track Type Colors
@@ -503,7 +504,8 @@ function getPost(asPost) {
case 'picture': case 'picture':
var sTakenOn = (asPost.taken_on == '0000-00-00 00:00:00')?'':' et prise le '+asPost.taken_on_formatted+self.tmp('site_tz_notice'); var sTakenOn = (asPost.taken_on == '0000-00-00 00:00:00')?'':' et prise le '+asPost.taken_on_formatted+self.tmp('site_tz_notice');
var $Image = $('<img>', {'src': asPost.thumb_path, title: 'Click pour zoomer'}); var $Image = $('<img>', {'src': asPost.thumb_path, title: 'Click pour zoomer'});
$Body = $('<a>', {href: asPost.pic_path, 'data-lightbox': 'post-pictures', 'data-title': 'Photo ajoutée le '+sAbsTime+sTakenOn, 'data-orientation': asPost.rotate}).append($Image); var sVideo = asPost.pic_path.toLowerCase().split('.').pop()=='mov'?'true':'false';
$Body = $('<a>', {href: asPost.pic_path, 'data-video': sVideo, 'data-lightbox': 'post-pictures', 'data-title': 'Photo ajoutée le '+sAbsTime+sTakenOn, 'data-orientation': asPost.rotate}).append($Image);
break; break;
case 'post': case 'post':
$Body = $('<div>') $Body = $('<div>')

View File

@@ -1,5 +1,5 @@
<div id="upload"> <div id="upload">
<h1>Pictures upload</h1> <h1>Picture &amp; Video Uploads</h1>
<input id="fileupload" type="file" name="files[]" multiple> <input id="fileupload" type="file" name="files[]" multiple>
<div id="progress"> <div id="progress">
<div class="bar" style="width: 0%;"></div> <div class="bar" style="width: 0%;"></div>
@@ -15,7 +15,7 @@ oSpot.pageInit = function(asHash)
.attr('data-url', self.getActionLink('upload')) .attr('data-url', self.getActionLink('upload'))
.fileupload({ .fileupload({
dataType: 'json', dataType: 'json',
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i, acceptFileTypes: /(\.|\/)(gif|jpe?g|png|mov)$/i,
done: function (e, asData) { done: function (e, asData) {
var $Status = $('#status'); var $Status = $('#status');
$.each(asData.result.files, function(iKey, oFile) { $.each(asData.result.files, function(iKey, oFile) {

View File

@@ -6,7 +6,7 @@
## To Do List ## To Do List
* require js * require js
* Video support * Video support
* Upload * Thumbnail
* Preloader * Preloader
* Resize * Resize
* Navigation * Navigation

View File

@@ -62,6 +62,9 @@
to prevent xss and other injection attacks. to prevent xss and other injection attacks.
*/ */
sanitizeTitle: false sanitizeTitle: false
//ADDED-START
, hasVideo: false
//ADDED-END
}; };
Lightbox.prototype.option = function(options) { Lightbox.prototype.option = function(options) {
@@ -109,6 +112,19 @@
this.$image = this.$lightbox.find('.lb-image'); this.$image = this.$lightbox.find('.lb-image');
this.$nav = this.$lightbox.find('.lb-nav'); this.$nav = this.$lightbox.find('.lb-nav');
//ADDED-START
if(self.options.hasVideo) {
this.$video = $('<video class="lb-video" width="560" height="315" src="" controls autoplay></video>');
this.$image.after(this.$video);
this.videoBorderWidth = {
top: parseInt(this.$video.css('border-top-width'), 10),
right: parseInt(this.$video.css('border-right-width'), 10),
bottom: parseInt(this.$video.css('border-bottom-width'), 10),
left: parseInt(this.$video.css('border-left-width'), 10)
};
}
//ADDED-END
// Store css values for future lookup // Store css values for future lookup
this.containerPadding = { this.containerPadding = {
top: parseInt(this.$container.css('padding-top'), 10), top: parseInt(this.$container.css('padding-top'), 10),
@@ -217,6 +233,7 @@
title: $link.attr('data-title') || $link.attr('title') title: $link.attr('data-title') || $link.attr('title')
//ADDED-START //ADDED-START
, orientation: $link.attr('data-orientation') , orientation: $link.attr('data-orientation')
, video: (self.options.hasVideo && typeof $link.attr('data-video') !== 'undefined' && $link.attr('data-video') === 'true')
//ADDED-END //ADDED-END
}); });
} }
@@ -248,7 +265,7 @@
} }
} }
} }
// Position Lightbox // Position Lightbox
var top = $window.scrollTop() + this.options.positionFromTop; var top = $window.scrollTop() + this.options.positionFromTop;
var left = $window.scrollLeft(); var left = $window.scrollLeft();
@@ -275,9 +292,35 @@
this.$overlay.fadeIn(this.options.fadeDuration); this.$overlay.fadeIn(this.options.fadeDuration);
$('.lb-loader').fadeIn('slow'); $('.lb-loader').fadeIn('slow');
this.$lightbox.find('.lb-image, .lb-nav, .lb-prev, .lb-next, .lb-dataContainer, .lb-numbers, .lb-caption').hide(); //ADDED-START
//this.$lightbox.find('.lb-image, .lb-nav, .lb-prev, .lb-next, .lb-dataContainer, .lb-numbers, .lb-caption').hide();
this.$lightbox.find('.lb-image, .lb-video, .lb-nav, .lb-prev, .lb-next, .lb-dataContainer, .lb-numbers, .lb-caption').hide();
//ADDED-END
this.$outerContainer.addClass('animating'); this.$outerContainer.addClass('animating');
//ADDED-START
if(self.options.hasVideo) {
var $video = this.$lightbox.find('.lb-video');
var $lbContainer = this.$lightbox.find('.lb-container');
var $hasVideoNav = $lbContainer.hasClass('lb-video-nav');
if(self.album[imageNumber].video) {
$video.attr('src', self.album[imageNumber].link);
var $videoWidth = parseInt($video.attr('width'));
var $videoHeight = parseInt($video.attr('height'));
this.currentImageIndex = imageNumber;
self.sizeContainer($videoWidth, $videoHeight, 'video');
if(!$hasVideoNav) $lbContainer.addClass('lb-video-nav');
return;
}
else {
$video.attr('src', '');
if($hasVideoNav) $lbContainer.removeClass('lb-video-nav');
}
}
//ADDED-END
// When image to show is preloaded, we send the width and height to sizeContainer() // When image to show is preloaded, we send the width and height to sizeContainer()
var preloader = new Image(); var preloader = new Image();
@@ -341,7 +384,10 @@
} }
} }
} }
self.sizeContainer($image.width(), $image.height()); //ADDED-START
//self.sizeContainer($image.width(), $image.height());
self.sizeContainer($image.width(), $image.height(), 'image');
//ADDED-END
}; };
preloader.src = this.album[imageNumber].link; preloader.src = this.album[imageNumber].link;
@@ -356,14 +402,24 @@
}; };
// Animate the size of the lightbox to fit the image we are showing // Animate the size of the lightbox to fit the image we are showing
Lightbox.prototype.sizeContainer = function(imageWidth, imageHeight) { //ADDED-START
var self = this; //Lightbox.prototype.sizeContainer = function(imageWidth, imageHeight) {
Lightbox.prototype.sizeContainer = function(imageWidth, imageHeight, media) {
media = media || 'image';
//ADDED-END
var self = this;
var oldWidth = this.$outerContainer.outerWidth(); var oldWidth = this.$outerContainer.outerWidth();
var oldHeight = this.$outerContainer.outerHeight(); var oldHeight = this.$outerContainer.outerHeight();
var newWidth = imageWidth + this.containerPadding.left + this.containerPadding.right + this.imageBorderWidth.left + this.imageBorderWidth.right; //ADDED-START
var newHeight = imageHeight + this.containerPadding.top + this.containerPadding.bottom + this.imageBorderWidth.top + this.imageBorderWidth.bottom; //var newWidth = imageWidth + this.containerPadding.left + this.containerPadding.right + this.imageBorderWidth.left + this.imageBorderWidth.right;
//var newHeight = imageHeight + this.containerPadding.top + this.containerPadding.bottom + this.imageBorderWidth.top + this.imageBorderWidth.bottom;
var mediaBorderWidth = (media=='image')?(this.imageBorderWidth.left + this.imageBorderWidth.right):(this.videoBorderWidth.left + this.videoBorderWidth.right);
var mediaBorderHeight = (media=='image')?(this.imageBorderWidth.top + this.imageBorderWidth.bottom):(this.videoBorderWidth.top + this.videoBorderWidth.bottom);
var newWidth = imageWidth + this.containerPadding.left + this.containerPadding.right + mediaBorderWidth;
var newHeight = imageHeight + this.containerPadding.top + this.containerPadding.bottom + mediaBorderHeight;
//ADDED-END
function postResize() { function postResize() {
self.$lightbox.find('.lb-dataContainer').width(newWidth); self.$lightbox.find('.lb-dataContainer').width(newWidth);
self.$lightbox.find('.lb-prevLink').height(newHeight); self.$lightbox.find('.lb-prevLink').height(newHeight);
@@ -386,8 +442,13 @@
// Display the image and its details and begin preload neighboring images. // Display the image and its details and begin preload neighboring images.
Lightbox.prototype.showImage = function() { Lightbox.prototype.showImage = function() {
this.$lightbox.find('.lb-loader').stop(true).hide(); this.$lightbox.find('.lb-loader').stop(true).hide();
this.$lightbox.find('.lb-image').fadeIn(this.options.imageFadeDuration);
//ADDED-START
//this.$lightbox.find('.lb-image').fadeIn(this.options.imageFadeDuration);
if(this.options.hasVideo && this.album[this.currentImageIndex].video) this.$lightbox.find('.lb-video').fadeIn(this.options.imageFadeDuration);
else this.$lightbox.find('.lb-image').fadeIn(this.options.imageFadeDuration);
//ADDED-END
this.updateNav(); this.updateNav();
this.updateDetails(); this.updateDetails();
this.preloadNeighboringImages(); this.preloadNeighboringImages();
@@ -433,7 +494,7 @@
// Display caption, image number, and closing button. // Display caption, image number, and closing button.
Lightbox.prototype.updateDetails = function() { Lightbox.prototype.updateDetails = function() {
var self = this; var self = this;
// Enable anchor clicks in the injected caption html. // Enable anchor clicks in the injected caption html.
// Thanks Nate Wright for the fix. @https://github.com/NateWr // Thanks Nate Wright for the fix. @https://github.com/NateWr
if (typeof this.album[this.currentImageIndex].title !== 'undefined' && if (typeof this.album[this.currentImageIndex].title !== 'undefined' &&
@@ -515,6 +576,18 @@
// Closing time. :-( // Closing time. :-(
Lightbox.prototype.end = function() { Lightbox.prototype.end = function() {
this.disableKeyboardNav(); this.disableKeyboardNav();
//ADDED-START
if(this.options.hasVideo) {
var $video = this.$lightbox.find('.lb-video');
var $lbContainer = this.$lightbox.find('.lb-container');
var $hasVideoNav = $lbContainer.hasClass('lb-video-nav');
$video.attr('src', '');
if($hasVideoNav) $lbContainer.removeClass('lb-video-nav');
}
//ADDED-END
$(window).off('resize', this.sizeOverlay); $(window).off('resize', this.sizeOverlay);
this.$lightbox.fadeOut(this.options.fadeDuration); this.$lightbox.fadeOut(this.options.fadeDuration);
this.$overlay.fadeOut(this.options.fadeDuration); this.$overlay.fadeOut(this.options.fadeDuration);

View File

@@ -7,40 +7,42 @@
@extend .#{$fa-css-prefix}-#{$icon}; @extend .#{$fa-css-prefix}-#{$icon};
} }
.lb-cancel { .lightbox {
@include lightbox-icon(cancel); .lb-cancel {
@extend .flicker; @include lightbox-icon(cancel);
color: #CCC; @extend .flicker;
} color: #CCC;
}
.lb-nav a.lb-prev, .lb-nav a.lb-next {
color: white;
text-decoration: none;
&:before { .lb-nav a.lb-prev, .lb-nav a.lb-next {
position: absolute; color: white;
top: calc(50% - 1em); text-decoration: none;
&:before {
position: absolute;
top: calc(50% - 1em);
}
}
.lb-nav a.lb-prev {
@include lightbox-icon(prev);
&:before {
left: 2em;
}
} }
}
.lb-nav a.lb-prev { .lb-nav a.lb-next {
@include lightbox-icon(prev); @include lightbox-icon(next);
&:before { &:before {
left: 2em; right: 2em;
}
} }
}
.lb-data .lb-close {
.lb-nav a.lb-next { @include lightbox-icon(close);
@include lightbox-icon(next); }
&:before {
right: 2em; .lb-image {
image-orientation: from-image;
} }
}
.lb-data .lb-close {
@include lightbox-icon(close);
}
.lb-image {
image-orientation: from-image;
} }

View File

@@ -38,6 +38,16 @@ html.lb-disable-scrolling {
border: 4px solid white; border: 4px solid white;
} }
//ADDED-START
.lightbox .lb-video {
border-radius: 4px;
box-sizing: content-box;
}
.lightbox .lb-video-nav .lb-nav {
height: calc(100% - 45px);
}
//ADDED-END
.lightbox a img { .lightbox a img {
border: none; border: none;
} }

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long