Subversion Repositories eFlore/Applications.cel

Rev

Rev 3631 | Rev 3824 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3631 Rev 3823
1
function WidgetPhotoPopup( proprietes ) {
1
function WidgetPhotoPopup( proprietes ) {
2
	if( this.valOk( proprietes ) ) {
2
	if( this.valOk( proprietes ) ) {
3
		this.urlWidget    = proprietes.urlWidget;
3
		this.urlWidget                    = proprietes.urlWidget;
4
		this.urls         = proprietes.urls;
4
		this.urls                         = proprietes.urls;
5
		this.infos_images = proprietes.infos_images;
5
		this.infos_images                 = proprietes.infos_images;
6
		this.indexImage   = proprietes.indexImage;
6
		this.indexImage                   = proprietes.indexImage;
7
		this.urlImage     = proprietes.urlImage;
7
		this.urlImage                     = proprietes.urlImage;
8
		this.tailleMax    = proprietes.tailleMax;
8
		this.tailleMax                    = proprietes.tailleMax;
9
		this.popup_url       = proprietes.popup_url;
9
		this.popupUrl                     = proprietes.popupUrl;
-
 
10
		this.urlBaseTelechargement        = proprietes.urlBaseTelechargement;
-
 
11
		this.urlServiceRegenererMiniature = proprietes.urlServiceRegenererMiniature;
10
	}
12
	}
-
 
13
 
-
 
14
	this.mettreAJourInfosImage();
11
}
15
}
12
 
16
 
13
WidgetPhotoPopup.prototype =  new WidgetPhotoCommun();
17
WidgetPhotoPopup.prototype =  new WidgetPhotoCommun();
14
 
18
 
15
WidgetPhotoPopup.prototype.initTpl = function() {
19
WidgetPhotoPopup.prototype.initTpl = function() {
16
	this.redimensionnerGalerie();
20
	this.redimensionnerGalerie();
17
	if( this.valOk( this.urlImage, false, 'null' ) ) {
21
	if( this.valOk( this.urlImage, false, 'null' ) ) {
-
 
22
 
18
		this.indexImage = this.urls.indexOf( this.urlImage );
23
		this.indexImage = this.urls.indexOf( this.urlImage );
-
 
24
 
19
		$( '#info-img-galerie' ).find( '.active' ).removeClass( 'active' );
25
		$( '#info-img-galerie' ).find( '.active' ).removeClass( 'active' );
20
		$( '#img-cadre-' + this.indexImage + ',#indicateur-img-' + this.indexImage ).addClass( 'active' );
26
		$( '#img-cadre-' + this.indexImage + ',#indicateur-img-' + this.indexImage ).addClass( 'active' );
-
 
27
 
21
		this.afficherTitreImage();
28
		this.mettreAJourPopup();
22
	}
29
	}
-
 
30
 
23
	this.redimentionnerModaleCarousel();
31
	this.redimentionnerModaleCarousel();
24
};
32
};
25
 
33
 
26
WidgetPhotoPopup.prototype.initEvts = function() {
34
WidgetPhotoPopup.prototype.initEvts = function() {
27
	const lthis = this;
35
	const lthis = this;
28
 
36
 
29
	this.initEvtsDefilerImage();
37
	this.initEvtsDefilerImage();
30
	this.initEvtsContact();
38
	this.initEvtsContact();
31
	$( window ).on( 'resize', lthis.redimentionnerModaleCarousel.bind( lthis ) );
39
	$( window ).on( 'resize', lthis.redimentionnerModaleCarousel.bind( lthis ) );
32
	this.initEvtsFonstionsPhoto();
40
	this.initEvtsFonctionsPhoto();
33
	this.initEvtsRetourGalerieResponsive();
41
	this.initEvtsRetourGalerieResponsive();
34
	this.initEvtsTagsPF();
42
	this.initEvtsTagsPF();
35
};
43
};
-
 
44
 
-
 
45
WidgetPhotoPopup.prototype.mettreAJourPopup = function() {
-
 
46
	this.mettreAJourInfosImage();
-
 
47
	this.afficherTitreImage();
-
 
48
	this.traiterMetas();
-
 
49
	this.regenererMiniature();
-
 
50
	this.fournirLienIdentiplante();
-
 
51
};
-
 
52
 
-
 
53
WidgetPhotoPopup.prototype.mettreAJourInfosImage = function() {
-
 
54
	this.item         = this.infos_images[this.urls[this.indexImage]];
-
 
55
	this.titreImage   = this.item['titre'];
-
 
56
	this.lienEflore   = this.item['lien'];
-
 
57
	this.idImage      = this.item['id_photo'];
-
 
58
	this.urlThisImage = this.item['url_photo']+'.jpg';
-
 
59
	this.obs          = this.item['obs'];
-
 
60
	this.nn           = '[nn' + this.obs['nom_sel_nn']+']';
-
 
61
	this.urlIP        = 'https://'+this.obs['url_ip'];
-
 
62
	this.auteur       = this.item['utilisateur']['nom_utilisateur'];
-
 
63
	this.urlProfil    = '/profil-par-id/'+this.item['utilisateur']['id_utilisateur'];
-
 
64
	this.date         = this.item['date'];
-
 
65
};
36
 
66
 
