/**
* Slideshow (for jQuery)
* version: 2.1 (27/12/2010)
* @requires jQuery v1.4.0 or later
* @copyright 2010 Cécile Aubin
*/
if(parseFloat($().jquery) < 1.4){
alert("Librairie JQuery incompatible avec le slideshow.\nMerci d'utiliser Jquery >= 1.4.0");
}
var $slideshow = null;
$.slideshow = function(settings) {
new Slideshow(settings);
}
$.fn.slideshow = function(settings) {
settings = (typeof settings == 'undefined' ? {} : settings);
settings.id = this.attr('id');
new Slideshow(settings);
}
Slideshow = function(settings){
this.__construct(settings);
};
Slideshow.defaultSettings = {
id : 'slideshow_trans', // @public Id de la div à charger
index: '', // @public Id du slideshow (permet pour les éditos d'enregistrer les stats d'affichage)
skin : false, // @public Skin graphique
size : 700, // @public Largeur du diaporama 700 / 1000 / etc
first : 0, // @public Position du slideshow
display: 1, // @public Nombre d'image affiché dans le viewport
nb_img_load: 3, // @public Nombre d'image chargés (suivantes et précedentes) à celle en cours
animate_duration: 700, // @public Durée (en millisecondes) de l'animation des photos
has_thumbnails: 'ss_thumbnails', // @public Affichage un slideshow composée de miniature
parent: false, // @Private
legend: false, // @public Affichage de la légende de la photo
parse_legend: false, // @public Affichage de la légende parsée de la photo (utilisé en embed)
page_last: false, // @public Passerelle vers la dernière page
page_first: false, // @public Passerelle vers la première page
pagination_thumbs: false, // @public Pagination des miniatures par href
edito : false, // @public Mode edito du diaporama transverse
auto_load : false, // @public Si false, force un diaporama edito aux rechargement des pages
urlPage : false, // @public Remplit le href des liens suivants/precedents/premier et dernier (pour click droit)
autoslide : 3E3, // @public Temps de changement (en millisecondes) d'image pour la lecture du diaporama
nb_thumbs : -1 // @public Nombre de miniatures affichées dans le slide miniature
};
Slideshow.prototype = {
/**
* Instanciation et apparition de la facebox
*/
__construct : function(settings){
var othis = this;
if(typeof slideshowSettings != 'undefined'){
Slideshow.defaultSettings = $.extend({}, Slideshow.defaultSettings, slideshowSettings);
}
if(settings){
this.settings = $.extend({
context : $('body')
}, Slideshow.defaultSettings, settings);
}
// Forcer certains paramètres si miniatures
if (this.settings.parent){
this.settings.has_thumbnails = false;
this.settings.legend = false;
// desactivation pour les miniatures et le viewport
this.settings.page_first = false;
this.settings.page_last = false;
}
// DESACTIVATION PERMANTENTE DE FIRST ET LAST
this.settings.page_first = false;
this.settings.page_last = false;
// On enregistre les stats d'affichage pour les "Editos"
if (this.settings.edito){
$.ajax({
url: "/api/slideshow/ajax/count.php?id="+this.settings.index+"&type=diaporama",
cache: false
});
}
// Buttons
var dom_pagination_parent = "";
if (!this.settings.parent){
var dom_pagination_parent = " .ss_viewport ";
}
this.bnext = $('#'+this.settings.id+' > '+dom_pagination_parent+'.ss_pagination .ss_next');
this.bprev = $('#'+this.settings.id+' > '+dom_pagination_parent+'.ss_pagination .ss_prev');
this.bfirst = $('#'+this.settings.id+' > '+dom_pagination_parent+'.ss_pagination .ss_first');
this.blast = $('#'+this.settings.id+' > '+dom_pagination_parent+'.ss_pagination .ss_last');
// Listing des élements
this.first = $('#'+this.settings.id+' > .ss_viewport li:first');
this.last = $('#'+this.settings.id+' > .ss_viewport li:last-child');
this.viewport = $('#'+this.settings.id+' > .ss_viewport');
this.list = $('#'+this.settings.id+' > .ss_viewport .ss_main');
if (this.settings.parse_legend){
this.allparselegend = $('#'+this.settings.id+' > .ss_allparselegend');
}
// Informations
this.title = $('#'+this.settings.id+' > .ss_info_photo .ss_title');
this.credit = $('#'+this.settings.id+' > .ss_info_photo .ss_credit');
this.legend = $('#'+this.settings.id+' > .ss_info_photo .ss_legend');
this.pcurrent = $('#'+this.settings.id+' > .ss_informations .ss_pcurrent');
this.timeout = false;
this.thumbnails = false;
this.firstload = true;
// Template et skin
if (this.settings.auto_load || !this.settings.edito){ // Alleger les editos sans autoload, en supprimant certaines actions deja fait dans le dom
// Initialiser les dimensions
this.setDimensions();
this.list.css({'width':$('#'+this.settings.id+' .ss_main li').length * this.viewport_width});
// Ajout des skins (celle par défaut et celle appelée)
$('#'+this.settings.id).addClass('ss_default_slideshow');
$('#'+this.settings.id).addClass('ss_width_'+this.settings.size);
if (this.settings.skin) $('#'+this.settings.id).addClass('ss_'+this.settings.skin);
if (this.settings.legend) $('
',{'class': 'ss_legend'}).insertAfter('#'+this.settings.id+' div.ss_title');
this.setButtons();
if (!this.settings.parent ){ // Si diaporama principal
this.goPosition(this.settings.first);
}else{ // Si thumbnails
this.goPagePosition(this.settings.first);
}
// Actions du clavier
$(document).keydown( function(e) {
if( (e.which == 37 || e.which == 39 )&& e.target.nodeName != 'TEXTAREA'){
e.stopImmediatePropagation();
e.preventDefault();
if(e.which == 37){othis.goPrev(1); }
if(e.which == 39){othis.goNext(1); }
}
});
}
// Création d'un Thumbnails
if (this.settings.has_thumbnails){
// Si pas passé en paramètre le nombre est prédéfini
// (garantie la compatibilité avec les diaporamas hors module)
if(this.settings.nb_thumbs < 0){
if (this.settings.size == 'mobile') {var nb_thumbs = 4;}
if (this.settings.size == 300) {var nb_thumbs = 4;}
if (this.settings.size == 700) {var nb_thumbs = 5;}
if (this.settings.size == 1000) {var nb_thumbs = 7;}
}else{
var nb_thumbs = this.settings.nb_thumbs;
}
/* Slideshow Miniatures */
this.thumbnails = new Slideshow({
id : 'ss_thumbnails'+this.settings.index,
index: this.settings.index,
has_thumbnails: false,
size: this.settings.size,
first: this.settings.first,
display: nb_thumbs,
nb_img_load: parseInt(nb_thumbs*2),
animate_duration: 1000,
parent: this
});
}
},
// Lecture automatique
play: function (){
var othis = this;
// Désactiver les boutons le temps de l'animation
this.desactiveButtons();
if (!this.timeout) { othis.goNext(1); }
this.timeout = setTimeout(function() {
if (!othis.Element.next().length ) {
othis.goFirst();
}else{
othis.goNext(1);
}
}, this.settings.autoslide);
},
// Arreter la lecture automatique
stop: function (){ clearTimeout(this.timeout); this.timeout = null; this.activeButtons();},
focusVignette : function() { this.Element.find('img').addClass('focus');},
clearFocus : function() { this.list.children().each(function(index) { $(this).find('img').removeClass('focus');}); },
getCurrentPositionX : function () { var i = this.getCurrentIndex(); if (i == 0) return 0; else return (i * this.image_width); },// Retourne la position en cours (en pixels)
getCurrentIndex : function(){ return parseInt(this.Element.attr('nav'));},
getViewportPosition : function (){ return -parseInt(this.list.css('left'));}, // Valeur absolue
goFirst : function(e) {
this.clearFocus(); this.Element = this.first; this.positionVignette(e); this.focusVignette();
if (this.settings.has_thumbnails && this.thumbnails){ this.thumbnails.goFirst(e); }// Répercuter sur le thumbnails
},
goLast : function(e) {
this.clearFocus(); this.Element = this.last; this.focusVignette(); this.positionVignette(e);
if (this.settings.has_thumbnails){ this.thumbnails.goLast(e); }// Répercuter sur le thumbnails
},
goPosition :function (i){this.clearFocus(); this.changeElement('position',parseInt(i)); this.focusVignette(); this.positionVignette();},
goPositionWF :function (i){ this.changeElement('position',parseInt(i)); this.positionVignette();},
// Le slideshow recule suivant un nombre d'elements demandées, et réalise une animation
goNext : function(nb, e) {
// On modifie l'Element en cours
var ret = this.changeElement('next',nb);
// Si changement ok
if(ret){
this.clearFocus(); this.positionVignette(e); this.focusVignette();
// Répercuter next sur le slideshow des thumbnails
if (this.settings.has_thumbnails && this.thumbnails){ this.thumbnails.goPagePosition(this.getCurrentIndex()); }
if (this.timeout){ this.play();}
}else if (this.settings.auto_load ){ // Si diaporama edito auto load, et qu'il ne trouve pas le suivant on envoie sur la page de listing
$(location).attr('href','/diaporama/');
}
},
// Le slideshow recule suivant un nombre d'elements demandées, et réalise une animation
goPrev : function(nb, e) {
// On modifie l'Element en cours
var ret = this.changeElement('prev',nb);
if (ret){
this.clearFocus(); this.positionVignette(e); this.focusVignette();
// Répercuter sur le slideshow des thumbnails
if (this.settings.has_thumbnails && this.thumbnails){this.thumbnails.goPagePosition(this.getCurrentIndex());}
}
},
// Aller sur la page précedente (spécifique au thumbnails)
goPagePrev : function (){
// goPagePrev // On avance le viewport de plus X suivant la position actuelle du viewport
if ( this.settings.parent){
var page = Math.floor(this.getCurrentIndex() / this.settings.display)-1;
// Position du viewport
this.goPositionWF(parseInt(page*this.settings.display));
}
},
goPagePosition : function (index){
if ( this.settings.parent){
var page = Math.floor(index / this.settings.display);
// Position du viewport
this.goPosition(parseInt(page*this.settings.display));
// Position sur le dernier l'element du viewport
this.clearFocus();
this.changeElement('position',index);
this.focusVignette();
}
},
// Aller sur la page suivante (spécifique au thumbnails)
goPageNext : function (){
if ( this.settings.parent){
var page = Math.floor(this.getCurrentIndex() / this.settings.display)+1;
this.goPositionWF(parseInt(page*this.settings.display));
}
},
// On modifie l'element en cours, (peut etre appelé en direct, ou depuis la fonction goPrev/goNext si on doit positionner le slideshow sur l'element
changeElement: function (action,nb){
var ret = false;
if (action == 'position'){
ret = true;
}else if(this.Element.next().length && action == 'next'){
ret = true;
}else if (this.Element.prev().length && action == 'prev'){
ret = true;
}
if (ret){
if (nb == 1){// Si on demande la voisine
if (action == 'next') {this.Element = this.Element.next(); }
else if (action == 'prev'){this.Element = this.Element.prev(); }
else if (action == 'position'){this.Element = $('#'+this.settings.id+' > .ss_viewport li:eq('+nb+')');}
// Sinon
}else{
if (action == 'next') {
var l = this.Element.nextAll();
if (l.size() > nb){
var i = parseInt(this.Element.attr('nav'));
this.Element = $('#'+this.settings.id+' > .ss_viewport li:eq('+parseInt(i+nb)+')');// +5
}
}else if (action == 'prev'){
var l = this.Element.prevAll();
if (l.size() >= 1){
var i = parseInt(this.Element.attr('nav'));
var index = parseInt(i-nb);
if (index < 0) index = 0;
this.Element = $('#'+this.settings.id+' > .ss_viewport li:eq('+index+')');// +5
}
}else if (action == 'position'){
this.Element = $('#'+this.settings.id+' > .ss_viewport li:eq('+nb+')');
}
}
}
return ret;
},
/**
* Positionne le slideshow sur la vignette en cours
*/
positionVignette : function(e) {
var othis = this;
// Chargement des images
this.loadImage(this.Element);
this.loadPrevImages(); this.loadNextImages();
// Désactiver les boutons le temps de l'animation si on est pas en mode lecture &
// && Réactiver en callback animate( properties, [ duration ], [ easing ], [ callback ] )
if (!this.timeout) { this.desactiveButtons(); }
// Positionnement de la photo
this.list.animate({ left: '-'+this.getCurrentPositionX()}, this.settings.animate_duration , '', function (){ if (!othis.timeout) { othis.activeButtons();} });
// Zoom
this.Element.hover(
function(){ $(this).find('a.zoom').css('display','block');},
function(){$(this).find('a.zoom').css('display','none');}
);
// Mise à jour des informations: Titre / Crédit / Légende / Page en cours
// Si ce n'est pas une miniature d'un edito sans recharchegement auto
if(!this.settings.parent && (!this.settings.edito || this.settings.auto_load)){
this.title.html(this.Element.find('h2.ssp_titre').html());
this.credit.html('Crédit : '+(this.Element.find('span.ssp_credit').html()!=''?this.Element.find('span.ssp_credit').html():'DR'));
this.pcurrent.html(parseInt(this.Element.attr('nav'))+1);
// Si le slideshow possède des légendes
if (this.settings.legend){
// Si le slideshow possède des légendes parsées
if (this.settings.parse_legend){
var legend = this.allparselegend.find('.ss_pl'+this.Element.attr('nav')).html();
if ((typeof legend != undefined) && legend !== null){
legend = Utils.htmlspecialchars_decode(legend);
this.legend.html(legend);
}
}else{ // Autrement des légendes normales
this.legend.html(this.Element.find('span.ssp_legend').html());
}
}
if (this.settings.size != 'mobile' && this.settings.auto_load && this.settings.edito && !this.firstload){
// ne pas rafraichir la pub au premier chargement
if(typeof refreshAds == 'function') {
refreshAds();
}
if(typeof refreshTags == 'function') {
refreshTags();
}
// On enregistre les stats d'affichage pour les "Editos"
$.ajax({
url: "/api/slideshow/ajax/count.php?id="+this.settings.index+"&type=diaporama",
cache: false
});
}else{
this.firstload = false;
}
}
this.toggleButtons();
},
/**
* Charge une image dans le DOM
*/
loadImage : function(elt) {
var othis = this;
var lia = elt.find('a.ss_aimg');
if (!lia.has('img').length || elt.hasClass('load')){
if (!lia.has('img').length){
lia.html($('
![]()
',{'src': lia.attr('rel'), 'class':'ss_img', alt:lia.attr('title'), title:lia.attr('title')}));
}
elt.removeClass('load');
if (!this.settings.parent){
if (!this.settings.urlPage && this.settings.size == 300){
lia.click(function(e){othis.goNext(1); e.preventDefault(); });
}
}else{
// Si slideshow miniatues, on envoie sur la grande image
var parent = othis.settings.parent;
if (parent.settings.auto_load || !parent.settings.edito){
lia.click(function(e){othis.clearFocus(); othis.changeElement('position',elt.attr('nav')); othis.focusVignette(); parent.goPosition(elt.attr('nav')); e.preventDefault(); });
}
// Si non c'est le lien href existant qui est pris en compte
}
}
},
/**
* Chargement des images précedentes si besoin
*/
loadPrevImages: function(){
var i = 0;
var cprev = this.Element.prev();
while(cprev.length && i < this.settings.nb_img_load){
this.loadImage(cprev);
cprev = cprev.prev();
i++;
}
},
/**
* Chargement des images suivantes si besoin
*/
loadNextImages: function(){
var i = 0;
var cnext = this.Element.next();
while(cnext.length && i < this.settings.nb_img_load){
this.loadImage(cnext); cnext = cnext.next(); i++;
}
},
/**
* Réactive les boutons après une animation
*/
activeButtons : function (){
this.actionButtonPrev(); this.actionButtonNext(); this.actionButtonFirst(); this.actionButtonLast();
},
/**
* Désactive les boutons pendant une animation
*/
desactiveButtons : function (){
this.bprev.unbind('click'); this.bnext.unbind('click');
if (this.settings.page_first){ this.bfirst.unbind('click'); }
if (this.settings.page_last){ this.blast.unbind('click'); }
},
/**
* Action sur le bouton first
*/
actionButtonFirst : function (){
if (this.settings.page_first){
if (!this.settings.parent){ // Si slideshow principal
if (this.settings.urlPage){ // Si il existe un url -- on permet sur click normal onclick, et sur click droit d'ouvrir une page
// On remplit l'url avec l'url existante dans les miniatures
this.bfirst.attr('href',this.settings.page_first);
}
var othis = this;
this.bfirst.click(function(e){ othis.goFirst(e); e.preventDefault();});
}
}
},
/**
* Action sur le bouton first
*/
actionButtonLast : function (){
if (this.settings.page_last){
if (!this.settings.parent){ // Si slideshow principal
if (this.settings.urlPage){ // Si il existe un url -- on permet sur click normal onclick, et sur click droit d'ouvrir une page
// On remplit l'url avec l'url existante dans les miniatures
this.blast.attr('href',this.settings.page_last);
}
var othis = this;
this.blast.click(function(e){ othis.goLast(e); e.preventDefault();});
}
}
},
/**
* Action sur le bouton précedent
*/
actionButtonPrev : function (){
var othis = this;
if (!this.settings.parent){ // Si slideshow principal
if (this.settings.urlPage){ // Si il existe un url -- on permet sur click normal onclick, et sur click droit d'ouvrir une page
if (this.thumbnails.Element){
// On remplit l'url avec l'url existante dans les miniatures
this.bprev.attr('href',this.thumbnails.Element.prev().find('.ss_aimg').attr('href'));
}
}
this.bprev.click(function(e){ e.stopImmediatePropagation(); othis.goPrev(1); e.preventDefault(); });
}else{ // Si thumbnails
this.bprev.click(function(e){ othis.goPagePrev();});
}
},
/**
* Action sur le bouton suivant
*/
actionButtonNext : function (){
var othis = this;
if (!this.settings.parent){ // Si slideshow principale
if (this.Element.next().length){ // S'il existe une image suivante
if (this.settings.urlPage){ // S'il existe une url -- on permet sur click normal onclick, et sur click droit d'ouvrir une page
if (this.thumbnails.Element){
// On remplit l'url avec l'url existante dans les miniatures
this.bnext.attr('href',this.thumbnails.Element.next().find('.ss_aimg').attr('href'));
}
}
this.bnext.click(function(e){ e.stopImmediatePropagation(); othis.goNext(1); e.preventDefault(); });
}else if (this.settings.edito && this.settings.auto_load && this.settings.redirect_to_list ){ // si pas d'image suivante mais diaporama edito en auto load, on ajoute une url spécial
this.bnext.attr('href',this.settings.redirect_to_list);
}
}else{ // Si thumbnails
this.bnext.click(function(e){ othis.goPageNext();});
}
},
/**
* Initialise les boutons
*/
setButtons: function () {
// Bouton play/stop
var othis = this;
$('#'+this.settings.id+' #ss_auto'+this.settings.index).click(function(obj,e){
if ($('#'+this.id).hasClass('ss_read')){
othis.play();
$('#'+this.id).addClass('ss_stop');
$('#'+this.id).removeClass('ss_read');
$('#'+this.id).html('Arrêter le diaporama');
}else{
othis.stop();
$('#'+this.id).addClass('ss_read');
$('#'+this.id).removeClass('ss_stop');
$('#'+this.id).html('Lancer le diaporama');
}
});
// Supprimer les buttons s'ils existent sans etre appelés
if (!this.settings.page_first){ $('#'+this.settings.id+' > .ss_pagination a').remove('.ss_first') };
if (!this.settings.page_last){ $('#'+this.settings.id+' > .ss_pagination a').remove('.ss_last') };
},
/**
* Affiche ou Cache les boutons
*/
toggleButtons : function() {
var prev = false;
// Recherche du précedent
if (this.settings.display == 1){
prev = this.Element.prev();
}else{
var l = this.Element.prevAll();
if (l.size() >= 1){
var i = parseInt(this.Element.attr('nav'));
var index = parseInt(i-this.settings.display);
if (index < 0) index = 0;
prev = $('#'+this.settings.id+' > .ss_viewport li:eq('+index+')');// -X
}
}
// Affichage ou non du bouton précédent
if (!prev.length){
this.bprev.hide();
if (this.settings.page_first) { this.bfirst.hide(); }
}else{
this.bprev.show();
if (this.settings.page_first) { this.bfirst.show(); }
}
var next = false;
// Recherche du suivant
if (this.settings.display == 1){
next = this.Element.next();
}else{
var l = this.Element.nextAll();
if (l.size() > this.settings.display-1){
var i = parseInt(this.Element.attr('nav'));
next = $('#'+this.settings.id+' > .ss_viewport li:eq('+parseInt(i+this.settings.display)+')');// +X
}
}
// Affichage ou non du bouton suivant
if (!next.length){
// Si le diaporama n'est pas en edito auto load ou s'il n'a pas de lien de redirection vers un listing, on cache
if (!this.settings.auto_load || !this.settings.redirect_to_list) {this.bnext.hide(); }
if (this.settings.page_last) { this.blast.hide(); }
} else{
this.bnext.show();
if (this.settings.page_last) { this.blast.show(); }
}
},
/**
* Paramétrage les dimensions : Calcul de la taille du viewport et des images
*/
setDimensions : function(){
// Si Slideshow classique
if (!this.settings.parent){
this.viewport_width = parseInt(this.viewport.css('width'));
this.image_width = parseInt(this.viewport_width / this.settings.display);
// Child Slideshow "imbriqué miniatures"
}else{
// Paramètres des miniatures - Slideshow avec des propriétés spécifiques
this.viewport_width = parseInt(this.viewport.css('width'));
var li =$('#'+this.settings.id+' .ss_main li');
this.image_width = parseInt(li.css('width'))+parseInt(li.css('padding-left'))+parseInt(li.css('padding-right'));
}
}
};