front_idill/src/mosaic/mosaic/js/mosaic.js
author bastiena
Mon, 14 May 2012 17:20:35 +0200
changeset 32 4003f84cd349
permissions -rw-r--r--
Front IDILL : Player implemented and was mostly tested, still memory leaks.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
     1
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
     2
* This file is part of the TraKERS\Front IDILL package.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
     3
*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
     4
* (c) IRI <http://www.iri.centrepompidou.fr/>
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
     5
*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
     6
* For the full copyright and license information, please view the LICENSE
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
     7
* file that was distributed with this source code.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
     8
*/
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
     9
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    10
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    11
 * Projet : TraKERS
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    12
 * Module : Front IDILL
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    13
 * Fichier : mosaic.js
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    14
 * 
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    15
 * Auteur : alexandre.bastien@iri.centrepompidou.fr
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    16
 * 
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    17
 * Fonctionnalités : Définit la "classe" mosaïque et définit des fonctions d'intéractions.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    18
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    19
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    20
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    21
 * Classe définissant la mosaïque.
4003f84cd349 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.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    23
 * Contient également les dimensions en px de la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    24
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    25
function mosaic(len, imgToShow, zoomPercentage, prezoomPercentage, zoomedMargin)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    26
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    27
    //S'il s'agit d'un rectangle.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    28
    if(imgToShow % len == 0)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    29
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    30
        //Longueur horizontale.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    31
        this.length = len;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    32
        //Nombre d'images dans la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    33
        this.imagesToShow = imgToShow;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    34
        //Tableaux des urls des vidéos, des snapshots et de leur position dans la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    35
        this.videos = [];
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    36
        this.urls = [];
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    37
        this.imgs = [];
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    38
        this.ids = [];
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    39
        //Dimensions de la mosaïque en pixels.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    40
        this.width;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    41
        this.height;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    42
        //Dimensions d'un snapshot en pixels.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    43
        this.snapshotWidth;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    44
        this.snapshotHeight;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    45
        //Espacement entre les snapshots en pixels.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    46
        this.marginWidth;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    47
        
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    48
        //Temps d'intéractions/d'animations.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    49
        this.preZoomTime;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    50
        this.preUnzoomTime;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    51
        this.zoomTime;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    52
        this.unzoomTime;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    53
        this.timeNeighbourGlowing;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    54
        this.timeNeighbourUnglowing;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    55
        this.timeMovingToNeighbour;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    56
        
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    57
        //Booléens permettant ou non certaines intéractions selon le contexte.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    58
        this.zoomed;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    59
        this.fullscreen;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    60
        this.canMoveToNeighbour;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    61
        
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    62
        //Mode actuel.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    63
        this.currentMode;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    64
        //Snapshot sur lequel on a zoomé.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    65
        this.previousZoomedSN;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    66
        //Son ID.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    67
        this.previousId;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    68
        //Largeur de la marge pour le centrage vertical de la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    69
        this.MPTop_margin;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    70
        this.top_margin;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    71
        //Pourcentage d'agrandissement lors d'un prézoom et d'un zoom.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    72
        this.prezoomPercentage = prezoomPercentage;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    73
        this.zoomPercentage = zoomPercentage;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    74
        //Espacement des snapshots après un zoom.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    75
        this.zoomedMargin = zoomedMargin;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    76
        //Mosaïque locale.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    77
        this.localMos;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    78
        //Position des voisins lors d'un zoom.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    79
        this.neighboursIds = [];
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    80
        //ID du snapshot du milieu lors d'un zoom.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    81
        this.centerId;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    82
		
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    83
		this.player;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    84
		
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    85
		this.loadFromJson('./player/json/videos.json');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    86
    }
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    87
    else
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    88
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    89
        //Affiche un message d'erreur.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    90
    }
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    91
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    92
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    93
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    94
 * Méthode d'affichage de la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    95
 * Génère une matrice de imgs.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    96
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    97
mosaic.prototype.createMosaic = function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    98
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
    99
    this.previousZoomedSN = '';
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   100
    this.previousPrezoomDiv = '';
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   101
    this.fullscreen = false;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   102
    this.canMoveToNeighbour = false;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   103
    var str = '';
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   104
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   105
    if(this.imgs.length >= this.imagesToShow)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   106
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   107
        for(var i = 0 ; i < this.imagesToShow ; i++)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   108
        {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   109
            //On charge les images de petite taille pour ne pas surcharger la mosaïque lors de l'affichage global.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   110
            str += '<div id="snapshotDiv-' + i + '" class="snapshotDivs"><img id="snapshot-' + i + '" class="snapshots" src="snapshots-little/' + this.imgs[i] + '" /></div>';
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   111
        }
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   112
    }
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   113
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   114
	console.log(this.imagesToShow);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   115
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   116
    return str;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   117
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   118
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   119
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   120
 * Permet de raffraichir la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   121
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   122
mosaic.prototype.loadMosaic = function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   123
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   124
	var createMosaic = this.createMosaic();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   125
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   126
	if(createMosaic == '')
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   127
	{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   128
		return;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   129
	}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   130
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   131
	var _this = this;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   132
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   133
    //On affecte les chemins vers les images à la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   134
    this.previousZoomedSN;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   135
    //this.width = 
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   136
    //On met à jour la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   137
    $('#mainPanel').html(createMosaic);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   138
    //On récupère la taille des bordures.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   139
    this.marginWidth = $('.snapshotDivs').css('margin-bottom');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   140
    this.marginWidth = parseFloat(mos.marginWidth)*2;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   141
    //On calcule la taille des divs contenant les snapshots.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   142
    this.width = $('#mainPanel').innerWidth();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   143
    //On ne calculera pas tout de suite la hauteur de la mosaique étant donnée qu'elle est calculée par la suite dynamiquement.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   144
    this.snapshotWidth = this.width / this.length - this.marginWidth;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   145
    this.snapshotHeight = this.snapshotWidth*9/16;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   146
    $('.snapshotDivs').css('width', this.snapshotWidth).css('height', this.snapshotHeight).css('margin', this.marginWidth/2);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   147
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   148
    this.height = $('#mainPanel').innerHeight();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   149
    //On centre verticalement la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   150
    this.MPTop_margin = ($(document).height() - $('#mainPanel').height())/2;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   151
    $('#mainPanel').css('margin-top', this.MPTop_margin).css('margin-bottom', this.MPTop_margin);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   152
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   153
	$('.snapshotDivs').mouseenter(function ()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   154
	{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   155
		//On effectue un prézoom dès qu'on va sur une image.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   156
		_this.preZoom($(this));
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   157
	});
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   158
	$('body').keypress(function (event)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   159
	{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   160
		//Si on a appuié sur la touche 'q' ou 'Q';
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   161
		if(event.which == 113 || event.which == 81)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   162
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   163
		   _this.unzoom();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   164
		}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   165
	});
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   166
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   167
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   168
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   169
 * 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.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   170
 * 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.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   171
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   172
mosaic.prototype.preZoom = function(snapshot)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   173
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   174
    if(this.fullscreen)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   175
	{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   176
        return;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   177
	}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   178
    //Mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   179
    var mosaic = this;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   180
    //Dimensions de la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   181
    var h = this.height, w = this.width;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   182
    //Longueur en images, nombre d'images et taille de bordure de la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   183
    var len = this.length, imgs = this.imagesToShow, margin = this.marginWidth;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   184
    //Dimensions et position d'un snapshot dans la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   185
    var snHeight = this.snapshotHeight, snWidth = this.snapshotWidth;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   186
    var sTop = snapshot.position().top, sLeft = snapshot.position().left;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   187
    var prezoomPercentage = this.prezoomPercentage;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   188
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   189
    //ID de l'image actuelle.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   190
    var currentId = $('img', snapshot).attr('id');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   191
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   192
    //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.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   193
    if(this.zoomed)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   194
	{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   195
        if($('#preZoomContainer-' + currentId) != $(this) && this.previousZoomedSN != '' && this.previousId != '')
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   196
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   197
            this.preUnzoom();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   198
		}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   199
        else
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   200
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   201
            return;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   202
		}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   203
	}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   204
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   205
    //On indique qu'on a zoomé et on spécifie le snapshot sur lequel on a zoomé.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   206
    this.zoomed = true;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   207
    this.previousZoomedSN = snapshot;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   208
    this.previousId = currentId;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   209
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   210
    //On récupère les attributs de l'image.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   211
    var fakeImg = $('img', snapshot);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   212
    //On forme la balise de la fausse image et on passe son url pour les grands snapshots.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   213
    fakeImg = '<img id="fake-' + currentId + '" class="snapshots" src="' + fakeImg.attr('src').replace('-little/', '/') + '" />';
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   214
    //On génère un faux snapshot identique au précédent et qu'on va coller dessus.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   215
    var fakeSnapshot = '<div id="prezoomContainer-' + currentId + '" class="prezoomContainers"><div id="prezoomSnapshot-' + currentId + '" class="snapshotDivs">' + fakeImg + '</div></div>';
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   216
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   217
    //On l'ajoute à la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   218
    $('#mainPanel').append(fakeSnapshot);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   219
    //On modifie ses attributs.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   220
    $('#fake-' + currentId).load(function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   221
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   222
        $('#prezoomContainer-' + currentId).css('display', 'block');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   223
        $('#prezoomContainer-' + currentId).css('top', sTop).css('left', sLeft).css('width', (snWidth + margin)).css('height', (snHeight + margin));
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   224
        $('#prezoomSnapshot-' + currentId).css('width', (snWidth)).css('height', (snHeight));
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   225
        
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   226
        //Dimensions et coordonnées initiales du div sur lequel on zoom.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   227
        var initialDivWidth = $('#prezoomContainer-' + currentId).width(), initialDivHeight = $('#prezoomContainer-' + currentId).height();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   228
        var initialDivTop = $('#prezoomContainer-' + currentId).position().top, initialDivLeft = $('#prezoomContainer-' + currentId).position().left;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   229
        //Dimensions et coordonnées finales du div.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   230
        var finalDivWidth = initialDivWidth * (prezoomPercentage+1), diffWidth = finalDivWidth - initialDivWidth, finalDivHeight = initialDivHeight + diffWidth;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   231
        var finalDivTop = (initialDivTop - (finalDivHeight - snHeight)/2), finalDivLeft = (initialDivLeft - (finalDivWidth - snWidth)/2);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   232
        
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   233
        //CAS PARTICULIER pour la position du snapshot zoomé : les bordures.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   234
        if(finalDivTop < 0)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   235
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   236
            finalDivTop = -margin;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   237
		}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   238
        if(finalDivTop + finalDivHeight > h)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   239
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   240
            finalDivTop = h - finalDivHeight;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   241
		}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   242
        if(finalDivLeft < 0)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   243
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   244
            finalDivLeft = 0;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   245
		}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   246
        if(finalDivLeft + finalDivWidth + margin*2 > w)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   247
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   248
            finalDivLeft = w - finalDivWidth - margin*2;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   249
		}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   250
        
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   251
        ////Code de debug.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   252
        ////CAUTION////
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   253
        /*var red = '<div id="red"></div>';
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   254
        if($('#red') != null || $('#red') != undefined)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   255
            $('body').append(red);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   256
        $('#red').css('background-color', '#FF0000').css('position', 'absolute').css('top', '0px').css('left', '0px').css('width', '100px').css('height', '100px');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   257
        $('#red').css('top', finalDivTop).css('left', finalDivLeft).css('width', finalDivWidth).css('height', finalDivHeight);*/
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   258
        //alert("initial : " + initialDivWidth + " " + initialDivHeight + " ; final : " + finalDivWidth + " " + finalDivHeight);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   259
        ////CAUTION////
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   260
        
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   261
        //On prézoom le div en le centrant sur le milieu du snapshot pointé.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   262
        $('#prezoomSnapshot-' + currentId).animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   263
        {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   264
            width: finalDivWidth + margin,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   265
            height: finalDivHeight - margin*2,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   266
            top: finalDivTop + margin,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   267
            left: finalDivLeft + margin
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   268
        }, this.preZoomTime);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   269
        $('#prezoomContainer-' + currentId).animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   270
        {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   271
            width: finalDivWidth + margin*2,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   272
            height: finalDivHeight - margin,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   273
            top: finalDivTop + margin,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   274
            left: finalDivLeft
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   275
        }, this.preZoomTime);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   276
    });
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   277
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   278
    //Si on clique sur le snapshot prézoomé, on enclenche un zoom total sur ce snapshot.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   279
    $('#prezoomContainer-' + currentId).click(function ()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   280
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   281
        if(this.previousZoomedSN != '')
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   282
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   283
            mosaic.zoom();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   284
		}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   285
    });
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   286
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   287
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   288
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   289
 * 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é.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   290
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   291
mosaic.prototype.preUnzoom = function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   292
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   293
    //Si on n'a pas zoomé, on quitte la fonction.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   294
    if(!this.zoomed)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   295
	{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   296
        return;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   297
	}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   298
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   299
    //On spécifie la marge afin de centrer le prédézoom.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   300
    var margin = this.marginWidth;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   301
    //ID du snapshot précédemment pointé.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   302
    var id = this.previousId;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   303
    //On ne zoom plus.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   304
    this.zoomed = false;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   305
    //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.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   306
    $('#prezoomSnapshot-' + id).animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   307
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   308
        width: this.snapshotWidth,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   309
        height: this.snapshotHeight,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   310
        top: this.previousZoomedSN.position().top,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   311
        left: this.previousZoomedSN.position().left
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   312
    }, this.preUnzoomTime);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   313
    $('#prezoomContainer-' + id).animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   314
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   315
        width: this.snapshotWidth + margin,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   316
        height: this.snapshotHeight + margin,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   317
        top: this.previousZoomedSN.position().top,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   318
        left: this.previousZoomedSN.position().left
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   319
    }, this.preUnzoomTime, function(){ $(this).remove(); this.zoomed = false; });
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   320
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   321
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   322
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   323
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   324
 * Zoom d'un snapshot en plein écran.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   325
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   326
mosaic.prototype.zoom = function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   327
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   328
    var mos = this;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   329
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   330
    //Si la mosaïque est en pleine écran, pas la peine de zoomer.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   331
    if(this.fullscreen)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   332
	{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   333
        return;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   334
	}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   335
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   336
    //On prend les attributs nécessaires au calculs.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   337
    var margin = this.marginWidth, len = this.length, imgs = this.imagesToShow;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   338
    var initMPWidth = this.previousZoomedSN.width() * len + margin*len, initMPHeight = this.previousZoomedSN.height() * (imgs / len) + margin*(imgs / len);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   339
    var newMPWidth = initMPWidth * len + this.zoomedMargin * (len), newMPHeight = initMPHeight * (imgs / len) + this.zoomedMargin * ((imgs / len));
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   340
    var newPreMPWidth = initMPWidth * len * this.zoomPercentage + this.zoomedMargin * (len), newPreMPHeight = initMPHeight * (imgs / len) * this.zoomPercentage + this.zoomedMargin * ((imgs / len));
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   341
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   342
    //Dimensions et coordonnées initiales du div sur lequel on zoom.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   343
    var initialDivWidth = this.previousZoomedSN.width(), initialDivHeight = this.previousZoomedSN.height();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   344
    var initialDivTop = this.previousZoomedSN.position().top, initialDivLeft = this.previousZoomedSN.position().left;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   345
    //Dimensions et coordonnées finales du div.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   346
    var finalDivWidth = initialDivWidth * (this.zoomPercentage+1), finalDivHeight = initialDivHeight * (this.zoomPercentage+1);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   347
    var newZoomTop = -this.previousZoomedSN.position().top*(newPreMPHeight/initMPHeight) - this.zoomedMargin/2 + (initMPHeight - initMPHeight * this.zoomPercentage)/2, newZoomLeft = -this.previousZoomedSN.position().left*(newPreMPWidth/initMPWidth) - this.zoomedMargin/2 + (initMPWidth - initMPWidth * this.zoomPercentage)/2;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   348
    var newSnWidth = initMPWidth * this.zoomPercentage, newSnHeight = initMPHeight * this.zoomPercentage;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   349
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   350
    this.preUnzoom(this);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   351
    /*SINGULARITE*/
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   352
    this.fullscreen = true;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   353
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   354
    //On passe l'image du snapshot pointé en HD.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   355
    var zoomedImg = $('img', this.previousZoomedSN);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   356
    var src = zoomedImg.attr('src');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   357
    zoomedImg.attr('src', src.replace('-little/', '/'));
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   358
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   359
    //On récupère son ID.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   360
    var tab, zoomedImgId;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   361
    tab = mos.previousId.split('-');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   362
    zoomedImgId = tab[1];
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   363
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   364
    //Les snapshots baissent alors en opacité, donnant l'impression qu'ils sont grisés.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   365
    $('.snapshotDivs').animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   366
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   367
        width: newSnWidth,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   368
        height: newSnHeight,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   369
        margin: this.zoomedMargin/2 + 'px',
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   370
        opacity: '0.4'
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   371
    }, this.zoomTime);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   372
    //Le snapshot du milieu revient à une opacité optimale, ce qui attire l'attention de l'utilisateur.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   373
    $(this.previousZoomedSN).animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   374
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   375
        opacity: '1'
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   376
    }, this.zoomTime);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   377
    //On zoome sur la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   378
    $('#mainPanel').animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   379
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   380
        width: newPreMPWidth,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   381
        height: newPreMPHeight,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   382
        top: newZoomTop,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   383
        left: newZoomLeft
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   384
    }, this.zoomTime, function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   385
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   386
        //On charge les interactions avec les voisins.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   387
        mos.centerId = zoomedImgId;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   388
        mos.listenToNeighbours();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   389
        mos.currentMode = 'VIDEO';
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   390
		
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   391
		console.log('h : ' + -newZoomLeft + " " + zoomedImg.position().left);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   392
		
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   393
		mos.loadPlayer((zoomedImg.position().top + newZoomTop + mos.MPTop_margin), (zoomedImg.position().left + newZoomLeft), newSnWidth + 1, newSnHeight + 1);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   394
		
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   395
        /*mos.unload();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   396
        mos.localMos.loadLocalMosaic(newZoomTop, newZoomLeft, newSnWidth, newSnHeight, mos.imgs, tab[1]);*/
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   397
    });
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   398
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   399
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   400
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   401
 * Chargement du player basé sur le metadataplayer.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   402
