(function($){ $.fn.jdiaporama = function(options) { var defaults = { auto: true, delay: 3, animationspeed: "normal", controls: true, keyboard: true, infos: true, currentimage: true, paused: false, boucles: 0, sens: "right", onrollover: true }; var options = $.extend(defaults, options); this.each(function(){ // si le diaporama comporte plus qu'une image if($("li", diapo).length > 1){ var diapo = $(this); var mouseover = false; var sens = options.sens; var pause = false; var width = 0; var height = 0; var current_slide = 0; diapo.wrap("
"); // detection et actions des mouseover diapo.parent().mouseenter(function(){ mouseover = true; if(options.onrollover) displayinfos($("li.active", diapo), "show"); if(options.controls) diapo.siblings(".jdiaporama_controls").fadein(); }).mouseleave(function(){ mouseover = false; if(options.onrollover) displayinfos($("li.active", diapo), "hide"); if(options.controls) diapo.siblings(".jdiaporama_controls").hide(); }); function init() { // ajustement de la taille du container width = $("li:first-child img", diapo).width(); height = $("li:first-child img", diapo).height(); diapo.width(width); diapo.height(height); diapo.parent().width(width); diapo.parent().height(height); if(options.controls) diapo.siblings(".jdiaporama_status").show(); if(options.auto && options.paused) $(".pause", diapo.siblings()).trigger("click"); if(!options.onrollover) displayinfos($("li", diapo), "show"); $("#jdiaporama_bullet_"+(parseint($("li", diapo).index($("li:first-child", diapo)))+1), diapo.siblings()).addclass("active"); } var inter = ""; if(options.auto && !options.paused) inter = setinterval(function(){displaydiaporama(options)}, (options.delay*1000)); $("li", diapo).hide(); $("li:first-child", diapo).addclass("active").fadein(options.animationspeed, init); // pour chaque �l�ment $("li", diapo).each(function(){ elt = $(this); i = parseint($("li", diapo).index($(this))+1); $(this).attr("id", "jdiaporama_image_"+i); // affichage de la description si renseign� et activ� if(options.infos) { var is_desc = ($("img", elt).attr("title") != ""); var is_title = ($("img", elt).attr("alt") != ""); if(is_desc) elt.append("

"+$("img", elt).attr("title")+"

"); if(is_title) elt.append("

"+$("img", elt).attr("alt")+"

"); if(options.currentimage) elt.append("

"+parseint($("li", diapo).index(elt)+1)+"/"+diapo.children().length+"

"); } }) // navigation au clavier if(options.keyboard) $(document).keydown(function(event) { switch(event.keycode){ case 37 : // fl�che gauche prev(); break; case 39 : // fl�che droite next(); break; } }); // controls if(options.controls) { // etat du diaporama diapo.after("
"); $("li", diapo).each(function(){ i = parseint($("li", diapo).index($(this))+1); $(".jdiaporama_status", diapo.parent()).append("image "+i+""); }) $(".jdiaporama_status", diapo.parent()).css("margin-left", -($(".jdiaporama_status", diapo.parent()).width()/2)); $(".jdiaporama_status a", diapo.parent()).click(function(){ nextimage(options, $(this)); return false; }) diapo.after("
" + ((options.auto)?"pause":"") + "
"); $(".prev", diapo.siblings()).click(function(){ prev(); return false; }); $(".next", diapo.siblings()).click(function(){ next(); return false; }); $(".pause", diapo.siblings()).click(function(){ if($(this).hasclass("pause")) { $(this).removeclass("pause").addclass("play"); clearinterval(inter); pause = true; } else { $(this).removeclass("play").addclass("pause"); inter = setinterval(function(){displaydiaporama(options)}, (options.delay*1000)); pause = false; } return false; }); } function next() { if(!$("li.active", diapo).is(":last-child")) elt = $("li.active", diapo).next(); else elt = $("li:first-child", diapo); nextimage(options, elt); sens = "right"; } function prev() { if(!$("li.active", diapo).is(":first-child")) elt = $("li.active", diapo).prev(); else elt = $("li:last-child", diapo); nextimage(options, elt); sens = "left"; } // affichage des infos sur l'image courante function displayinfos(elt, display) { var is_desc = ($("img", elt).attr("title") != ""); var is_title = ($("img", elt).attr("alt") != ""); if(is_desc) if(display == "show") $(".desc", elt).slidedown("fast"); else $(".desc", elt).slideup("fast"); if(is_title) if(display == "show") $(".title", elt).slidedown("fast"); else $(".title", elt).slideup("fast"); if(options.currentimage) if(display == "show") $(".count", elt).slidedown("fast"); else $(".count", elt).slideup("fast"); } // affiche l'�l�ment suivant function nextimage(options, elt) { clearinterval(inter); $("li.active", diapo).fadeout(options.animationspeed).removeclass("active"); $(".jdiaporama_status a", diapo.parent()).removeclass("active"); id = elt.attr("id").split("_")[2]; $("li#jdiaporama_image_"+id, diapo).addclass("active").fadein(options.animationspeed); $("#jdiaporama_bullet_"+id, diapo.siblings()).addclass("active"); if(options.infos && mouseover && options.onrollover) displayinfos($("li.active", diapo), "show"); else if(!mouseover && options.onrollover) displayinfos($("li.active", diapo), "hide"); if(!pause && options.auto) { if(options.boucles == 0 || (options.boucles > 0 && (diapo.data("current_slide")/diapo.children().length) < options.boucles )) inter = setinterval(function(){displaydiaporama(options)}, (options.delay*1000)); else $(".pause", diapo.siblings()).remove(); } } function displaydiaporama(options) { current_slide++; diapo.data("current_slide", current_slide); if(sens == "right") next(); else prev(); } } }); return this; }; })(jquery);