|
1 | 1 | /** |
2 | | - * Isotope v1.4.110906 |
| 2 | + * Isotope v1.5.0 beta |
3 | 3 | * An exquisite jQuery plugin for magical layouts |
4 | 4 | * http://isotope.metafizzy.co |
5 | 5 | * |
|
45 | 45 | } |
46 | 46 | } |
47 | 47 |
|
48 | | - var transformProp = getStyleProperty('transform'); |
| 48 | + var transformProp = getStyleProperty('transform'), |
| 49 | + transitionProp = getStyleProperty('transitionProperty'); |
| 50 | + |
49 | 51 |
|
50 | 52 | // ========================= miniModernizr =============================== |
51 | 53 | // <3<3<3 and thanks to Faruk and Paul for doing the heavy lifting |
|
92 | 94 | }, |
93 | 95 |
|
94 | 96 | csstransitions: function() { |
95 | | - return !!getStyleProperty('transitionProperty'); |
| 97 | + return !!transitionProp; |
96 | 98 | } |
97 | 99 | }; |
98 | 100 |
|
|
247 | 249 | }; |
248 | 250 |
|
249 | 251 | } |
| 252 | + |
| 253 | + // ========================= get transition-end event =============================== |
| 254 | + |
| 255 | + if ( Modernizr.csstransitions ) { |
| 256 | + var transitionEndEvent = { |
| 257 | + WebkitTransitionProperty: 'webkitTransitionEnd', // webkit |
| 258 | + MozTransitionProperty: 'transitionend', |
| 259 | + OTransitionProperty: 'oTransitionEnd', |
| 260 | + transitionProperty: 'transitionEnd' |
| 261 | + }[ transitionProp ]; |
| 262 | + var transitionDurProp = getStyleProperty('transitionDuration'); |
| 263 | + } |
250 | 264 |
|
251 | | - |
| 265 | + // ========================= smartresize =============================== |
252 | 266 |
|
253 | 267 | /* |
254 | 268 | * smartresize: debounced resize event for jQuery |
|
295 | 309 |
|
296 | 310 |
|
297 | 311 | // our "Widget" object constructor |
298 | | - $.Isotope = function( options, element ){ |
| 312 | + $.Isotope = function( options, element, callback ){ |
299 | 313 | this.element = $( element ); |
300 | 314 |
|
301 | 315 | this._create( options ); |
302 | | - this._init(); |
| 316 | + this._init( callback ); |
303 | 317 | }; |
304 | 318 |
|
305 | 319 | // styles of container element we want to keep track of |
|
423 | 437 |
|
424 | 438 | this.$filteredAtoms = this._filter( this.$allAtoms ); |
425 | 439 | this._sort(); |
426 | | - |
427 | 440 | this.reLayout( callback ); |
428 | 441 |
|
429 | 442 | }, |
|
588 | 601 | this.styleQueue.push({ $el: this.element, style: containerStyle }); |
589 | 602 | } |
590 | 603 |
|
591 | | - this._processStyleQueue(); |
592 | | - |
593 | | - // provide $elems as context for the callback |
594 | | - if ( callback ) { |
595 | | - callback.call( $elems ); |
596 | | - } |
| 604 | + this._processStyleQueue( $elems, callback ); |
597 | 605 |
|
598 | 606 | this.isLaidOut = true; |
599 | 607 | }, |
600 | 608 |
|
601 | | - _processStyleQueue : function() { |
| 609 | + _processStyleQueue : function( $elems, callback ) { |
602 | 610 | // are we animating the layout arrangement? |
603 | 611 | // use plugin-ish syntax for css or animate |
604 | 612 | var styleFn = !this.isLaidOut ? 'css' : ( |
605 | 613 | this.isUsingJQueryAnimation ? 'animate' : 'css' |
606 | 614 | ), |
607 | 615 | animOpts = this.options.animationOptions, |
608 | 616 | _isInsertingAnimated = this._isInserting && this.isUsingJQueryAnimation, |
609 | | - objStyleFn; |
610 | | - |
| 617 | + objStyleFn, processor, |
| 618 | + triggerCallbackNow, callbackFn; |
| 619 | + |
| 620 | + // default styleQueue processor, may be overwritten down below |
| 621 | + processor = function( i, obj ) { |
| 622 | + obj.$el[ styleFn ]( obj.style, animOpts ); |
| 623 | + }; |
| 624 | + |
| 625 | + if ( this._isInserting || !callback ) { |
| 626 | + // process styleQueue |
| 627 | + processor = function( i, obj ) { |
| 628 | + // only animate if it not being inserted |
| 629 | + objStyleFn = _isInsertingAnimated && obj.$el.hasClass('no-transition') ? 'css' : styleFn; |
| 630 | + obj.$el[ objStyleFn ]( obj.style, animOpts ); |
| 631 | + }; |
| 632 | + |
| 633 | + } else { |
| 634 | + var isCallbackTriggered = false; |
| 635 | + callbackFn = function() { |
| 636 | + // trigger callback only once |
| 637 | + if ( isCallbackTriggered ) { |
| 638 | + return; |
| 639 | + } |
| 640 | + callback( $elems ); |
| 641 | + isCallbackTriggered = true; |
| 642 | + }; |
| 643 | + |
| 644 | + if ( this.isUsingJQueryAnimation ) { |
| 645 | + // add callback to animation options |
| 646 | + animOpts.complete = callbackFn; |
| 647 | + } else if ( Modernizr.csstransitions ) { |
| 648 | + // detect if first item has transition |
| 649 | + var i = 0, |
| 650 | + testElem = this.styleQueue[0].$el; |
| 651 | + // get first non-empty jQ object |
| 652 | + // console.log( this.styleQueue ) |
| 653 | + if ( !testElem.length ) { |
| 654 | + return; |
| 655 | + } |
| 656 | + // get transition duration of the first element in that object |
| 657 | + // yeah, this is inexact |
| 658 | + var duration = parseFloat( getComputedStyle( testElem[0] )[ transitionDurProp ] ); |
| 659 | + if ( duration > 0 ) { |
| 660 | + processor = function( i, obj ) { |
| 661 | + obj.$el[ styleFn ]( obj.style, animOpts ) |
| 662 | + // trigger callback at transition end |
| 663 | + .one( transitionEndEvent, callbackFn ); |
| 664 | + } |
| 665 | + } else { |
| 666 | + // no transition? hit it now, son |
| 667 | + triggerCallbackNow = true; |
| 668 | + } |
| 669 | + } |
| 670 | + } |
| 671 | + |
611 | 672 | // process styleQueue |
612 | | - $.each( this.styleQueue, function( i, obj ) { |
613 | | - objStyleFn = _isInsertingAnimated && obj.$el.hasClass('no-transition') ? 'css' : styleFn; |
614 | | - obj.$el[ objStyleFn ]( obj.style, animOpts ); |
615 | | - }); |
| 673 | + $.each( this.styleQueue, processor ); |
| 674 | + |
| 675 | + if ( triggerCallbackNow ) { |
| 676 | + callbackFn() |
| 677 | + } |
616 | 678 |
|
617 | 679 | // clear out queue for next time |
618 | 680 | this.styleQueue = []; |
|
695 | 757 | $newAtoms.removeClass('no-transition'); |
696 | 758 | // reveal newly inserted filtered elements |
697 | 759 | instance.styleQueue.push({ $el: $newAtoms, style: instance.options.visibleStyle }); |
698 | | - instance._processStyleQueue(); |
699 | | - delete instance._isInserting; |
700 | | - if ( callback ) { |
701 | | - callback( $newAtoms ); |
702 | | - } |
| 760 | + instance._isInserting = false; |
| 761 | + instance._processStyleQueue( $newAtoms, callback ); |
703 | 762 | }, 10 ); |
704 | 763 | }, |
705 | 764 |
|
|
1246 | 1305 | // A bit from jcarousel |
1247 | 1306 | // https://github.com/jsor/jcarousel/blob/master/lib/jquery.jcarousel.js |
1248 | 1307 |
|
1249 | | - $.fn.isotope = function( options ) { |
| 1308 | + $.fn.isotope = function( options, callback ) { |
1250 | 1309 | if ( typeof options === 'string' ) { |
1251 | 1310 | // call method |
1252 | 1311 | var args = Array.prototype.slice.call( arguments, 1 ); |
|
1271 | 1330 | if ( instance ) { |
1272 | 1331 | // apply options & init |
1273 | 1332 | instance.option( options ); |
1274 | | - instance._init(); |
| 1333 | + instance._init( callback ); |
1275 | 1334 | } else { |
1276 | 1335 | // initialize new instance |
1277 | | - $.data( this, 'isotope', new $.Isotope( options, this ) ); |
| 1336 | + $.data( this, 'isotope', new $.Isotope( options, this, callback ) ); |
1278 | 1337 | } |
1279 | 1338 | }); |
1280 | 1339 | } |
|
0 commit comments