PageSourceSearch

https://www.la-sofia.org/wp-content/themes/sofia/js/sofia.js

js la-sofia.org collected 2026-09-24 18:16:33 UTC 11,000 bytes, 361 lines download raw bytes

1var $ = jQuery.noConflict();
2$(function() {
3	$('.modal').modal({
4		dismissible: true
5	});
6//	$('.modal').modal();
7	$('#slide-menu').sidenav({ edge: 'right' });
8	$('.collapsible').collapsible();
9	$('#dbsearch-modal').modal();
10	$('#search-by-kw').modal({
11		opacity: .85,
12		onOpenEnd: function() {
13			$('#kw-search-input').focus();
14		}
15	});
16});
17$(document).ready(function() {
18	$('.search-overlay').removeClass('wait');
19	$('.news-slider').slick({
20		slidesToShow: 3,
21		responsive: [
22			{
23				breakpoint: 990,
24				settings: {
25					slidesToShow: 2
26				}
27			},
28			{
29				breakpoint: 600,
30				settings: {
31					slidesToShow: 1,
32					dots: true,
33					arrows: false
34				}
35			}
36		]
37	});
38
39	$(document).on('click','.ask-right-modal-trigger', function (e){
40		e.preventDefault();
41		var book_title = $(this).data('title'),
42			book_ean = $(this).data('ean'),
43			book_editor = $(this).data('editor'),
44			book_bnf = $(this).data('bnf');
45		$('#ask-rights-modal h5').text( book_title + ' - EAN : ' + book_ean + ' (' + book_editor + ')' );
46		$('#ask-rights-modal #book_title').val( book_title );
47		$('#ask-rights-modal #book_editor').val( book_editor );
48		$('#ask-rights-modal #book_ean').val( book_ean );
49		$('#ask-rights-modal #book_bnf').val( book_bnf );
50		$('#ask-rights-modal').modal('open');
51	});
52
53	$(document).on('click', '#db-search-result .dbsearch-result tr._author', function(e){
54		return;
55		e.preventDefault();
56		window.location = $(this).data('url');
57		//let form = $(this).data('form');
58		//$('#' + form).submit();
59	});
60
61	$(document).on('click', '#db-search-result .dbsearch-result tr.has-rights', function(e){
62		const title = $(this).data('title');
63		const ean = $(this).data('ean');
64		const idsof = $(this).data('idsof');
65
66		if ( !ean ){
67			return;
68		}
69
70		let formData = new FormData();
71		formData.append('action', 'sofia_book_rights');
72		formData.append('ean', ean);
73		formData.append('ean', ean);
74		formData.append('idsof', idsof);
75		$('#rights-modal-list tbody').html("");
76		$('#detail-rights-modal .spinner').removeClass('cache');
77		$('#rights-modal-list').addClass('cache');
78		$('#detail-rights-modal').modal('open');
79
80		$.ajax({
81			type: 'POST',
82			url: sofia.ajaxurl,
83			data: formData,
84			contentType: false,
85			processData: false,
86
87			success: function(response){
88				data = JSON.parse(response);
89
90				if ( data.body ){
91					const body = JSON.parse(data.body);
92					console.log(body);
93
94					if ( body.length ){
95						body.forEach(elt => {
96							if ( !elt.DDP && ! elt.LI){
97								return;
98							}
99
100							elt.DDP = elt.DDP.replace('SOFIA', 'Droits versés par la Sofia directement à l\'auteur'); 
101							elt.DDP = elt.DDP.replace('EDITEUR', 'Droits versés par la Sofia à l’éditeur '); 
102							//elt.DDP = elt.DDP.replace('SOFIA', 'Droits connus sur ce titre'); 
103							//elt.DDP = elt.DDP.replace('EDITEUR', 'Droits connus sur ce titre'); 
104							elt.DDP = elt.DDP.replace('OGC', 'Droits versés par la Sofia à l’OGC de l’auteur '); 
105							elt.DDP = elt.DDP.replace('En Attente', 'Droits non versés, <a href="/contact/">contactez-nous</a>'); 
106							elt.DDP = elt.DDP.replace('n/a', 'Titre non concerné');
107							elt.LI = elt.LI.replace('n/a', 'Titre non concerné');
108							elt.DDP = elt.DDP.replace('Payé', 'Droits versés par la Sofia directement à l\'auteur ');
109							elt.LI = elt.LI.replace('Payé', 'Droits versés par la Sofia directement à l\'auteur ');
110
111
112							let row = '<tr><td>' + elt.annee + '</td><td>' + (elt.DDP? elt.DDP : "Titre non concerné") + '</td><td>' + (elt.LI? elt.LI : "Titre non concerné") + '</td>' + 
113							'<td>' ;
114
115							if ( elt.LI && (elt.LI.includes('Identifier') || elt.LI.includes('Identifié'))){
116								row += '<a data-editor="' + elt.editeur + '" data-title="' + elt.titre + '" data-ean="' + elt.ean + '" data-bnf="' + elt.idbnf + '" class="ask-right-modal-trigger" href="">Si vous êtes l\'auteur, contactez nous</a>'; 
117							}
118
119							row += '</td></tr>';
120							$('#rights-modal-list tbody').append(row);
121						});
122					} else {
123						const row = '<tr><td colspan="4">Aucun droit trouvé</td></tr>';
124						$('#rights-modal-list tbody').append(row);
125					}
126
127					$('#detail-rights-modal .spinner').addClass('cache');
128					$('#rights-modal-list').removeClass('cache');
129				}
130			},
131			error: function(error){
132				console.log(error);
133			}
134		});
135	});
136
137});
138
139$('.modal-close').on('click', function(e){
140	e.preventDefault();
141	$('.modal.open').removeClass('open');
142	$('.modal-overlay').css('display', 'none');
143	console.log('fermer');
144})
145
146$(".news-slider").on('init', function () {
147	$('.news-slider .post-item').matchHeight();
148});
149$('#main-nav .menu-login a').click(function(e) {
150	e.preventDefault();
151	$("#sidenav-btn").trigger('click');
152});
153function PopupCenter(url, title, w, h) {
154    // Fixes dual-screen position	Most browsers	Firefox
155    var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
156    var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
157
158    var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
159    var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
160
161    var left = ((width / 2) - (w / 2)) + dualScreenLeft;
162    var top = ((height / 2) - (h / 2)) + dualScreenTop;
163    var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
164
165    // Puts focus on the newWindow
166    if (window.focus) {
167        newWindow.focus();
168    }
169}
170$(document).on('click','ul.share-buttons a.share', function(e) {
171	e.preventDefault();
172	var url = $(this).attr('href'),
173		title = $(this).attr('title'),
174		width = $(this).data('width'),
175		height = $(this).data('height');
176	PopupCenter(url, title, width, height);
177});
178$('.extranet-login a.view-pswd').click(function(e) {
179	e.preventDefault();
180	if( $('#pwd').hasClass('text') ){
181		$('#pwd').replaceWith( $('#pwd').clone().attr('type', 'password').removeClass('text') );
182	}else{
183		$('#pwd').replaceWith( $('#pwd').clone().attr('type', 'text').addClass('text') );
184	}
185});
186/* contact form */
187$('#contact-form').on('submit', function(e) {
188	e.preventDefault();
189	// vars
190	var $button = $('button',this),
191		$loader = $('span.loader',this);
192	// disable button on submit
193	$button.prop('disabled',true);
194	$loader.html(sofia.loader);
195	
196	
197	grecaptcha.ready(function() {
198        // do request for recaptcha token
199        // response is promise with passed token
200        grecaptcha.execute('6LeJDfYUAAAAAAlXRmwczznztEMyVZf2BzQ8pmNj', {action: 'sofia_contact'}).then(function(token) {
201	        // add token to form
202	        $('#contact-form').prepend('<input type="hidden" name="g-recaptcha-response" value="' + token + '">');
203		    
204			var form_data = new FormData();
205			var datas = $('#contact-form').serialize();	
206			form_data.append('data', datas);
207			form_data.append('action', 'sofia_contact');
208			
209			$.ajax({
210			    type: 'POST',
211			    url: sofia.ajaxurl,
212			    data: form_data,
213				token: token,
214			    contentType: false,
215			    processData: false,
216			    success: function(response){
217					M.toast({ html: response, displayLength: 6000 });
218					$button.prop('disabled',false);
219					$loader.html('');
220				},
221				error: function(error){
222					$button.removeClass('disabled').prop('disabled', false);
223					M.toast({html: error})
224				}
225			});
226		});
227    });
228});
229
230
231$('#dbsearch input[type="radio"]').click(function() {
232	var placeholder = $(this).data('placeholder');
233	$('#db_title').attr( 'placeholder', placeholder ).focus();
234});
235
236$(document).on( 'change', '#pages-redirect', function(e) {
237	var target = $(this).val();
238	if( target != '' ){
239		window.location.href = target;
240	}else{
241		e.preventDefault();
242	}
243});
244$(document).on('submit','form.newsletter-optin', function (e){
245	e.preventDefault();
246	var subscriber = $('#optin_email', this).val();
247	var $button =  $('button', this);
248	if(subscriber!=''){
249		$button.html('<i class="fa fa-spinner fa-spin" aria-hidden="true"></i>');
250		$.post(
251		    sofia.ajaxurl, {
252		    	action: 'sofia_register', 
253		    	subscriber: subscriber
254		    }, 
255		    function(response){
256				M.toast({html: response});
257		    	$button.html('<i class="fa fa-envelope" aria-hidden="true"></i>');
258		    }
259		);
260	}else{
261		M.toast({html: 'Entrez votre e-mail svp'});
262	}	
263});
264
265$(document).on('click','.dbsearch-result .contact-sofia', function (e){
266	e.preventDefault();
267	var book_title = $(this).data('title'),
268		book_ean = $(this).data('ean'),
269		book_bnf = $(this).data('bnf');
270	$('#ask-rights-modal h5').text( book_title );
271	$('#ask-rights-modal #book_title').val( book_title );
272	$('#ask-rights-modal #book_ean').val( book_ean );
273	$('#ask-rights-modal #book_bnf').val( book_bnf );
274	$('#ask-rights-modal').modal('open');
275});
276
277$('#ask-rights-form').submit(function(e) {
278	e.preventDefault();
279	var $button = $('button',this);
280	var data = $(this).serialize();
281	$button.prop('disabled',true);
282	$('.search-overlay').addClass('wait');
283	$.post(
284	    sofia.ajaxurl, {
285	    	action: 'sofia_ask_rights', 
286	    	data: data
287	    }, 
288	    function(response){
289			$('.search-overlay').removeClass('wait');
290			if( response == 'success' ){
291				$('#ask-rights-modal').modal('close');
292				alert( sofia.ask_rights_confirm );
293			}else{
294				$button.prop('disabled',false);
295				M.toast({html: response});
296			}
297	    }
298	);
299});
300
301$(document).on('submit','#dbsearch.unsubmitted', function (e){
302	e.preventDefault();
303	$(this).removeClass('unsubmitted');
304	$('.search-overlay').addClass('wait');
305
306	const form = document.querySelector('#dbsearch');
307	const formData = new FormData(form);
308	const params = new URLSearchParams();
309	const formAction = form.getAttribute('action');
310
311	for (const pair of formData) {
312		params.append(encodeURIComponent(pair[0]), encodeURIComponent(pair[1]));
313	}
314
315	const url = formAction + '?' + params.toString();
316
317	window.location.href = url;
318
319	//$(this).submit();
320});
321
322$(document).on('submit','#inlinesearch.unsubmitted', function (e){
323	e.preventDefault();
324	$(this).removeClass('unsubmitted');
325	$('.search-overlay').addClass('wait');
326
327	const title = $('#inline_title').val();
328	const author = $('#inline_author').val();
329
330	if ( !title && !author){
331		e.preventDefault();
332		return false;
333	}
334
335	$('#inline_db_title').val(title? title : author);
336	$('#inline_search_type').val(title? 'title' : 'author');
337
338	const form = document.querySelector('#inlinesearch');
339	const formData = new FormData(form);
340	const params = new URLSearchParams();
341	const formAction = form.getAttribute('action');
342
343	for (const pair of formData) {
344		params.append(encodeURIComponent(pair[0]), encodeURIComponent(pair[1]));
345	}
346
347	const url = formAction + '?' + params.toString();
348	window.location.href = url;
349
350	//$(this).submit();
351});
352
353$(document).on('click','.view-books.unsubmitted', function (e){
354	e.preventDefault();
355	$(this).removeClass('unsubmitted');
356	$('.search-overlay').addClass('wait');
357	$(this).trigger('click');
358});
359
360
361

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.