commit f57605278d891122eb538c8ec0a6ca32c570ad40
Author: Olivier Legat <olivier.legat@ldc.fr>
Date: Wed Feb 10 08:45:45 2021 +0100
selection des medias dans le panier
Download de médias
Tous formats system=1
commit 567476c5467361bb7ab3958804d49ed4229c6526
Author: Olivier Legat <olivier.legat@ldc.fr>
Date: Mon Feb 8 17:24:47 2021 +0100
Accès à la page panier depuis le menu du composant
127 lines
4.4 KiB
JavaScript
Vendored
127 lines
4.4 KiB
JavaScript
Vendored
$(document).ready(function() {
|
|
/****************************************
|
|
Page publique des paniers
|
|
*****************************************/
|
|
if ( $( ".public_basket" ).length ) {
|
|
|
|
|
|
// ---- Aperçu des médias du panier
|
|
$(".public_basket ").on("dblclick", '.imageItem' , function(event) {
|
|
var imgPreview = $(this).attr('data-preview')+'?t='+ new Date().getTime();
|
|
|
|
if($(this).attr('data-typemedia') == 1|| $(this).attr('data-typemedia') == 2 || $(this).attr('data-typemedia') == 5){ // image
|
|
$.fancybox.open('<img style="width: 640px; height:auto;" src="'+imgPreview+'" alt="" />');
|
|
}else if ($(this).attr('data-typemedia') == 3) { // vidéo
|
|
$.fancybox.open('<video src="'+$(this).attr('data-src')+'" controls></video>');
|
|
}else if ($(this).attr('data-typemedia') == 4) { // Audio
|
|
$.fancybox.open('<audio controls src="'+$(this).attr('data-src')+'"></audio>');
|
|
}
|
|
});
|
|
|
|
// ---- selection de medias pour download
|
|
$(".public_basket ").on("click", '.imageItem' , function(event) {
|
|
//toggle selection
|
|
$(this).attr('aria-grabbed',!JSON.parse($(this).attr('aria-grabbed')));
|
|
});
|
|
|
|
// ---- Propriétés d'un panier
|
|
$('.public_basket .btn_basket_Info').on('click',function(event){
|
|
event.preventDefault();
|
|
$.fancybox.open({
|
|
src : '#form_basket_property',
|
|
type : 'inline',
|
|
opts : {
|
|
animationDuration : 350,
|
|
animationEffect : 'material',
|
|
}
|
|
});
|
|
});
|
|
|
|
// ---- Popup pour télécharger des médias en masse
|
|
$('.public_basket .btn_basket_download').on('click',function(event){
|
|
event.preventDefault();
|
|
var medias = [];
|
|
$('.media_container .imageItem').each(function (index) {
|
|
if( $(this ).attr("aria-grabbed") == "true" ){
|
|
medias.push($(this ).attr("data-id"));
|
|
}
|
|
});
|
|
|
|
if(medias.length == 0){
|
|
$.fancyMessage({title : "Télécharger des médias", message : "Veuillez sélectionner au moins un média.", type : "info"});
|
|
}else{
|
|
$("#form_download").fancybox({
|
|
type : 'inline',
|
|
opts : {
|
|
animationDuration : 350,
|
|
animationEffect : 'material',
|
|
},
|
|
beforeShow : function() {
|
|
$("#form_download .medias").val(medias.join());
|
|
}
|
|
}).trigger("click");
|
|
}
|
|
});
|
|
|
|
$("#form_download button[type=submit]").on('click',function(event){
|
|
$(this).parent().submit();
|
|
});
|
|
|
|
//téléchargement
|
|
$("#form_download").submit(function(event){
|
|
event.preventDefault();
|
|
$.ajax({
|
|
url: '/ajax/download-media',
|
|
method: 'POST',
|
|
//dataType : 'json',
|
|
data: {
|
|
format: $('select[name=format] option:selected').val(),
|
|
medias: $('input[name=medias]').val()
|
|
},
|
|
xhrFields: {
|
|
responseType: 'blob' // to avoid binary data being mangled on charset conversion
|
|
},
|
|
success: function(blob, status, xhr){
|
|
// check for a filename
|
|
var filename = "";
|
|
var disposition = xhr.getResponseHeader('Content-Disposition');
|
|
if (disposition && disposition.indexOf('attachment') !== -1) {
|
|
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
|
var matches = filenameRegex.exec(disposition);
|
|
if (matches != null && matches[1]) filename = matches[1].replace(/['"]/g, '');
|
|
}
|
|
|
|
if (typeof window.navigator.msSaveBlob !== 'undefined') {
|
|
// IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
|
|
window.navigator.msSaveBlob(blob, filename);
|
|
} else {
|
|
var URL = window.URL || window.webkitURL;
|
|
var downloadUrl = URL.createObjectURL(blob);
|
|
|
|
if (filename) {
|
|
// use HTML5 a[download] attribute to specify filename
|
|
var a = document.createElement("a");
|
|
// safari doesn't support this yet
|
|
if (typeof a.download === 'undefined') {
|
|
window.location.href = downloadUrl;
|
|
} else {
|
|
a.href = downloadUrl;
|
|
a.download = filename;
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
}
|
|
} else {
|
|
window.location.href = downloadUrl;
|
|
}
|
|
|
|
setTimeout(function () { URL.revokeObjectURL(downloadUrl); }, 100); // cleanup
|
|
}
|
|
},
|
|
error: function(jqXHR, textStatus, errorThrown) {
|
|
$.fancybox.close();
|
|
$.fancyMessage({title : "Attention", message : "Erreur ! ", type : "error"});
|
|
}
|
|
});
|
|
});
|
|
}
|
|
});
|