37
WidgetPhotoPopup.prototype.initEvtsDefilerImage = function() {
67
WidgetPhotoPopup.prototype.initEvtsDefilerImage = function() {
38
	const lthis = this;
68
	const lthis = this;
39
 
69
 
40
	$( '#precedent, #suivant' ).on( 'click', function() {
70
	$( '#precedent, #suivant' ).on( 'click', function() {
41
		lthis.defilerImage( this.id );
71
		lthis.defilerImage( this.id );
42
	});
72
	});
-
 
73
 
43
	$( '#print_content:not(saisir-tag)' ).on( 'keydown', function( event ) {
74
	$( '#print_content:not(saisir-tag)' ).on( 'keydown', function( event ) {
44
		var sens = '';
-
 
45
 
-
 
46
		event = event || window.event;
75
 
47
		// event.keyCode déprécié, on tente d'abord event.key
76
		const determinerSens = function( enventKey, left, right ) {
48
		if ( 'key' in event ) {
77
			switch ( enventKey ) {
49
			if( event.key === 'ArrowLeft') { // gauche
78
				case left:
50
				sens = 'suivant';
79
					return 'suivant';
51
			} else if ( event.key === 'ArrowRight' ) {  // droite
80
				case right:
-
 
81
					return 'precedent'
-
 
82
				default:
52
				sens = 'precedent';
83
					break;
53
			}
-
 
-
 
84
			}
54
		} else if( event.keyCode == 37 ) { // gauche
85
 
55
			sens = 'suivant';
-
 
56
		} else if( event.keyCode == 39 ) { // droite
-
 
57
			sens = 'precedent';
86
			return;
-
 
87
		}
-
 
88
 
-
 
89
		event = (event || window.event);
-
 
90
		// event.keyCode déprécié, on tente d'abord event.key
-
 
91
		let sens = ( 'key' in event ) ? determinerSens( event.key, 'ArrowLeft', 'ArrowRight' ) : determinerSens( event.keyCode, 37, 39 );;
58
		}
92
 
59
		if ( lthis.valOk( sens ) ) {
93
		if ( lthis.valOk( sens ) ) {
60
			lthis.defilerImage( sens );
94
			lthis.defilerImage( sens );
61
		}
95
		}
62
	});
96
	});
63
};
97
};
64
 
98
 
65
WidgetPhotoPopup.prototype.initEvtsContact = function() {
99
WidgetPhotoPopup.prototype.initEvtsContact = function() {
66
	const lthis = this;
100
	const lthis = this;
67
 
101
 
68
	$( '#bloc-infos-img' ).on( 'click', '.lien_contact', function( event ) {
102
	$( '#bloc-infos-img' ).on( 'click', '.lien_contact', function( event ) {
69
		event.preventDefault();
103
		event.preventDefault();
70
		lthis.chargerContenuModale( this.href );
104
		lthis.chargerContenuModale( this.href );
71
	});
105
	});
72
};
106
};
73
 
107
 
74
WidgetPhotoPopup.prototype.initEvtsFonstionsPhoto = function() {
108
WidgetPhotoPopup.prototype.initEvtsFonctionsPhoto = function() {
75
	const lthis = this;
109
	const lthis = this;
76
 
110
 
77
	$( '#boutons-footer #bloc-fct a, #retour-metas' ).on( 'click', function( event ){
111
	$( '#boutons-footer #bloc-fct a, #retour-metas' ).on( 'click', function( event ){
78
		event.preventDefault();
112
		event.preventDefault();
79
		var voletAOuvrir = $( this ).data( 'volet' ),
113
		var voletAOuvrir = $( this ).data( 'volet' ),
80
			voletAFermer = $( '.bloc-volet:not(.hidden)' ).data( 'volet' );
114
			voletAFermer = $( '.bloc-volet:not(.hidden)' ).data( 'volet' );
81
 
115
 
82
		lthis.ouvrirVoletFct( voletAOuvrir, voletAFermer );
116
		lthis.ouvrirVoletFct( voletAOuvrir, voletAFermer );
83
		if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
117
		if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
84
			$( '#info-img-galerie' ).addClass( 'hidden' );
118
			$( '#info-img-galerie' ).addClass( 'hidden' );
85
			$( '#volet, #retour-galerie' ).removeClass( 'hidden' );
119
			$( '#volet, #retour-galerie' ).removeClass( 'hidden' );
86
		}
120
		}
87
	});
121
	});
88
};
122
};
89
 
123
 
90
WidgetPhotoPopup.prototype.initEvtsRetourGalerieResponsive = function() {
124
WidgetPhotoPopup.prototype.initEvtsRetourGalerieResponsive = function() {
91
	$( '#retour-galerie' ).on( 'click', function( event ) {
125
	$( '#retour-galerie' ).on( 'click', function( event ) {
92
		event.preventDefault();
126
		event.preventDefault();
93
		$( '#info-img-galerie' ).removeClass( 'hidden' );
127
		$( '#info-img-galerie' ).removeClass( 'hidden' );
94
		$( this ).addClass( 'hidden' );
128
		$( this ).addClass( 'hidden' );
95
		if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
129
		if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
96
			$( '#volet' ).addClass( 'hidden' );
130
			$( '#volet' ).addClass( 'hidden' );
97
			$( '.bouton-fct.actif' ).removeClass( 'actif' );
131
			$( '.bouton-fct.actif' ).removeClass( 'actif' );
98
		}
132
		}
99
	});
133
	});
