Skip to content
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
45 changes: 33 additions & 12 deletions js/flickity.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ Flickity.defaults = {
selectedAttraction: 0.025,
setGallerySize: true
// watchCSS: false,
// wrapAround: false
// wrapAround: false,
// noDomMod: false
};

// hash of methods triggered on _create()
Expand All @@ -131,8 +132,16 @@ proto._create = function() {
this.velocity = 0;
this.originSide = this.options.rightToLeft ? 'right' : 'left';
// create viewport & slider
this.viewport = document.createElement('div');
this.viewport.className = 'flickity-viewport';
if (this.options.noDomMod) {
this.viewport = this.element.querySelector('.flickity-viewport');
if ( !this.viewport && console ) {
console.error( 'Could not find ".flickity-viewport"' );
return;
}
} else {
this.viewport = document.createElement('div');
this.viewport.className = 'flickity-viewport';
}
this._createSlider();

if ( this.options.resize || this.options.watchCSS ) {
Expand Down Expand Up @@ -178,9 +187,11 @@ 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.options.noDomMod) {
moveElements( cellElems, this.slider );
this.viewport.appendChild( this.slider );
this.element.appendChild( this.viewport );
}
// get cells from children
this.reloadCells();

Expand Down Expand Up @@ -213,10 +224,17 @@ 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';
slider.style[ this.originSide ] = 0;
this.slider = slider;
if (this.options.noDomMod) {
this.slider = this.element.querySelector('.flickity-slider');
if ( !this.slider && console ) {
console.error( 'Could not find ".flickity-slider"' );
return;
}
} else {
this.slider = document.createElement('div');
this.slider.className = 'flickity-slider';
}
this.slider.style[ this.originSide ] = 0;
};

proto._filterFindCellElements = function( elems ) {
Expand All @@ -226,6 +244,8 @@ proto._filterFindCellElements = function( elems ) {
// goes through all children
proto.reloadCells = function() {
// collection of item elements
this.afterShiftCells=[];
this.beforeShiftCells=[];
this.cells = this._makeCells( this.slider.children );
this.positionCells();
this._getWrapShiftCells();
Expand Down Expand Up @@ -846,9 +866,10 @@ proto.deactivate = function() {
this.cells.forEach( function( cell ) {
cell.destroy();
});
this.element.removeChild( this.viewport );
this.unselectSelectedSlide();
if (! this.options.noDomMod ) this.element.removeChild( this.viewport );
// move child elements back into element
moveElements( this.slider.children, this.element );
if (! this.options.noDomMod ) moveElements( this.slider.children, this.element );
if ( this.options.accessibility ) {
this.element.removeAttribute('tabIndex');
this.element.removeEventListener( 'keydown', this );
Expand Down
12 changes: 10 additions & 2 deletions js/page-dots.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,16 @@ PageDots.prototype = new TapListener();

PageDots.prototype._create = function() {
// create holder element
this.holder = document.createElement('ol');
this.holder.className = 'flickity-page-dots';
if (this.parent.options.noDomMod) {
this.holder = this.parent.element.querySelector('.flickity-page-dots');
if ( !this.holder && console ) {
console.error( 'Could not find ".flickity-page-dots"' );
return;
}
} else {
this.holder = document.createElement('ol');
this.holder.className = 'flickity-page-dots';
}
// create dots, array of elements
this.dots = [];
// events
Expand Down