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

Keep element structure if it is already in the correct structure. #707

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
29 changes: 19 additions & 10 deletions dist/flickity.pkgd.js
Original file line number Diff line number Diff line change
Expand Up @@ -1296,9 +1296,13 @@ proto._create = function() {
this.x = 0;
this.velocity = 0;
this.originSide = this.options.rightToLeft ? 'right' : 'left';
// create viewport & slider
this.viewport = document.createElement('div');
this.viewport.className = 'flickity-viewport';

this.viewport = this.element.querySelector('.flickity-viewport');
if (!this.viewport) {
// create viewport & slider
this.viewport = document.createElement('div');
this.viewport.className = 'flickity-viewport';
}
this._createSlider();

if ( this.options.resize || this.options.watchCSS ) {
Expand Down Expand Up @@ -1336,11 +1340,13 @@ proto.activate = function() {
}

this.getSize();
// move initial cell elements so they can be loaded as cells
var cellElems = this._filterFindCellElements( this.element.children );
moveElements( cellElems, this.slider );
this.viewport.appendChild( this.slider );
this.element.appendChild( this.viewport );
if (!this.slider.childElementCount) {
// move initial cell elements so they can be loaded as cells
var cellElems = this._filterFindCellElements( this.element.children );
moveElements( cellElems, this.slider );
this.viewport.appendChild( this.slider );
this.element.appendChild( this.viewport );
}
// get cells from children
this.reloadCells();

Expand Down Expand Up @@ -1371,8 +1377,11 @@ proto.activate = function() {
// slider positions the cells
proto._createSlider = function() {
// slider element does all the positioning
var slider = document.createElement('div');
slider.className = 'flickity-slider';
var slider = this.viewport.querySelector('.flickity-slider');
if (!slider) {
slider = document.createElement('div');
slider.className = 'flickity-slider';
}
slider.style[ this.originSide ] = 0;
this.slider = slider;
};
Expand Down
Loading