100
};
134
};
101
 
135
 
102
WidgetPhotoPopup.prototype.initEvtsTagsPF = function() {
136
WidgetPhotoPopup.prototype.initEvtsTagsPF = function() {
103
	//recupérer tags en ajax (voir pictoflora, peut-être dans le php?)
137
	//recupérer tags en ajax (voir pictoflora, peut-être dans le php?)
104
	//	_OPTIONS
138
	//	_OPTIONS
105
	// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
139
	// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
106
	//	_GET
140
	//	_GET
107
	// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
141
	// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
108
	this.tagsPfCustom();
142
	this.tagsPfCustom();
109
	$( '#bloc-tags' ).on( 'click', '.tag', function( event ) {
143
	$( '#bloc-tags' ).on( 'click', '.tag', function( event ) {
110
		event.preventDefault();
144
		event.preventDefault();
111
		$( this ).toggleClass( 'actif' );
145
		$( this ).toggleClass( 'actif' );
112
	});
146
	});
113
	$( '#bloc-tags' ).on( 'click', '.custom-tag.actif .fermer', function( event ) {
147
	$( '#bloc-tags' ).on( 'click', '.custom-tag.actif .fermer', function( event ) {
114
		event.preventDefault();
148
		event.preventDefault();
115
		//			Supprimer un custom-tag
149
		//			Supprimer un custom-tag
116
		//	_OPTIONS
150
		//	_OPTIONS
117
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
151
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
118
		// 	_paramètres
152
		// 	_paramètres
119
		// L'id du tag à la fin de l'url
153
		// L'id du tag à la fin de l'url
120
		//	_DELETE
154
		//	_DELETE
121
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
155
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
122
		// 	_réponse:
156
		// 	_réponse:
123
		// ""
157
		// ""
124
		// 			Mettre à jour les mots cles
158
		// 			Mettre à jour les mots cles
125
		//	_OPTIONS
159
		//	_OPTIONS
126
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
160
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
127
		//	_GET
161
		//	_GET
128
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
162
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
129
		$( this ).parent( '.custom-tag' ).remove();
163
		$( this ).parent( '.custom-tag' ).remove();
130
	});
164
	});
131
 
165
 
132
	$( '#bloc-tags' ).on( 'keyup', '.custom-tag.actif', function( event ) {
166
	$( '#bloc-tags' ).on( 'keyup', '.custom-tag.actif', function( event ) {
133
		var supprimerTag = false;
167
		let supprimerTag = false;
134
 
168
 
135
		event = event || window.event;
169
		event = ( event || window.event );
136
		// event.keyCode déprécié, on tente d'abord event.key
170
		// event.keyCode déprécié, on tente d'abord event.key
137
		if ( 'key' in event ) {
171
		if ( 'key' in event ) {
138
			supprimerTag = ( 'Delete' === event.key || 'Backspace' === event.key );
172
			supprimerTag = ( 'Delete' === event.key || 'Backspace' === event.key );
139
		} else {
173
		} else {
140
			supprimerTag = ( 46 === event.keyCode || 8 === event.keyCode );
174
			supprimerTag = ( 46 === event.keyCode || 8 === event.keyCode );
141
		}
175
		}
142
		if ( supprimerTag ) {
176
		if ( supprimerTag ) {
143
		//			Supprimer un custom-tag
177
			//			Supprimer un custom-tag
144
		//	_OPTIONS
178
			//	_OPTIONS
145
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
179
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
146
		// 	_paramètres
180
			// 	_paramètres
147
		// L'id du tag à la fin de l'url
181
			// L'id du tag à la fin de l'url
148
		//	_DELETE
182
			//	_DELETE
149
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
183
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/38368
150
		// 	_réponse:
184
			// 	_réponse:
151
		// ""
185
			// ""
152
		// 			Mettre à jour les mots cles
186
			// 			Mettre à jour les mots cles
153
		//	_OPTIONS
187
			//	_OPTIONS
154
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
188
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
155
		//	_GET
189
			//	_GET
156
		// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
190
			// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
157
			$( this ).parent( '.custom-tag' ).remove();
191
			$( this ).parent( '.custom-tag' ).remove();
158
		}
192
		}
159
	});
193
	});
160
};
194
};
161
 
195
 
162
WidgetPhotoPopup.prototype.defilerImage = function( sens ) {
196
WidgetPhotoPopup.prototype.defilerImage = function( sens ) {
163
	if ( this.valOk( sens, true, 'suivant' ) ) {
197
	if ( 'suivant' === sens ) {
164
		this.indexImage++ ;
198
		this.indexImage++ ;
165
		if( this.indexImage >= this.urls.length ) {
199
		if( this.indexImage >= this.urls.length ) {
166
			this.indexImage = 0;
200
			this.indexImage = 0;
167
		}
201
		}
168
	} else if ( this.valOk( sens, true, 'precedent' ) ) {
202
	} else if ( 'precedent' === sens ) {
169
		this.indexImage--;
203
		this.indexImage--;
170
		if( this.indexImage <= 0 ) {
204
		if( this.indexImage <= 0 ) {
171
			this.indexImage = this.urls.length -1;
205
			this.indexImage = this.urls.length -1;
172
		}
206
		}
173
	}
207
	}
-
 
208
	// @TODO: Modifier l'attr content de 'meta[property=og:image]' et y mettre l'url de l'image
174
	this.afficherTitreImage();
209
	this.mettreAJourPopup();
175
};
210
};
176
 
