Subversion Repositories eFlore/Applications.cel

Rev

Rev 3823 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3631 idir 1
function WidgetPhotoPopup( proprietes ) {
2
	if( this.valOk( proprietes ) ) {
3
		this.urlWidget    = proprietes.urlWidget;
4
		this.urls         = proprietes.urls;
5
		this.infos_images = proprietes.infos_images;
6
		this.indexImage   = proprietes.indexImage;
7
		this.urlImage     = proprietes.urlImage;
8
		this.tailleMax    = proprietes.tailleMax;
9
		this.popup_url       = proprietes.popup_url;
10
	}
11
}
12
 
13
WidgetPhotoPopup.prototype =  new WidgetPhotoCommun();
14
 
15
WidgetPhotoPopup.prototype.initTpl = function() {
16
	this.redimensionnerGalerie();
17
	if( this.valOk( this.urlImage, false, 'null' ) ) {
18
		this.indexImage = this.urls.indexOf( this.urlImage );
19
		$( '#info-img-galerie' ).find( '.active' ).removeClass( 'active' );
20
		$( '#img-cadre-' + this.indexImage + ',#indicateur-img-' + this.indexImage ).addClass( 'active' );
21
		this.afficherTitreImage();
22
	}
23
	this.redimentionnerModaleCarousel();
24
};
25
 
26
WidgetPhotoPopup.prototype.initEvts = function() {
27
	const lthis = this;
28
 
29
	this.initEvtsDefilerImage();
30
	this.initEvtsContact();
31
	$( window ).on( 'resize', lthis.redimentionnerModaleCarousel.bind( lthis ) );
32
	this.initEvtsFonstionsPhoto();
33
	this.initEvtsRetourGalerieResponsive();
34
	this.initEvtsTagsPF();
35
};
36
 
37
WidgetPhotoPopup.prototype.initEvtsDefilerImage = function() {
38
	const lthis = this;
39
 
40
	$( '#precedent, #suivant' ).on( 'click', function() {
41
		lthis.defilerImage( this.id );
42
	});
43
	$( '#print_content:not(saisir-tag)' ).on( 'keydown', function( event ) {
44
		var sens = '';
45
 
46
		event = event || window.event;
47
		// event.keyCode déprécié, on tente d'abord event.key
48
		if ( 'key' in event ) {
49
			if( event.key === 'ArrowLeft') { // gauche
50
				sens = 'suivant';
51
			} else if ( event.key === 'ArrowRight' ) {  // droite
52
				sens = 'precedent';
53
			}
54
		} else if( event.keyCode == 37 ) { // gauche
55
			sens = 'suivant';
56
		} else if( event.keyCode == 39 ) { // droite
57
			sens = 'precedent';
58
		}
59
		if ( lthis.valOk( sens ) ) {
60
			lthis.defilerImage( sens );
61
		}
62
	});
63
};
64
 
65
WidgetPhotoPopup.prototype.initEvtsContact = function() {
66
	const lthis = this;
67
 
68
	$( '#bloc-infos-img' ).on( 'click', '.lien_contact', function( event ) {
69
		event.preventDefault();
70
		lthis.chargerContenuModale( this.href );
71
	});
72
};
73
 
74
WidgetPhotoPopup.prototype.initEvtsFonstionsPhoto = function() {
75
	const lthis = this;
76
 
77
	$( '#boutons-footer #bloc-fct a, #retour-metas' ).on( 'click', function( event ){
78
		event.preventDefault();
79
		var voletAOuvrir = $( this ).data( 'volet' ),
80
			voletAFermer = $( '.bloc-volet:not(.hidden)' ).data( 'volet' );
81
 
82
		lthis.ouvrirVoletFct( voletAOuvrir, voletAFermer );
83
		if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
84
			$( '#info-img-galerie' ).addClass( 'hidden' );
85
			$( '#volet, #retour-galerie' ).removeClass( 'hidden' );
86
		}
87
	});
88
};
89
 
90
WidgetPhotoPopup.prototype.initEvtsRetourGalerieResponsive = function() {
91
	$( '#retour-galerie' ).on( 'click', function( event ) {
92
		event.preventDefault();
93
		$( '#info-img-galerie' ).removeClass( 'hidden' );
94
		$( this ).addClass( 'hidden' );
95
		if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
96
			$( '#volet' ).addClass( 'hidden' );
97
			$( '.bouton-fct.actif' ).removeClass( 'actif' );
98
		}
99
	});
100
};
101
 
