|
1 |
| -/* |
2 |
| - * Moving Boxes v2.2.8 |
| 1 | +/* |
| 2 | + * Moving Boxes v2.2.9 |
3 | 3 | * by Chris Coyier
|
4 | 4 | * http://css-tricks.com/moving-boxes/
|
5 | 5 | */
|
|
69 | 69 |
|
70 | 70 | // Activate moving box on click or when an internal link obtains focus
|
71 | 71 | base.$wrap.click(function(){
|
72 |
| - base.active(); |
| 72 | + if (!base.$wrap.hasClass('mb-active-slider')) { |
| 73 | + base.active(); |
| 74 | + } |
73 | 75 | });
|
74 | 76 | base.$panels.delegate('a', 'focus' ,function(e){
|
75 | 77 | e.preventDefault();
|
|
99 | 101 | });
|
100 | 102 |
|
101 | 103 | // Bind Events
|
102 |
| - $.each('initialized initChange beforeAnimation completed'.split(' '), function(i,evt){ |
| 104 | + $.each('preinit initialized initChange beforeAnimation completed'.split(' '), function(i,evt){ |
103 | 105 | if ($.isFunction(o[evt])){
|
104 | 106 | base.$el.bind(evt + '.movingBoxes', o[evt]);
|
105 | 107 | }
|
|
108 | 110 | // Set up "Current" panel
|
109 | 111 | base.curPanel = (o.hashTags) ? base.getHash() || o.startPanel : o.startPanel;
|
110 | 112 |
|
| 113 | + base.$el.trigger( 'preinit.movingBoxes', [ base, base.curPanel ] ); |
| 114 | + |
111 | 115 | // animate to chosen start panel - starting from the first panel makes it look better
|
112 | 116 | setTimeout(function(){
|
113 | 117 | base.change(base.curPanel, function(){
|
|
189 | 193 |
|
190 | 194 | // Creates the numbered navigation links
|
191 | 195 | base.buildNav = function() {
|
192 |
| - if (base.$nav) { base.$nav.remove(); } |
| 196 | + if (base.$nav) { |
| 197 | + base.$nav.find('.mb-links').empty(); |
| 198 | + } else { |
| 199 | + base.$nav = $('<div class="mb-controls"><span class="mb-links"></span></div>').appendTo(base.$wrap); |
| 200 | + } |
193 | 201 | if (o.buildNav && base.totalPanels > 1) {
|
194 |
| - base.$nav = $('<div class="mb-controls"><a class="mb-testing"></a></div>').appendTo(base.$wrap); |
195 |
| - var j, a = '', |
196 |
| - navFormat = $.isFunction(o.navFormatter), |
197 |
| - // need link in place to get CSS properties |
198 |
| - hiddenText = parseInt( base.$nav.find('.mb-testing').css('text-indent'), 10) < 0; |
199 |
| - base.$panels.filter(':not(.cloned)').each(function(i) { |
| 202 | + var t, j, a = '', $a, |
| 203 | + navFormat = $.isFunction(o.navFormatter); |
| 204 | + base.$panels.filter(':not(.cloned)').each(function(i){ |
200 | 205 | j = i + 1;
|
201 |
| - a += '<a href="#" class="mb-panel' + j; |
| 206 | + a = '<a class="mb-link mb-panel' + j + '" href="#"></a>'; |
| 207 | + $a = $(a); |
202 | 208 | // If a formatter function is present, use it
|
203 |
| - if (navFormat) { |
204 |
| - var tmp = o.navFormatter(j, $(this)); |
205 |
| - // Add formatting to title attribute if text is hidden |
206 |
| - a += (hiddenText) ? ' ' + o.tooltipClass +'" title="' + tmp : ''; |
207 |
| - a += '">' + tmp + '</a> '; |
| 209 | + if ($.isFunction(o.navigationFormatter)) { |
| 210 | + t = o.navigationFormatter(i, $(this)); |
| 211 | + if (typeof(t) === "string") { |
| 212 | + $a.html(t); |
| 213 | + } else { |
| 214 | + $a = $('<a/>', t); |
| 215 | + } |
208 | 216 | } else {
|
209 |
| - a += '">' + j + '</a> '; |
| 217 | + $a.html(j); |
210 | 218 | }
|
| 219 | + $a |
| 220 | + .appendTo(base.$nav.find('.mb-links')) |
| 221 | + .addClass('mb-link mb-panel' + j) |
| 222 | + .data('index', j); |
211 | 223 | });
|
212 | 224 | base.$nav
|
213 |
| - .html(a) |
214 |
| - .find('a').bind('click', function() { |
215 |
| - base.change( $(this).index() + 1 ); |
| 225 | + .find('a.mb-link').bind('click', function() { |
| 226 | + base.change( $(this).data('index') ); |
216 | 227 | return false;
|
217 | 228 | });
|
218 | 229 | }
|
|
279 | 290 |
|
280 | 291 | if (base.initialized && flag) {
|
281 | 292 | // make this moving box active
|
282 |
| - base.active(); |
| 293 | + if (!base.$wrap.hasClass('mb-active-slider')) { base.active(); } |
283 | 294 | // initChange event - has extra parameter with targeted panel (not cleaned)
|
284 | 295 | base.$el.trigger( 'initChange.movingBoxes', [ base, curPanel ] );
|
285 | 296 | }
|
|
346 | 357 |
|
347 | 358 | // Update navigation links
|
348 | 359 | if (o.buildNav && base.$nav.length) {
|
349 |
| - base.$nav.find('a') |
| 360 | + base.$nav.find('a.mb-link') |
350 | 361 | .removeClass(o.currentPanel)
|
351 | 362 | .eq(curPanel - 1).addClass(o.currentPanel);
|
352 | 363 | }
|
|
415 | 426 | disabled : 'disabled',// class added to arrows that are disabled (left arrow when on first panel, right arrow on last panel)
|
416 | 427 |
|
417 | 428 | // Callbacks
|
418 |
| - initialized : null, // callback when MovingBoxes has completed initialization |
419 |
| - initChange : null, // callback upon change panel initialization |
| 429 | + preinit : null, // callback after the basic MovingBoxes structure has been built; before "initialized" |
| 430 | + initialized : null, // callback when MovingBoxes has completed initialization; all images loaded |
| 431 | + initChange : null, // callback upon change panel change initialization |
420 | 432 | beforeAnimation : null, // callback before any animation occurs
|
421 | 433 | completed : null // callback after animation completes
|
422 | 434 | };
|
|
0 commit comments