211
 
177
WidgetPhotoPopup.prototype.afficherTitreImage = function() {
212
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  =
213
	let lienContact  =
183
			this.urlWidget +'?mode=contact&nn=' + infos.nn +
214
			this.urlWidget +'?mode=contact&nn=' + this.nn +
184
			'&nom_sci=' + infos.nom_sci +
215
			'&nom_sci=' + this.obs['nom_sel'] +
185
			'&date=' + infos.date +
216
			'&date=' + this.date +
-
 
217
			'&localisation=' + this.obs['localisation'] +
186
			'&id_image=' + item['guid'] +
218
			'&id_image=' + this.idImage +
187
			'&auteur=' + infos.auteur;
219
			'&auteur=' + this.auteur;
188
 
220
 
189
	if ( this.valOk( this.popup_url ) ) {
221
	if ( this.valOk( this.popupUrl ) ) {
190
		if (! this.popup_url.match( new RegExp( '/img:000' + item['guid'] ) ) ) {
222
		if (! this.popupUrl.match( new RegExp( 'img:' + this.idImage ) ) ) {
191
			this.popup_url = this.actualiserPopupUrl( this.popup_url, urlThisImage );
223
			this.popupUrl = this.actualiserPopupUrl( this.popupUrl, this.urlThisImage );
192
		}
224
		}
193
		lienContact += '&popup_url=' + encodeURIComponent( this.popup_url );
225
		lienContact += '&popup_url=' + encodeURIComponent( this.popupUrl );
194
	}
226
	}
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 + ' ';
227
 
200
	$( '#bloc-infos-img' ).html( titre );
-
 
201
};
-
 
202
 
-
 
203
WidgetPhotoPopup.prototype.decouperTitre = function( titre ) {
228
	$( '#bloc-infos-img' ).html(
204
	var tab_titre       = titre.split( '[nn' ),
229
		'<a href="' + this.lienEflore + '">' + this.obs['nom_sel'] + '</a> '+
205
		nom_sci         = tab_titre[0],
230
		' par '+
206
		tab_titre_suite = tab_titre[1].split( ' par ' ),
231
		'<a class="lien_contact" href="' + lienContact + '">' + this.auteur + '</a> '+
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
232
		' le ' + this.date + ' - ' + this.obs['localisation']
216
		};
-
 
217
 
-
 
218
	return titre_decoupe;
233
	);
219
};
234
};
220
 
235
 
221
WidgetPhotoPopup.prototype.actualiserPopupUrl = function( queryString, remplacement ) {
236
WidgetPhotoPopup.prototype.actualiserPopupUrl = function( queryString, remplacement ) {
222
	const lthis = this;
-
 
223
	var queryStringParsee = queryString.substring(1).split('&');
237
	let queryStringParsee = queryString.substring(1).split('&');
224
 
238
 
225
	$.each( queryStringParsee,  function( i, param ) {
239
	$.each( queryStringParsee,  function( i, param ) {
226
		if( /url_image/.test( param ) ) {
240
		if( /url_image/.test( param ) ) {
227
			queryString = queryString.replace( param, 'url_image=' + remplacement );
241
			queryString = queryString.replace( param, 'url_image=' + remplacement );
228
			return false;
242
			return false;
229
		}
243
		}
230
	});
244
	});
231
	return queryString;
245
	return queryString;
232
};
246
};
233
 
247
 
234
WidgetPhotoPopup.prototype.redimentionnerModaleCarousel = function() {
248
WidgetPhotoPopup.prototype.redimentionnerModaleCarousel = function() {
235
	this.redimensionnerGalerie();
249
	this.redimensionnerGalerie();
236
	if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
250
	if ( window.matchMedia( '(max-width: 991px)' ).matches ) {
237
		$( '#volet, #retour-galerie' ).addClass( 'hidden' );
251
		$( '#volet, #retour-galerie' ).addClass( 'hidden' );
238
		$( '#info-img-galerie' ).removeClass( 'hidden' );
252
		$( '#info-img-galerie' ).removeClass( 'hidden' );
239
		$( '.bouton-fct.actif' ).removeClass( 'actif' );
253
		$( '.bouton-fct.actif' ).removeClass( 'actif' );
240
		$( '.nettoyage-volet.haut' ).text( $( '#bloc-infos-img' ).text() );
254
		$( '.nettoyage-volet.haut' ).text( $( '#bloc-infos-img' ).text() );
241
		$( '#boutons-footer, #info-img-galerie' ).removeClass( 'col-lg-8' );
255
		$( '#boutons-footer, #info-img-galerie' ).removeClass( 'col-lg-8' );
242
		$( '#bloc-infos-img, #volet' ).removeClass( 'col-lg-4' );
256
		$( '#bloc-infos-img, #volet' ).removeClass( 'col-lg-4' );
243
	} else {
257
	} else {
244
		$( '#volet, #info-img-galerie' ).removeClass( 'hidden' );
258
		$( '#volet, #info-img-galerie' ).removeClass( 'hidden' );
245
		if ( this.valOk( $( '.bloc-volet:not(.hidden)' ) ) ) {
259
		if ( this.valOk( $( '.bloc-volet:not(.hidden)' ) ) ) {
246
			$( '.bouton-fct.' + $( '.bloc-volet:not(.hidden)' ).data( 'volet' ) ).addClass( 'actif' );
260
			$( '.bouton-fct.' + $( '.bloc-volet:not(.hidden)' ).data( 'volet' ) ).addClass( 'actif' );
247
		}
261
		}
248
		$( '.nettoyage-volet.bas' ).text( $( '#bloc-infos-img' ).text() );
262
		$( '.nettoyage-volet.bas' ).text( $( '#bloc-infos-img' ).text() );
249
		$( '#boutons-footer, #info-img-galerie' ).addClass( 'col-lg-8' );
263
		$( '#boutons-footer, #info-img-galerie' ).addClass( 'col-lg-8' );
250
		$( '#bloc-infos-img, #volet' ).addClass( 'col-lg-4' );
264
		$( '#bloc-infos-img, #volet' ).addClass( 'col-lg-4' );
251
		$( '#retour-galerie' ).addClass( 'hidden' );
265
		$( '#retour-galerie' ).addClass( 'hidden' );
252
	}
266
	}
253
};
267
};
254
 
