|
90 | 90 | * @deprecated will be replaced with a more robust implementation |
91 | 91 | */ |
92 | 92 |
|
93 | | - var w; |
| 93 | + var |
| 94 | + /** |
| 95 | + * @type {Boolean} |
| 96 | + * |
| 97 | + * Mutex to control horizontal animation |
| 98 | + * Disables clicking of tabs while animating |
| 99 | + * They mess up otherwise as currentPane gets set *after* animation is done |
| 100 | + */ |
| 101 | + animating, |
| 102 | + /** |
| 103 | + * @type {Number} |
| 104 | + * |
| 105 | + * Initial width of tab panes |
| 106 | + */ |
| 107 | + w; |
94 | 108 |
|
95 | 109 | $.tools.tabs.addEffect("horizontal", function(i, done) { |
| 110 | + if (animating) return; // don't allow other animations |
96 | 111 |
|
| 112 | + var nextPane = this.getPanes().eq(i), |
| 113 | + currentPane = this.getCurrentPane(); |
| 114 | + |
97 | 115 | // store original width of a pane into memory |
98 | 116 | w || ( w = this.getPanes().eq(0).width() ); |
| 117 | + animating = true; |
99 | 118 |
|
100 | | - // set current pane's width to zero |
101 | | - this.getCurrentPane().animate({width: 0}, function(){ |
102 | | - $(this).hide(); |
103 | | - }); |
| 119 | + nextPane.show(); // hidden by default |
104 | 120 |
|
105 | | - // grow opened pane to it's original width |
106 | | - this.getPanes().eq(i).animate({width: w}, function() { |
107 | | - $(this).show(); |
108 | | - done.call(); |
| 121 | + // animate current pane's width to zero |
| 122 | + // animate next pane's width at the same time for smooth animation |
| 123 | + currentPane.animate({width: 0}, { |
| 124 | + step: function(now){ |
| 125 | + nextPane.css("width", w-now); |
| 126 | + }, |
| 127 | + complete: function(){ |
| 128 | + $(this).hide(); |
| 129 | + done.call(); |
| 130 | + animating = false; |
| 131 | + } |
109 | 132 | }); |
110 | | - |
| 133 | + // Dirty hack... onLoad, currentPant will be empty and nextPane will be the first pane |
| 134 | + // If this is the case, manually run callback since the animation never occured, and reset animating |
| 135 | + if (!currentPane.length){ |
| 136 | + done.call(); |
| 137 | + animating = false; |
| 138 | + } |
111 | 139 | }); |
112 | 140 |
|
113 | 141 |
|
|
130 | 158 | $.extend(this, { |
131 | 159 | click: function(i, e) { |
132 | 160 |
|
133 | | - var tab = tabs.eq(i); |
| 161 | + var tab = tabs.eq(i); |
134 | 162 |
|
135 | 163 | if (typeof i == 'string' && i.replace("#", "")) { |
136 | 164 | tab = tabs.filter("[href*=" + i.replace("#", "") + "]"); |
|
160 | 188 |
|
161 | 189 | // call the effect |
162 | 190 | effects[conf.effect].call(self, i, function() { |
163 | | - |
| 191 | + current = i; |
164 | 192 | // onClick callback |
165 | 193 | e.type = "onClick"; |
166 | | - trigger.trigger(e, [i]); |
167 | | - current = i; |
| 194 | + trigger.trigger(e, [i]); |
168 | 195 | }); |
169 | 196 |
|
170 | 197 | // default behaviour |
|
0 commit comments