Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LazyLoad only visible cells #430

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 35 additions & 20 deletions dist/flickity.pkgd.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@

/**
* Bridget makes jQuery widgets
* v2.0.0
* v2.0.1
* MIT license
*/

/* jshint browser: true, strict: true, undef: true, unused: true */

( function( window, factory ) {
'use strict';
/* globals define: false, module: false, require: false */

// universal module definition
/*jshint strict: false */ /* globals define, module, require */
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'jquery-bridget/jquery-bridget',[ 'jquery' ], function( jQuery ) {
factory( window, jQuery );
return factory( window, jQuery );
});
} else if ( typeof module == 'object' && module.exports ) {
// CommonJS
Expand Down Expand Up @@ -1228,6 +1227,13 @@ function Flickity( element, options ) {
return;
}
this.element = queryElement;
// do not initialize twice on same element
if ( this.element.flickityGUID ) {
var instance = instances[ this.element.flickityGUID ];
instance.option( options );
return instance;
}

// add jQuery
if ( jQuery ) {
this.$element = jQuery( this.element );
Expand Down Expand Up @@ -1844,7 +1850,9 @@ proto.getAdjacentCellElements = function( adjCount, index ) {
}

var cellElems = [];
for ( var i = index - adjCount; i <= index + adjCount ; i++ ) {
var min = this.options.cellAlign === 'left' ? index : index - adjCount;
var max = this.options.cellAlign === 'right' ? index : index + adjCount;
for ( var i = min; i <= max ; i++ ) {
var slideIndex = this.options.wrapAround ? utils.modulo( i, len ) : i;
var slide = this.slides[ slideIndex ];
if ( slide ) {
Expand Down Expand Up @@ -4045,7 +4053,7 @@ return Flickity;
});

/*!
* Flickity asNavFor v2.0.0
* Flickity asNavFor v2.0.1
* enable asNavFor for Flickity
*/

Expand All @@ -4059,26 +4067,22 @@ return Flickity;
define( 'flickity-as-nav-for/as-nav-for',[
'flickity/js/index',
'fizzy-ui-utils/utils'
], function( classie, Flickity, utils ) {
return factory( window, classie, Flickity, utils );
});
], factory );
} else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory(
window,
require('flickity'),
require('fizzy-ui-utils')
);
} else {
// browser global
window.Flickity = factory(
window,
window.Flickity,
window.fizzyUIUtils
);
}

}( window, function factory( window, Flickity, utils ) {
}( window, function factory( Flickity, utils ) {



Expand Down Expand Up @@ -4124,35 +4128,46 @@ proto.setNavCompanion = function( elem ) {
// click
this.on( 'staticClick', this.onNavStaticClick );

this.navCompanionSelect();
this.navCompanionSelect( true );
};

proto.navCompanionSelect = function() {
proto.navCompanionSelect = function( isInstant ) {
if ( !this.navCompanion ) {
return;
}
// select slide that matches first cell of slide
var selectedCell = this.navCompanion.selectedCells[0];
var cellIndex = this.navCompanion.cells.indexOf( selectedCell );
this.selectCell( cellIndex );
var firstIndex = this.navCompanion.cells.indexOf( selectedCell );
var lastIndex = firstIndex + this.navCompanion.selectedCells.length - 1;
var selectIndex = Math.floor( lerp( firstIndex, lastIndex,
this.navCompanion.cellAlign ) );
this.selectCell( selectIndex, false, isInstant );
// set nav selected class
this.removeNavSelectedElements();
// stop if companion has more cells than this one
if ( cellIndex >= this.cells.length ) {
if ( selectIndex >= this.cells.length ) {
return;
}
this.navSelectedElements = this.slides[ this.selectedIndex ].getCellElements();

var selectedCells = this.cells.slice( firstIndex, lastIndex + 1 );
this.navSelectedElements = selectedCells.map( function( cell ) {
return cell.element;
});
this.changeNavSelectedClass('add');
};

function lerp( a, b, t ) {
return ( b - a ) * t + a;
}

proto.changeNavSelectedClass = function( method ) {
this.navSelectedElements.forEach( function( navElem ) {
navElem.classList[ method ]('is-nav-selected');
});
};

proto.activateAsNavFor = function() {
this.navCompanionSelect();
this.navCompanionSelect( true );
};

proto.removeNavSelectedElements = function() {
Expand Down
Loading