268
 
255
WidgetPhotoPopup.prototype.redimensionnerGalerie = function() {
269
WidgetPhotoPopup.prototype.redimensionnerGalerie = function() {
256
	const lthis = this;
-
 
257
	var maxSize = ( $( window ).width() / $( window ).height() ) < 1 ? $( window ).width() : $( window ).height();
270
	var maxSize = ( $( window ).width() / $( window ).height() ) < 1 ? $( window ).width() : $( window ).height();
258
 
271
 
259
	maxSize -= 30;
272
	maxSize -= 30;
260
	$( '.carousel-item img' ).each( function( index, image ) {
273
	$( '.carousel-item img' ).each( function( index, image ) {
261
		var proportion  = image.dataset.width / image.dataset.height,
274
		var proportion  = image.dataset.width / image.dataset.height,
262
			cssResize   = {};
275
			cssResize   = {};
263
 
276
 
264
		if ( proportion >= 1 ) {
277
		if ( proportion >= 1 ) {
265
			cssResize['width'] = maxSize;
278
			cssResize['width'] = maxSize;
266
		}
279
		}
267
		if ( proportion <= 1) {
280
		if ( proportion <= 1) {
268
			cssResize['height'] = maxSize;
281
			cssResize['height'] = maxSize;
269
		}
282
		}
270
		$( image ).css( cssResize );
283
		$( image ).css( cssResize );
271
	});
284
	});
272
};
285
};
273
 
286
 
274
WidgetPhotoPopup.prototype.ouvrirVoletFct = function( voletAOuvrir, voletAFermer ) {
287
WidgetPhotoPopup.prototype.ouvrirVoletFct = function( voletAOuvrir, voletAFermer ) {
275
	if( voletAOuvrir !== voletAFermer ) {
288
	if( voletAOuvrir !== voletAFermer ) {
276
		$( '#boutons-footer  .' + voletAFermer ).removeClass( 'actif' );
289
		$( '#boutons-footer  .' + voletAFermer ).removeClass( 'actif' );
277
		$( '#boutons-footer  .' + voletAOuvrir ).addClass( 'actif' );
290
		$( '#boutons-footer  .' + voletAOuvrir ).addClass( 'actif' );
278
		$( '#bloc-' + voletAFermer ).addClass( 'hidden' );
291
		$( '#bloc-' + voletAFermer ).addClass( 'hidden' );
279
		$( '#bloc-' + voletAOuvrir ).removeClass( 'hidden' );
292
		$( '#bloc-' + voletAOuvrir ).removeClass( 'hidden' );
280
		$( '#volet' ).scrollTop(0);
293
		$( '#volet' ).scrollTop(0);
281
		if( 'meta' !== voletAOuvrir ) {
-
 
282
			$( '#retour-metas' ).removeClass( 'hidden' );
294
		$( '#retour-metas' ).removeClass( 'hidden', 'meta' === voletAOuvrir );
283
		} else {
-
 
284
			$( '#retour-metas' ).addClass( 'hidden' );
-
 
285
		}
-
 
286
	}
295
	}
287
};
296
};
288
 
297
 
