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