*/
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   403
mosaic.prototype.loadPlayer = function(newZoomTop, newZoomLeft, newSnWidth, newSnHeight)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   404
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   405
	//On configure les options de lancement.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   406
	IriSP.libFiles.defaultDir = "../lib/";
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   407
	IriSP.widgetsDir = "./player/metadataplayer/"
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   408
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   409
	var videoToPlay = this.videos[this.centerId];
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   410
	var currentMetadata = this.urls[this.centerId];
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   411
	console.log('VIDEO[' + this.centerId + '] : ' + videoToPlay);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   412
	console.log('MD[' + this.centerId + '] : ' + currentMetadata);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   413
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   414
	console.log(newZoomTop + " " + newZoomLeft);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   415
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   416
	var _metadata = {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   417
		url: currentMetadata,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   418
		format: 'ldt'
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   419
	};
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   420
	var _config = {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   421
		gui: {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   422
			width: newSnWidth,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   423
			height: newSnHeight,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   424
			container: 'LdtPlayer',
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   425
			default_options: {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   426
				metadata: _metadata
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   427
			},
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   428
			css:'./player/metadataplayer/LdtPlayer-core.css',
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   429
			widgets: [
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   430
				{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   431
					type: "Timeline"
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   432
				}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   433
			]
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   434
		},
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   435
		player:{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   436
			type: 'html5', // player type
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   437
			video: videoToPlay,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   438
			live: true,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   439
			height: newSnHeight,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   440
			width: newSnWidth,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   441
			autostart: true
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   442
		}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   443
	};
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   444
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   445
	//On positionne le player.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   446
	$('.LdtPlayer').css(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   447
	{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   448
		//display: 'none',
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   449
		position: 'absolute',
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   450
		'background-color': '#000000',
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   451
		top: newZoomTop,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   452
		left: newZoomLeft
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   453
	});
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   454
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   455
	//On démarre le player.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   456
	this.player = null;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   457
	this.player = new IriSP.Metadataplayer(_config, _metadata);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   458
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   459
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   460
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   461
 * Retour à la taille normale de la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   462
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   463
mosaic.prototype.unzoom = function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   464
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   465
    //Si on n'est pas en plein écran, on quitte.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   466
    if(!this.fullscreen)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   467
	{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   468
        return;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   469
	}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   470
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   471
    //On charge les attributs nécessaires aux calculs.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   472
    var sWidth = this.snapshotWidth, sHeight = this.snapshotHeight;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   473
    var mpWidth = this.width, mpHeight = this.height;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   474
    var mos = this;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   475
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   476
    //On passe le snapshot sur lequel on a zoomé en SD.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   477
    var zoomedImg = $('img', this.previousZoomedSN);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   478
    var src = zoomedImg.attr('src');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   479
    zoomedImg.attr('src', src.replace('snapshots/', 'snapshots-little/'));
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   480
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   481
	$('div').remove('.LdtPlayer');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   482
	$('body').append('<div class="LdtPlayer" id="LdtPlayer"></div>');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   483
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   484
    //On rend leur opacité aux snapshots. Qui ne sont alors plus grisés.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   485
    $('.snapshotDivs').animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   486
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   487
        width: sWidth,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   488
        height: sHeight,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   489
        margin: this.marginWidth/2 + 'px',
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   490
        opacity: '1'
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   491
    }, this.unzoomTime);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   492
    //On dézoom sur la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   493
    $('#mainPanel').animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   494
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   495
        width: mpWidth,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   496
        height: mpHeight,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   497
        top: '0px',
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   498
        left: '0px'
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   499
    }, this.unzoomTime, function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   500
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   501
        //On n'est plus en plein écran, et on ne peut plus se déplacer vers le prochain voisin.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   502
        mos.fullscreen = false;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   503
        mos.canMoveToNeighbour = false;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   504
        //On revient en mode MOSAIC.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   505
        mos.currentMode = 'MOSAIC';
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   506
        //On ne permet plus le déplacement vers les voisins.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   507
        $('.snapshotDivs').unbind('mouseenter', mos.selectNeighbour);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   508
    });
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   509
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   510
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   511
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   512
 * Affecte les listeners mouseenter aux voisins lors d'une vue en plein écran.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   513
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   514
mosaic.prototype.listenToNeighbours = function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   515
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   516
    ////TEST
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   517
    //$('.test').empty();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   518
    this.canMoveToNeighbour = false;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   519
    var currentLine = Math.floor(this.centerId / this.length), currentColumn = this.centerId % this.length;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   520
    var zoomedImg = $('img', this.previousZoomedSN);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   521
    var mos = this;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   522
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   523
    //On cherche l'ID des voisins.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   524
    //Si le voisin de gauche est sur la même ligne, on n'est pas sur la bordure de gauche.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   525
    this.neighboursIds[0] = (currentColumn > 0) ? (this.centerId - 1) : -1;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   526
    //Si le voisin de droite est sur la même ligne, on n'est pas sur la bordure de droite.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   527
    this.neighboursIds[1] = (currentColumn < this.length) ? (+this.centerId + 1) : -1;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   528
    //Si le voisin du haut est sur la même colonne, on n'est pas sur la bordure du haut.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   529
    this.neighboursIds[2] = (currentLine > 0) ? (this.centerId - this.length) : -1;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   530
    //Si le voisin du bas est sur la même colonne, on n'est pas sur la bordure du bas.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   531
    this.neighboursIds[3] = (currentLine < (this.imagesToShow / this.length)) ? (+this.centerId + this.length) : -1;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   532
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   533
	//ID du cadre voisin.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   534
	var preId;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   535
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   536
    for(var i = 0 ; i < this.neighboursIds.length ; i++)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   537
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   538
        if(this.neighboursIds[i] != -1)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   539
        {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   540
			preId = '#neighbourFrameBorder-' + this.neighboursIds[i];
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   541
            //On permet le déplacement vers les voisins.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   542
            // $('#snapshotDiv-' + this.neighboursIds[i] + ', ' + preId + '-left,' + preId + '-right,' + preId + '-up,' + preId + '-down').mouseenter(mos.selectNeighbour);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   543
            $('#snapshotDiv-' + this.neighboursIds[i]).mouseenter(mos.selectNeighbour);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   544
        }
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   545
    }
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   546
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   547
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   548
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   549
 * Change la coloration d'une bordure où on se positionne lors d'une vue en plein écran.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   550
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   551
mosaic.prototype.selectNeighbour = function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   552
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   553
    ////TEST
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   554
    //$('.test').append(mos.currentMode + " " + $(this).attr('id') + " " + 'snapshotDiv-' + mos.centerId + ',');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   555
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   556
    //Si on est en mode VIDEO (plein écran) ET si le snapshot pointé est un voisin.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   557
    if((mos.currentMode == 'VIDEO') && ($(this).attr('id') != 'snapshotDiv-' + mos.centerId))
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   558
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   559
        //On crée le cadre qui va être superposé au voisin.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   560
        //On le colle au voisin.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   561
		var tab = $(this).attr('id').split('-');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   562
		var snapshotId = tab[1];
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   563
        var neighbourFrame = '';
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   564
		var marginValue = parseFloat($(this).css('margin'));
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   565
		
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   566
		neighbourFrame += '<div class="neighbourFrame" id="neighbourFrame-' + snapshotId + '"><div class="neighbourImgBg" id="neighbourImgBg-' + snapshotId + '"><div class="neighbourImg" id="neighbourImg-' + snapshotId + '"></div></div></div>';
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   567
		
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   568
        $('#mainPanel').append(neighbourFrame);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   569
		
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   570
		//On positionne le div de background juste au niveau du voisin.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   571
        $('#neighbourFrame-' + snapshotId).css(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   572
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   573
			'top': (+$(this).position().top + marginValue),
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   574
			'left': (+$(this).position().left + marginValue),
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   575
			'width': $(this).width(),
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   576
			'height': $(this).height()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   577
		});
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   578
		//On positionne le div de background noir juste au niveau de l'image du voisin.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   579
        $('#neighbourImgBg-' + snapshotId).css(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   580
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   581
			'top': marginValue,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   582
			'left': marginValue,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   583
			'width': $(this).width() - marginValue*2,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   584
			'height': $(this).height() - marginValue*2,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   585
		});
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   586
		//On met par dessus le div de l'image clonée du voisin.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   587
		$('#neighbourImg-' + snapshotId).css(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   588
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   589
			'top': 0,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   590
			'left': 0,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   591
			'width': $(this).width() - marginValue*2,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   592
			'height': $(this).height() - marginValue*2,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   593
			'background-image': 'url("' + $('img', $(this)).attr('src') + '")',
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   594
			'background-size': $(this).width() + 'px ' + $(this).height() + 'px',
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   595
			'background-position': -marginValue + 'px ' + -marginValue + 'px',
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   596
			'opacity': '0.4'
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   597
		});
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   598
		
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   599
		var fId = '#neighbourFrame-' + snapshotId;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   600
		
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   601
		$(fId).animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   602
        {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   603
            //On le fait apparaître.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   604
            opacity: '1'
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   605
        }, timeNeighbourGlowing, function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   606
        {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   607
            //On peut désormais se déplacer vers ce voisin.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   608
            mos.canMoveToNeighbour = true;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   609
        });
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   610
		//Lorsqu'on quitte un des snapshots (bien entendu le voisin en question), on retire le cadre.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   611
		$(fId).mouseleave(mos.deselectNeighbour)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   612
		//Si on clique sur le voisin ou son cadre, on passe au voisin suivant.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   613
		$(fId).click(mos.moveToNeighbour);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   614
    }
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   615
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   616
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   617
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   618
 * Change la coloration d'une bordure quittée lors d'une vue en plein écran.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   619
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   620
mosaic.prototype.deselectNeighbour = function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   621
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   622
    ////TEST
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   623
    //$('.test').append('un,');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   624
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   625
    //On ne peut plus se déplacer vers les voisins.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   626
    mos.canMoveToNeighbour = false;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   627
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   628
	//On récupère le voisin.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   629
	var neighbourFrame = $(this);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   630
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   631
    //Si on est en mode VIDEO.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   632
    if(mos.currentMode == 'VIDEO')
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   633
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   634
        //On le fait disparaître progressivement.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   635
        neighbourFrame.animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   636
        {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   637
            opacity: '0'
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   638
        }, timeNeighbourUnglowing, function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   639
        {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   640
            //Une fois invisible, on le supprime.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   641
            neighbourFrame.remove();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   642
        });
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   643
    }
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   644
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   645
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   646
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   647
 * 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.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   648
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   649
mosaic.prototype.moveToNeighbour = function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   650
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   651
    //Si on ne peut pas se déplacer vers les voisins, on quitte.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   652
    if(!mos.canMoveToNeighbour)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   653
	{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   654
        return;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   655
	}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   656
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   657
    //On obtient l'ID de destination.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   658
    var tab = $(this).attr('id').split('-');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   659
    var destinationId = tab[1];
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   660
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   661
    //On charge les attributs nécessaires aux calculs.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   662
    var MPCurrentTop = $('#mainPanel').position().top, MPCurrentLeft = $('#mainPanel').position().left;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   663
    var divideCoeffTop = Math.floor(destinationId / mos.length) == 0 ? 1 : Math.floor(destinationId / mos.length);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   664
    var divideCoeffLeft = destinationId % mos.length == 0 ? 1 : destinationId % mos.length;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   665
    var neighbourFrameTop = $('#snapshotDiv-' + destinationId).position().top, neighbourFrameLeft = $('#snapshotDiv-' + destinationId).position().left;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   666
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   667
    //On définit pour le déplacement vertical s'il est nécessaire de se déplacer en haut ou en bas.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   668
    if(mos.previousZoomedSN.position().top > neighbourFrameTop)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   669
        MPCurrentTop += Math.abs(neighbourFrameTop - mos.previousZoomedSN.position().top);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   670
    else if(mos.previousZoomedSN.position().top < neighbourFrameTop)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   671
        MPCurrentTop -= Math.abs(neighbourFrameTop - mos.previousZoomedSN.position().top);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   672
    //On définit pour le déplacement horizontal s'il est nécessaire de se déplacer à gauche ou à droite.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   673
    if(mos.previousZoomedSN.position().left > neighbourFrameLeft)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   674
        MPCurrentLeft += Math.abs(neighbourFrameLeft - mos.previousZoomedSN.position().left);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   675
    else if(mos.previousZoomedSN.position().left < neighbourFrameLeft)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   676
        MPCurrentLeft -= Math.abs(neighbourFrameLeft - mos.previousZoomedSN.position().left);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   677
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   678
    //On passe le snapshot de destination en HD.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   679
    var destinationImg = $('#snapshot-' + destinationId);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   680
    var destinationImgSrc = destinationImg.attr('src');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   681
    destinationImg.attr('src', destinationImgSrc.replace('snapshots-little/', 'snapshots/'));
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   682
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   683
    //On passe l'ancien snapshot en SD.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   684
    var currentImgSrc = $('img', mos.previousZoomedSN).attr('src');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   685
    $('img', mos.previousZoomedSN).attr('src', currentImgSrc.replace('snapshots/', 'snapshots-little/'));
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   686
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   687
    //On obtient l'ID du div de coloration du snapshot vers lequel on se déplace afin de le supprimer.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   688
    var neighbourFrame = $(this);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   689
    var tab = neighbourFrame.attr('id').split('-');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   690
    mos.centerId = tab[1];
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   691
    $(this).css('opacity', '0');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   692
    neighbourFrame.remove();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   693
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   694
	$('div').remove('.LdtPlayer');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   695
	$('body').append('<div class="LdtPlayer" id="LdtPlayer"></div>');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   696
	
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   697
    //On grise le snapshot qu'on vient de quitter.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   698
    mos.previousZoomedSN.animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   699
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   700
        opacity: '0.4'
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   701
    });
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   702
    
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   703
    //On se déplace.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   704
    $('#mainPanel').animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   705
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   706
        top: MPCurrentTop,
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   707
        left: MPCurrentLeft
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   708
    }, timeMovingToNeighbour, function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   709
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   710
        //On fait apparaître le snapshot vers lequel on s'est déplacé.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   711
        $('#snapshotDiv-' + destinationId).animate(
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   712
        {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   713
            opacity: '1'
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   714
        }, mos.zoomTime, function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   715
        {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   716
            //On recharge les voisins.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   717
            $('.snapshotDivs').unbind('mouseenter', mos.selectNeighbour);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   718
            mos.previousZoomedSN = $('#snapshotDiv-' + mos.centerId);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   719
            mos.listenToNeighbours();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   720
			
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   721
			mos.loadPlayer((destinationImg.position().top + MPCurrentTop + mos.MPTop_margin), (destinationImg.position().left + MPCurrentLeft), destinationImg.width(), destinationImg.height());
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   722
        });
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   723
    });
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   724
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   725
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   726
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   727
 * Déchargement du contenu de la mosaïque pour le chargement de la mosaïque locale.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   728
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   729
mosaic.prototype.unload = function()
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   730
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   731
    //On supprime les event listeners des objets de la mosaïque.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   732
    $('.snapshotDivs').unbind();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   733
    $('.snapshots').unbind();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   734
    $('.prezoomContainers').unbind();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   735
    //On supprime physiquement les objets.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   736
    $('#mainPanel').empty();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   737
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   738
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   739
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   740
 * Centre verticalement un snapshot.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   741
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   742
/*function verticalCenterImg(mosaic, img)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   743
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   744
    //On récupère sa hauteur.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   745
    var image_height = img.height();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   746
    //Calcule la marge du haut de chaque div pour le centrage.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   747
    if(mosaic.top_margin == undefined)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   748
        mosaic.top_margin = (mosaic.snapshotHeight > image_height) ? (mosaic.snapshotHeight - image_height)/2 : (image_height - mosaic.snapshotHeight)/2;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   749
    //On centre le snapshot.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   750
    img.css('margin-top', mosaic.top_margin).css('margin-bottom', mosaic.top_margin);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   751
}*/
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   752
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   753
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   754
 * Permet de tester l'égalité des éléments de deux objets.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   755
 * Pour ce faire on compare les éléments définissant ces objets.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   756
 */
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   757
$.fn.equals = function(compareTo)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   758
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   759
    if (!compareTo || !compareTo.length || this.length!=compareTo.length)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   760
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   761
        return false;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   762
    }
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   763
    for (var i=0; i<this .length; i++)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   764
    {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   765
        if (this[i]!==compareTo[i])
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   766
        {
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   767
            return false;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   768
        }
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   769
    }
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   770
    return true;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   771
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   772
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   773
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   774
 * Charge les vidéos, les snapshots et les annotations depuis un fichier json.
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   775
*/
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   776
mosaic.prototype.loadFromJson = function(path)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   777
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   778
	var _this = this;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   779
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   780
	$.getJSON(path, function(data)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   781
	{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   782
		$.each(data, function(key, val)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   783
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   784
			// console.log(val);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   785
			$.each(val, function(key_video, val_video)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   786
			{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   787
				$.getJSON(val_video.metadata, function(meta)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   788
				{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   789
					_this.affectVideoById(val_video.metadata, meta.medias[0].url.replace('rtmp://', 'http://').replace('/ddc_player/', '/'));
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   790
					//console.log(meta.medias[0].url.replace('rtmp://', 'http://').replace('/ddc_player/', '/'));
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   791
				});
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   792
				
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   793
				_this.imgs.push(val_video.snapshot);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   794
				_this.urls.push(val_video.metadata);
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   795
			});
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   796
		});
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   797
		console.log('rdy');
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   798
		_this.loadMosaic();
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   799
	});
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   800
}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   801
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   802
/*
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   803
 * Affecte une vidéo au tableau des vidéos selon son id
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   804
*/
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   805
mosaic.prototype.affectVideoById = function(metadata_id, video)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   806
{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   807
	for (i = 0 ; i < this.urls.length ; i++)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   808
	{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   809
		if(this.urls[i] == metadata_id)
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   810
		{
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   811
			this.videos[i] = video;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   812
			break;
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   813
		}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   814
	}
4003f84cd349 Front IDILL :
bastiena
parents:
diff changeset
   815
}