3 // fonction pour montrer un contenu
4 jQuery
.fn
.montre_onglet = function( selector
) {
6 if(this.is('.onglets_titre')) {
7 var contenu
= '#' + this[0].id
.replace(/titre/,'contenu');
8 var bloc
= this.parent().parent();
9 bloc
.children('.selected').removeClass('selected').end()
10 .children('.onglets_liste').children('.selected').removeClass('selected');
11 jQuery(contenu
).addClass('selected');
12 this.addClass('selected');
15 if(this.is('.onglets_contenu')) {
16 var titre
= this[0].id
.replace(/contenu/,'titre');
17 jQuery('#'+titre
).montre_onglet();
22 // compatibilite Ajax : ajouter "this" a "jQuery" pour mieux localiser les actions
23 function onglets_init() {
24 var cs_bloc
= jQuery('div.onglets_bloc_initial', this);
26 cs_bloc
.prepend('<div class="onglets_liste"></div>')
27 .children('.onglets_contenu').each(function(i
) {
28 this.id
= 'onglets_contenu_' + i
;
29 jQuery(this).parent().children('.onglets_liste').append(
30 '<h2 id="'+'onglets_titre_' + i
+ '" class="onglets_titre">' + this.firstChild
.innerHTML
+ '</h2>'
33 .children('h2').remove();
34 jQuery('div.onglets_liste', this).each(function() {
35 this.firstChild
.className
+= ' selected';
36 this.nextSibling
.className
+= ' selected';
38 jQuery('h2.onglets_titre', this).hover(
40 jQuery(this).addClass('hover')
42 jQuery(this).removeClass('hover')
45 jQuery('div.onglets_bloc_initial', this)
46 .attr('class','onglets_bloc').each(function(i
) {this.id
= 'ongl_'+i
;});
48 jQuery('h2.onglets_titre', this).click(function(e
) {
49 jQuery(this).montre_onglet();
52 // clic des <a>, au cas ou...
53 jQuery('h2.onglets_titre a', this).click(function(e
){
54 jQuery(this).parents('h2').click();
55 if (e
.stopPropagation
) e
.stopPropagation();
56 e
.cancelBubble
= true;
59 // activation d'onglet(s) grace a l'url
60 if(onglet_get
&& (this==document
)) {
61 var onglets
= onglet_get
.split(',');
62 for (var i
=0; i
<onglets
.length
; i
++)
63 jQuery('#onglets_titre_'+onglets
[i
]).click();
65 // clic vers une note dans un onglet
66 jQuery('.spip_note['+cs_sel_jQuery
+'name^=nb], .spip_note['+cs_sel_jQuery
+'id^=nb]').each(function(i
) {
67 jQuery(this).click(function(e
){
68 var href
= this.href
.substring(this.href
.lastIndexOf("#"));
69 jQuery(href
).parents('.onglets_contenu').eq(0).montre_onglet();
76 function get_onglet(url
) {
77 tab
=url
.search
.match(/[?&]onglet=([0-9,]*)/) || url
.hash
.match(/#onglet([0-9,]*)/);
78 if (tab
==null) return false;
82 var onglet_get
= get_onglet(window
.location
);