102
WidgetPhotoPopup.prototype.initEvtsTagsPF = function() {
103
	//recupérer tags en ajax (voir pictoflora, peut-être dans le php?)
104
	//	_OPTIONS
105
	// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
106
	//	_GET
107
	// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
108
	this.tagsPfCustom();
109
	$( '#bloc-tags' ).on( 'click', '.tag', function( event ) {
110
		event.preventDefault();
111
		$( this ).toggleClass( 'actif' );
112
	});
113
	$( '#bloc-tags' ).on( 'click', '.custom-tag.actif .fermer', function( event ) {
114
		event.preventDefault();
115
		//			Supprimer un custom-tag
116
		//	_OPTIONS
117
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
118
		// 	_paramètres
119
		// L'id du tag à la fin de l'url
120
		//	_DELETE
121
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
122
		// 	_réponse:
123
		// ""
124
		// 			Mettre à jour les mots cles
125
		//	_OPTIONS
126
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
127
		//	_GET
128
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
129
		$( this ).parent( '.custom-tag' ).remove();
130
	});
131
 
132
	$( '#bloc-tags' ).on( 'keyup', '.custom-tag.actif', function( event ) {
133
		var supprimerTag = false;
134
 
135
		event = event || window.event;
136
		// event.keyCode déprécié, on tente d'abord event.key
137
		if ( 'key' in event ) {
138
			supprimerTag = ( 'Delete' === event.key || 'Backspace' === event.key );
139
		} else {
140
			supprimerTag = ( 46 === event.keyCode || 8 === event.keyCode );
141
		}
142
		if ( supprimerTag ) {
143
		//			Supprimer un custom-tag
144
		//	_OPTIONS
145
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
146
		// 	_paramètres
147
		// L'id du tag à la fin de l'url
148
		//	_DELETE
149
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
150
		// 	_réponse:
151
		// ""
152
		// 			Mettre à jour les mots cles
153
		//	_OPTIONS
154
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
155
		//	_GET
156
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
157
			$( this ).parent( '.custom-tag' ).remove();
158
		}
159
	});
160
};
161
 
162
WidgetPhotoPopup.prototype.defilerImage = function( sens ) {
163
	if ( this.valOk( sens, true, 'suivant' ) ) {
164
		this.indexImage++ ;
165
		if( this.indexImage >= this.urls.length ) {
166
			this.indexImage = 0;
167
		}
168
	} else if ( this.valOk( sens, true, 'precedent' ) ) {
169
		this.indexImage--;
170
		if( this.indexImage <= 0 ) {
171
			this.indexImage = this.urls.length -1;
172
		}
173
	}
174
	this.afficherTitreImage();
175
};
176
 
177
WidgetPhotoPopup.prototype.afficherTitreImage = function() {
178
	var item         = this.infos_images[this.urls[this.indexImage]],
179
		titre        = item['titre'],
180
		infos        = this.decouperTitre( titre ),
181
		urlThisImage = $( '#illustration-' + this.indexImage ).attr( 'src' );
182
		lienContact  =
183
			this.urlWidget +'?mode=contact&nn=' + infos.nn +
184
			'&nom_sci=' + infos.nom_sci +
185
			'&date=' + infos.date +
186
			'&id_image=' + item['guid'] +
187
			'&auteur=' + infos.auteur;
188
 
189
	if ( this.valOk( this.popup_url ) ) {
190
		if (! this.popup_url.match( new RegExp( '/img:000' + item['guid'] ) ) ) {
191
			this.popup_url = this.actualiserPopupUrl( this.popup_url, urlThisImage );
192
		}
193
		lienContact += '&popup_url=' + encodeURIComponent( this.popup_url );
194
	}
195
 
196
	titre =
197
		'<a href="' + item['lien'] + '">' + infos.nom_sci + '</a> '+
198
		' par <a class="lien_contact" href="' + lienContact + '">' + infos.auteur + '</a> '+
199
		' le ' + infos.date + ' ';
200
	$( '#bloc-infos-img' ).html( titre );
201
};
202
 
203
WidgetPhotoPopup.prototype.decouperTitre = function( titre ) {
204
	var tab_titre       = titre.split( '[nn' ),
205
		nom_sci         = tab_titre[0],
206
		tab_titre_suite = tab_titre[1].split( ' par ' ),
207
		nn              = '[nn' + tab_titre_suite[0],
208
		tab_titre_fin   = tab_titre_suite[1].split( ' le ' ),
209
		utilisateur     = tab_titre_fin[0],
210
		date            = tab_titre_fin[1],
211
		titre_decoupe = {
212
			'nom_sci' : nom_sci,
213
			'nn'      : nn,
214
			'date'    : date,
215
			'auteur'  : utilisateur
216
		};
217
 
218
	return titre_decoupe;
219
};
220
 
221
WidgetPhotoPopup.prototype.actualiserPopupUrl = function( queryString, remplacement ) {
222
	const lthis = this;
223
	var queryStringParsee = queryString.substring(1).split('&');
224
 
225
	$.each( queryStringParsee,  function( i, param ) {
226
		if( /url_image/.test( param ) ) {
227
			queryString = queryString.replace( param, 'url_image=' + remplacement );
228
			return false;
229
		}
230
	});
231
	return queryString;
232
};
233
 
