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