289
WidgetPhotoPopup.prototype.tagsPfCustom = function() {
298
WidgetPhotoPopup.prototype.tagsPfCustom = function() {
290
	const lthis = this;
299
	const lthis = this;
291
 
300
 
292
	$( '#saisir-tag' ).on( 'blur keyup', function( event ) {
301
	$( '#saisir-tag' ).on( 'blur keyup', function( event ) {
293
		event = event || window.event;
302
		event = ( event || window.event );
294
 
303
 
295
		var ajouterTag = ( 'blur' === event.type );
304
		var ajouterTag = ( 'blur' === event.type );
296
 
305
 
297
		// event.keyCode déprécié, on tente d'abord event.key
306
		// event.keyCode déprécié, on tente d'abord event.key
298
		if ( 'key' in event  ) {
307
		if ( 'key' in event  ) {
299
			if ( 'Enter' === event.key ) {
308
			if ( 'Enter' === event.key ) {
300
				ajouterTag = true;
309
				ajouterTag = true;
301
			}
310
			}
302
		} else if ( 13 === event.keyCode ) {
311
		} else if ( 13 === event.keyCode ) {
303
			ajouterTag = true;
312
			ajouterTag = true;
304
		}
313
		}
305
		if	( ajouterTag ) {
314
		if	( ajouterTag ) {
306
			var nouveauTag     = $( this ).val(),
315
			var nouveauTag     = $( this ).val(),
307
				nouveauTagAttr = lthis.chaineValableAttributsHtml( nouveauTag.toLowerCase() );
316
				nouveauTagAttr = lthis.chaineValableAttributsHtml( nouveauTag.toLowerCase() );
308
 
317
 
309
			if( lthis.valOk( nouveauTagAttr ) && !lthis.valOk( $( '#' + nouveauTagAttr + '.tag' ) ) ) {
318
			if( lthis.valOk( nouveauTagAttr ) && !lthis.valOk( $( '#' + nouveauTagAttr + '.tag' ) ) ) {
310
				// 			Envoyer tags en ajax :
319
				// 			Envoyer tags en ajax :
311
				// 	_OPTIONS
320
				// 	_OPTIONS
312
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/
321
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/
313
				//  _paramètres :
322
				//  _paramètres :
314
				//rien
323
				//rien
315
				// 	_PUT
324
				// 	_PUT
316
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/
325
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles/
317
				// 	_paramètres :
326
				// 	_paramètres :
318
				// image=197938&mot_cle=motcleperso&auteur.id=44084
327
				// image=197938&mot_cle=motcleperso&auteur.id=44084
319
				// 			Mettre à jour les mots cles
328
				// 			Mettre à jour les mots cles
320
				//	_OPTIONS
329
				//	_OPTIONS
321
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
330
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
322
				//	_GET
331
				//	_GET
323
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
332
				// https://api-test.tela-botanica.org/service:del:0.1/mots-cles?image=197938
324
				$( '#tags-pf-supp' ).append(
333
				$( '#tags-pf-supp' ).append(
325
					'<a id="' + nouveauTagAttr + '" class="btn tag custom-tag">' +
334
					'<a id="' + nouveauTagAttr + '" class="btn tag custom-tag actif">' +
326
						nouveauTag + '&nbsp;<i class="fas fa-times-circle fermer"></i>' +
335
						nouveauTag + '&nbsp;<i class="fas fa-times-circle fermer"></i>' +
327
					'</a>'
336
					'</a>'
328
				);
337
				);
329
				$( '#form-tags-auteur' )[0].reset();
338
				$( '#form-tags-auteur' )[0].reset();
330
				$( this ).val( '' );
339
				$( this ).val( '' );
331
			}
340
			}
332
		}
341
		}
333
	});
342
	});
334
};
343
};
-
 
344
 
-
 
345
WidgetPhotoPopup.prototype.traiterMetas = function() {
-
 
346
	this.afficherMetas();
-
 
347
	this.afficherPopupLocalisation();
-
 
348
	this.afficherMetasPlus();
-
 
349
	this.fournirLienTelechargement();
-
 
350
};
-
 
351
 
-
 
352
WidgetPhotoPopup.prototype.afficherMetas = function() {
-
 
353
	const lthis         = this;
-
 
354
	const META_CONTENUS = {
-
 
355
		'nom' : '<a href="' + this.lienEflore + '" target="_blank">' + this.obs['nom_sel'] + '</a> ',
-
 
356
		'localisation' : this.obs['localisation'],
-
 
357
		'auteur' : this.auteur,
-
 
358
		'date-obs' : this.date,
-
 
359
		'commentaire' : this.obs['commentaire'],
-
 
360
		'certitude' : this.obs['certitude'],
-
 
361
		'fiabilite' : this.obs['fiabilite'],
-
 
362
		'num-photo' : this.idImage,
-
 
363
		'titre-original' : this.item['nom_original'],
-
 
364
		'date-photo' : this.formaterDate( this.item['date_photo'] ),
-
 
365
		'attribution-copy' : this.item['attribution'],
-
 
366
		'url-copy' : this.urlThisImage
-
 
367
	};
-
 
368
 
-
 
369
	$.each( META_CONTENUS, function( attrId, contenu ) {
-
 
370
		let $metaContainer = $( '#bloc-meta #'+attrId );
-
 
371
 
-
 
372
		if ( lthis.valOk( contenu ) ) {
-
 
373
			switch( attrId ) {
-
 
374
				case 'attribution-copy' :
-
 
375
				case 'url-copy' :
-
 
376
					$metaContainer.val( contenu );
-
 
377
					lthis.copieAutoChamp( $metaContainer );
-
 
378
					break;
-
 
379
				case 'nom' :
-
 
380
					$( '.contenu', $metaContainer ).html( contenu );
-
 
381
					$( '.bouton', $metaContainer ).attr( 'href', lthis.lienEflore );
-
 
382
					break;
-
 
383
				case 'auteur' :
-
 
384
					$( '.bouton', $metaContainer ).attr( 'href', lthis.urlProfil );
-
 
385
				default:
-
 
386
					$( '.contenu', $metaContainer ).text( contenu );
-
 
387
					break;
-
 
388
			}
-
 
389
		}
-
 
390
	});
-
 
391
};
-
 
392
 
-
 