234
WidgetPhotoPopup.prototype.redimentionnerModaleCarousel = function() {
235
	this.redimensionnerGalerie();
236
	if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
237
		$( '#volet, #retour-galerie' ).addClass( 'hidden' );
238
		$( '#info-img-galerie' ).removeClass( 'hidden' );
239
		$( '.bouton-fct.actif' ).removeClass( 'actif' );
240
		$( '.nettoyage-volet.haut' ).text( $( '#bloc-infos-img' ).text() );
241
		$( '#boutons-footer, #info-img-galerie' ).removeClass( 'col-lg-8' );
242
		$( '#bloc-infos-img, #volet' ).removeClass( 'col-lg-4' );
243
	} else {
244
		$( '#volet, #info-img-galerie' ).removeClass( 'hidden' );
245
		if ( this.valOk( $( '.bloc-volet:not(.hidden)' ) ) ) {
246
			$( '.bouton-fct.' + $( '.bloc-volet:not(.hidden)' ).data( 'volet' ) ).addClass( 'actif' );
247
		}
248
		$( '.nettoyage-volet.bas' ).text( $( '#bloc-infos-img' ).text() );
249
		$( '#boutons-footer, #info-img-galerie' ).addClass( 'col-lg-8' );
250
		$( '#bloc-infos-img, #volet' ).addClass( 'col-lg-4' );
251
		$( '#retour-galerie' ).addClass( 'hidden' );
252
	}
253
};
254
 
255
WidgetPhotoPopup.prototype.redimensionnerGalerie = function() {
256
	const lthis = this;
257
	var maxSize = ( $( window ).width() / $( window ).height() ) < 1 ? $( window ).width() : $( window ).height();
258
 
259
	maxSize -= 30;
260
	$( '.carousel-item img' ).each( function( index, image ) {
261
		var proportion  = image.dataset.width / image.dataset.height,
262
			cssResize   = {};
263
 
264
		if ( proportion >= 1 ) {
265
			cssResize['width'] = maxSize;
266
		}
267
		if ( proportion <= 1) {
268
			cssResize['height'] = maxSize;
269
		}
270
		$( image ).css( cssResize );
271
	});
272
};
273
 
274
WidgetPhotoPopup.prototype.ouvrirVoletFct = function( voletAOuvrir, voletAFermer ) {
275
	if( voletAOuvrir !== voletAFermer ) {
276
		$( '#boutons-footer  .' + voletAFermer ).removeClass( 'actif' );
277
		$( '#boutons-footer  .' + voletAOuvrir ).addClass( 'actif' );
278
		$( '#bloc-' + voletAFermer ).addClass( 'hidden' );
279
		$( '#bloc-' + voletAOuvrir ).removeClass( 'hidden' );
280
		$( '#volet' ).scrollTop(0);
281
		if( 'meta' !== voletAOuvrir ) {
282
			$( '#retour-metas' ).removeClass( 'hidden' );
283
		} else {
284
			$( '#retour-metas' ).addClass( 'hidden' );
285
		}
286
	}
287
};
288
 
289
WidgetPhotoPopup.prototype.tagsPfCustom = function() {
290
	const lthis = this;
291
 
292
	$( '#saisir-tag' ).on( 'blur keyup', function( event ) {
293
		event = event || window.event;
294
 
295
		var ajouterTag = ( 'blur' === event.type );
296
 
297
		// event.keyCode déprécié, on tente d'abord event.key
298
		if ( 'key' in event  ) {
299
			if ( 'Enter' === event.key ) {
300
				ajouterTag = true;
301
			}
302
		} else if ( 13 === event.keyCode ) {
303
			ajouterTag = true;
304
		}
305
		if	( ajouterTag ) {
306
			var nouveauTag     = $( this ).val(),
307
				nouveauTagAttr = lthis.chaineValableAttributsHtml( nouveauTag.toLowerCase() );
308
 
309
			if( lthis.valOk( nouveauTagAttr ) && !lthis.valOk( $( '#' + nouveauTagAttr + '.tag' ) ) ) {
310
				// 			Envoyer tags en ajax :
311
				// 	_OPTIONS
312
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/
313
				//  _paramètres :
314
				//rien
315
				// 	_PUT
316
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/
317
				// 	_paramètres :
318
				// image=197938&mot_cle=motcleperso&auteur.id=44084
319
				// 			Mettre à jour les mots cles
320
				//	_OPTIONS
321
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
322
				//	_GET
323
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
324
				$( '#tags-pf-supp' ).append(
325
					'<a id="' + nouveauTagAttr + '" class="btn tag custom-tag">' +
326
						nouveauTag + '&nbsp;<i class="fas fa-times-circle fermer"></i>' +
327
					'</a>'
328
				);
329
				$( '#form-tags-auteur' )[0].reset();
330
				$( this ).val( '' );
331
			}
332
		}
333
	});
334
};