front_idill/src/mosaic/js/mosaic.js
author bastiena
Fri, 27 Apr 2012 14:38:23 +0200
changeset 30 45c889eae324
child 31 2c7fc855eba8
permissions -rw-r--r--
Front IDILL : Creation of the main parts of the 2 first Modes : MOSAIC : prezoom/preunzoom, zoom/unzoom. local mosaic developpement aborted and postponed for the late developpement parts. VIDEO : moving to a neighbour snapshot.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
30
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     1
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     2
* This file is part of the TraKERS\Front IDILL package.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     3
*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     4
* (c) IRI <http://www.iri.centrepompidou.fr/>
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     5
*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     6
* For the full copyright and license information, please view the LICENSE
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     7
* file that was distributed with this source code.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     8
*/
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
     9
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    10
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    11
 * Projet : TraKERS
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    12
 * Module : Front IDILL
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    13
 * Fichier : mosaic.js
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    14
 * 
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    15
 * Auteur : alexandre.bastien@iri.centrepompidou.fr
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    16
 * 
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    17
 * Fonctionnalités : Définit la "classe" mosaïque et définit des fonctions d'intéractions.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    18
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    19
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    20
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    21
 * Classe définissant la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    22
 * Elle contient sa longueur, le nombre d'images total, une liste d'urls pour les vidéos, leurs snapshots principaux et leur position.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    23
 * Contient également les dimensions en px de la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    24
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    25
function mosaic(len, imgToShow, zoomPercentage, prezoomPercentage, zoomedMargin)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    26
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    27
    //S'il s'agit d'un rectangle.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    28
    if(imgToShow % len == 0)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    29
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    30
        //Longueur horizontale.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    31
        this.length = len;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    32
        //Nombre d'images dans la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    33
        this.imagesToShow = imgToShow;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    34
        //Tableaux des urls des vidéos, des snapshots et de leur position dans la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    35
        this.urls = [];
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    36
        this.imgs = [];
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    37
        this.ids = [];
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    38
        //Dimensions de la mosaïque en pixels.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    39
        this.width;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    40
        this.height;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    41
        //Dimensions d'un snapshot en pixels.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    42
        this.snapshotWidth;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    43
        this.snapshotHeight;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    44
        //Espacement entre les snapshots en pixels.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    45
        this.marginWidth;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    46
        
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    47
        //Temps d'intéractions/d'animations.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    48
        this.preZoomTime;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    49
        this.preUnzoomTime;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    50
        this.zoomTime;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    51
        this.unzoomTime;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    52
        this.timeNeighbourGlowing;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    53
        this.timeNeighbourUnglowing;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    54
        this.timeMovingToNeighbour;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    55
        
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    56
        //Booléens permettant ou non certaines intéractions selon le contexte.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    57
        this.zoomed;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    58
        this.fullscreen;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    59
        this.canMoveToNeighbour;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    60
        
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    61
        //Mode actuel.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    62
        this.currentMode;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    63
        //Snapshot sur lequel on a zoomé.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    64
        this.previousZoomedSN;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    65
        //Son ID.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    66
        this.previousId;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    67
        //Largeur de la marge pour le centrage vertical de la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    68
        this.MPTop_margin;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    69
        this.top_margin;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    70
        //Pourcentage d'agrandissement lors d'un prézoom et d'un zoom.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    71
        this.prezoomPercentage = prezoomPercentage;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    72
        this.zoomPercentage = zoomPercentage;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    73
        //Espacement des snapshots après un zoom.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    74
        this.zoomedMargin = zoomedMargin;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    75
        //Mosaïque locale.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    76
        this.localMos;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    77
        //Position des voisins lors d'un zoom.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    78
        this.neighboursIds = [];
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    79
        //ID du snapshot du milieu lors d'un zoom.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    80
        this.centerId;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    81
    }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    82
    else
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    83
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    84
        //Affiche un message d'erreur.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    85
    }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    86
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    87
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    88
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    89
 * Méthode d'affichage de la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    90
 * Génère une matrice de imgs.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    91
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    92
mosaic.prototype.createMosaic = function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    93
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    94
    this.previousZoomedSN = '';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    95
    this.previousPrezoomDiv = '';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    96
    this.fullscreen = false;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    97
    this.canMoveToNeighbour = false;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    98
    var str = '';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
    99
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   100
    if(this.imgs.length >= this.imagesToShow)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   101
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   102
        for(var i = 0 ; i < this.imagesToShow ; i++)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   103
        {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   104
            //On charge les images de petite taille pour ne pas surcharger la mosaïque lors de l'affichage global.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   105
            str += '<div id="snapshotDiv-' + i + '" class="snapshotDivs"><img id="snapshot-' + i + '" class="snapshots" src="snapshots-little/' + this.imgs[i] + '" /></div>';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   106
        }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   107
    }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   108
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   109
    return str;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   110
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   111
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   112
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   113
 * Permet de raffraichir la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   114
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   115
mosaic.prototype.loadMosaic = function(imgsTab)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   116
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   117
    //On affecte les chemins vers les images à la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   118
    this.imgs = imgsTab;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   119
    this.previousZoomedSN;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   120
    //this.width = 
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   121
    //On met à jour la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   122
    $('#mainPanel').html(this.createMosaic());
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   123
    //On récupère la taille des bordures.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   124
    this.marginWidth = $('.snapshotDivs').css('margin-bottom');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   125
    this.marginWidth = parseFloat(mos.marginWidth)*2;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   126
    //On calcule la taille des divs contenant les snapshots.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   127
    this.width = $('#mainPanel').innerWidth();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   128
    //On ne calculera pas tout de suite la hauteur de la mosaique étant donnée qu'elle est calculée par la suite dynamiquement.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   129
    this.snapshotWidth = this.width / this.length - this.marginWidth;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   130
    this.snapshotHeight = this.snapshotWidth*9/16;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   131
    $('.snapshotDivs').css('width', this.snapshotWidth).css('height', this.snapshotHeight).css('margin', this.marginWidth/2);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   132
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   133
    this.height = $('#mainPanel').innerHeight();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   134
    //On centre verticalement la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   135
    this.MPTop_margin = ($(document).height() - $('#mainPanel').height())/2;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   136
    $('#mainPanel').css('margin-top', this.MPTop_margin).css('margin-bottom', this.MPTop_margin);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   137
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   138
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   139
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   140
 * Zoom sur la position d'une image, 1ère partie. Durant le laps de temps de time ms, l'utilisateur a le choix de zoomer sur une autre image.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   141
 * Après ce laps de temps, l'image zoom complétement et il n'est plus possible de sélectionner une autre image par pointage.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   142
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   143
mosaic.prototype.preZoom = function(snapshot)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   144
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   145
    if(this.fullscreen)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   146
        return;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   147
    //Mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   148
    var mosaic = this;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   149
    //Dimensions de la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   150
    var h = this.height, w = this.width;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   151
    //Longueur en images, nombre d'images et taille de bordure de la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   152
    var len = this.length, imgs = this.imagesToShow, margin = this.marginWidth;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   153
    //Dimensions et position d'un snapshot dans la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   154
    var snHeight = this.snapshotHeight, snWidth = this.snapshotWidth;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   155
    var sTop = snapshot.position().top, sLeft = snapshot.position().left;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   156
    var prezoomPercentage = this.prezoomPercentage;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   157
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   158
    //ID de l'image actuelle.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   159
    var currentId = $('img', snapshot).attr('id');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   160
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   161
    //Si un zoom est déjà en cours, on ne zoom sur rien d'autre en attendant que ce snapshot ai dézoomé en cas de mouseleave.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   162
    if(this.zoomed)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   163
        if($('#preZoomContainer-' + currentId) != $(this) && this.previousZoomedSN != '' && this.previousId != '')
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   164
            this.preUnzoom();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   165
        else
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   166
            return;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   167
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   168
    //On indique qu'on a zoomé et on spécifie le snapshot sur lequel on a zoomé.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   169
    this.zoomed = true;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   170
    this.previousZoomedSN = snapshot;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   171
    this.previousId = currentId;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   172
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   173
    //On récupère les attributs de l'image.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   174
    var fakeImg = $('img', snapshot);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   175
    //On forme la balise de la fausse image et on passe son url pour les grands snapshots.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   176
    fakeImg = '<img id="fake-' + currentId + '" class="snapshots" src="' + fakeImg.attr('src').replace('-little/', '/') + '" />';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   177
    //On génère un faux snapshot identique au précédent et qu'on va coller dessus.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   178
    var fakeSnapshot = '<div id="prezoomContainer-' + currentId + '" class="prezoomContainers"><div id="prezoomSnapshot-' + currentId + '" class="snapshotDivs">' + fakeImg + '</div></div>';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   179
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   180
    //On l'ajoute à la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   181
    $('#mainPanel').append(fakeSnapshot);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   182
    //On modifie ses attributs.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   183
    $('#fake-' + currentId).load(function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   184
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   185
        $('#prezoomContainer-' + currentId).css('display', 'block');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   186
        $('#prezoomContainer-' + currentId).css('top', sTop).css('left', sLeft).css('width', (snWidth + margin)).css('height', (snHeight + margin));
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   187
        $('#prezoomSnapshot-' + currentId).css('width', (snWidth)).css('height', (snHeight));
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   188
        
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   189
        //Dimensions et coordonnées initiales du div sur lequel on zoom.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   190
        var initialDivWidth = $('#prezoomContainer-' + currentId).width(), initialDivHeight = $('#prezoomContainer-' + currentId).height();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   191
        var initialDivTop = $('#prezoomContainer-' + currentId).position().top, initialDivLeft = $('#prezoomContainer-' + currentId).position().left;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   192
        //Dimensions et coordonnées finales du div.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   193
        var finalDivWidth = initialDivWidth * (prezoomPercentage+1), diffWidth = finalDivWidth - initialDivWidth, finalDivHeight = initialDivHeight + diffWidth;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   194
        var finalDivTop = (initialDivTop - (finalDivHeight - snHeight)/2), finalDivLeft = (initialDivLeft - (finalDivWidth - snWidth)/2);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   195
        
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   196
        //CAS PARTICULIER pour la position du snapshot zoomé : les bordures.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   197
        if(finalDivTop < 0)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   198
            finalDivTop = -margin;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   199
        if(finalDivTop + finalDivHeight > h)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   200
            finalDivTop = h - finalDivHeight;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   201
        if(finalDivLeft < 0)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   202
            finalDivLeft = 0;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   203
        if(finalDivLeft + finalDivWidth + margin*2 > w)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   204
            finalDivLeft = w - finalDivWidth - margin*2;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   205
        
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   206
        ////Code de debug.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   207
        ////CAUTION////
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   208
        /*var red = '<div id="red"></div>';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   209
        if($('#red') != null || $('#red') != undefined)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   210
            $('body').append(red);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   211
        $('#red').css('background-color', '#FF0000').css('position', 'absolute').css('top', '0px').css('left', '0px').css('width', '100px').css('height', '100px');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   212
        $('#red').css('top', finalDivTop).css('left', finalDivLeft).css('width', finalDivWidth).css('height', finalDivHeight);*/
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   213
        //alert("initial : " + initialDivWidth + " " + initialDivHeight + " ; final : " + finalDivWidth + " " + finalDivHeight);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   214
        ////CAUTION////
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   215
        
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   216
        //On prézoom le div en le centrant sur le milieu du snapshot pointé.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   217
        $('#prezoomSnapshot-' + currentId).animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   218
        {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   219
            width: finalDivWidth + margin,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   220
            height: finalDivHeight - margin*2,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   221
            top: finalDivTop + margin,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   222
            left: finalDivLeft + margin
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   223
        }, this.preZoomTime);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   224
        $('#prezoomContainer-' + currentId).animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   225
        {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   226
            width: finalDivWidth + margin*2,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   227
            height: finalDivHeight - margin,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   228
            top: finalDivTop + margin,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   229
            left: finalDivLeft
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   230
        }, this.preZoomTime);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   231
    });
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   232
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   233
    //Si on clique sur le snapshot prézoomé, on enclenche un zoom total sur ce snapshot.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   234
    $('#prezoomContainer-' + currentId).click(function ()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   235
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   236
        if(this.previousZoomedSN != '')
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   237
            mosaic.zoom();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   238
    });
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   239
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   240
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   241
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   242
 * Dézoome sur la position de l'image. Il est à noter que ce dézoome diffère du dézoom global dans la mesure où celui-ci ne concerne que l'image sur laquelle on a zoomé.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   243
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   244
mosaic.prototype.preUnzoom = function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   245
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   246
    //Si on n'a pas zoomé, on quitte la fonction.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   247
    if(!this.zoomed)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   248
        return;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   249
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   250
    //On spécifie la marge afin de centrer le prédézoom.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   251
    var margin = this.marginWidth;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   252
    //ID du snapshot précédemment pointé.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   253
    var id = this.previousId;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   254
    //On ne zoom plus.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   255
    this.zoomed = false;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   256
    //On rétrécit le snapshot de prézoom, puis on le supprime en donnant l'illusion qu'il s'agissait du véritable snapshot, alors qu'en fait c'était un clone.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   257
    $('#prezoomSnapshot-' + id).animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   258
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   259
        width: this.snapshotWidth,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   260
        height: this.snapshotHeight,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   261
        top: this.previousZoomedSN.position().top,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   262
        left: this.previousZoomedSN.position().left
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   263
    }, this.preUnzoomTime);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   264
    $('#prezoomContainer-' + id).animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   265
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   266
        width: this.snapshotWidth + margin,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   267
        height: this.snapshotHeight + margin,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   268
        top: this.previousZoomedSN.position().top,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   269
        left: this.previousZoomedSN.position().left
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   270
    }, this.preUnzoomTime, function(){ $(this).remove(); this.zoomed = false; });
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   271
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   272
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   273
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   274
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   275
 * Zoom d'un snapshot en plein écran.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   276
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   277
mosaic.prototype.zoom = function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   278
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   279
    var mos = this;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   280
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   281
    //Si la mosaïque est en pleine écran, pas la peine de zoomer.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   282
    if(this.fullscreen)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   283
        return;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   284
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   285
    //On prend les attributs nécessaires au calculs.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   286
    var margin = this.marginWidth, len = this.length, imgs = this.imagesToShow;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   287
    var initMPWidth = this.previousZoomedSN.width() * len + margin*len, initMPHeight = this.previousZoomedSN.height() * (imgs / len) + margin*(imgs / len);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   288
    var newMPWidth = initMPWidth * len + this.zoomedMargin * (len), newMPHeight = initMPHeight * (imgs / len) + this.zoomedMargin * ((imgs / len));
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   289
    var newPreMPWidth = initMPWidth * len * this.zoomPercentage + this.zoomedMargin * (len), newPreMPHeight = initMPHeight * (imgs / len) * this.zoomPercentage + this.zoomedMargin * ((imgs / len));
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   290
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   291
    //Dimensions et coordonnées initiales du div sur lequel on zoom.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   292
    var initialDivWidth = this.previousZoomedSN.width(), initialDivHeight = this.previousZoomedSN.height();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   293
    var initialDivTop = this.previousZoomedSN.position().top, initialDivLeft = this.previousZoomedSN.position().left;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   294
    //Dimensions et coordonnées finales du div.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   295
    var finalDivWidth = initialDivWidth * (this.zoomPercentage+1), finalDivHeight = initialDivHeight * (this.zoomPercentage+1);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   296
    var newZoomTop = -this.previousZoomedSN.position().top*(newPreMPHeight/initMPHeight) - this.zoomedMargin/2 + (initMPHeight - initMPHeight * this.zoomPercentage)/2 + 'px', newZoomLeft = -this.previousZoomedSN.position().left*(newPreMPWidth/initMPWidth) - this.zoomedMargin/2 + (initMPWidth - initMPWidth * this.zoomPercentage)/2 + 'px';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   297
    var newSnWidth = initMPWidth * this.zoomPercentage, newSnHeight = initMPHeight * this.zoomPercentage;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   298
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   299
    this.preUnzoom(this);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   300
    /*SINGULARITE*/
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   301
    this.fullscreen = true;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   302
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   303
    //On passe l'image du snapshot pointé en HD.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   304
    var zoomedImg = $('img', this.previousZoomedSN);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   305
    var src = zoomedImg.attr('src');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   306
    zoomedImg.attr('src', src.replace('-little/', '/'));
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   307
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   308
    //On récupère son ID.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   309
    var tab, zoomedImgId;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   310
    tab = mos.previousId.split('-');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   311
    zoomedImgId = tab[1];
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   312
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   313
    //Les snapshots baissent alors en opacité, donnant l'impression qu'ils sont grisés.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   314
    $('.snapshotDivs').animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   315
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   316
        width: newSnWidth,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   317
        height: newSnHeight,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   318
        margin: this.zoomedMargin/2 + 'px',
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   319
        opacity: '0.4'
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   320
    }, this.zoomTime);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   321
    //Le snapshot du milieu revient à une opacité optimale, ce qui attire l'attention de l'utilisateur.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   322
    $(this.previousZoomedSN).animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   323
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   324
        opacity: '1'
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   325
    }, this.zoomTime);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   326
    //On zoome sur la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   327
    $('#mainPanel').animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   328
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   329
        width: newPreMPWidth,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   330
        height: newPreMPHeight,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   331
        top: newZoomTop,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   332
        left: newZoomLeft
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   333
    }, this.zoomTime, function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   334
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   335
        //On charge les interactions avec les voisins.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   336
        mos.centerId = zoomedImgId;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   337
        mos.listenToNeighbours();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   338
        mos.currentMode = 'VIDEO';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   339
        /*mos.unload();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   340
        mos.localMos.loadLocalMosaic(newZoomTop, newZoomLeft, newSnWidth, newSnHeight, mos.imgs, tab[1]);*/
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   341
    });
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   342
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   343
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   344
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   345
 * Retour à la taille normale de la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   346
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   347
mosaic.prototype.unzoom = function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   348
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   349
    //Si on n'est pas en plein écran, on quitte.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   350
    if(!this.fullscreen)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   351
        return;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   352
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   353
    //On charge les attributs nécessaires aux calculs.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   354
    var sWidth = this.snapshotWidth, sHeight = this.snapshotHeight;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   355
    var mpWidth = this.width, mpHeight = this.height;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   356
    var mos = this;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   357
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   358
    //On passe le snapshot sur lequel on a zoomé en LD.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   359
    var zoomedImg = $('img', this.previousZoomedSN);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   360
    var src = zoomedImg.attr('src');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   361
    zoomedImg.attr('src', src.replace('snapshots/', 'snapshots-little/'));
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   362
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   363
    //On rend leur opacité aux snapshots. Qui ne sont alors plus grisés.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   364
    $('.snapshotDivs').animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   365
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   366
        width: sWidth,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   367
        height: sHeight,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   368
        margin: this.marginWidth/2 + 'px',
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   369
        opacity: '1'
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   370
    }, this.unzoomTime);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   371
    //On dézoom sur la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   372
    $('#mainPanel').animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   373
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   374
        width: mpWidth,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   375
        height: mpHeight,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   376
        top: '0px',
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   377
        left: '0px'
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   378
    }, this.unzoomTime, function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   379
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   380
        //On n'est plus en plein écran, et on ne peut plus se déplacer vers le prochain voisin.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   381
        mos.fullscreen = false;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   382
        mos.canMoveToNeighbour = false;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   383
        //On revient en mode MOSAIC.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   384
        mos.currentMode = 'MOSAIC';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   385
        //On ne permet plus le déplacement vers les voisins.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   386
        $('.snapshotDivs').unbind('mouseenter', mos.changeNeighbourColor);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   387
    });
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   388
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   389
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   390
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   391
 * Affecte les listeners mouseenter aux voisins lors d'une vue en plein écran.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   392
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   393
mosaic.prototype.listenToNeighbours = function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   394
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   395
    ////TEST
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   396
    //$('.test').empty();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   397
    this.canMoveToNeighbour = false;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   398
    var currentLine = Math.floor(this.centerId / this.length), currentColumn = this.centerId % this.length;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   399
    var zoomedImg = $('img', this.previousZoomedSN);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   400
    var mos = this;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   401
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   402
    //On cherche l'ID des voisins.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   403
    //Si le voisin de gauche est sur la même ligne, on n'est pas sur la bordure de gauche.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   404
    this.neighboursIds[0] = (currentColumn > 0) ? (this.centerId - 1) : -1;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   405
    //Si le voisin de droite est sur la même ligne, on n'est pas sur la bordure de droite.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   406
    this.neighboursIds[1] = (currentColumn < this.length) ? (+this.centerId + 1) : -1;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   407
    //Si le voisin du haut est sur la même colonne, on n'est pas sur la bordure du haut.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   408
    this.neighboursIds[2] = (currentLine > 0) ? (this.centerId - this.length) : -1;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   409
    //Si le voisin du bas est sur la même colonne, on n'est pas sur la bordure du bas.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   410
    this.neighboursIds[3] = (currentLine < (this.imagesToShow / this.length)) ? (+this.centerId + this.length) : -1;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   411
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   412
    for(var i = 0 ; i < this.neighboursIds.length ; i++)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   413
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   414
        if(this.neighboursIds[i] != -1)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   415
        {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   416
            //On permet le déplacement vers les voisins.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   417
            $('#snapshotDiv-' + this.neighboursIds[i]).mouseenter(mos.changeNeighbourColor);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   418
        }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   419
    }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   420
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   421
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   422
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   423
 * Change la coloration d'une bordure où on se positionne lors d'une vue en plein écran.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   424
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   425
mosaic.prototype.changeNeighbourColor = function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   426
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   427
    ////TEST
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   428
    //$('.test').append(mos.currentMode + " " + $(this).attr('id') + " " + 'snapshotDiv-' + mos.centerId + ',');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   429
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   430
    //Si on est en mode VIDEO (plein écran) ET si le snapshot pointé est un voisin.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   431
    if((mos.currentMode == 'VIDEO') && ($(this).attr('id') != 'snapshotDiv-' + mos.centerId))
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   432
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   433
        //On crée le div cyan qui va être superposé au voisin.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   434
        var cyanDiv = '<div class="cyan" id="cyan-' + $(this).attr('id') + '"></div>';
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   435
        //On le colle au voisin.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   436
        $('#mainPanel').append(cyanDiv);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   437
        $('#cyan-' + $(this).attr('id')).css('top', $(this).position().top).css('left', $(this).position().left).css('width', $(this).width()).css('height', $(this).height()).css('margin', $(this).css('margin')).animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   438
        {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   439
            //On le fait apparaître.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   440
            opacity: '0.4'
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   441
        }, timeNeighbourUnglowing, function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   442
        {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   443
            //On peut désormais se déplacer vers ce voisin.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   444
            mos.canMoveToNeighbour = true;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   445
        }).mouseleave(mos.unchangeNeighbourColor).click(mos.moveToNeighbour);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   446
    }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   447
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   448
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   449
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   450
 * Change la coloration d'une bordure quittée lors d'une vue en plein écran.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   451
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   452
mosaic.prototype.unchangeNeighbourColor = function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   453
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   454
    ////TEST
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   455
    //$('.test').append('un,');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   456
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   457
    //On ne peut plus se déplacer vers les voisins.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   458
    mos.canMoveToNeighbour = false;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   459
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   460
    //Si on est en mode VIDEO.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   461
    if(mos.currentMode == 'VIDEO')
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   462
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   463
        //On obtient le div de coloration superposé au voisin.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   464
        var cyanDiv = $(this);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   465
        
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   466
        //On le fait disparaître progressivement.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   467
        $(this).animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   468
        {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   469
            opacity: '0'
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   470
        }, timeNeighbourGlowing, function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   471
        {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   472
            //Une fois invisible, on le supprime.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   473
            cyanDiv.remove();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   474
        });
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   475
    }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   476
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   477
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   478
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   479
 * Lors d'une vue en plein écran, on se déplace vers le voisin dont l'id a été spécifié dans la fonction appelante.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   480
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   481
mosaic.prototype.moveToNeighbour = function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   482
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   483
    //Si on ne peut pas se déplacer vers les voisins, on quitte.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   484
    if(!mos.canMoveToNeighbour)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   485
        return;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   486
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   487
    //On obtient l'ID de destination.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   488
    var tab = $(this).attr('id').split('-');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   489
    var destinationId = tab[2];
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   490
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   491
    //On charge les attributs nécessaires aux calculs.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   492
    var MPCurrentTop = $('#mainPanel').position().top, MPCurrentLeft = $('#mainPanel').position().left;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   493
    var divideCoeffTop = Math.floor(destinationId / mos.length) == 0 ? 1 : Math.floor(destinationId / mos.length);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   494
    var divideCoeffLeft = destinationId % mos.length == 0 ? 1 : destinationId % mos.length;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   495
    var cyanTop = $(this).position().top, cyanLeft = $(this).position().left;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   496
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   497
    //On définit pour le déplacement vertical s'il est nécessaire de se déplacer en haut ou en bas.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   498
    if(mos.previousZoomedSN.position().top > cyanTop)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   499
        MPCurrentTop += Math.abs(cyanTop - mos.previousZoomedSN.position().top);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   500
    else if(mos.previousZoomedSN.position().top < cyanTop)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   501
        MPCurrentTop -= Math.abs(cyanTop - mos.previousZoomedSN.position().top);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   502
    //On définit pour le déplacement horizontal s'il est nécessaire de se déplacer à gauche ou à droite.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   503
    if(mos.previousZoomedSN.position().left > cyanLeft)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   504
        MPCurrentLeft += Math.abs(cyanLeft - mos.previousZoomedSN.position().left);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   505
    else if(mos.previousZoomedSN.position().left < cyanLeft)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   506
        MPCurrentLeft -= Math.abs(cyanLeft - mos.previousZoomedSN.position().left);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   507
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   508
    //On passe le snapshot de destination en HD.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   509
    var destinationImg = $('#snapshot-' + destinationId);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   510
    var destinationImgSrc = destinationImg.attr('src');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   511
    destinationImg.attr('src', destinationImgSrc.replace('snapshots-little/', 'snapshots/'));
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   512
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   513
    //On passe l'ancien snapshot en LD.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   514
    var currentImgSrc = $('img', mos.previousZoomedSN).attr('src');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   515
    $('img', mos.previousZoomedSN).attr('src', currentImgSrc.replace('snapshots/', 'snapshots-little/'));
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   516
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   517
    //On obtient l'ID du div de coloration du snapshot vers lequel on se déplace afin de le supprimer.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   518
    var cyan = $(this);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   519
    var tab = cyan.attr('id').split('-');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   520
    mos.centerId = tab[2];
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   521
    $(this).css('opacity', '0');
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   522
    cyan.remove();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   523
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   524
    //On grise le snapshot qu'on vient de quitter.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   525
    mos.previousZoomedSN.animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   526
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   527
        opacity: '0.4'
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   528
    });
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   529
    
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   530
    //On se déplace.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   531
    $('#mainPanel').animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   532
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   533
        top: MPCurrentTop,
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   534
        left: MPCurrentLeft
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   535
    }, timeMovingToNeighbour, function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   536
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   537
        //On fait apparaître le snapshot vers lequel on s'est déplacé.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   538
        $('#snapshotDiv-' + destinationId).animate(
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   539
        {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   540
            opacity: '1'
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   541
        }, mos.zoomTime, function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   542
        {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   543
            //On recharge les voisins.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   544
            $('.snapshotDivs').unbind('mouseenter', mos.changeNeighbourColor);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   545
            mos.previousZoomedSN = $('#snapshotDiv-' + mos.centerId);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   546
            mos.listenToNeighbours();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   547
        });
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   548
    });
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   549
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   550
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   551
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   552
 * Déchargement du contenu de la mosaïque pour le chargement de la mosaïque locale.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   553
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   554
mosaic.prototype.unload = function()
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   555
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   556
    //On supprime les event listeners des objets de la mosaïque.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   557
    $('.snapshotDivs').unbind();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   558
    $('.snapshots').unbind();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   559
    $('.prezoomContainers').unbind();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   560
    //On supprime physiquement les objets.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   561
    $('#mainPanel').empty();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   562
}
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   563
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   564
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   565
 * Centre verticalement un snapshot.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   566
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   567
/*function verticalCenterImg(mosaic, img)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   568
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   569
    //On récupère sa hauteur.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   570
    var image_height = img.height();
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   571
    //Calcule la marge du haut de chaque div pour le centrage.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   572
    if(mosaic.top_margin == undefined)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   573
        mosaic.top_margin = (mosaic.snapshotHeight > image_height) ? (mosaic.snapshotHeight - image_height)/2 : (image_height - mosaic.snapshotHeight)/2;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   574
    //On centre le snapshot.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   575
    img.css('margin-top', mosaic.top_margin).css('margin-bottom', mosaic.top_margin);
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   576
}*/
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   577
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   578
/*
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   579
 * Permet de tester l'égalité des éléments de deux objets.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   580
 * Pour ce faire on compare les éléments définissant ces objets.
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   581
 */
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   582
$.fn.equals = function(compareTo)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   583
{
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   584
    if (!compareTo || !compareTo.length || this.length!=compareTo.length)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   585
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   586
        return false;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   587
    }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   588
    for (var i=0; i<this .length; i++)
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   589
    {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   590
        if (this[i]!==compareTo[i])
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   591
        {
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   592
            return false;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   593
        }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   594
    }
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   595
    return true;
45c889eae324 Front IDILL :
bastiena
parents:
diff changeset
   596
}