393
WidgetPhotoPopup.prototype.copieAutoChamp = function($champACopier) {
-
 
394
	$champACopier.on( 'click', function() {
-
 
395
 
-
 
396
		$( this ).select();
-
 
397
		document.execCommand( 'copy' );
-
 
398
 
-
 
399
		$( this ).after(
-
 
400
			'<p class="copy-message alert-success" style="width: 100%; height:' + $( this ).outerHeight() + 'px; margin: 0; display:flex;">'+
-
 
401
				'<span style="margin:auto; font-size:1rem;">Copié dans le presse papier</span>'+
-
 
402
			'</p>'
-
 
403
		).addClass( 'hidden' );
-
 
404
 
-
 
405
		setTimeout( function() {
-
 
406
			$( '.copy-message' ).remove();
-
 
407
			$champACopier.removeClass( 'hidden' );
-
 
408
		}, 1000 );
-
 
409
	});
-
 
410
};
-
 
411
 
-
 
412
WidgetPhotoPopup.prototype.afficherMetasPlus = function() {
-
 
413
	const lthis         = this;
-
 
414
	const META_LABELS  = {
-
 
415
		'id_obs' : 'observation n°',
-
 
416
		'projet' : 'projet',
-
 
417
		'date_obs' : 'date d´observation',
-
 
418
		'nom_sel': 'nom scientifique',
-
 
419
		'nom_sel_nn' : 'nom scientifique n°',
-
 
420
		'nom_ret' : 'nom retenu',
-
 
421
		'nom_ret_nn' : 'nom retenu n°',
-
 
422
		'famille' : 'famille',
-
 
423
		'nom_referentiel' : 'réferentiel',
-
 
424
		'commentaire' : 'commentaire',
-
 
425
		'certitude' : 'certitude',
-
 
426
		'fiabilite' : 'fiabilite',
-
 
427
		'tags_obs' : 'tags de l´observation',
-
 
428
		'localisation' : 'localisation',
-
 
429
		'lieudit' : 'lieu dit',
-
 
430
		'station' : 'station',
-
 
431
		'milieu' : 'milieu',
-
 
432
		'latitude' : 'latitude',
-
 
433
		'longitude' : 'longitude',
-
 
434
		'altitude' : 'altitude',
-
 
435
		'localisation_precision': 'précision de la localisation',
-
 
436
		'code_insee' : 'code insee de la commune',
-
 
437
		'dept' : 'département',
-
 
438
		'pays' : 'pays',
-
 
439
		'est_ip_valide' : 'validée sur identiplante',
-
 
440
		'score_ip' : 'score identiplante',
-
 
441
		'url_ip' : 'url identiplante',
-
 
442
		'abondance' : 'abondance',
-
 
443
		'phenologie' : 'phénologie',
-
 
444
		'spontaneite' : 'spontaneite',
-
 
445
		'type_donnees' : 'type de donnees',
-
 
446
		'biblio' : 'bibliographie',
-
 
447
		'source' : 'source',
-
 
448
		'herbier' : 'herbier',
-
 
449
		'observateur' : 'observateur',
-
 
450
		'observateur_structure' : 'structure'
-
 
451
	};
-
 
452
	const $contenuPlusMeta  = $( '#contenu-meta-plus' );
-
 
453
	let degres = '0';
-
 
454
 
-
 
455
	this.rotationFleche( degres );
-
 
456
 
-
 
457
	$.each( META_LABELS, function( cle, label ) {
-
 
458
		let idAttr = cle.replace( '_', '-' ),
-
 
459
			contenu = lthis.obs[cle];
-
 
460
 
-
 
461
		if ( 0 <= $.inArray( cle, ['est_ip_valide', 'herbier'] ) && '0' === contenu ) {
-
 
462
			contenu = 'non';
-
 
463
		} else if ( 'date_obs' === cle ) {
-
 
464
			contenu = lthis.formaterDate(contenu);
-
 
465
		}
-
 
466
 
-
 
467
		if ( lthis.valOk( contenu ) ) {
-
 
468
			$contenuPlusMeta.append(
-
 
469
				'<li id="' + idAttr + '-meta-plus" class="row">'+
-
 
470
					'<div class="col-5 label">' + label.charAt( 0 ).toUpperCase() + label.slice( 1 ) + '</div>'+
-
 
471
					'<div class="col-5 contenu">' + contenu + '</div>'+
-
 
472
				'</li>'
-
 
473
			);
-
 
474
		}
-
 
475
	});
-
 
476
 
-
 
477
	$contenuPlusMeta.hide();
-
 
478
	$( '#plus-meta' ).off( 'click' ).on( 'click', function( event ) {
-
 
479
		event.preventDefault();
-
 
480
 
-
 
481
		$contenuPlusMeta.toggle( 200, function() {
-
 
482
			degres = $contenuPlusMeta.is( ':visible' ) ? '180' : '0';
-
 
483
			lthis.rotationFleche( degres );
-
 
484
		});
-
 
485
	});
-
 
486
};
-
 
487
 
-
 
488
WidgetPhotoPopup.prototype.rotationFleche = function( degres ) {
-
 
489
	$( '#plus-meta i' ).css({
-
 
490
		'-webkit-transform' : 'rotate('+ degres +'deg)',
-
 
491
		'-moz-transform' : 'rotate('+ degres +'deg)',
-
 
492
		'-ms-transform' : 'rotate('+ degres +'deg)',
-
 
493
		'transform' : 'rotate('+ degres +'deg)'
-
 
494
	});
-
 
495
};
-
 
496
 
-
 
