Dotclear

source: admin/js/jquery/jquery.pageTabs.js @ 1737:8c9305c14ab4

Revision 1737:8c9305c14ab4, 2.8 KB checked in by kevin@…, 12 years ago (diff)

Ticket #1452 : Les ancres n'afficher pas le bonne onglet au chargement
+ des tests unitaire pour pageTabs.js

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

Sites map