[SPIP] ~maj v2.1.25-->2.1.26
[velocampus/web/www.git] / www / plugins / auto / couteau_suisse / couteau_suisse / outils / decoupe.js
1 var onglet_actif = 0;
2
3 // fonction pour montrer un contenu
4 jQuery.fn.montre_onglet = function( selector ) {
5 // click sur un titre
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');
13 }
14 // click sur un titre
15 if(this.is('.onglets_contenu')) {
16 var titre = this[0].id.replace(/contenu/,'titre');
17 jQuery('#'+titre).montre_onglet();
18 }
19 return this;
20 };
21
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);
25 if(cs_bloc.length) {
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>'
31 );
32 })
33 .children('h2').remove();
34 jQuery('div.onglets_liste', this).each(function() {
35 this.firstChild.className += ' selected';
36 this.nextSibling.className += ' selected';
37 });
38 jQuery('h2.onglets_titre', this).hover(
39 function(){
40 jQuery(this).addClass('hover')
41 },function(){
42 jQuery(this).removeClass('hover')
43 }
44 );
45 jQuery('div.onglets_bloc_initial', this)
46 .attr('class','onglets_bloc').each(function(i) {this.id = 'ongl_'+i;});
47 // clic du titre...
48 jQuery('h2.onglets_titre', this).click(function(e) {
49 jQuery(this).montre_onglet();
50 return false;
51 });
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;
57 return false;
58 });
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();
64 }
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();
70 return true;
71 });
72 });
73 }
74 }
75
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;
79 return tab[1];
80 }
81
82 var onglet_get = get_onglet(window.location);