1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
<script>
// configuration :
// Définir le mode d'affichage des images par défaut
$defaultViewMode = "normal"; // full, normal, original
$tsMargin = 30; // première et dernière marge de vignette (pour une meilleure interaction du curseur)
$scrollEasing = 600; // assouplissement du défilement (0 pour aucune atténuation)
$scrollEasingType = "easeOutCirc"; // type d'accélération de défilement
$thumbnailsContainerOpacity = 0.8; // opacité par défaut de la zone des vignettes
$thumbnailsContainerMouseOutOpacity = 0; // opacité de la zone des vignettes à la souris
$thumbnailsOpacity = 0.6; // vignettes opacité par défaut
$nextPrevBtnsInitState = "show"; // Etat initial des boutons image suivant/précédent ("masquer" ou "afficher")
$keyboardNavigation = "on"; // activer/désactiver la navigation au clavier ("on" ou "off")
// cache vars
$thumbnails_wrapper = $("#thumbnails_wrapper");
$outer_container = $("#outer_container");
$thumbScroller = $(".thumbScroller");
$thumbScroller_container = $(".thumbScroller .container");
$thumbScroller_content = $(".thumbScroller .content");
$thumbScroller_thumb = $(".thumbScroller .thumb");
$preloader = $("#preloader");
$toolbar = $("#toolbar");
$toolbar_a = $("#toolbar a");
$bgimg = $("#bgimg");
$img_title = $("#img_title");
$nextImageBtn = $(".nextImageBtn");
$prevImageBtn = $(".prevImageBtn");
$(window).load(function () {
$toolbar.data("imageViewMode", $defaultViewMode); // mode d'affichage par défaut
if ($defaultViewMode == "full") {
$toolbar_a.html("<img src='~/Photos/toolbar_n_icon.png' style='width: 50px; height: 50px' />").attr("onClick", "ImageViewMode('normal');return false").attr("title", "Minimize");
} else {
$toolbar_a.html("<img src='~/Photos/toolbar_fs_icon.png' style='width: 50px; height: 50px' />").attr("onClick", "ImageViewMode('full');return false").attr("title", "Maximize");
}
ShowHideNextPrev($nextPrevBtnsInitState);
// scroller miniature
$thumbScroller_container.css("marginLeft", $tsMargin + "px"); // ajouter de la marge
sliderLeft = $thumbScroller_container.position().left;
sliderWidth = $outer_container.width();
$thumbScroller.css("width", sliderWidth);
var totalContent = 0;
fadeSpeed = 200;
var $the_outer_container = document.getElementById("outer_container");
var $placement = findPos($the_outer_container);
$thumbScroller_content.each(function () {
var $this = $(this);
totalContent += $this.innerWidth();
$thumbScroller_container.css("width", totalContent);
$this.children().children().children(".thumb").fadeTo(fadeSpeed, $thumbnailsOpacity);
});
$thumbScroller.mousemove(function (e) {
if ($thumbScroller_container.width() > sliderWidth) {
var mouseCoords = (e.pageX - $placement[1]);
var mousePercentX = mouseCoords / sliderWidth;
var destX = -((((totalContent + ($tsMargin * 2)) - (sliderWidth)) - sliderWidth) * (mousePercentX));
var thePosA = mouseCoords - destX;
var thePosB = destX - mouseCoords;
if (mouseCoords > destX) {
$thumbScroller_container.stop().animate({ left: -thePosA }, $scrollEasing, $scrollEasingType); //with easing
} else if (mouseCoords < destX) {
$thumbScroller_container.stop().animate({ left: thePosB }, $scrollEasing, $scrollEasingType); //with easing
} else {
$thumbScroller_container.stop();
}
}
});
$thumbnails_wrapper.fadeTo(fadeSpeed, $thumbnailsContainerOpacity);
$thumbnails_wrapper.hover(
function () { // passer la souris sur (mouse over)
var $this = $(this);
$this.stop().fadeTo("slow", 1);
},
function () { // passer la souris (mouse out)
var $this = $(this);
$this.stop().fadeTo("slow", $thumbnailsContainerMouseOutOpacity);
}
);
$thumbScroller_thumb.hover(
function () { // passer la souris sur (mouse over)
var $this = $(this);
$this.stop().fadeTo(fadeSpeed, 1);
},
function () { // passer la souris (mouse out)
var $this = $(this);
$this.stop().fadeTo(fadeSpeed, $thumbnailsOpacity);
}
);
// sur la fenêtre redimensionner l'image et réinitialiser le défilement des petites images
$(window).resize(function () {
FullScreenBackground("#bgimg", $bgimg.data("newImageW"), $bgimg.data("newImageH"));
$thumbScroller_container.stop().animate({ left: sliderLeft }, 400, "easeOutCirc");
var newWidth = $outer_container.width();
$thumbScroller.css("width", newWidth);
sliderWidth = newWidth;
$placement = findPos($the_outer_container);
});
// charger la 1ère image
var the1stImg = new Image();
the1stImg.onload = CreateDelegate(the1stImg, theNewImg_onload);
the1stImg.src = $bgimg.attr("src");
$outer_container.data("nextImage", $(".content").first().next().find("a").attr("href"));
$outer_container.data("prevImage", $(".content").last().find("a").attr("href"));
});
function BackgroundLoad($this, imageWidth, imageHeight, imgSrc) {
$this.fadeOut("fast", function () {
$this.attr("src", "").attr("src", imgSrc); // changer la source de l'image
FullScreenBackground($this, imageWidth, imageHeight); // échelle image de fond
$preloader.fadeOut("fast", function () { $this.fadeIn("slow"); });
var imageTitle = $img_title.data("imageTitle");
if (imageTitle) {
$this.attr("alt", imageTitle).attr("title", imageTitle);
$img_title.fadeOut("fast", function () {
$img_title.html(imageTitle).fadeIn();
});
} else {
$img_title.fadeOut("fast", function () {
$img_title.html($this.attr("title")).fadeIn();
});
}
});
}
// barre d'outils mouseover
if ($toolbar.css("display") != "none") {
$toolbar.fadeTo("fast", 0.4);
}
$toolbar.hover(
function () { // passer la souris sur (mouse over)
var $this = $(this);
$this.stop().fadeTo("fast", 1);
},
function () { // passer la souris (mouse out)
var $this = $(this);
$this.stop().fadeTo("fast", 0.4);
}
);
// Cliquer sur la vignette change l'image d'arrière-plan
$("#outer_container a").click(function (event) {
event.preventDefault();
var $this = $(this);
GetNextPrevImages($this);
GetImageTitle($this);
SwitchImage(this);
ShowHideNextPrev("show");
});
// boutons images suivantes / images précédentes
$nextImageBtn.click(function (event) {
event.preventDefault();
SwitchImage($outer_container.data("nextImage"));
var $this = $("#outer_container a[href='" + $outer_container.data("nextImage") + "']");
GetNextPrevImages($this);
GetImageTitle($this);
});
$prevImageBtn.click(function (event) {
event.preventDefault();
SwitchImage($outer_container.data("prevImage"));
var $this = $("#outer_container a[href='" + $outer_container.data("prevImage") + "']");
GetNextPrevImages($this);
GetImageTitle($this);
});
// images suivantes / images précédentes flèches du clavier
if ($keyboardNavigation == "on") {
$(document).keydown(function (ev) {
if (ev.keyCode == 39) { // flèche droite
SwitchImage($outer_container.data("nextImage"));
var $this = $("#outer_container a[href='" + $outer_container.data("nextImage") + "']");
GetNextPrevImages($this);
GetImageTitle($this);
return false; // n'exécute pas l'action par défaut (défilement ou autre)
} else if (ev.keyCode == 37) { // Flèche gauche
SwitchImage($outer_container.data("prevImage"));
var $this = $("#outer_container a[href='" + $outer_container.data("prevImage") + "']");
GetNextPrevImages($this);
GetImageTitle($this);
return false; // n'exécute pas l'action par défaut(défilement ou autre)
}
});
}
function ShowHideNextPrev(state) {
if (state == "hide") {
$nextImageBtn.fadeOut();
$prevImageBtn.fadeOut();
} else {
$nextImageBtn.fadeIn();
$prevImageBtn.fadeIn();
}
}
// obtenir le titre de l'image
function GetImageTitle(elem) {
var title_attr = elem.children("img").attr("title"); // obtenir l'attribut titre de l'image
$img_title.data("imageTitle", title_attr); // titre de l'image du magasin
}
// obtenir les images suivantes / prev
function GetNextPrevImages(curr) {
var nextImage = curr.parents(".content").next().find("a").attr("href");
if (nextImage == null) { // si dernière image, la suivante est la première
var nextImage = $(".content").first().find("a").attr("href");
}
$outer_container.data("nextImage", nextImage);
var prevImage = curr.parents(".content").prev().find("a").attr("href");
if (prevImage == null) { // si première image, précédent est dernier
var prevImage = $(".content").last().find("a").attr("href");
}
$outer_container.data("prevImage", prevImage);
}
// changer d'image
function SwitchImage(img) {
$preloader.fadeIn("fast"); // montrer le préchargement
var theNewImg = new Image();
theNewImg.onload = CreateDelegate(theNewImg, theNewImg_onload);
theNewImg.src = img;
}
// obtenir de nouvelles dimensions d'image
function CreateDelegate(contextObject, delegateMethod) {
return function () {
return delegateMethod.apply(contextObject, arguments);
}
}
// nouvelle image en charge
function theNewImg_onload() {
$bgimg.data("newImageW", this.width).data("newImageH", this.height);
BackgroundLoad($bgimg, this.width, this.height, this.src);
}
// Fonction d'échelle d'image
function FullScreenBackground(theItem, imageWidth, imageHeight) {
var winWidth = $(window).width();
var winHeight = $(window).height();
if ($toolbar.data("imageViewMode") != "original") { //scale
var picHeight = imageHeight / imageWidth;
var picWidth = imageWidth / imageHeight;
if ($toolbar.data("imageViewMode") == "full") { // mode image plein écran
if ((winHeight / winWidth) < picHeight) {
$(theItem).attr("width", winWidth);
$(theItem).attr("height", picHeight * winWidth);
} else {
$(theItem).attr("height", winHeight);
$(theItem).attr("width", picWidth * winHeight);
};
} else { // mode d'image de taille normale
if ((winHeight / winWidth) > picHeight) {
$(theItem).attr("width", winWidth);
$(theItem).attr("height", picHeight * winWidth);
} else {
$(theItem).attr("height", winHeight);
$(theItem).attr("width", picWidth * winHeight);
};
}
$(theItem).css("margin-left", (winWidth - $(theItem).width()) / 2);
$(theItem).css("margin-top", (winHeight - $(theItem).height()) / 2);
} else { // pas d'échelle
$(theItem).attr("width", imageWidth);
$(theItem).attr("height", imageHeight);
$(theItem).css("margin-left", (winWidth - imageWidth) / 2);
$(theItem).css("margin-top", (winHeight - imageHeight) / 2);
}
}
// Fonction de mode de visualisation d'image - plein écran ou taille normale
function ImageViewMode(theMode) {
$toolbar.data("imageViewMode", theMode);
FullScreenBackground($bgimg, $bgimg.data("newImageW"), $bgimg.data("newImageH"));
if (theMode == "full") {
$toolbar_a.html("<img src='~/Photos/toolbar_n_icon.png' style='width: 50px; height: 50px' />").attr("onClick", "ImageViewMode('normal');return false").attr("title", "Minimize");
} else {
$toolbar_a.html("<img src='~/Photos/toolbar_fs_icon.png' style='width: 50px; height: 50px' />").attr("onClick", "ImageViewMode('full');return false").attr("title", "Maximize");
}
}
// fonction pour trouver l'élément Position
function findPos(obj) {
var curleft = curtop = 0;
if (obj.offsetParent) {
curleft = obj.offsetLeft
curtop = obj.offsetTop
while (obj = obj.offsetParent) {
curleft += obj.offsetLeft
curtop += obj.offsetTop
}
}
return [curtop, curleft];
}
</script> |