Dotclear

source: admin/js/jquery/jquery.pageTabs.js @ 1700:46ec5d1c6f0d

Revision 1700:46ec5d1c6f0d, 2.7 KB checked in by kevin@…, 11 years ago (diff)

Ticket #1452
Permet d'utiliser les ancres pour afficher les onglets dans l'administration.
Les onglets modifie l'url comme les ancres ( C'est des ancres, en fait... )
script suplémentaire pour les vieux ie 6..7

Line 
1jQuery.pageTabs = function(start_tab,settings) {
2     return new jQuery._pageTabs(start_tab,settings);
3};
4
5jQuery._pageTabs = function(start_tab,settings) {
6     var defaults = {
7          className: 'multi-part',
8          listClassName: 'part-tabs',
9          breakerClassName: 'clear'
10     };
11
12     var index = start_tab ? start_tab : 0;
13
14     this.params = jQuery.extend(defaults,settings);
15     this.divs = jQuery('div.'+this.params.className);
16     this.createList();
17     this.showDiv(index);
18     var pageTabs = this;
19     
20     window.onhashchange = function (event) {
21          pageTabs.showDiv(document.location.hash.split('#').join(''));
22    }
23};
24
25jQuery._pageTabs.prototype = {
26     items: new Array(),
27
28     createList: function() {
29          if (this.divs.length <= 0) {
30               return;
31          }
32
33          this.block = document.createElement('div');
34          this.block.className = this.params.listClassName;
35          this.list = document.createElement('ul');
36          //this.list.className = this.params.listClassName;
37          this.block.appendChild(this.list);
38          var li, a;
39
40          var This = this;
41          var i=0;
42          jQuery('.'+this.params.className).each(function() {
43               if (this.tagName == "DIV") {
44                    li = document.createElement('li');
45                    a = document.createElement('a');
46                    $(a).html(this.title);
47                    this.title = '';
48                    a.fn = This.showDiv;
49                    a.index = this.id || i;
50                    a.href = '#'+a.index;
51                    li.id = "part-tabs-"+a.index;
52                    a.obj = This;
53                    li.appendChild(a);
54                    This.list.appendChild(li);
55                    This.items[i] = li;
56                    i++;
57               } else {
58                    li = document.createElement('li');
59                    li.className = This.params.listClassName+'-link';
60                    li.appendChild(this);
61                    This.list.appendChild(li);
62               }
63          });
64
65          this.breaker = document.createElement('br');
66          this.breaker.className = this.params.breakerClassName;
67
68          jQuery(this.divs.get(0)).before(this.block);
69          jQuery(this.block).after(this.breaker);
70     },
71
72     showDiv: function(index) {
73          var This = this;
74          var i = 0;
75          var to_trigger = null;
76
77          this.divs.each(function() {
78               if ((this.id != '' && this.id == index) || i == index) {
79                    jQuery(this).show(0);
80                    This.items[i].className = This.params.listClassName+'-active';
81                    to_trigger = i;
82               } else {
83                    jQuery(this).hide(0);
84                    This.items[i].className = '';
85               }
86
87               i++;
88          });
89
90          if (to_trigger != null) {
91               jQuery(this.divs[to_trigger]).onetabload();
92               jQuery(this.divs[to_trigger]).tabload();
93          }
94     }
95};
96
97jQuery.fn.tabload = function(f) {
98     this.each(function() {
99          if (f) {
100               chainHandler(this,'tabload',f)
101          } else {
102               var h = this.tabload;
103               if (h) { h.apply(this); }
104          }
105     });
106     return this;
107};
108jQuery.fn.onetabload = function(f) {
109     this.each(function() {
110          if (f) {
111               chainHandler(this,'onetabload',f);
112          } else {
113               var h = this.onetabload;
114               if (h != null) {
115                    h.apply(this);
116                    this.onetabload = null;
117               }
118          }
119     });
120     return this;
121};
Note: See TracBrowser for help on using the repository browser.

Sites map