PageSourceSearch

https://convergences26.fr/plugins/auto/blocsdepliables/v1.4.2/js/blocs.js?1750406074

js convergences26.fr collected 2026-10-07 18:12:38 UTC 9,026 bytes, 245 lines download raw bytes

1// variables modifiables afin d'initialiser l'ouverture d'un bloc (simple ou numerote)
2if(typeof(bloc_actif)=='undefined') var bloc_actif = '';
3if(typeof(bloc_actif_num)=='undefined') var bloc_actif_num = '';
4
5// fonction surchargeable : gestion du slide jQuery
6jQuery.fn.blocs_toggle_slide_dist = function( selector ) {
7	this.toggleClass('blocs_slide');
8	if(typeof jQuery.fn.blocs_toggle_slide=='function')
9		return this.blocs_toggle_slide();
10	return this.is(".blocs_slide")?this.slideUp(blocs_slide):this.slideDown(blocs_slide);
11};
12
13jQuery.fn.blocs_set_title = function( selector ) {
14	var title = this.parent().find('.blocs_title:last').text();
15	if(!title) title = blocs_title_def;
16	title = title.split(blocs_title_sep);
17	this.children('a').attr('title', title[jQuery(this).is('.blocs_replie')?0:1]);
18	return this;
19};
20
21// fonction de de/re-pliement
22jQuery.fn.blocs_toggle = function() {
23	if (!this.length) return this;
24	// applique-t-on la fonction sur cs_blocs ou sur blocs_titre ?
25	var cible = this.is('.cs_blocs')? this.children('.blocs_titre').eq(0) : this;
26	// on replie/deplie la cible...
27	cible.toggleClass('blocs_replie').blocs_set_title();
28	var dest = this[0].id.match('^cs_bloc_id_')?jQuery('div.'+this[0].id):cible.next();
29	if(blocs_slide==='aucun') {
30		dest.toggleClass('blocs_invisible');
31		// est-on sur un resume ?
32		if (dest.is('div.blocs_resume')) dest.next().toggleClass('blocs_invisible');
33	} else {
34		dest.blocs_toggle_slide_dist();
35		// est-on sur un resume ?
36		if (dest.is('div.blocs_resume')) dest.next().blocs_toggle_slide_dist();
37	}
38	// est-on sur un bloc ajax ?
39	var lien = cible.children();
40	var url = lien.attr("href");
41	if(!url.includes('#_bloc_non_ajax')) {
42		// une fois le bloc ajax en place, plus besoin de le recharger ensuite
43		lien.attr("href", 'javascript:;').addClass('ouvrir_fermer');
44		// ici, on charge !
45		cible.parent().children(".blocs_destination")
46		//.animeajax()
47		.load(url);
48	}
49	return this;
50};
51
52// replie tout sauf le bloc appelant et sa lignee parentale
53jQuery.fn.blocs_replie_tout = function() {
54	if(blocs_replier_tout) {
55		// applique-t-on la fonction sur cs_blocs ou sur blocs_titre ?
56		var cible = this.is('.cs_blocs')? this : this.parents('div.cs_blocs');
57		// lignee du bloc
58		var lignee = cible.children('.blocs_titre');
59		jQuery('.blocs_titre').not('.blocs_replie').not(lignee).blocs_toggle();
60	}
61	return this;
62}
63
64// une variable globale stockant le(s) bloc(s) a deplier si un clic ajax a eu lieu
65var blocs_clic_ajax = null;
66
67// compatibilite Ajax : ajouter "this" a "jQuery" pour mieux localiser les actions
68// et tagger avec cs_done pour eviter de binder plrs fois le meme bloc
69function blocs_init() {
70	// clic sur un titre de bloc
71	jQuery('.blocs_titre', this).cs_todo()
72		.each( function(){
73			jQuery(this).blocs_set_title()
74				.find('a.ouvrir_fermer')
75				.on('click', function(){
76					jQuery(this).parent().blocs_replie_tout().blocs_toggle();
77					// annulation du clic
78					return false;
79				});
80		});
81	// pour un lien 'replier_bloc' present dans le bloc
82	jQuery('.blocs_destination a.replier_bloc', this).cs_todo()
83	 .click( function(){
84		s = jQuery(this).parents('.cs_blocs:first');
85		// scroll vers le debut du bloc, si le plugin 'SrollTo' est present
86		if(typeof jQuery.fn.scrollTo=="function") jQuery('body').scrollTo(s, 500,
87			{margin:true, /*axis:'y',*/ onAfter:function(){s.blocs_replie_tout().blocs_toggle();}});
88		else s.blocs_replie_tout().blocs_toggle();
89		// annulation du clic
90		return false;
91	   });
92	// activation de blocs numerotes grace a l'url
93	var blocs = blocs_get_blocs(window.location, true);
94	if(blocs && (this==document)) blocs_clic_blocs(blocs, true);
95	// activation de blocs simples (numerotes sur la base zero) grace a l'url
96	blocs = blocs_get_blocs(window.location);
97	if(blocs && (this==document)) blocs_clic_blocs(blocs);
98	// clic vers une note dans un bloc
99	jQuery('.spip_note['+cs_sel_jQuery+'name^=nb], .spip_note['+cs_sel_jQuery+'id^=nb]').each(function(i) {
100		jQuery(this).click(function(e){
101			var href = this.href.substring(this.href.lastIndexOf("#"));
102			href = jQuery(href).parents('.cs_blocs').eq(0).children('.blocs_titre').eq(0);
103			// on neutralise une eventuelle animation
104			old_blocs_slide = blocs_slide;
105			if(blocs_slide!='aucun') blocs_slide = -1;
106			if(href.is('.blocs_replie')) href.click();
107			blocs_slide = old_blocs_slide;
108			return true;
109		});
110	});
111
112/*
113// LA SUITE DE CE CODE NE FONCTIONNE POUR L'INSTANT QUE SUR LE PREMIER CLIC, JE NE SAIS PAS ENCORE PKOI...
114	// stockage du bloc (numerote !) a reouvrir dans le cas d'un clic ajax sur une
115	// pagination SPIP contenue a l'interieur
116	jQuery(".ajaxbloc .pagination a.noajax", this).cs_todo()
117	  .click( function(){
118		var parent = jQuery(this).parents('.cs_blocs');
119		if(!parent.length) return true;
120		var numero = /cs_bloc\d+/.exec(parent[0].className);
121		if(numero!==null) blocs_clic_ajax = numero[0];
122		return true;
123	   });
124	// rouvre le nouveau bloc ajax si un clic a eu lieu a l'interieur de l'ancien
125	if(blocs_clic_ajax!==null) {
126		jQuery('.'+blocs_clic_ajax, this).blocs_toggle();
127		blocs_clic_ajax = null
128	}
129*/
130}
131
132// un JS actif replie les blocs invisibles, sans utiliser document.write()
133var valStyle = document.createElement('style');
134var valCss = 'div.blocs_invisible { display:none; }';
135var valHead = document.head || document.getElementsByTagName('head')[0];
136valHead.appendChild(valStyle);
137valStyle.type = 'text/css';
138valStyle.appendChild(document.createTextNode(valCss));
139
140// Sauve l'etat des blocs numerotes dans un cookie si on quitte la page
141function cs_blocs_cookie() {
142	if(typeof jQuery.cookie!='function') return;
143	var blocs_cookie_name = 'blocs' + window.location.pathname + window.location.search
144	blocs_cookie_name = blocs_cookie_name.replace(/[ ;,=]/,'_');
145	var deplies = jQuery.cookie(blocs_cookie_name);
146	jQuery.cookie(blocs_cookie_name, null);
147	if(deplies)
148		jQuery(deplies).blocs_replie_tout().blocs_toggle();
149	jQuery(window).on('unload', function() {
150		jQuery.cookie(blocs_cookie_name, blocs_deplies());
151	});
152}
153
154// renvoie la liste des selecteurs de blocs ouverts
155function blocs_deplies() {
156	var deplies = '';
157	jQuery('.cs_blocs').each(function() {
158		var numero = /cs_bloc\d+/.exec(this.className);
159		if(numero==null) return;
160		replie = jQuery(this).children('.blocs_titre').eq(0).is('.blocs_replie');
161		if(!replie) deplies += (deplies.length?', ':'') + 'div.' + numero[0];
162	});
163	return deplies.length?deplies:null;
164}
165
166// clic sur les blocs (Niemes blocs en base zero pour les blocs simples)
167function blocs_clic_blocs(liste, numerote) {
168	var blocs = liste.split(',');
169	for (var i=0; i<blocs.length; i++)
170		(numerote)
171			?jQuery('div.cs_bloc' + blocs[i] + ' .blocs_titre').eq(0).click()
172			:jQuery('div.cs_blocs .blocs_titre').eq(blocs[i]).click();
173}
174
175// examen des parametes url (blocs simples ou numerotes)
176function blocs_get_blocs(url, numerote) {
177	tab = numerote
178		?url.search.match(/[?&]deplier_num=([0-9,]*)/) || url.hash.match(/#deplier_num([0-9,]*)/)
179		:url.search.match(/[?&]deplier=([0-9,]*)/) || url.hash.match(/#deplier([0-9,]*)/);
180	return tab==null?(numerote?bloc_actif_num:bloc_actif):tab[1];
181}
182
183// une fonction et une variable pour reperer une pagination
184function blocs_get_pagination(url) {
185	tab = url.match(/#pagination([0-9]+)/);
186	return tab==null?bloc_actif:tab[1];
187}
188
189var blocs_pagination = blocs_get_pagination(window.location.hash);
190
191/*
192// Si un bloc contient une pagination inseree dans un bloc,
193// code JS a inserer dans le header de votre squelette APRES les appels du Couteau Suisse :
194jQuery(function($) {
195	if(blocs_pagination!==false) {
196		$('div.cs_bloc' + blocs_pagination + ' .blocs_titre').eq(0).click();
197		window.location.hash = '#pagination' + blocs_pagination;
198	}
199});
200*/
201
202/*
203//	Pour un bloc depliable du genre :
204//	<BOUCLE_art(ARTICLES)>
205//		#BLOC_TITRE
206//		#TITRE
207//		#BLOC_RESUME
208//		#INTRODUCTION
209//		#BLOC_DEBUT
210//		#TEXTE
211//		#BLOC_FIN
212//	</BOUCLE_art>
213//	le clic sur un point de suite cliquable de la balise #INTRODUCTION produit l'ouverture du bloc.
214//	code JS a inserer dans le header de votre squelette APRES les appels du Couteau Suisse :
215jQuery(function($){
216	$('.blocs_resume>a.pts_suite')
217	  .click( function(){
218		$(this).parents('.cs_blocs:first').children('.blocs_titre')
219			.blocs_replie_tout().blocs_toggle();
220		// annulation du clic
221		return false;
222		});
223});
224*/
225
226/* Init */
227jQuery.fn.cs_todo=function(){
228	return this.not('.cs_done').addClass('cs_done');
229};
230var cs_sel_jQuery='';
231jQuery(function($){
232	blocs_init.apply(document);
233	if(typeof onAjaxLoad=='function') onAjaxLoad(blocs_init);
234	if(blocs_js_cookie && $('div.cs_blocs').length) $.getScript(blocs_js_cookie, cs_blocs_cookie);
235	/* Quand on pointe vers une ancre qui est à l'intérieur d'un bloc, on
236	   déplie le bloc */
237	var ancre = location.hash.substring(1);
238	if (ancre) {
239	    $('.cs_blocs').has('[name="' + ancre + '"]')
240	        .find('.blocs_titre.blocs_replie').blocs_toggle();
241	    $('.cs_blocs').has('#' + ancre)
242	        .find('.blocs_titre.blocs_replie').blocs_toggle();
243	    location = location;
244	}
245});

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.