497
WidgetPhotoPopup.prototype.fournirLienTelechargement = function() {
-
 
498
	const lthis = this;
-
 
499
 
-
 
500
	$( '#formats' ).on( 'change', function() {
-
 
501
		let format             = ( $( this ).val() || 'O' ),
-
 
502
			lienTelechargement = lthis.urlBaseTelechargement + lthis.idImage + '?methode=telecharger&format=' + format;
-
 
503
 
-
 
504
		$( '#telecharger' ).attr( 'href', lienTelechargement );
-
 
505
	});
-
 
506
 
-
 
507
	$( '#formats' ).trigger( 'change' );
-
 
508
};
-
 
509
 
-
 
510
 
-
 
511
WidgetPhotoPopup.prototype.afficherPopupLocalisation = function() {
-
 
512
	const lthis = this;
-
 
513
 
-
 
514
	$( '#localisation a.bouton' ).on( 'click', function( event ){
-
 
515
		event.preventDefault();
-
 
516
 
-
 
517
		$( this ).after(
-
 
518
			'<div id="localisation-map-container">'+
-
 
519
				'<button id="map-close" type="button" class="bouton btn btn-sm btn-outline-secondary" aria-label="Close">'+
-
 
520
					'<span aria-hidden="true">×</span>'+
-
 
521
				'</button>'+
-
 
522
				'<div id="localisation-map"></div>'+
-
 
523
			'</div>'
-
 
524
		);
-
 
525
 
-
 
526
		let lat = lthis.obs['latitude'],
-
 
527
			lng = lthis.obs['longitude'],
-
 
528
			map = L.map( 'localisation-map', {
-
 
529
				zoomControl: true,
-
 
530
				dragging: false,
-
 
531
				scrollWheelZoom: 'center'
-
 
532
			} ).setView( [lat, lng], 12 );
-
 
533
 
-
 
534
		map.markers = [];
-
 
535
 
-
 
536
		L.tileLayer(
-
 
537
			'https://osm.tela-botanica.org/tuiles/osmfr/{z}/{x}/{y}.png',
-
 
538
			{
-
 
539
				attribution: 'Data © <a href="http://osm.org/copyright">OpenStreetMap</a>',
-
 
540
				maxZoom: 18
-
 
541
			}
-
 
542
		).addTo( map );
-
 
543
 
-
 
544
		map.addLayer( new L.FeatureGroup() );
-
 
545
 
-
 
546
		let marker = new L.Marker(
-
 
547
			{
-
 
548
				'lat': lat,
-
 
549
				'lng': lng
-
 
550
			},
-
 
551
			{
-
 
552
				draggable: false,
-
 
553
			}
-
 
554
		);
-
 
555
 
-
 
556
 
-
 
557
		map.addLayer( marker );
-
 
558
		map.markers.push( marker );
-
 
559
 
-
 
560
		$( '#map-close' ).on( 'click', function( event ){
-
 
561
			$( '#localisation-map-container' ).remove();
-
 
562
		});
-
 
563
	});
-
 
564
 
-
 
565
	$( '#fenetre-modal' ).on( 'click', function( event ) {
-
 
566
		if(
-
 
567
			!$( event.target ).closest( '#localisation-map-container' ).length
-
 
568
			&& !$( event.target ).closest( '#obs-localisation' ).length
-
 
569
		) {
-
 
570
			$( '#localisation-map-container' ).remove();
-
 
571
		}
-
 
572
	});
-
 
573
};
-
 
574
 
-
 
575
 
-
 
576
WidgetPhotoPopup.prototype.regenererMiniature = function() {
-
 
577
	const lthis = this;
-
 
578
	$( '#regenerer-miniature' ).off( 'click' ).on( 'click', function( event ) {
-
 
579
		event.preventDefault();
-
 
580
 
-
 
581
		let url = lthis.urlServiceRegenererMiniature + lthis.idImage;
-
 
582
 
-
 
583
		$.get( url ).fail( function() {
-
 
584
			console.log( 'a foiré :(' );
-
 
585
		});
-
 
586
	});
-
 
587
};
-
 
588
 
-
 
589
WidgetPhotoPopup.prototype.formaterDate = function( sqlDate ) {
-
 
590
	dateFormatee = sqlDate
-
 
591
		.substring( 0, 10 )
-
 
592
		.split( '-' )
-
 
593
		.reverse()
-
 
594
		.join('/');
-
 
595
 
-
 
596
	return dateFormatee;
-
 
597
};
-
 
598
 
-
 
599
WidgetPhotoPopup.prototype.fournirLienIdentiplante = function() {
-
 
600
	const lthis = this;
-
 
601
	$( '.signaler-erreur-obs' ).each( function() {
-
 
602
		$( this ).attr( 'href', lthis.urlIP );
-
 
603
	});
-
 
604
};
-
 
605
 
-
 
606
// WidgetPhotoPopup.prototype.afficherTags = function() {
-
 
607
// 	const lthis = this;
-
 
608
// 	const TAGS_BASE = [
-
 
609
// 		'port',
-
 
610
// 		'fleur',
-
 
611
// 		'fruit',
-
 
612
// 		'feuille',
-
 
613
// 		'ecorce',
-
 
614
// 		'rameau',
-
 
615
// 		'planche',
-
 
616
// 		'insecte'
-
 
617
// 	];
-
 
618
 
-
 
619
	
-
 
620
// };
335
621