Librairie Lightbox v2
Retour à la liste des scripts
Informations
LIGHTBOX - version 2 - 16.08.2008
Auteur : Julien Theler - www.twiip.ch
Contact :
Licence : CC-by-nc [Ne pas supprimer ou modifier la notification de parternité dans les commentaires des fichiers]
L'œuvre peut être librement utilisée, à la condition de l'attribuer à l'auteur en citant son nom.
Le titulaire de droits peut autoriser tous les types d’utilisation ou au contraire restreindre aux utilisations non commerciales (les utilisations commerciales restant soumises à son autorisation).
Fichiers
La librairie contient 6 fichiers indispensables :
lightboxClass.php (télécharger ) : Contient les constantes de configuration, une fonction pour l'appel en AJAX et la class Lightbox
lightbox.js (télécharger ) : Contient le code javascript composé de variables globales et de fonctions
lightbox.css (télécharger ) : Contient le CSS des différents éléments HTML utilisés
loader.gif (télécharger ) : Image affichée lors du préchargement des images
arrowleft.png (télécharger ) : Flèche de navigation entre les images
arrowright.png (télécharger ) : Flèche de navigation entre les images
white.png (télécharger ) : Image blanche affichée lors de l'agrandissement
1. Configuration
Trois constantes doivent être configurées dans le fichier lightbox.php (trois premières lignes du code) :
MAXWIDTH -> Largeur maximale des images (les images plus grandes sont redimensionnées, les proportions sont conservées) et largeur par défaut des box contenant du texte
MAXHEIGHT -> Hauteur maximale des images (les images plus grandes sont redimensionnées, les proportions sont conservées)
LIGHTBOXPATH -> Chemin absolu du répertoire de la librairie depuis la racine (ex : /dossier/lightbox/)
2. Mise en place
Le fichier lightbox.php contenant la class Lightbox doit être inclu de la façon suivante avant l'utilisation des lightbox :
require_once($_SERVER['DOCUMENT_ROOT'].'[/chemin/chemin]/lightbox.php');
3. Création d'un objet Lightbox
L'objet Lightbox doit être créé pour pouvoir générer des lightbox. Sa création insère les fichiers nécessaires (lightbox.css et lightbox.js ) ainsi
que les div utilisées par la librairie.
$lb = new Lightbox();
4. Fonctions d'affichage d'une image
Affichage d'un lien ouvrant une image : function lightboxImage(string lien, string image, [string titre])
lien : texte ou code à afficher en lien (peut être une image, par exemple une miniature)
image : chemin absolu de l'image à afficher
titre : titre affiché au-dessus de l'image, par défaut : vide
Exemple :
echo $lb->lightboxImage('<img src="'.$miniature.'" border="0" />', $image);
Warning : getimagesize(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in
/home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line
21
Warning : getimagesize(http://dev.twiip.ch/scripts/ressources/images/2.jpg): failed to open stream: no suitable wrapper could be found in
/home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line
21
Affichage d'une miniature générée ouvrant une image : function lightboxImageMini(string image, [int widthMini], [int heightMini], [string titre])
image : chemin absolu de l'image à afficher
widthMini : largeur de la miniature générée, si vide : proportionnelle à la hauteur spécifiée
heightMini : hauteur de la miniature générée, si vide : proportionnelle à la largeur spécifiée
titre : titre affiché au-dessus de l'image, par défaut : vide
Exemple :
echo $lb->lightboxImageMini('/images/image.jpg', 200, null, 'Ceci est un titre');
Warning : getimagesize(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in
/home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line
21
Warning : getimagesize(http://dev.twiip.ch/scripts/ressources/images/8.jpg): failed to open stream: no suitable wrapper could be found in
/home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line
21
5. Fonctions d'affichage d'une série d'images
Affichage d'un lien ouvrant une série d'images : function lightboxImageArray(string lien, array images, [int position], [array titres])
lien : texte ou code à afficher en lien (peut être une image, par exemple une miniature)
images : tableau contenant les chemins absolus des images
position : position dans l'array de l'image à afficher lors de l'ouverture de la box, par défaut: 0
titres : tableau contenant les titres à afficher pour chaque image, par défaut: vide
Exemple :
echo $lb->lightboxImageArray('<img src="'.$miniature.'" border="0" />', $array, 0);
Warning : getimagesize(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in
/home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line
21
Warning : getimagesize(http://dev.twiip.ch/scripts/ressources/images/1.jpg): failed to open stream: no suitable wrapper could be found in
/home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line
21
Affichage d'une miniature générée ouvrant une série d'images : function lightboxImageArrayMini(string image, array images, [int position], [int widthMini], [int heightMini], [string titre])
image : chemin absolu de l'image à afficher
images : tableau contenant les chemins absolus des images
position : position dans l'array de l'image à afficher lors de l'ouverture de la box, par défaut: 0
widthMini : largeur de la miniature générée, si vide : proportionnelle à la hauteur spécifiée
heightMini : hauteur de la miniature générée, si vide : proportionnelle à la largeur spécifiée
titres : tableau contenant les titres à afficher pour chaque image, par défaut: vide
Exemple :
echo $lb->lightboxImageArrayMini($image, $array, 0, null, 150, $array_titres);
Warning : getimagesize(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in
/home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line
21
Warning : getimagesize(http://dev.twiip.ch/scripts/ressources/images2/1.jpg): failed to open stream: no suitable wrapper could be found in
/home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line
21
6. Fonctions d'affichage d'un texte
Affichage d'un texte : lightboxContenu(string lien, string contenu, [int width], [string titre])
lien : texte ou code à afficher en lien
contenu : texte afficher dans la box ouverte, peut contenir du code HTML
width : largeur de la box, par défaut : valeur MAXWIDTH de la configuration;
titre : titre affiché au-dessus du texte, par défaut : vide
7. Exemple d'utilisation de la librairie pour afficher une galerie
Warning : getimagesize(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(http://dev.twiip.ch/scripts/ressources/images/1.jpg): failed to open stream: no suitable wrapper could be found in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(http://dev.twiip.ch/scripts/ressources/images/2.jpg): failed to open stream: no suitable wrapper could be found in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(http://dev.twiip.ch/scripts/ressources/images/3.jpg): failed to open stream: no suitable wrapper could be found in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(http://dev.twiip.ch/scripts/ressources/images/4.jpg): failed to open stream: no suitable wrapper could be found in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(http://dev.twiip.ch/scripts/ressources/images/5.jpg): failed to open stream: no suitable wrapper could be found in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(http://dev.twiip.ch/scripts/ressources/images/6.jpg): failed to open stream: no suitable wrapper could be found in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(http://dev.twiip.ch/scripts/ressources/images/7.jpg): failed to open stream: no suitable wrapper could be found in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(): http:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21
Warning : getimagesize(http://dev.twiip.ch/scripts/ressources/images/8.jpg): failed to open stream: no suitable wrapper could be found in /home/clients/ea7c959d9c8a630663d0f6bbfcca20a9/twiip.ch/subdomains/dev/httpdocs/scripts/lightbox/lightboxClass.php on line 21